Index Constituents - Start of every year with Market Cap

Hi

I want to get the index constituents of the .TRXFLDINP index from the start of every years since 2012, along with the Market Cap and Average Value Traded (so Volume x Price) at the start of every year.

I have gone through some of the questions posted but do not find the solution I am looking for.

Thanks

Best Answer

  • Hi @vbala ,

    I would try to divide the task:

    1. Compile the list of dates at the beginning of the year
    2. Request the list of constituents
    3. Request the market caps and average values traded

    Try this, and you may wish to tune the approach on your side to your requirements:

    import datetime
    for year in range(2012, 2022):
    sdate_for_year = str(year)+'-01-01'
    print("sdate ", year, " = ", sdate_for_year)

    df, err = ek.get_data(
    instruments = ['.TRXFLDINP'],
    fields = ['TR.IndexConstituentRIC',
    'TR.IndexConstituentName'],
    parameters = {
    'SDate':sdate_for_year
    }
    )
    print('Constituents:')
    print(df)

    df2, err = ek.get_data(
    instruments = df['Constituent RIC'].tolist(),
    fields = ['TR.CompanyMarketCap',
    'TR.AvgMonthlyValTraded1Year'],
    parameters = {
    'SDate': sdate_for_year
    }
    )
    print(df2)

    This results in the output:

    mcapout.gif

    Hope that this suggestion is of help


Answers

  • Thank you
  • Hello @vbala ,

    My understanding is that you have copied the code, and the request should be exactly the same, the request is valid.

    Is the error consistent, do you reproduce it repeatedly?

    Is it specific to this request, are you able to run other requests at this time, for example:

    ek.get_data('IBM.N','ASK')