Python: getting dates for all tickers/symbols, even for dates in which data is not available.
I have the following function in Python (snippet 1):
´Snippet 1:
import eikon as ek #import Eikon module
import numpy as np
def get_data(identifiers,tr_fields,settings,eikon_id):
ek.set_app_id(eikon_id)
df = ek.get_data(identifiers, tr_fields,settings)[0]
df.columns = df.columns.str.replace(r"[ ]", "_")
df.columns = df.columns.str.replace(r"[-]", "_")
df = df.fillna(np.nan)
return df
If I use it with these parameters (snippet 2), I get the following outcome (image 1):
Snippet 2:
tr_fields=['TR.TotalReturn.calcDate', 'TR.TotalReturn']
sets={'SDate': '03/27/2017', 'EDate': '03/31/2017', 'Frq': 'D'}
id='XXXX'
instruments=['BP8Y3X2','6071475']
a=get_data(instruments,tr_fields,sets,id)
Image 1:
My guess is that Eikon has some sort of default setting that avoids populating a Dataframe with missing data. But, what if I wanted to have that missing data? For this particular case, I'd like to have all five dates for BP8Y3X2 in the Dataframe, obviously with NaN values in their respective Calc_Date and Total_Return columns.
Is something like this possible?
Thanks in advance for your help.
Best Answer
-
The reason why it does not return is that BP8Y3X2 does not exist as an instrument. If you check the error part of the get_date() tuple, you will see something like:
[{'code': 416,
'col': 1,
'message': "Unable to collect data for the field 'TR.TOTALRETURN.calcDate' and some specific identifier(s).",
'row': 0},
{'code': 416,
'col': 2,
'message': "Unable to collect data for the field 'TR.TOTALRETURN' and some specific identifier(s).",
'row': 0}]On to the second part of the question. Requests like this will indeed yield the datapoints that exist in the database, rather than mapping them to some time range. With pandas you can actually do it yourself, which is pretty straight forward.
Do the request:
response, error = tr.get_data(instruments=['GAZP.MM','6071475'], fields=['TR.TotalReturn.calcDate', 'TR.TotalReturn'], parameters={'SDate': '0', 'EDate': '-20', 'Frq': 'D'})
Rebuild dataframe, so that the date is the index:df = response.pivot_table(values='Total Return', index=['Calc Date', 'Instrument']).unstack('Instrument')
Convert index format to date:
df.index = pd.to_datetime(df.index)
Reindex with the new date range:
df.reindex(pd.date_range(start='2017-12-01', end='2018-01-18', freq=pd.offsets.BDay()))
The result will look like this:
2
Answers
-
Thanks a lot for your solution
Is there any way to index an instrument that ceased to exist or is no longer listed? Because for this particular case, BP8Y3X2 was an instrument for a certain company (can't remember now which one), but I guess the company used another SEDOL for it. Is there a way I can index this into the Dataframe as well?
0 -
I'm afraid not. You can only find active equity issues using CUSIP/SEDOL/ISIN in Eikon.
0
Categories
- All Categories
- 6 AHS
- 39 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 中文论坛