Discover Refinitiv
MyRefinitiv Refinitiv Perspectives Careers
Created with Sketch.
All APIs Questions & Answers  Register |  Login
Ask a question
  • Questions
  • Tags
  • Badges
  • Unanswered
Search:
  • Home /
  • Eikon Data APIs /
avatar image
Question by Florian92 · Apr 02, 2020 at 07:26 PM · eikon apiget_datacalculatemathematical operators

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'

People who like this

0 Show 0
Comment
10 |1500 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

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

2 Replies

  • Sort: 
avatar image
REFINITIV
Best Answer
Answer by Alex Putkov. · Apr 02, 2020 at 08:07 PM

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'})
Comment
Florian92

People who like this

1 Show 0 · Share
10 |1500 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

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

avatar image
Answer by Florian92 · Apr 02, 2020 at 08:24 PM

Thank you very much!! Ok, I see my mistake. I tried both of your suggestions but I get the same (daily) values for both requests. In the very end I am only interested in yearly median of my bid-ask spreads.I think I have to run each year separately right? Or is there any way to use lets say a five year period

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

which retrieves only the median value for each year (MSFT.O, 2010, XX; MSFT.O, 2011, XX; MSFT.O, 2012, XX....)?

Comment

People who like this

0 Show 4 · Share
10 |1500 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

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

avatar image
REFINITIV
Alex Putkov. ♦♦ · Apr 02, 2020 at 08:34 PM 0
Share

To get the annual median you either need to submit separate get_data request for the median for each year or you can retrieve the entire daily series and calculate the annual median using capabilities of pandas.

avatar image
Florian92 Alex Putkov. ♦♦ · Apr 02, 2020 at 08:41 PM 0
Share

Ok, thats what I expected. Should not be a problem using pandas. Using your (corrected) expression above however still gives me dialy values even when using the MEDIAN operator. Do I need to specify frequency 1Y or "Yearly" as in Datastream somewhere?

avatar image
REFINITIV
Alex Putkov. ♦♦ Florian92 · Apr 02, 2020 at 09:09 PM 0
Share

I'm not sure I understand. My original example that uses MEDIAN function in the field expression returns pandas dataframe with a single row, which contains the median for the daily series framed by the values of SDate and EDate parameters. It does not return daily series.

median.png (56.9 KiB)

Watch this question

Add to watch list
Add to your watch list to receive emailed updates for this question. Too many emails? Change your settings >
12 People are following this question.

Related Questions

get_data returns multiple lines instead of one. leading to many 400 errors when requesting

Eikon API - get_data estimate - footnote does not align

ek.get_data Historic data

Adding year/qtr/date to data frame retrieved from get_data function

How to sort an ek.get_data request by instrument and fiscal period (absolute)?

  • Feedback
  • Copyright
  • Cookie Policy
  • Privacy Statement
  • Terms of Use
  • Careers
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Alpha
  • App Studio
  • Block Chain
  • Bot Platform
  • Calais
  • Connected Risk APIs
  • DSS
  • Data Fusion
  • Data Model Discovery
  • Datastream
  • Eikon COM
  • Eikon Data APIs
  • Elektron
    • EMA
    • ETA
    • WebSocket API
  • Legal One
  • Messenger Bot
  • Messenger Side by Side
  • ONESOURCE
    • Indirect Tax
  • Open PermID
    • Entity Search
  • Org ID
  • PAM
    • PAM - Logging
  • ProView
  • ProView Internal
  • Product Insight
  • Project Tracking
  • Refinitiv Data Platform
    • Refinitiv Data Platform Libraries
  • Rose's Space
  • Screening
    • Qual-ID API
    • Screening Deployed
    • Screening Online
    • World-Check One
    • World-Check One Zero Footprint
  • Side by Side Integration API
  • TR Knowledge Graph
  • TREP APIs
    • CAT
    • DACS Station
    • Open DACS
    • RFA
    • UPA
  • TREP Infrastructure
  • TRIT
  • TRKD
  • TRTH
  • Thomson One Smart
  • Transactions
    • REDI API
  • Velocity Analytics
  • Wealth Management Web Services
  • World-Check Data File
  • Explore
  • Tags
  • Questions
  • Badges