...g Eikon API
Hi everyone,
I am relatively new using Eikon API and I am also relatively unfamiliar with the code. I want to retrieve the monthly institutional shareholding data for about 200 firms from 2003 to 2023 without having to download the shareholder report for every company one by one. Specifically, taking one company's shareholder report as an example, it contains information of every investor's name, the % Outstanding, position ($M), position change (etc). However, for each of my 200 firms, I want to retrive every investor's name, the percentage of shares held by each investor (TR.PctOfSharesOutHeld), the Investor Type ( 'TR.InvParentType') of each investor, the Investor Sub-type ('TR.InvestorType' of each investor, the investment stype ('TR.InvInvestmentStyleCode') of each investor, the country/region ('TR.InvAddrCountry') in which the investor locates every month from 2003 to 2023. I know there is monthly data available through checking one specific company's shareholder report in Refinitiv Workspace. I want the final dataframe to be in the following format (I just choose two companies as an example. I want my dataframe to include all 200 firms, the Date column to include all month from 2003/1/31 to 2023/12/31 for every firm, the Investor Name and the following columns to include all investors for the specific company). Is there any code that will enable me to do this?
In addition, I have already tried the following code myself. But it fails to return me the dataframe. Can anyone help me with this? Thank you very much!
ek.set_timeout(200)
instruments = ['AAL.L' 'ABDN.L' 'ABF.L' 'ADML.L' 'AHT.L' 'ANTO.L' 'ATST.L' 'AZN.L'
'BAB.L' 'BAES.L' 'BALF.L' 'BARC.L' 'BATS.L' 'BDEV.L' 'BEZG.L' 'BKGH.L'
'BLND.L' 'BOY.L' 'BP.L' 'BWNG.L' 'BWY.L' 'BYG.L' 'CAL.L' 'CBRO.L' 'CCL.L'
'CHG.L' 'CLDN.L' 'CLLN.L' 'CLSH.L' 'CNA.L' 'CNE.L' 'CPG.L' 'CPI.L'
'CRDA.L' 'CURY.L' 'DLAR.L' 'DLN.L' 'EMG.L' 'EZJ.L' 'GFRD.L' 'GFTU_u.L'
'GNC.L' 'GPEG.L' 'GRI.L' 'GSK.L' 'HBR.L' 'HEAD.L' 'HFD.L' 'HLCL.L'
'HLMA.L' 'HMSO.L' 'HSBA.L' 'HSX.L' 'HTG.L' 'HWG.L' 'ICGIN.L' 'IHG.L'
'III.L' 'INF.L' 'INVP.L' 'ITRK.L' 'ITV.L' 'IWG.L' 'JDW.L' 'JMAT.L'
'KGF.L' 'KIE.L' 'KLR.L' 'LLOY.L' 'LSEG.L' 'MARS.L' 'MCG.L' 'MGNS.L'
'MKS.L' 'MSLH.L' 'MTO.L' 'NG.L' 'NWG.L' 'NXT.L' 'PAGE.L' 'PAGPA.L'
'PFC.L' 'PFD.L' 'PHARP.L' 'PINE.L' 'PNN.L' 'PSN.L' 'PSON.L' 'PZC.L'
'RAT.L' 'RIO.L' 'RNK.L' 'ROR.L' 'RR.L' 'RSW.L' 'RTO.L' 'RWI.L' 'SBRY.L'
'SDR.L' 'SDY.L' 'SFR.L' 'SGE.L' 'SGRO.L' 'SHEL.L' 'SHI.L' 'SJP.L'
'SMDS.L' 'SMIN.L' 'SMWH.L' 'SN.L' 'SPT.L' 'SPX.L' 'SRP.L' 'SSE.L'
'STAN.L' 'SVS.L' 'SVT.L' 'SXS.L' 'TATE.L' 'TPK.L' 'TPT.L' 'TSCO.L' 'TW.L'
'ULVR.L' 'UTG.L' 'UU.L' 'VANQ.L' 'VCTX.L' 'VOD.L' 'VSVS.L' 'VTYV.L'
'WEIR.L' 'WG.L' 'WKP.L' 'WTB.L' 'ZIG.L']
dataframes = {}
# Loop through each instrument and fetch data
for instrument in instruments:
success = False
retries = 100
for attempt in range(retries):
try:
df, err = ek.get_data(
[instrument],
['TR.CompanyName','TR.PctOfSharesOutHeld.date', 'TR.PctOfSharesOutHeld', 'TR.InvestorFullName', 'TR.InvParentType', 'TR.InvestorType', 'TR.InvInvestmentStyleCode', 'TR.InvestorAddrCity', 'TR.InvAddrCountry'],
parameters={'SDate': '2003-01-01', 'EDate': '2024-01-02', 'Frq': 'M'}
)
if err is None:
dataframes[instrument] = df
success = True
print(f"Data successfully retrieved for {instrument}")
break # Exit the retry loop on success
except ek.EikonError as e:
print(f"Attempt {attempt + 1} failed for {instrument}: {e}")
time.sleep(5) # Wait 5 seconds before retrying
if not success and attempt == retries - 1:
print(f"Failed to retrieve data for {instrument} after {retries} attempts.")