question

Upvotes
Accepted
5 0 0 3

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"

python#technology#productrefinitiv-data-platform
icon clock
10 |1500

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

Hi @xavier.bishop ,

I did a quick test with these examples:

1713861221085.png


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_etfs


1713861277120.png


Would you mind giving us a few RIC examples to test with?

1713861221085.png (110.3 KiB)
1713861277120.png (28.4 KiB)

1 Answer

· Write an Answer
Upvote
Accepted
10.2k 18 6 9

@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()
rics

1713867947129.png


You 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.


1713867947129.png (48.7 KiB)
icon clock
10 |1500

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

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?

Write an Answer

Hint: Notify or tag a user in this post by typing @username.

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.