using datastream API, how to get constituents of a stock index list, and then get the financial indicators of the stocks achieved.
for example, get the main financial indicators of the companies listed in S&P 500
using datastream API, how to get constituents of a stock index list, and then get the financial indicators of the stocks achieved.
for example, get the main financial indicators of the companies listed in S&P 500
Hi @tutan,
Have you had a look at the LSEG Developer Portal's Datastream page? In particular, the Documentation tab? I believe that the information you are after might be found there.
Else, I had a look into the Datastream Navigator to find the mnemonic that may link to S&P 500, and found "LS&PCOMP". Then reading the documentation, it looks like you need "|L" at the end of the mnemonic to get the constituent list:
import DatastreamPy as ds # We can use our LSEG's Datastream API keys that allows us to be identified by Refinitiv's back-end services and enables us to request (and fetch) data: Credentials are placed in a text file so that it may be used in this code without showing it itself. ds_username = open("Datastream_username.txt", "r") ds_password = open("Datastream_password.txt", "r") ds = ds.DataClient( config=None, username=str(ds_username.read()), password=str(ds_password.read()), proxies=None, sslVerify=None, sslCert=None) # It is best to close the files we opened in order to make sure that we don't stop any other services/programs from accessing them if they need to. ds_username.close() ds_password.close() # # Alternatively one can use the following: # import getpass # dsusername = input() # dspassword = getpass.getpass() # ds = dsws.Datastream(username = dsusername, password = dspassword) ds.get_data(tickers='LS&PCOMP|L', fields =["MNEM"], kind=0)
Note that my credentials are placed in a text file so that it may be used in this code without showing it itself:
df_of_mnemonic = ds.get_data(tickers='LS&PCOMP|L', fields =["MNEM"], kind=0) df_list = df_of_mnemonic.Value.to_list() print(df_list)
ds.get_data(tickers=",".join(df_list[0:10]), fields =["P"], kind=0)
I'm not sure what you mean by "financial indicators"; do you have a field name in Datastream that refers to it?