Extracting multiple historic relative valuation ratios via Eikon API (python)

Hi,

I'm hoping someone may be able to help me with the following issue. I'm new to python so this may seem like a novice request. Apologies in advance.

I wish to extract relative valuation data (P/E, P/B, P/S, EV/EBITDA - all TTM) on all S&P500 constituent stocks for the period 2006-2021 into a table on python. What is the cleanest way to code this? I have tried manually including each RIC & also (unsuccessfully) manipulating the 'peers' function.

I'm aware there will be leavers and joiners included in the dataset but that does not pose an issue to the research I then plan to complete on the dataset.

I've read numerous other threads that pose a similar question but I haven't been able to successfully alter their code to achieve my goal. I can share my code thus far if it helps.

Thank you!

Best Answer

  • Hi @student.02 ,


    Please use the Data Item Browser to find the fields you're after

    1657525341876.png


    1657525362050.png


    import refinitiv.data as rd
    rd.open_session()
    df1 = rd.get_history(
    universe=["0#.SPX"],
    fields=["TR.PE"],
    interval="1D",
    start="2021-10-01",
    end="2021-10-03",
    )
    display(df1)
    rd.close_session()




Answers


  • import refinitiv.data as rd
    rd.open_session()
    df1 = rd.get_history(
       universe=["0#.SPX"],
       fields=["TR.PE"],
       interval="1D",
       start="2021-10-01",
       end="2021-10-03",
    )
    display(df1)
    rd.close_session()



    1657525827966.png



  • Hi @student.02 ,

    Please let me add more information regarding the RD library that was mentioned by my colleague above, feel free to check the resources below those are related to the RD library

    I hope this helps. However, you don't need to apologize for the question as we are happy to assist you regarding API usage.

  • Hi jonathan.legrand and raksina.samasiri,

    Great, thank you!

    Is it then possible to re-write this code to extract the monthly returns for numerous ETFs for a given period? I have coded it in the following format, but my output is not as I would have expected; it appears as if the fund identifier codes I am using in this example (LP40119861, LP40119862, LP40039184) are not recognised.


    image.png


    Thanks!

  • Hi @student.02, Please use the Data Item Browser to find the fields you're after; you might be after revenues more than returns, but they are only released along with financial statements, and they look like they're released every quarter only. You may want to interpolate monthly data in a technique such as the one outlined here: Using the Holt Winters Model to Interpolate GDP Values. You can use the comments section on YouTube if you have any questions.