Calculate within EIKON API request

Hi,
I am currently trying to retrieve the yearly median of bid-ask spreads for given firms. In Datastream this expression looks like this: MED#((X(PA)-X(PB)/(X(PA)+X(PB)/2)),01/01/2010,31/12/2015) with X being the respective company identifier and frequency set to "Yearly" to get the yearly median.
Is there any way to do the same in the EIKON API? I tried calculating with:
data, error=ek.get_data('MSFT.O', [('TR.ASKPRICE'-'TR.BIDPRICE')/(('TR.ASKPRICE'+'TR.BIDPRICE')/2)], parameters={'SDate':'2010-01-01', 'EDate':'2015-12-31'}) but received an error:
unsupported operand type(s) for -: 'str' and 'str'
Best Answer
-
You have a syntax error in your expression. The second argument of get_data method must be a string or a list of strings. If you'd like the timeseries of the ratio of bid/ask spread to the mid price use:
ek.get_data('MSFT.O',
['TR.BIDPRICE.date',
'2*(TR.ASKPRICE-TR.BIDPRICE)/(TR.ASKPRICE+TR.BIDPRICE)'],
{'SDate':'2010-01-01', 'EDate':'2015-12-31'})If you just need the median of the series use:
ek.get_data('MSFT.O',
'2*MEDIAN((TR.ASKPRICE-TR.BIDPRICE)/(TR.ASKPRICE+TR.BIDPRICE))',
{'SDate':'2010-01-01', 'EDate':'2015-12-31'})0
Answers
-
Thank you very much!! Ok, I see my mistake. I tried both of your suggestions but I get the same (daily) values for both requests. In the very end I am only interested in yearly median of my bid-ask spreads.I think I have to run each year separately right? Or is there any way to use lets say a five year period
- ek.get_data('MSFT.O',
- '2*MEDIAN((TR.ASKPRICE-TR.BIDPRICE)/(TR.ASKPRICE+TR.BIDPRICE))',
- {'SDate':'2010-01-01', 'EDate':'2015-12-31'})
which retrieves only the median value for each year (MSFT.O, 2010, XX; MSFT.O, 2011, XX; MSFT.O, 2012, XX....)?
0 -
To get the annual median you either need to submit separate get_data request for the median for each year or you can retrieve the entire daily series and calculate the annual median using capabilities of pandas.
0 -
Ok, thats what I expected. Should not be a problem using pandas. Using your (corrected) expression above however still gives me dialy values even when using the MEDIAN operator. Do I need to specify frequency 1Y or "Yearly" as in Datastream somewhere?
0 -
I'm not sure I understand. My original example that uses MEDIAN function in the field expression returns pandas dataframe with a single row, which contains the median for the daily series framed by the values of SDate and EDate parameters. It does not return daily series.
0 -
I had another look at your code and you are right. I missed the opening and closing paranthesis on the median function. This resulted in daily data instead of one median datapoint!
Thanks again for your help, appreciate it!0
Categories
- All Categories
- 3 Polls
- 6 AHS
- 36 Alpha
- 166 App Studio
- 6 Block Chain
- 4 Bot Platform
- 18 Connected Risk APIs
- 47 Data Fusion
- 34 Data Model Discovery
- 685 Datastream
- 1.4K DSS
- 620 Eikon COM
- 5.2K Eikon Data APIs
- 10 Electronic Trading
- Generic FIX
- 7 Local Bank Node API
- 3 Trading API
- 2.9K Elektron
- 1.4K EMA
- 254 ETA
- 557 WebSocket API
- 38 FX Venues
- 14 FX Market Data
- 1 FX Post Trade
- 1 FX Trading - Matching
- 12 FX Trading – RFQ Maker
- 5 Intelligent Tagging
- 2 Legal One
- 23 Messenger Bot
- 3 Messenger Side by Side
- 9 ONESOURCE
- 7 Indirect Tax
- 60 Open Calais
- 276 Open PermID
- 44 Entity Search
- 2 Org ID
- 1 PAM
- PAM - Logging
- 6 Product Insight
- Project Tracking
- ProView
- ProView Internal
- 23 RDMS
- 1.9K Refinitiv Data Platform
- 656 Refinitiv Data Platform Libraries
- 4 LSEG Due Diligence
- LSEG Due Diligence Portal API
- 4 Refinitiv Due Dilligence Centre
- Rose's Space
- 1.2K Screening
- 18 Qual-ID API
- 13 Screening Deployed
- 23 Screening Online
- 12 World-Check Customer Risk Screener
- 1K World-Check One
- 46 World-Check One Zero Footprint
- 45 Side by Side Integration API
- 2 Test Space
- 3 Thomson One Smart
- 10 TR Knowledge Graph
- 151 Transactions
- 143 REDI API
- 1.8K TREP APIs
- 4 CAT
- 27 DACS Station
- 121 Open DACS
- 1.1K RFA
- 104 UPA
- 193 TREP Infrastructure
- 229 TRKD
- 917 TRTH
- 5 Velocity Analytics
- 9 Wealth Management Web Services
- 90 Workspace SDK
- 11 Element Framework
- 5 Grid
- 18 World-Check Data File
- 1 Yield Book Analytics
- 46 中文论坛