I'm looking for a code sample, using Refinitiv Data Platform APIs, preferably in python, that would show how to retrieve the list of live option contracts for a given equity or equity index.
I have seen the great article on search (https://developers.refinitiv.com/en/article-catalog/article/building-search-into-your-application-workflow) but wondering if a code snippet illustrating the above question exists.
Yes, the more we look at the results, the more we will filter - search will always be iterative :-).
Good point about the date check - when applying the expiryDate filter, this resulted in ~100 fewer hits for the '.VIX' symbol. Regarding the inability of the UnderlyingQuoteRIC not being able to support the exact match capability, you can always apply a little trickery to force exact matching, i.e.
- ric = "'.VIX'"
- view = rdp.SearchViews.EquityDerivativeQuotes,
- filter = "AssetState eq 'AC' and \
- startswith(UnderlyingQuoteRIC, " + ric + ") and \
- endswith(UnderlyingQuoteRIC," + ric + ") and \
- RCSAssetClass eq 'OPT' and IsChain eq false and \
- ExpiryDate ge " + dt.datetime.today().strftime('%Y-%m-%d'),
- select = "DocumentTitle, RIC, ExpiryDate, CallPutOption, StrikePrice",
- top = 10000
It may not be as clean but should help avoid getting hits for things like 'AAPL.OQ'
I see that field UnderlyingNDAQuoteRICcontains information about underlying instrument but is not "searchable". Here is what I was able to get using PermID of an instrument
permid = rdp.convert_symbols( symbols = ['IBM'], to_symbol_types = [rdp.SymbolTypes.OAPermID] ) rdp.search(view = rdp.SearchViews.EquityDerivativeQuotes, filter = "AssetState eq 'AC' and UnderlyingIssuerOAPermID eq '" + permid['IssuerOAPermID'] + "' and DerivedCategory eq 'OPTION'", select = 'RIC', top=10000 )
rdp.search( view = rdp.SearchViews.EquityDerivativeQuotes, filter = "AssetState eq 'AC' and UnderlyingQuoteRIC eq 'IBM' and \ RCSAssetClass eq 'OPT' and IsChain eq false", select = "DocumentTitle, RIC, ExpiryDate, CallPutOption, StrikePrice", top = 10000 )
I don't know what you were expecting back in terms of rows, but we could possibly narrow down the result set if you see some items in the list that shouldn't be there. For example, the last one in the screenshot below may be something that you want to ignore.
Given how the search is structure I think using the expiry date for filtering might be a good way to go to exclude non-viable RICs (or drop anything from the dataframe that doesn't have one)
rdp.search( view = rdp.SearchViews.EquityDerivativeQuotes, filter = "AssetState eq 'AC' and UnderlyingQuoteRIC eq 'IBM' and \ RCSAssetClass eq 'OPT' and IsChain eq false and \ ExpiryDate ge " + date.today().strftime('%Y-%m-%d'), select = "DocumentTitle, RIC, ExpiryDate, CallPutOption, StrikePrice", top = 10000 )
On the "live" part; in my experience it's best to use the ExpiryDate to filter for live options, I've seen on occasion a delay between an option contract expiring and being removed from the real time feeds, and actually being tagged as inactive and being removed from search like here for the first couple here (expired yesterday, no longer retrievable but still in search):
Something to be aware of re UnderlyingQuoteRIC as criterion. It uses an exact match to produce results. I.e. you need the specific listing that the options are listed for. Especially for US options this might prove a problem from a user perspective, as they may be looking at specific exchange listing like NYSE (IBM.N), or Nasdaq (AAPL.OQ) whereas the options themselves have the consolidated listings as underlyings (IBM, AAPL.O). So possibly the approach @marcin.bunkowski suggested might be valid.