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

Overview |  Quickstart |  Documentation |  Downloads |  Tutorials |  Articles


13 1 1 4

get_data for all RIC based on an option roots

Hello! Last week you helped me build out the open interest for a range of options for a particular root. But i actually need to go back a step further. (and achieve the same output). so the first try was great, and was as follows:

r, e = ek.get_data(instruments=['0#MCUZ8+'], fields=['X_RIC_NAME']) 
instruments = r['Instrument'].tolist()

r, e = ek.get_data(instruments=instruments, fields=['TR.OPENINTEREST(SDate=0,EDate=-7,Frq=D).date;TR.OPENINTEREST(SDate=0,EDate=-7,Frq=D)','DSPLY_NAME','EXPIR_DATE','CONTR_MNTH','STRIKE_PRC','TR.IMPLIEDVOLATILITY']) 


All good. But the problem is that the option root i really need to examine is 0#MCU+

So as you can see on the screen shot below - the option root calls ALL of the open options - not just the month "Z" as i called in the code above. However, when I plug in the root - i just get blanks.

Is there a way of running teh script for the root and getting the same output - open interest, expir_date, strike_PRC ect ect ??

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

4.6k 26 7 22

Try something along the lines of:

Get underlying instruments from 0#MCU+ chain

request = tr.get_data(instruments=['0#MCU+'], fields=['X_RIC_NAME'])[0]

Get all underlying instruments in a list of pandas data frames:

dfs = [tr.get_data(instruments=[x], fields=['X_RIC_NAME','DSPLY_NAME'])[0] for x in request['Instrument'].tolist()]

Parse out the list of options (every RIC longer than 6 chars):

all_instruments = [x for df in dfs for x in df['Instrument'].tolist() if len(x) > 6]

Please note that for simplicity I am not checking the error object, so such code can not be used in production.

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.

excellent. So i can see the full options list now - with basic display data (i understand code to the line dfs=) - but the last line..hmm not so sure - so can I now parse each RIC and extract the open interest ? 'TR.OPENINTEREST'

options-chain.png (68.4 KiB)

thanks. I got it working now. appreciate your help

yep, you can now create a separate request with all those RICs for the TR.OPENINTEREST field