Historical data for bid and ask price per minute
Hi,
I am looking for historical data (bid and ask price) regarding bonds.
I can retrieve the data when i use yearly, monthly and daily frequency. However, when I am trying to reload data per minute or 30 minutes i get the output of N/A.
Here is an example of the code i use :
import datetime
import eikon as ek
## Set the datetime
start_date = datetime.datetime(2023, 3, 1).strftime('%Y-%m-%d')
end_date = datetime.datetime(2023, 3, 2).strftime('%Y-%m-%d')
##Reload data from Refinitv
df, err = ek.get_data(
instruments= =['NL188254462='],
fields=['TR.ASKPRICE', 'TR.ASKYIELD', 'TR.BIDPRICE', 'TR.BIDYIELD'],
parameters={'SDate': start_date, 'EDate': end_date, 'Frq': 'minute'})
print(df)
The problem seems that is the way i add the frequency.
Thank you in advance,
Kind regards,
Kyriakos
Best Answer
-
Thank you for your question. For retrieving historical prices, I would advise using rd.get_history function from our latest RD Libraries (you can install via - pip install refinitiv-data) which will allow getting 1-year intraday historical data and 3-month tick data. Please see the code below:
import datetime
import refinitiv.data as rd
## Set the datetime
start_date = datetime.datetime(2022, 1, 1).strftime('%Y-%m-%d')
end_date = datetime.datetime(2023, 3, 2).strftime('%Y-%m-%d')
##Reload data from Refinitv
df = rd.get_history(
universe= ['NL188254462='],
fields=['ASK', 'ASK_YIELD', 'BID', 'BID_YIELD'],
start = start_date,
end = end_date,
interval = '1min'
)
dfHope this helps, let me know should you have any further questions.
Best regards,
Haykaz
0
Answers
-
Dear Haykaz,
Thank you for your response@"h.aramyan01" .
I did like this but now i have another issue regarding the app_key.
Should i change the set_app key function?
Thank you in advance,
Best,
Kyriakos
0 -
Here, in RD, instead of ek.set_app_key('') you need to run rd.open_session(). Please note, that as in Eikon you need to have workspace running on the background.
Best regards,
Haykaz
0 -
Hi @h.aramyan01,
Thank you for your response.
I tried to run the rd.open_session, however i am not sure which kind of app_key i need to use.
Could you please give me some more details on how this works?
Thank you,
Kind regards,
Kyriakos
0 -
You don't need to specify the APPKEY in case of RD, it will automatically get that from your Workspace which as I mentioned before need to be open on the background (as it is in case of Eikon API). So your final code should look like this:
import datetime
import refinitiv.data as rd
rd.open_session()
## Set the datetime
start_date = datetime.datetime(2022, 1, 1).strftime('%Y-%m-%d')
end_date = datetime.datetime(2023, 3, 2).strftime('%Y-%m-%d')
##Reload data from Refinitv
df = rd.get_history(
universe= ['NL188254462='],
fields=['ASK', 'ASK_YIELD', 'BID', 'BID_YIELD'],
start = start_date,
end = end_date,
interval = '1min'
)
dfBest regards,
Haykaz
0 -
Dear @h.aramyan01,
Thank you very much for your response.
Do I have to download the the refinitiv data workspace ? Or it works when i have the Eikon workspace running.
Sorry for the many questions, but i am not familiar with it, since i use it for the first time.
Thank you in advance,
Kind regards,
Kyriakos
0 -
Hi @kyriakos.eleftheriadis ,
No worries at all, happy to address those. Eikon should be fine.
Best regards,
Haykaz
0 -
Hi @h.aramyan01,
Thank you again for the help.
I have the Eikon workspace running, however, when i execute my code i receive this output:
Empty DataFrame
Columns: []
Index: []
Process finished with exit code 0
Although I am sure that the data exists, not sure what is the problem.
Thank you in advance,
Best regards,
Kyriakos
0 -
Could you please enable the logs for us to see if we are getting any errors by adding the following code after importing the RD lib?:
rd.get_config().set_param(
param=f"logs.transports.console.enabled", value=True
)Best regards,
Haykaz
0 -
Hi @h.aramyan01,
I added the code you mentioned but there are no errors.
The code runs and returns the values when i use one ISIN, for example from a bond.
However, when i try to add more (i use identifiers from Mongo) the output is as i described before. Fyi, I use a list of several bonds which is called 'identifiers'
Notice that when i used the Eikon function the same code with the identifiers worked.
That's my whole code:
import datetime
import refinitiv.data as rd
from tradingutils.db.connection import get_mongo_vm_db
##Set the app_key for refinitiv (must be logged in)
rd.open_session()
## get client from Mongo
mongo = get_mongo_vm_db()
audit_feed = mongo['audit_feed']['prod']
## Find the query
find_query = {
'TRADDESK': 'EUFFFI',
'last_modified': {'$gte': datetime.datetime.utcnow() - datetime.timedelta(days=90)}}
project_query = {'IDENTIFIER': 1}
##Retrieve identifiers from Mongo
identifiers = audit_feed.find(filter=find_query, projection=project_query)
identifiers = {doc.get('IDENTIFIER') for doc in identifiers}
print(identifiers)
## Set the datetime
start_date = datetime.datetime(2023, 3, 1).strftime('%Y-%m-%d')
end_date = datetime.datetime(2023, 3, 2).strftime('%Y-%m-%d')
##Reload data from Refinitv
df = rd.get_history(
universe= list(identifiers),
fields=['TR.ASKPRICE', 'TR.ASKYIELD', 'TR.BIDPRICE', 'TR.BIDYIELD'],
parameters={'SDate': start_date, 'EDate': end_date, 'Frq': '1Min'})
print(df)Thank you,
Kind regards,
Kyriakos
0 -
It would be more helpful if you could share the identifies within list(identifiers) (at least some of those) for me to test on my end. Also the code I have suggested was the following not the one I can see in your current post. Could you please try with the code below?
df = rd.get_history(
universe= ['NL188254462='],
fields=['ASK', 'ASK_YIELD', 'BID', 'BID_YIELD'],
start = start_date,
end = end_date,
interval = '1min'
)
dfBest regards,
Haykaz
0 -
Hi @h.aramyan01,
When I try the code you described above it works and i get the data.
The only problem is when i add the list with the several identifiers. Then it gives me no values
To be more specific some examples of the bonds are : 'PTOTELOE0028', 'DE000HCB0BH9', 'XS2538778478', 'XS1887485032', 'FR0013429073', 'XS2558343476', 'FR0013231768', 'XS2200513070', 'XS2056395606', 'ES0413211873', 'NL0000102234', 'DE000A2GSLV6', 'IT0001444378', 'ZL0647897', 'XS1180256528'.
Is it possible that because the list is really huge that i cant get the data ?
Thank you again for your help.
Kind regards,
Kyriakos
0 -
Instead of using ISINs I would advice converting the ISINs into RICs first:
from refinitiv.data.content import symbol_conversion
symbol_list = ['PTOTELOE0028','DE000HCB0BH9',
'XS2538778478', 'XS1887485032', 'FR0013429073', 'XS2558343476', 'FR0013231768',
'XS2200513070', 'XS2056395606', 'ES0413211873', 'NL0000102234', 'DE000A2GSLV6',
'IT0001444378', 'ZL0647897', 'XS1180256528'
]
response = symbol_conversion.Definition(
symbols= symbol_list,
).get_data()
response.data.dfThen you can retrieve the list of RICs and pass that to the get_history function:
rics = response.data.df['RIC'].values.dropna()
rics
## Set the datetime
start_date = datetime.datetime(2023, 3, 1).strftime('%Y-%m-%d')
end_date = datetime.datetime(2023, 3, 2).strftime('%Y-%m-%d')
##Reload data from Refinitv
df = rd.get_history(
universe= rics,
fields=['ASK', 'ASK_YIELD', 'BID', 'BID_YIELD'],
start = start_date,
end = end_date,
interval = '1min'
)
dfBest regards,
Haykaz
0 -
Hi @h.aramyan01,
Thank you very much, now it works from what i can see
Thank you again for the help,
Kind regards,
Kyriakos
0 -
You are very welcome, happy to help!0
-
Hi @h.aramyan01,
Hope you are doing fine.
Is it possible to get the historical data for bid and ask for an index ?
For instance, i have the ICE BofA Euro High Yield Index. Are the data available when it comes to an index?
Do i have to use another code to reload the data?
Thank you in advance,
Kind regards,
Kyriakos
0 -
Sure, you can use the index's RIC (which is .MERHE00 I believe) for the "universe" parameter. You may comment out fields parameter also to get all available fields for the request.
Best regards,
Haykaz
0 -
Good morning @h.aramyan01,
Thank you for your answer.
I mean to get all the index constituents data. I think there are about 900 bonds.
Is this possible?
Thank you again for the help.
Kind regards,
Kyriakos
0 -
This is the code to get index constituents. Please see the example for FTSE:
df = rd.get_data('.FTSE',
['TR.IndexConstituentRIC' , 'TR.IndexConstituentName'])
dfHowever, this code produces NAs for .MERHE00. I have checked in Workspace and there is no constituent data for that there as well. To learn more about the reasons, I would advise raising a content query via MyRefinitiv.
Best regards,
Haykaz
0 -
0
-
Hi @h.aramyan01 ,
I hope you are doing well.
I have a question regarding how to retrieve tick historical data for bonds using pycharm.
To get historical time series data i used the following script which you provided me:
df = rd.get_history( universe=rics, fields=['ASK', 'ASK_YIELD', 'BID', 'BID_YIELD'], start=start_date, end=end_date, interval='1M'Does the same work or i need to adjust my script?
Thank you in advance,
Kind regards,
Kyriakos
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 中文论坛