How do I time restrict a get_data request and execute it for multiple stocks?

For the following code, what changes do I need to make so that: a) the request is for a list of c.400 stocks that I have created in Eikon b) the request pulls data for the time period today to 1 year previous on a trailing basis (i.e. if I repeat the request in one week the period will have shifted one week forward) Thanks df, e = ek.get_data(['AEFS.L'], [ 'TR.RNSFilerName', 'TR.RNSAnnouncedDate', 'TR.RNSTransactionType', 'TR.RNSARNumShrsTransacted', 'TR.RNSARPctOSTransacted', 'TR.RNSARTransactionPrice', 'TR.RNSARMktValTransaction', 'TR.RNSARTotShrsPostTrans', 'TR.RNSARPctOSPostTrans' ]) df.head()

Best Answer

  • a) the request is for a list of c.400 stocks that I have created in Eikon

    You can use lists() in get_data

    1. Open Screener app

    2. Click Edit on List

    3. Click "Launch Data Item Library" icon

    4. Look at your List/Portfolio code field

    image

    I will use "test-port" for my example.

    df,e = ek.get_data("lists('test-port')","TR.RIC")
    ric_list = df['Instrument'].tolist()
    ric_list #print out list to see what are inside this list.
    #ek.get_data(['AEFS.L'],   <<<<<
    #ek.get_data(ric_list,     <<<<< replace RIC List


    b) the request pulls data for the time period today to 1 year

    Refer to sample on https://stackoverflow.com/questions/29370057/select-dataframe-rows-between-two-dates

    Here is the sample code:

    df, e = ek.get_data(['AEFS.L'],
                        ['TR.RNSFilerName',
                         'TR.RNSAnnouncedDate',
                         'TR.RNSTransactionType',
                         'TR.RNSARNumShrsTransacted',
                         'TR.RNSARPctOSTransacted',
                         'TR.RNSARTransactionPrice',
                         'TR.RNSARMktValTransaction',
                         'TR.RNSARTotShrsPostTrans',
                         'TR.RNSARPctOSPostTrans'])
    start_date = '2019-01-31'
    end_date = '2020-01-31'
    df['RNS Announced Date'] = pd.to_datetime(df['RNS Announced Date'])
    mask = (df['RNS Announced Date'] > start_date) & (df['RNS Announced Date'] <= end_date)
    df = df.loc[mask]
    df

    Here is sample output:

    image

Answers

  • df, e = ek.get_data(['AEFS.L'], [ 'TR.RNSFilerName', 'TR.RNSAnnouncedDate', 'TR.RNSTransactionType', 'TR.RNSARNumShrsTransacted', 'TR.RNSARPctOSTransacted', 'TR.RNSARTransactionPrice', 'TR.RNSARMktValTransaction', 'TR.RNSARTotShrsPostTrans', 'TR.RNSARPctOSPostTrans' ]) df.head()

    1. df, e = ek.get_data(['AEFS.L'],
    2. [
    3. 'TR.RNSFilerName',
    4. 'TR.RNSAnnouncedDate',
    5. 'TR.RNSTransactionType',
    6. 'TR.RNSARNumShrsTransacted',
    7. 'TR.RNSARPctOSTransacted',
    8. 'TR.RNSARTransactionPrice',
    9. 'TR.RNSARMktValTransaction',
    10. 'TR.RNSARTotShrsPostTrans',
    11. 'TR.RNSARPctOSPostTrans'
    12. ])
    13. df.head()