I'm trying to get the sum of all assets of stocks in the ASX 200 Index. However, the constituent stocks of the index change over time. Therefore, i tried running a while loop for the following DFO function.
=DSGRID("LASX200I0900","LIST#(X,X(WC02999),SUM)","2000-09-01","2000-09-21","W","RowHeader=true;ColHeader=true;DispSeriesDescription=false;YearlyTSFormat=false;QuarterlyTSFormat=false","")
- where the instrument "LASX200I0900" gets updated for every loop, i.e. constituents for Sep 2000 becomes LASX200I0900, for Oct 2000 becomes LASX200I1000 (So LASX200I+mmyy).
My guess is that as Instruments change, DatastreamDSWS class cannot contain it as one time series and causing issue.
Would appreciate if you can assist - whether it be resolving the error, or advise on a different approach.
PYTHON CODE: You can copy paste the following into Jupyter notebook (for some reason cannot upload the file itself)
import pandas as pd
import datetime as dt
import DatastreamDSWS as DSWS
# ds = DSWS.Datastream(username ="username", password="password")
ds = DSWS.Datastream(username ="username", password="password")
Index = 'LASX200I' # 1. Input your index root mnemonic
Data_Type = 'WC02999' # 2. Input your Datatype
End_Date = dt.datetime.now()
End_Date = dt.datetime(End_Date.year,End_Date.month-1,End_Date.day)
Date = dt.datetime(2000,9,1) # 3. Input your start year and date. Day is set as 1st of month. Please check start date from DS
Start_Year = Date.year
Start_Month = Date.month
while Start_Month <= 12 and Date < End_Date:
Index_t = Index + Date.strftime("%m") + Date.strftime("%y")
Output_Total =[]
Field1 = 'LIST#(X,X(' + Data_Type + '),SUM)'
Start = Date.strftime("%Y") + '-' + Date.strftime("%m") + '-' + Date.strftime("%d")
End = Date.strftime("%Y") + '-' + Date.strftime("%m") + '-' + str(Date.day+21)
# print(Start,End)
Output_Total.append(ds.post_user_request(tickers=Index_t, fields=[Field1], start=Start, end=End, freq = "w"))#Timeseries data
#Output_Total.append(ds.post_user_request(tickers=Index_t, fields=['LIST#(X,X(WC02999),SUM)'], start='2000-09-01', end='2000-09-21', freq = "W"))#Timeseries data
#'LIST#(X,X('+Data_Type+')*X(MV),SUM)'
# print(Index_t)#checking ticker
Start_Month = Start_Month%12 + 1
if Start_Month == 1:
Start_Year+=1
Date = dt.datetime(Start_Year,Start_Month,1)
else:
Date = dt.datetime(Start_Year,Start_Month,1)
ds.get_bundle_data(bundleRequest=Output_Total)