Index constituents every month
How can I get index constituents every month? I am looking for the .HSLI index constituents every month end since 2015/1/30. I have used
df=ek.get_data('.HSLI', ['TR.IndexConstituentRIC'], {'SDate':'-50M'})[0]
With a loop from -50 to 0 so I get every month...
However, the data is there only for the last couple of years. On asking the support desk, they suggested Datastream would be a better source. I quote:
For historical constituents of <.HSLI> I would recommend to use Datastream excel add in formula to extract the historical constituents since it has more historical data.
The historical constituents of this index are available from March 2010 - April 2019 with the following codes below:
LHKHCOLC - Current constituent list of Hang Seng Large Cap index.
LHKHCOLC0419 - Latest constituent list of Hang Seng Large Cap index as of April 2019.
LHKHCOLC0310 - Earliest constituent list of Hang Seng Large Cap index as of March 2010.
Please note that the numerical figures in the code represents the month and year, so if you would like to get the constituent list as of January 2017, just add 0117 after the code LHKHCOLC so the code will be LHKHCOLC0117.
January 2015 =DSGRID("LHKHCOLC0115","NAME","Latest Value","","","RowHeader=true;ColHeader=true;DispSeriesDescription=true;DispDatatypeDescription=true","")
February 2015 =DSGRID("LHKHCOLC0215","NAME","Latest Value","","","RowHeader=true;ColHeader=true;DispSeriesDescription=true;DispDatatypeDescription=true","")
ENDQUOTE
Is it possible to query data stream using the python API? Appreciate your help.
Best Answer
-
@rajanraju
There are multiple ways to retrieve historical index constituents as of a given date using Eikon Data APIs. The following method requires you to know the portfolio code of the index, which is different from the index RIC and which you can only look up manually in the PORT app in Eikon.ek.get_data('Index(HSLI,20150331)',['TR.PortfolioConstituentName'])
The following method is the one I personally prefer, however it does not work at the moment due to a known bug. The fix for this bug is expected to be deployed in production at the end of June.ek.get_data('0#.HSLI(20150331)',['TR.RIC'])
For your purposes I think the most efficient way would be to reconstruct index constituents using the list of leavers and joiners. I.e. retrieve current constituents, retrieve the list of stocks that joined and left the index over your observation period, and reconstruct the constituents for each date in your series. Here's the code sample.import pandas as pd
import datetime as dt
import dateutil.relativedelta
import eikon as ek
ek.set_app_key('your_app_key')
ic, err = ek.get_data('.HSLI', ['TR.IndexConstituentRIC'])
lj, err = ek.get_data('.HSLI',
['TR.IndexJLConstituentChangeDate',
'TR.IndexJLConstituentRIC.change',
'TR.IndexJLConstituentRIC'],
{'SDate':'0D', 'EDate':'-55M', 'IC':'B'})
lj['Date']=pd.to_datetime(lj['Date']).dt.date
lj.sort_values(['Date','Change'],ascending=False,inplace=True)
dates = [dt.date(2015,1,30)]
i = 0
while (dates[0] + dateutil.relativedelta.relativedelta(months=+i+1)) < dt.date.today():
dates.append(dates[0] + dateutil.relativedelta.relativedelta(months=+i+1))
i = i + 1
dates.append(dt.date.today())
df = pd.DataFrame(index=dates, columns=['Index Constituents'])
ic_list = ic['Constituent RIC'].tolist()
for i in range(len(dates)):
print(str(dates[len(dates)-i-1]))
df.at[dates[len(dates)-i-1],'Index Constituents'] = ic_list[:]
for j in lj.index:
if lj['Date'].loc[j] <= dates[len(dates)-i-1]:
if lj['Date'].loc[j] > dates[len(dates)-i-2]:
if lj['Change'].loc[j] == 'Joiner':
print('Removing ' + lj['Constituent RIC'].loc[j])
ic_list.remove(lj['Constituent RIC'].loc[j])
elif lj['Change'].loc[j] == 'Leaver':
print('Adding ' + lj['Constituent RIC'].loc[j])
ic_list.append(lj['Constituent RIC'].loc[j])
else:
break
df3
Answers
-
Hi @rajanraju,
As far as I aware, the DataStream service provides access via the APIs: SOAP, REST or using their .NET libraries. In theory you can use Python to access using their REST service but the Eikon Data APIs for Python do not access the data stream services.
0 -
@nick.zincone.1is there a way to get the constituents without going to Datastream?
0 -
Hi @rajanraju,
You do provide what appears to be the correct formula to retrieve the constituents in your question, i.e.
df=ek.get_data('.HSLI', ['TR.IndexConstituentRIC'])
Can you elaborate if this is not what you are asking?
In general, you can use the Data Item Browser to research the assets properties. For example:
If you are not using this tool already, it will provide you with elements and parameters you can directly use within the Eikon Data API.
0 -
@Alex Putkov. Many thanks for the masterclass. Just awesome!!
0 -
awesome indeed. Can anyone tell me what "IC" parameter do?
'IC':'B'
0 -
Hi @newuser
You can use the Data Item Browser to check field parameters.
In this case, IC is "Constituent Change Type", B is "Both"
0 -
Hi guys, how are you?
Retrieving the constituents changes in .BVSP index, I've founded some RICs that not follow the pattern, as in the follow print:
Do you know what these type of RICs means?
0 -
Hi @manuel.alvarez,
This is a really old question and not being monitored. Please ask in a new question.
0 -
Hi guys, how are you?
Retrieving the constituents changes in .BVSP index, I've founded some RICs that not follow the pattern, as in the follow print:
Do you know what these type of RICs means?
0 -
Hi guys, how are you?
Retrieving the constituents changes in .BVSP index, I've founded some RICs that not follow the pattern, as in the follow print:
Do you know what these type of RICs means?
0 -
These RICs are from companies that got delisted indicated by "^".1
Categories
- All Categories
- 6 AHS
- 37 Alpha
- 161 App Studio
- 4 Block Chain
- 4 Bot Platform
- 16 Connected Risk APIs
- 47 Data Fusion
- 30 Data Model Discovery
- 608 Datastream
- 1.3K DSS
- 577 Eikon COM
- 4.9K Eikon Data APIs
- 7 Electronic Trading
- Generic FIX
- 7 Local Bank Node API
- Trading API
- 2.7K Elektron
- 1.3K EMA
- 236 ETA
- 519 WebSocket API
- 33 FX Venues
- 10 FX Market Data
- 1 FX Post Trade
- 1 FX Trading - Matching
- 12 FX Trading – RFQ Maker
- 5 Intelligent Tagging
- 2 Legal One
- 20 Messenger Bot
- 2 Messenger Side by Side
- 9 ONESOURCE
- 7 Indirect Tax
- 59 Open Calais
- 264 Open PermID
- 39 Entity Search
- 2 Org ID
- PAM
- PAM - Logging
- 8.4K Private Comments
- 6 Product Insight
- Project Tracking
- ProView
- ProView Internal
- 20 RDMS
- 1.4K Refinitiv Data Platform
- 367 Refinitiv Data Platform Libraries
- 3 Refinitiv Due Diligence
- LSEG Due Diligence Portal API
- 3 Refinitiv Due Dilligence Centre
- Rose's Space
- 1.1K Screening
- 18 Qual-ID API
- 13 Screening Deployed
- 23 Screening Online
- 10 World-Check Customer Risk Screener
- 990 World-Check One
- 44 World-Check One Zero Footprint
- 45 Side by Side Integration API
- Test Space
- 3 Thomson One Smart
- 1.2K TR Internal
- Global Hackathon 2015
- 2 Specialists Who Code
- 10 TR Knowledge Graph
- 150 Transactions
- 142 REDI API
- 1.7K TREP APIs
- 4 CAT
- 21 DACS Station
- 117 Open DACS
- 1.1K RFA
- 103 UPA
- 172 TREP Infrastructure
- 224 TRKD
- 886 TRTH
- 5 Velocity Analytics
- 5 Wealth Management Web Services
- 59 Workspace SDK
- 9 Element Framework
- 5 Grid
- 13 World-Check Data File
- Yield Book Analytics
- 46 中文论坛