Python: How to get just the number out of a TR.Formula using Eikon API?

Hello everyone, I have the following short code in which I acquire local returns:

import eikon as ek #import Eikon module
ek.set_app_id('someID') #setting AppID
df = ek.get_data('B1FJ0C0','TR.TotalReturn', {'SDate': '2017-02-03'})

print(df)
print (df[0])

The outcome goes as follows:

image

What I desire is to acquire just the numeric value of the return, I don't want to know about the instrument or any other field/value, just the value of the Total Return.

Does anybody know how? I'd be happy to know.

Thanks!

Best Answer

  • aquilesjlp300,

    To acquire just the numeric value of the return, you can do this:

    image

    First thing to note is that the call to get_data() returns a tuple containing the dataframe and error (if any).

Answers

  • Thanks a lot Nick. Is this a pandas dateframe, btw? The way the information is organized when I request information for a bigger list of identifiers does seem to give that appearance.

  • Yes, the default output is a Pandas DataFrame. For more details see the documentation for get_data method in Eikon Python API Reference Guide
    https://developers.thomsonreuters.com/eikon-data-apis/docs

  • I have an additional question Alex, it's somehow related to the post.

    Can I call TR formulas from the get_timeseries function? My guess from the reference guide you provided is "No", I can't do that. Since I'd like daily returns given a range of dates.

  • Due to an outage of the Thomson Reuters Developer
    Community email notification system from 2:30 PM CDT on November 29th until
    9:00 AM CDT on November 30th we are posting to all questions updated during
    this timeframe in order to ensure all customers receive all relevant email
    updates. Please review this question, and its associated answers, in order to
    ensure you are aware of any possible updates that may have occurred during this
    outage. We apologize for the delay and any inconvenience this has caused.

    Matthew Logterman, J.D.

    Sr. Product Manager, Thomson Reuters Developer Community

  • You're correct. You'd have to calculate the returns yourself, which is pretty easy to do.

  • I'm getting AttributeError: 'tuple' object has no attribute 'iloc'

  • @victor.delima
    If you have a question it's always best to start a new thread rather than posting an answer on an existing thread. I'm guessing, and this is only a guess, that what you did is something like

    df = ek.get_data('TRI.N','TR.Revenue')
    df.iloc[0],[1]

    instead of correct

    df, err = ek.get_data('TRI.N','TR.Revenue')
    df.iloc[0],[1]

    If this helps, great. If not, and you need further assistance, please start a new thread and provide detailed description of the issue you're experiencing.

  • Thanks man. That did the trick.