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() instruments.pop(0) 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']) r.dropna()
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 ??
Try something along the lines of:
Get underlying instruments from 0#MCU+ chain
request = tr.get_data(instruments=['0#MCU+'], fields=['X_RIC_NAME'])
Get all underlying instruments in a list of pandas data frames:
dfs = [tr.get_data(instruments=[x], fields=['X_RIC_NAME','DSPLY_NAME']) 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.