Requesting index constituents' prices in python
Hey there,
I am using the Datastream API in Python and I am tyring to retrieve historical end-of-month prices for all constituents of the Euro Stoxx 50 index in the selected period. The problem here is that the constituents have changed over the years so my initial thought was to create a dictionary first that delivers the constituents for every month in the selected period and after that making another datastream request based on the listed constituents in each month. Unfortunately, I've reached my data limit for this month because I ran my code multiple times and it seems like my code was quite inefficient retrieving the names and prices for 50 constituents every single month.
My code is the following:
import pandas as pd
import PyDSWS as dsws
import time
from datetime import date
from datetime import timedelta
from dateutil.rrule import rrule, MONTHLY
import calendar
#%%
ds = dsws.Datastream(username="xxxx",password="yyyy")
#%%
start_date = date(2018, 1, 31)
end_date = date(2023, 1, 31)
#%%
date_range = pd.date_range(start=start_date, end = end_date, freq='M').strftime('%Y-%m-%d')
#%%
data_dict = {}
for date in date_range:
data = ds.get_data('LDJES50I0118', fields = ['ISIN'],date=date)
data_dict[date] = data
#%%
data_dict_list = {k:v.values.tolist() for k,v, in data_dict.items()}
#%%
prices_dict = {}
for date, securities in data_dict_list.items():
prices = ds.get_data(securities, fields = ['P'], start = date, end = date)
prices_dict[date] = prices
#%%
df = pd.concat(prices_dict.values(), axis=0)
I know there have been similar questions on this platform, but I couldn't find a case where someone kept the changing constituents in mind. Does anyone have an idea of how to make this code more efficient so that I don't reach my datalimit after a couple of requests? Maybe by storing the requested results or anything similar?
Thank you in advance for your help!
Best Answer
-
Hi @roman.lengeling ,
I reached out to a specialist in-house to make sure, but to the best of my knowledge, your method is the only one that'd work. I'd advise using the `|L` nomenclature as shown here - to get constituents though - have you tried that? You could also get the lists on DFO and bring them into Python afterward, as shown here, giving you a higher request limit in effect.1
Answers
-
Hi
@jonathan.legrand ,thank you for your help. I haven't tried both of your recommmendations yet. I will try them first as soon as my account is unlocked again
0
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 中文论坛