Historical data : MarketCap of all listed companies in Japan.

I'm struggling with combining ① wiht ②. I'd greatly appreciate any suggestions you might have.


① I can get all listed companies in Japan with the below.

universe='SCREEN(U(IN(Equity(active,public,primary))/*UNV:Public*/),IN(TR.ExchangeCountryCode,"JP"), IN(TR.InstrumentTypeCode,"ORD"), CURN=JPY)'

data, err = ek.get_data(instruments=universe, fields=['TR.CommonName'])

data.head()

② I can get the historical data of some companies' MarketCap like this.

data= ek.get_data(['2195.T','3639.T','3640.T','3641.T'], ['TR.CompanyMarketCap'],

{'SDate': '2019-8-31', 'EDate':'2015-9-30', 'Period':'FQ0','FRQ': 'M','Scale': 6})

print(data)

by @tnksnsk314

Best Answer

  • Hi @tnksnsk314

    I would suggest you to split the call into 2 calls.

    1. Get RIC list first

    universe='SCREEN(U(IN(Equity(active,public,primary))/*UNV:Public*/),IN(TR.ExchangeCountryCode,"JP"), IN(TR.InstrumentTypeCode,"ORD"), CURN=JPY)'
    df,e = ek.get_data(universe, ['TR.RIC'])
    ric_list = df['Instrument'].tolist()

    #split the list into a smaller list (to avoid hitting limit)
    ric_list1 = ric_list[0:1000]
    ric_list2 = ric_list[1000:2000]
    ric_list3 = ric_list[2000:3000]
    ric_list4 = ric_list[3000:]


    2. Get MarketCap and MarketCap date from the RIC list

    data1, err = ek.get_data(ric_list1,['TR.CompanyMarketCap.Date','TR.CompanyMarketCap'],
                      {'SDate': '2015-9-30', 'EDate':'2019-8-31', 'Period':'FQ0','FRQ': 'M','Scale': 6})
    data1.head()

    Here is sample output:

    image


    I was able to get the data back from the whole list at once, but this is not suggested.

    image

Answers