how to convert rics or symbols to mnem for dsws?

hi,

I am trying to retrieve historical price data for a list of instruments with python Eikon and datastream. My dynamic list of instruments come from Eikon port


TotalList=(['Portfolio(0867/*Total List*/)'])
dataset, err=ek.get_data(TotalList,['tr.PriceClose'])
rics1 =pd.DataFrame(dataset.loc[:1,'Instrument'])
rics2 = rics1["Instrument"]
rics3 = rics2.tolist()


How do I convert the list of symbols to a list of mnemonics so that I can pass it through to a datastream query?:


ds=dsws.Datastream(username=xxxxxxxxxxxxxx,password='xx')

df=ds.get_data (tickers='mnemonics',
fields=['P'], start='2018-01-01', end='2018-01-10', freq='D')


Many thanks

Best Answer

  • @calice.l

    According to the function signature, the tickers argument of get_data method of dsws library cannot be a list. It must be a string of comma separated symbols. Try

    df, err = ek.get_data('Portfolio(SAMPLE_RU_LRGCORE)',['TR.CommonName'])
    df['DatastreamRICs'] = '<' + df['Instrument'] + '>'
    ds_rics_str = df['DatastreamRICs'].str.cat(sep=',')
    ds.get_data(ds_rics_str, fields=['P'], 
                start='2018-01-01', end='2018-01-10', freq='D')

    Note that the max number of symbols for get_data method of dsws library is 50. If your portfolio has more than 50 constituents, you need to split it into chunks of 50.

Answers

  • You don't need to convert RICs to Datastream mnemonics. You can use RICs in get_data method of DSWS library by enclosing each RIC into angle brackets, e.g.

    ds.get_data('<MSFT.O>,<AAPL.O>,<IBM.N>', fields=['P'], 
                start='2018-01-01', end='2018-01-10', freq='D')
  • Hi Alex,

    thanks for the input!

    Obviously new to this and still doing something wrong:

    TotalList=(['Portfolio(500867312/*Total List*/)'])
    dataset, err=ek.get_data(TotalAssetList,['tr.PriceClose'])
    rics1 =pd.DataFrame(dataset.loc[:,'Instrument'])

    rics1["Instrument"]='<'+rics1+'>'

    rics2 = rics1["Instrument"]

    rics3 = rics2.tolist()

    df=ds.get_data (tickers=rics3,
    fields=['ER#S'], start='2018-01-01', end='2018-01-10', freq='D')


    print(df)


    get_data : Exception Occured

    (<class 'AttributeError'>, AttributeError("'list' object has no attribute 'rfind'"), <traceback object at 0x00000190C20DC3C0>)



  • again, that worked well (for my equity dataset), thanks!

    However I'm also trying to retrieve historical pricing for a number of fixed income instruments that have matured. so I'm using

    fields =['TRPA']


    which does not work with "<RICs>". Is there another workaround for converting RICs to Datastream mnemonics (or is this another misunderstanding?)?

  • I'm not sure I understand the scenario. Matured bonds don't have RICs. RICs for instruments that become inactive are removed from Refinitiv Real-Time network. If you have ISIN for the bond, you can use it to retrieve price history for that bond from Datastream, e.g.

    ds.get_data('XS1035001921', fields=['MPD'], 
                start='2019-03-01', end='2019-04-01')

    Note that in the above example I used ISIN for a bond that matured on 2019-04-18.

    And if for whatever reason you need Datastream mnemonic for this bond, you can get it using

    ds.get_data('XS1035001921', fields=['MNEM'], kind=0)
  • thanks, had just realised that ISIN will provide data needed!