How to convert the ticker to RIC and then retrieve the market cap?

Hi, I encountered a problem as mentioned in the title. Currently, I have two ways:

1. rdp.convert_symbols(), where rdp is refinitiv.dataplatform

2. ek.symbology().

Take ['AAPL' , 'MSFT'] as an example. I found method 1 always requires a login and requires to open a session. Is that possible to avoid this issue. I mean only providing app key, say. Is there any converting function in refinitiv.data package?

If I turn bestmatch to True, the function always returns me an error but if False, it's a list. Should I simply select the first component of the list?

Then, for retrieving market cap, which function can I use to complete it more efficiently? Is that possible to only use eikon built-in functions to implement this?

Best Answer

  • @CharlesYan

    Thank you for reaching out to us.

    You can use the Refinitiv Data Library for Python instead. The library can be configured to use the desktop session that retrieves data via Eikon or Refinitiv Workspace by using the application key.

    The code to convert tickers to RICs looks like this.

    response = symbol_conversion.Definition(
        symbols=["AAPL","MSFT"],
        from_symbol_type=symbol_conversion.SymbolTypes.TICKER_SYMBOL,
        to_symbol_types=[
            symbol_conversion.SymbolTypes.RIC
        ],
    ).get_data()

    response.data.df

    The sample code is on GitHub.

    Then you can use the retrived RICs with the get_data method to retrieve the market cap.

    rd.get_data(["AAPL.O","MSFT.O"],fields=["TR.F.MktCap"])

Answers

  • Hi, Jirapongse. Thx so much for such a quick response. It works to me but I found some problems in retrieving market caps from below RICs:

    DIVL.K, CONY.K, ROYA.K, NDIA.K, BRAZ.K, etc. I searched them in eikon but they have valid MCap values.

  • There is also another problem. For attempts that failed to retrieve the corresponding RIC. Do you know how I can at least give a NA or something else to label it? I input a list of tickers with length 2000, say, but the code returned a dataframe with 1980 rows. The failed attempts were directly discarded by the code.
  • BTW, can I confirm with you that using rd does not require to set app key first, does it?
  • Hi @CharlesYan

    You can try and merge the results yourself to a dataframe by iterating over a raw response

    import pandas as pd
    #create an empty dataframe where you will concatenate the results
    converted = pd.DataFrame(columns=["Ticker","DocumentTitle","RIC"])

    tickers = ["AAPL","UNKNOWN","MSFT"]

    response = symbol_conversion.Definition(
    symbols= tickers,
    from_symbol_type=symbol_conversion.SymbolTypes.TICKER_SYMBOL,
    to_symbol_types=[
    symbol_conversion.SymbolTypes.RIC,
    ]
    ).get_data()

    #loop throught he list of results and check if the converted symbol was found
    for t in tickers:
    try:
    converted.loc[len(converted)] = [t,response.data.raw['Matches'][t]['DocumentTitle'],response.data.raw['Matches'][t]['RIC']]
    except KeyError:
    converted.loc[len(converted)] = [t,"",""]

    converted
  • @CharlesYan

    Please try with "TR.CompanyMarketCap" field.

  • @CharlesYan

    It still requires app key but you can set it in the configuration.

    1699960129515.png

    Then, set the sessions.default to "desktop.workspace".


  • Does it mean before I run my code, I need to run a file with this configuration?
  • Hi, Bunkowski. Thx for the assistance in detail. I will have a try right now.