Running a forloop on many ETFs in Python
Hello,
I'm currently utilizing Python as my programming language with Refinitiv Workspace as the API. My objective is to construct a for loop to gather ETF tickers (approximately 500 ETFs) in Python, subsequently converting them into daily returns, and finally plotting these returns into an Excel file. However, I've encountered an issue while attempting to retrieve these ETFs from Python. I've created a list of ETFs using `rd.get_history` (provided below), yet I consistently encounter the following error message:
Error processing 2023-01-03 00:00:00: Error code -1 | The '2' is unexpected in formula. Only the whole lexeme could be quoted. Escape sequence for quote, apostrophe and right brace is doubling. Requested universes: ["List('2023-01-03 00:00:00')"]. Requested fields: ['TR.CLOSEPRICE(CURN=USD)']
Is there a convenient function available for retrieving numerous ETFs from Refinitiv, perhaps in the form of a list that I could utilize within a for loop?
Thank you,
australian_etfs = df = rd.get_history(
universe=["List('AUS_ETF_Trial')"],
fields=["TR.ClosePrice(Curn=USD)"],
start="2022-12-31",
end="2023-12-31"
Best Answer
-
@xavier.bishop you can also try to create your universe using the search API :
etf_df = rd.discovery.search("Australian ETFs",top=10000)
rics = etf_df['RIC'].to_list()
ricsYou can then use that rics object directly into the API call @jonathan.legrand shows above. The search API is very powerful and with that power comes some complexity - however we have good examples in the Codebook App and also in this excellent article here and well as github repo containing more python code samples. I hope this can help.
1
Answers
-
Hi @xavier.bishop ,
I did a quick test with these examples:
And it seemed to work fine:
import refinitiv.data as rd
import pandas as pd
rd.open_session()
australian_etfs = rd.get_history(
universe=["US4642876555",
"US4642876555",
"US4642872000",
"US4642872000",
"US4642874659",
"US4642874659",
"US4642872349",
"US4642872349",
"US9229087690",
"US9229087690",
"US46434G8226"],
fields=["TR.ClosePrice(Curn=USD)"],
start="2024-01-01",
end="2024-01-12")
australian_etfsWould you mind giving us a few RIC examples to test with?
0 -
Hi Jason, thank you very much for your help. I am still new to Refintiv Workspace as well as Python so I am still learning the ropes. I was wondering what exactly is search API and how to download it?
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 中文论坛