I post the following code. I am retrieving info starting from ISIN codes and I want to retrieve FundCompany and LEI code. To do that I first retrieve the RIC code, then fetch fund company and from here I look for the LEI.
The problem is that using the FundCompany retrieved from Refinitiv, the API can never find the LEI code and the column is a bunch of 'None' values. What is the problem here?
Thanks
# Iterate through RICs
for ric in rics_list:
try:
data_response, err = ek.get_data(ric,
fields=['TR.FundLegalStructure', 'TR.FundType', 'TR.FundCompany', 'TR.LegalEntityIdentifier'])
except Exception as e:
print(f"Error fetching data for RIC {ric}: {e}")
continue
if not err:
# Check if 'TR.FundLegalStructure' field exists in the data_response
fund_legal_structure = data_response['Legal Structure'].iloc[0] if 'Legal Structure' in data_response.columns else None
# Check if 'TR.FundType' field exists in the data_response
fund_type = data_response['Fund Type'].iloc[0] if 'Fund Type' in data_response.columns else None
# Check if 'TR.FundCompany' field exists in the data_response
fund_company = data_response['Fund Company'].iloc[0] if 'Fund Company' in data_response.columns else None
# Initialize LEI as None
lei = None
if fund_company is not None:
print(fund_company)
try:
# Fetch the LEI using the Fund Company
lei_response, lei_err = ek.get_data(fund_company.upper(), fields= ['TR.LegalEntityIdentifier'])
if not lei_err:
if 'Legal Entity Identifier' in lei_response.columns:
lei = lei_response['Legal Entity Identifier'].iloc[0]
else:
print(f"LEI data not found for Fund Company {fund_company}")
except Exception as e:
print(f"Error fetching LEI for Fund Company {fund_company}: {e}")
# Append data row to the current batch's data_rows list
data_rows.append({
'ISIN': isin,
'RIC': ric[:max_rics_per_isin],
'FundLegalStructure': fund_legal_structure,
'FundType': fund_type,
'FundCompany': fund_company,
'Legal Entity Identifier': str(lei) # Add LEI to the data
})