For a deeper look into our Eikon Data API, look into:

Overview |  Quickstart |  Documentation |  Downloads |  Tutorials |  Articles

question

Upvotes
Accepted
5 0 0 4

Get RIC for the largest 10 companies in each stock market

I was trying to get the largest 10 companies with respect to the market cap each year for a list of countries over a particular time period. I use a loop like this:

country = ["IR","NL"]
for i in country: 
    for j in range(2000,2006,5):
        Start=str(j)+'-12-31'
        instruments = 'SCREEN(U(IN(Equity(active or inactive,public,primary))),IN(TR.ExchangeCountryCode, i),TOP(TR.CompanyMarketCap(SDate=Start), 10, nnumber), CURN=USD)'
        field = ["TR.CommonName"]
        df,err = ek.get_data(instruments, field)

But in the loop, the "i" is not recognised as item in the country list and the "Start" is not recognised as the variable created within the loop.

Any solution for the problem? or is there a better way to obtain the requested RIC codes?

Thank you.

eikon-data-apirefinitiv-dataplatform-eikonscreening-apiscreeneradfin
icon clock
10 |1500

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

1 Answer

Upvote
Accepted
24.9k 86 10 22

Hi @Jiaman.Xu

you are hardcoding the literal strings 'i' and 'Start' into the string parameter 'instruments' - so the value you are actually passing to the get_data calls looks like:

SCREEN(U(IN(Equity(active or inactive,public,primary))),IN(TR.ExchangeCountryCode,i),TOP(TR.CompanyMarketCap(SDate=Start), 10, nnumber), CURN=USD)'

rather than something like:

SCREEN(U(IN(Equity(active or inactive,public,primary))),IN(TR.ExchangeCountryCode,'IR'),TOP(TR.CompanyMarketCap(SDate='2000-12-31'), 10, nnumber), CURN=USD)'

You need to use python string formatting to substitute the actual values of 'i' and 'Start' into the 'instruments' parameter e.g.

country = ["IR","NL"]
content_df = []
for i in country: 
    for j in range(2000,2006,5):
        Start=str(j)+'-12-31'
        instruments = f'SCREEN(U(IN(Equity(active or inactive,public,primary))),IN(TR.ExchangeCountryCode,{i}),TOP(TR.CompanyMarketCap(SDate={Start}), 10, nnumber), CURN=USD)'
        field = ["TR.CommonName"]
        df,err = ek.get_data(instruments, field)
        content_df.append(df)

You can read up on Python string formatting on the web .e.g. Python String Formatting Best Practices – Real Python

Note that I am not that familiar with the SCREEN function - so cannot confirm if the above is returning what you are after..

icon clock
10 |1500

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.