question

Upvotes
Accepted
3 0 0 2

Insonsistent data retrieval with eikon get_data

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)

#productdata
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.

1 Answer

· Write an Answer
Upvote
Accepted
11k 22 6 9

@ralf.kellner Thanks for your question. So please try this code it works for me.

rics = ['CCL.N', 'NXGA.PK^E19', 'AFAQ.OQ^L22', 'GRLS.MC', 'GLXZ.PK']

for ric in rics:
    df, e = ek.get_data(rics,fields = ['TR.TotalReturn1D.date','TR.TotalReturn1D'],
                        parameters={"SDate": "2002-01-01", "EDate": "2024-09-15", "Frq": "D"}
)
    
df

1726504913735.png

If you have a much larger RIC list - you can just chunk it and present for chunk in chunks etc I hope this can help.


1726504913735.png (44.2 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.

Many thanks @jason.ramchandani01 this seems to help and creates consistent data retrieval. Just out of curiosity, do you know why using the "CH" parameter instroduces the inconsistent behavior? As I understand it from here, I thought it "just" makes sure that field names are used as row headers.

@ralf.kellner Apols for delay - missed this - so the CH:Fd parameter is something that applies to the excel functions - it is not part of the Python API parameters. In Python data frames are returned in various formats depending on multi-index or not etc. You can of course flatten, transpose etc to get the right shape for your dataframe. It could be the case that for a single field, multi-ric request you are given instruments as column headers -but all this is easily managed in the flexible python environment. I hope this can help.

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.