Hello , How to get S&P500 all stock daily weight by eikon with python API ? thank you.

Hello , How to get S&P500 all stock historical daily data and weight by eikon with python API ? thank you.

Best Answer

  • chavalit-jintamalit
    Answer ✓

    Hi @ethan.hayashi

    You can follow this code to get S&P500 RIC list and get historical data:

    (Because the get_timeseries accept up to 300 RIC so I have to split the list into 2 lists before calling the API)

    image

    As for weight, I do not understand the content you are trying to retrieve, please clarify or show me the sample data on the Eikon Desktop. I will try to see if it is accessible from API and will share the result.

    Thanks.

Answers

  • I would like to share some idea to calculate weight.

    1. Get all constituents

    2. Get individual market cap

    3. Sum market cap

    4. calculate weight for each individual stocks against total market cap.

    This is example code:

    image

  • Hi @chavalit.jintamalit,

    Thank you for your share .

    One more question.

    How can I add "date" everyday data , Thank you.

    [Instrument] [DSPLY_NAME] [DATE] [Company Market Cap] [Weight]

    ========================================================

    MSFT.OQ MICROSOFT CP/d 2019-08-29 1.0546e+12 3.946080310382849

  • You can add TR.CompanyMarketCap.Date field.

    df,e = ek.get_data('0#.SPX',['DSPLY_NAME','TR.CompanyMarketCap','TR.CompanyMarketCap.Date'])
    df
  • Hi Chavalit

    Thank you so much.

  • Hi Chavalit,

    Sorry , I need you help again.

    I would like get some date , eg. 2019/5/1

    How can I use it.

    df,e = ek.get_data('0#.SPX',['DSPLY_NAME','TR.CompanyMarketCap','TR.CompanyMarketCap.Date'])
    df

    like this ?? thank you.

    df,e = ek.get_data('0#.SPX',['DSPLY_NAME','TR.CompanyMarketCap','TR.CompanyMarketCap.Date'],parameters={'SDate':'2019-05-01','EDate':'2019-05-01'})
    df