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

Overview |  Quickstart |  Documentation |  Downloads |  Tutorials |  Articles

question

Upvotes
Accepted
2 0 0 2

variable parameter values for a list of instrument in R/Python API

Hi folks, I currently come up with the following syntax in R, which requests the revenue in the fiscal year 2014 for a list of instruments. My intention is to request the revenues at different fiscal years for each instrument (e.g., 'GE' revenue at 2015, 'AAPL.O' revenue at 2016, and 'CSCO.O' revenue at 2017 ). While I can use a cell reference in Eikon excel to define the period, would you kindly suggest how to use a reference/a list of variable parameters passed to ‘period’ in the R/Python environment? Many thanks.

get_data(instrument list, list('tr.revenue'=list('params'= list('scale'= '3', 'period'= 'FY2014'))))

eikonworkspaceworkspace-data-apirefinitiv-dataplatform-eikoneikon-data-api-r
icon clock
10 |1500

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

Upvotes
Accepted
13k 32 12 18

Try this in R. The get_data call is invoked inside the loop:

fylist=c('FY2014', 'FY2015', 'FY2016')
for (fyr in fylist) {
  print(fyr)
  get_data("IBM", list('TR.GrossProfit'= list('params'=list('period'= fyr))))  
}
icon clock
10 |1500

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

Thanks, @Gurpreet

However, the output comes as below. Merely 'fylist' is printed. Any suggestion? thank you again for this generous help.

> fylist=c('FY2014', 'FY2015', 'FY2016')
> for (fyr in fylist) {
+     print(fyr)
+     get_data("IBM", list('TR.GrossProfit'= list('params'=list('period'= fyr))))  
+ }
[1] "FY2014"
[1] "FY2015"
[1] "FY2016"


You will need to print the result of get_data call:

fylist=c('FY2014', 'FY2015', 'FY2016')
for (fyr in fylist) {
  print(fyr)
  res <- get_data("IBM", list('TR.GrossProfit'= list('params'=list('period'= fyr))))
  print(res)
}

[1] "FY2014"
  Instrument Gross Profit
1        IBM   4.6407e+10
[1] "FY2015"
  Instrument Gross Profit
1        IBM   4.0684e+10
[1] "FY2016"
  Instrument Gross Profit
1        IBM   3.8516e+10


@Gurpreet . Ah, many thanks. How could forget to print :) . Finally get it out. Much appreciated.

Upvote
13k 32 12 18

Hi @Jason Wang, You can reference variables in period parameter list like any other python/R variables.

Here is an example of a loop with three fiscal years using variables:

fyList = ['FY2014', 'FY2016', 'FY2018']
for fyr in fyList:
  df, err = ek.get_data('AAPL.O', ['TR.Revenue', 'TR.RevenuePerShare', 'TR.Revenue.fperiod'], parameters={'Period': fyr})
  print(df)

and the output:

  Instrument       Revenue  Revenue Per Share Financial Period Absolute
0     AAPL.O  182795000000           7.463868                    FY2014
  Instrument       Revenue  Revenue Per Share Financial Period Absolute
0     AAPL.O  215639000000           9.801272                    FY2016
  Instrument       Revenue  Revenue Per Share Financial Period Absolute
0     AAPL.O  265595000000          13.279461                    FY2018
icon clock
10 |1500

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

Upvote
13k 32 12 18

Forgot to add, since TR.Revenue is also available as series, you can request multiple years in a single call:

>>> df, err = ek.get_data('AAPL.O', ['TR.Revenue'], parameters={'SDate': '-4', 'EDate': '-8', 'Frq': 'FY'})
>>> df
  Instrument       Revenue
0     AAPL.O  215639000000
1     AAPL.O  233715000000
2     AAPL.O  182795000000
3     AAPL.O  170910000000
4     AAPL.O  156508000000
icon clock
10 |1500

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

Upvotes
2 0 0 2

Hi, @Gurpreet , thanks for the suggestions. The issue is I like to have a specific fiscal year passed to each instrument's revenue. For example, I created a instrument list ric=list('GE', 'AAPL.O', 'CSCO.O'), and followed your suggestion to create a fiscal year end list fyList = list ('FY2014', 'FY2016', 'FY2018'). I intend to have AAPL.O revenue at 2014, AAPL.O revenue at 2016, and CSCO.O revenue at 2018. While you used a single instrument, I hope to apply each specific fiscal year to each instrument. It seems get_data may not work so? I may have to further process data with other functions?

Moreover, may I ask why you put 'for fyr in fyList:'? what the 'for variable in vector' function works for here.

Thank you again for the great suggestions.

icon clock
10 |1500

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

Upvote
13k 32 12 18

@Jason Wang,

You won't be able to get data for different fields for different instruments in a same call. Better to use three unique get_data calls instead.

ek.get_data('AAPL.O', 'TR.Revenue', parameters={'Period': 'FY2014'})
ek.get_data('AAPL.O', 'TR.Revenue', parameters={'Period': 'FY2016'})
ek.get_data('CSCO.O', 'TR.Revenue', parameters={'Period': 'FY2018'})


The variable fyr assumes one of the value of the list in each iteration pass.

icon clock
10 |1500

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

Upvotes
2 0 0 2

Thanks, @Gurpreet , It seems the data need to be processed after calls with API. Great. Thank you again for the prompt help.

icon clock
10 |1500

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

Upvotes
2 0 0 2

Hi @Gurpreet , just a follow-up question, specifically in R. Hope you can kindly suggest.

I tried to follow your suggestion but work them around in R. However, I am not sure where these codes are mistaken. I came up with an output, where only the last value in vector was used. the major issue is I can not have multiple fiscal years (for just single instrument) as parameters in the R environment.

Below are the codes. I created 'fylist' with three fiscal years. however, the final outcome by using 'fyr' in 'get_date', shows only the instrument (i.e., IBM) gross profit at the last value in the 'fylist' (i.e., FY2016). I am not sure why not other two fiscal years (i.e., FY2014 and FY2015) were not used.

Thanks for the help.


>fylist=c('FY2014', 'FY2015', 'FY2016')
>for (fyr in fylist) {print(fyr)}
[1] "FY2014"
[1] "FY2015"
[1] "FY2016"
> get_data("IBM", list('TR.GrossProfit'= list('params'=list('period'= fyr))))

Instrument Gross Profit

1 IBM 3.8516e+10





icon clock
10 |1500

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

Click below to post an Idea Post Idea