Upgrade from Eikon -> Workspace. Learn about programming differences.

For a deeper look into our Eikon Data API, look into:

Overview |  Quickstart |  Documentation |  Downloads |  Tutorials |  Articles

question

Upvotes
Accepted
98 27 33 35

Python: Can I call a TR Formula inside the function get_timeseries?

Hello guys,

I'm trying to get TR.TotalReturn using Eikon Scripting API for Python, but I'd like to minimize the amount of calls I do to the API. So far, using a list of the identifiers helps minimizing the amount of calls. On the other hand, I want daily returns for a given range of dates. And I believe the only function can provide that kind of thing is get_timeseries.

Is it possible to use TR.TotalReturn combined with get_timeseries to acquire returns (or any other TR formula) into a timeseries? I readed the manual, and it doesn't seem to be a way https://developers.thomsonreuters.com/tr-eikon-scripting-apis/python-thin-library-pyeikon#get_timeseries

Do you know if there's any chance of doing it this way?

Thanks for your time!

eikoneikon-data-apipythonrefinitiv-dataplatform-eikonworkspaceworkspace-data-api
icon clock
10 |1500

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

1 Answer

· Write an Answer
Upvote
Accepted
78.8k 250 52 74

I am afraid not.

get_timeseries support the following fields: 'TIMESTAMP', 'VALUE', 'VOLUME', 'HIGH', 'LOW', 'OPEN', 'CLOSE', 'COUNT'.

However, you can use Build Formula in Eikon Excel to create a formula to retrieve TR.TotalReturn and then apply it to get_data function.

For example:

df = ek.get_data(["AAPL.O", "IBM.N"], 
                 ["TR.TotalReturn.Date","TR.TotalReturn",],
                 {"SDate":"2017-10-23","EDate":"2017-11-29","Frq":"D","CH":"Fd", "RH":"IN"});

It returns:

(   Instrument                  Date  Total Return
 0      AAPL.O  2017-11-29T00:00:00Z     -2.074305
 1      AAPL.O  2017-11-28T00:00:00Z     -0.585904
 2      AAPL.O  2017-11-27T00:00:00Z     -0.502943
 3      AAPL.O  2017-11-24T00:00:00Z      0.005716
 4      AAPL.O  2017-11-22T00:00:00Z      1.051172
 5      AAPL.O  2017-11-21T00:00:00Z      1.859042
 6      AAPL.O  2017-11-20T00:00:00Z     -0.099912
 7      AAPL.O  2017-11-17T00:00:00Z     -0.555231
...
icon clock
10 |1500

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

Thanks a lot for your valuable help.

Is there a way to make the dates appear as column headers and place the corresponding returns in them?

It can return JSON instead of data frame by setting raw_output parameter to True.

df = ek.get_data(["AAPL.O"], ["TR.Close.Date","TR.CLose",],{"SDate":"2015-08-01","EventType":"ALL", "EDate":"2017-11-20","CH":"Fd","RH":"IN"}, raw_output=True);

The output is:

{'columnHeadersCount': 1,
 'data': [['AAPL.O', '2015-08-03T00:00:00Z', 118.44],
...
  ['AAPL.O', '2017-11-20T00:00:00Z', 169.98]],
 'headerOrientation': 'horizontal',
 'headers': [[{'displayName': 'Instrument'},
   {'displayName': 'Date', 'field': 'TR.CLOSE.DATE'},
   {'displayName': 'Price Close', 'field': 'TR.CLOSE'}]],
...
}

Write an Answer

Hint: Notify or tag a user in this post by typing @username.

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.