Trying to use get_data() to download a series of total returns (TR.TotalReturn)

I am trying to use get_data() to download total return time-series for a selection of RICs. This works fine in excel with the following formula

=TR($E$9:$E$13;"TR.TotalReturn";"Frq=D SDate=2008-01-01 EDate=2018-01-01 CH=IN RH=date";H10)

This gives me a table with dates in the first column and with total return series in the other column, one column per RIC.

However, when I use the formula in Python using the same parameters as in the excel function call, I get a completely different output.

ek.get_data(rics, fields=ek.TR_Field("TR.TotalReturn"), parameters=
{"Frq": "D", "SDate": "2008-01-01", "EDate": "2018-01-01", "CH": "IN", "RH": "date"})

1. Why is this? Can I not replicate the excel output (which I built myself using the Layout button in the Excel Eikon Add-In)

2. Where can I find a description and a list of all possible parameters about the 'parameters' field of the method get_data()?

Thanks for any help!

Best Answer

  • It is not as simple, I am afraid, but the result is returned in a data frame format, that you can change to meet your goals. For instance, we can change your request into this:

    df, e = tr.get_data(['AAPL.O', 'TRI.N'], ["TR.TotalReturn.date","TR.TotalReturn.value"], parameters={"Frq": "D", "SDate": "2008-01-01", "EDate": "2018-01-01"})

    So, after you got your results into your data frame, you can create a pivot table:

    pt = df.pivot_table(values='value', index=['Date', 'Instrument']).unstack('Instrument')

    After that, your date index should be recognised as a date:

    import pandas as pd
    pt.index = pd.to_datetime(pt.index)
    pt.reindex()

    That's it:

    image

    To your second question, you can use the Data Item Browser app (DIB) on Eikon, select a field and then choose the parameters tab:

    image

Answers

  • Thank you Zhenya. Your answer to my first question helps, I will try this approach.
    My second question wasn't about the Eikon Excel AddIn. It was about how to use all parameters, which you can also set in the Eikon Excel AddIn, in the get_data(parameters) function. I can't find a description for it.

  • @dominique.brandl
    Please refer to this tutorial, which talks at length about translating Eikon Excel syntax to get_data call and using Data Item Browser app for metadata discovery (field names and parameters) to use in get_data method.