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'))))
Best Answer
-
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))))
}0
Answers
-
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 FY20181 -
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 1565080000001 -
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.
0 -
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.
1 -
Thanks, @Gurpreet , It seems the data need to be processed after calls with API. Great. Thank you again for the prompt help.
0 -
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
0 -
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"0 -
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+101 -
@Gurpreet . Ah, many thanks. How could forget to print . Finally get it out. Much appreciated.
0
Categories
- All Categories
- 6 AHS
- 37 Alpha
- 161 App Studio
- 4 Block Chain
- 4 Bot Platform
- 16 Connected Risk APIs
- 47 Data Fusion
- 30 Data Model Discovery
- 608 Datastream
- 1.3K DSS
- 577 Eikon COM
- 4.9K Eikon Data APIs
- 7 Electronic Trading
- Generic FIX
- 7 Local Bank Node API
- Trading API
- 2.7K Elektron
- 1.3K EMA
- 236 ETA
- 519 WebSocket API
- 33 FX Venues
- 10 FX Market Data
- 1 FX Post Trade
- 1 FX Trading - Matching
- 12 FX Trading – RFQ Maker
- 5 Intelligent Tagging
- 2 Legal One
- 20 Messenger Bot
- 2 Messenger Side by Side
- 9 ONESOURCE
- 7 Indirect Tax
- 59 Open Calais
- 264 Open PermID
- 39 Entity Search
- 2 Org ID
- PAM
- PAM - Logging
- 8.4K Private Comments
- 6 Product Insight
- Project Tracking
- ProView
- ProView Internal
- 20 RDMS
- 1.4K Refinitiv Data Platform
- 367 Refinitiv Data Platform Libraries
- 3 Refinitiv Due Diligence
- LSEG Due Diligence Portal API
- 3 Refinitiv Due Dilligence Centre
- Rose's Space
- 1.1K Screening
- 18 Qual-ID API
- 13 Screening Deployed
- 23 Screening Online
- 10 World-Check Customer Risk Screener
- 990 World-Check One
- 44 World-Check One Zero Footprint
- 45 Side by Side Integration API
- Test Space
- 3 Thomson One Smart
- 1.2K TR Internal
- Global Hackathon 2015
- 2 Specialists Who Code
- 10 TR Knowledge Graph
- 150 Transactions
- 142 REDI API
- 1.7K TREP APIs
- 4 CAT
- 21 DACS Station
- 117 Open DACS
- 1.1K RFA
- 103 UPA
- 172 TREP Infrastructure
- 224 TRKD
- 886 TRTH
- 5 Velocity Analytics
- 5 Wealth Management Web Services
- 59 Workspace SDK
- 9 Element Framework
- 5 Grid
- 13 World-Check Data File
- Yield Book Analytics
- 46 中文论坛