Get data with a variety of start and end dates

I'm trying to download post-earnings return data for a list of stocks.

For example, let's say AAPL, BA, C report on 1/1, 2/1, and 3/1 and I want returns over the 7 days after they report. How should I get the lists of start and end dates into this code?

returns = ek.get_data(instruments = ['AAPL.O', 'BA.N', 'C.N'], fields = ['TR.TotalReturn'], parameters= {'Sdate': ???, 'EDate': ???})

Best Answer

  • Hi @jsinegal

    You can have parameter in field level (applies to all RIC):

    image


    Or you can have parameter in request level (applies to all fields and all RIC)

    Note that you can only have 1 set of start/end date:

    image

Answers

  • Hi @jsinegal

    Here is an example:

    df,e = ek.get_data(['AAPL.O', 'BA.N', 'C.N'],
                       ['TR.TotalReturn(SDate=2020-02-03,EDate=2020-02-07,Frq=D).Date',
                       'TR.TotalReturn(SDate=2020-02-03,EDate=2020-02-07,Frq=D)',
                       'TR.TotalReturn(SDate=2020-01-01,EDate=2020-01-07,Frq=D).Date',
                       'TR.TotalReturn(SDate=2020-01-01,EDate=2020-01-07,Frq=D)'])
    df

    image


    Alternatively, you can seperate them into multiple API calls

  • chavalit.jintamalit for a larger amount of data (let's say all the stocks in the S&P 500), is there a way to pass in a list of associated dates? I can get it to accept instruments = list_of_stocks, but not 'Sdate': list_of_dates




  • Hi @jsinegal

    Is this what you are looking for?

    image

  • chavalit-jintamalit in that case, every stock in SPX is going to have a different earnings date. I have for instance: stocks = [AAPL, BA, C...] sdates = [2/1/2016, 2/17/2016, 2/21/2016...] edates = [2/8/2016, 2/24/2016, 2/28/2016...] and would like to get a list of returns as output without inputting each set of dates individually.

  • jsinegal
    jsinegal Newcomer

    Thank you. It seems there is unfortunately not a good way to call for one date per company. I appreciate the help!