Calculate within EIKON API request

Hi,

I am currently trying to retrieve the yearly median of bid-ask spreads for given firms. In Datastream this expression looks like this: MED#((X(PA)-X(PB)/(X(PA)+X(PB)/2)),01/01/2010,31/12/2015) with X being the respective company identifier and frequency set to "Yearly" to get the yearly median.

Is there any way to do the same in the EIKON API? I tried calculating with:

data, error=ek.get_data('MSFT.O', [('TR.ASKPRICE'-'TR.BIDPRICE')/(('TR.ASKPRICE'+'TR.BIDPRICE')/2)], parameters={'SDate':'2010-01-01', 'EDate':'2015-12-31'}) but received an error:

unsupported operand type(s) for -: 'str' and 'str'

Best Answer

  • Alex Putkov.1
    Alex Putkov.1 ✭✭✭✭✭
    Answer ✓

    You have a syntax error in your expression. The second argument of get_data method must be a string or a list of strings. If you'd like the timeseries of the ratio of bid/ask spread to the mid price use:

    ek.get_data('MSFT.O',
                ['TR.BIDPRICE.date',
                 '2*(TR.ASKPRICE-TR.BIDPRICE)/(TR.ASKPRICE+TR.BIDPRICE)'],
                {'SDate':'2010-01-01', 'EDate':'2015-12-31'})

    If you just need the median of the series use:

    ek.get_data('MSFT.O',
                 '2*MEDIAN((TR.ASKPRICE-TR.BIDPRICE)/(TR.ASKPRICE+TR.BIDPRICE))',
                {'SDate':'2010-01-01', 'EDate':'2015-12-31'})

Answers