Hello,
I need to collect historical data for multiple companies. While I wrote the code to do this and experimented with it, I realized that data which is returned differs sometimes, even though I am using the exact call. This is more than inconvenient because I can not rely upon the data which is collected. Has anyone experienced similar things or can someone tell me what I am doing wrong. In the attaced files, you can see my log data and how the outcome for collecting daily total returns varies for different trials.retrieve_returns_trials.zip A code snippet for five Rics is:
import logging
import eikon as ek
import pandas as pd
import time
logging.basicConfig(format='%(asctime)s : %(levelname)s : %(message)s', level=logging.INFO)
ek.set_app_key("your_key")
rics = ['CCL.N', 'NXGA.PK^E19', 'AFAQ.OQ^L22', 'GRLS.MC', 'GLXZ.PK']
for trial in range(5):
start = True
for ric in rics:
df, e = ek.get_data(
instruments=ric,
fields = [
'TR.TotalReturn1D',
'TR.TotalReturn1D.date'
] ,
parameters={"SDate": "2002-01-01", "EDate": "2024-09-15", "Frq": "D", "CH": "Fd"}
)
if not("Instrument") in df.columns:
logging.info("It seems like no data has been collected.")
logging.info(f"--------------------------------\n {df.head()} ----------------------------------\n")
if df.isna().sum().sum() > 0:
logging.info(f"Deleting NAs for ric {ric}")
df = df[df.isna().sum(axis = 1) == 0]
if start:
df_full = df.copy()
start = False
else:
df_full = pd.concat((df_full, df.copy()))
time.sleep(0.25)
df_full.to_csv(f"retrieve_returns_trial_{trial+1}.csv", index = False)