Why do I have values for get_data() and not for get_timeseries?

For get_data I have values for TLSA.O for the fields I have chosen.

#import packages
import eikon as ek # the Eikon Python wrapper package
import pandas as pd
import numpy as np
import datetime
from datetime import timedelta, date, datetime
from dateutil.relativedelta import relativedelta

#connects to Bill's Eikon terminal
ek.set_app_key('72d2821f21064a0b8890860db39e375eacd87e24')

df = pd.DataFrame(df)
df = ek.get_data('TSLA.O',
                    ['TR.NumOfStrongBuy',
                     'TR.NumOfBuy',
                     'TR.NumOfHold',
                     'TR.NumOfSell',
                     'TR.NumOfStrongSell'])

print(df)

Output:

(  Instrument  Recommendation - Number Of Strong Buy  \ 0     TSLA.O                                      6      Recommendation - Number Of Buy  Recommendation - Number Of Hold  \ 0                               3                               11      Recommendation - Number Of Sell  Recommendation - Number Of Strong Sell  0                               10                                       3  , None)

However, when requesting this data using get_timeseries all of the outputs are NaN. Why is this and how do I get it to give numbers in the same way that get_data() does?

#get dates and format as strings
end_date = datetime.now()
start_date = end_date - relativedelta(months=1)
end_date_str = datetime.strftime(end_date, "%Y-%m-%d")
start_date_str = datetime.strftime(start_date, "%Y-%m-%d")

#retreive time series
df = pd.DataFrame()
df = ek.get_timeseries('TSLA.O',
                    ['TR.NumOfStrongBuy',
                     'TR.NumOfBuy',
                     'TR.NumOfHold',
                     'TR.NumOfSell',
                     'TR.NumOfStrongSell'],
                start_date = start_date_str,
                end_date = end_date_str)

df

Output:

TSLA.OTR.NUMOFSTRONGBUYTR.NUMOFBUYTR.NUMOFHOLDTR.NUMOFSELLTR.NUMOFSTRONGSELLDate




2020-06-12NaNNaNNaNNaNNaN2020-06-15NaNNaNNaNNaNNaN2020-06-16NaNNaNNaNNaNNaN2020-06-17NaNNaNNaNNaNNaN2020-06-18NaNNaNNaNNaNNaN2020-06-19NaNNaNNaNNaNNaN2020-06-22NaNNaNNaNNaNNaN2020-06-23NaNNaNNaNNaNNaN2020-06-24NaNNaNNaNNaNNaN2020-06-25NaNNaNNaNNaNNaN2020-06-26NaNNaNNaNNaNNaN2020-06-29NaNNaNNaNNaNNaN2020-06-30NaNNaNNaNNaNNaN2020-07-01NaNNaNNaNNaNNaN2020-07-02NaNNaNNaNNaNNaN2020-07-06NaNNaNNaNNaNNaN2020-07-07NaNNaNNaNNaNNaN2020-07-08NaNNaNNaNNaNNaN2020-07-09NaNNaNNaNNaNNaN2020-07-10NaNNaNNaNNaNNaN

Best Answer

  • Hello @bill39

    get_timeseries(..) does not support the fields you specified above. The function supports only 'TIMESTAMP', 'VALUE', 'VOLUME', 'HIGH', 'LOW', 'OPEN', 'CLOSE', 'COUNT'. This is explained in Eikon Data APIs for Python - Reference Guide . That's why you get NaN.

    You can specify start date and end date in get_data(..) if the fields supports date. You can check if a field supports date or not using "Data Item Browser" tool. Please refer to the answer of this question which shows how to use the tool.

    I have checked your preference fields using "Data Item Browser" and the fields support date. The snipped example source code shows how to set start date and end date for the fields:

    end_date = datetime.now()
    start_date = end_date - relativedelta(months=1)
    end_date_str = datetime.strftime(end_date, "%Y-%m-%d")
    start_date_str = datetime.strftime(start_date, "%Y-%m-%d")
    print("start="+start_date_str + " ,end="+end_date_str)
    #return dataframe and errors
    test_1,err= ek.get_data('TSLA.O', 
            ['TR.NumOfStrongBuy.date', #show date
             'TR.NumOfStrongBuy',
             'TR.NumOfBuy',
             'TR.NumOfHold',
             'TR.NumOfSell',
             'TR.NumOfStrongSell'],
            {'SDate':start_date_str, 'EDate':end_date_str}) #set start and end date
    #show data
    test_1

    The example output:

    image

Answers

  • bill39
    bill39 Explorer

    Hi @Pimchaya.Wongrukun,

    I'm confused. According to the Reference Guide, get_timeseries(..) has the parameters start_date and end_date. Is this a mistake in the docs or is there something I have misunderstood?

    Thanks

  • Hello @bill39

    The document is correct. get_timeseries(..) has the parameters start_date and end_date but it provides only 'TIMESTAMP', 'VALUE', 'VOLUME', 'HIGH', 'LOW', 'OPEN', 'CLOSE', 'COUNT' field as an example shown in Eikon Data API Quick Start guide below:

    image

    If you would like to get other fields apart from get_timeseries(..) provides, you need to use get_data(..)