Hi, i am trying to create a strategy that looks at same day SPX options and am having trouble getting the filtering to work.
I start by adding the option options symbols and setting up the filtering:
option = self.add_index_option(self.spx, 'SPXW', Resolution.HOUR) #spxW is the tradeable on same day options
option.SetFilter(lambda option_filter_universe : option_filter_universe.IncludeWeeklys().Strikes(-5, 5).Expiration(0, 0))
self.spxOption = option.symbol
And then when i get the data i am looping through each contract and logging some data to check what contracts i got:
def OnData(self, slice: Slice) -> None:
if self.is_market_open(self.spxOption) and self.spx in slice.bars:
SPXChain = slice.option_chains.get(self.spxOption)
SPXTradeBar = slice.bars[self.spx]
if SPXChain:
for contract in SPXChain:
self.debug(f"{contract.symbol} | time: {slice.time} | closeTime: {market_close_time} | type: {type} | strike: {contract.Strike} | market: {SPXTradeBar.close} | lastUnder: {contract.UnderlyingLastPrice})
My expectation is that i would get 10 total contracts per time period with 5 under the current clossest to market strike and 5 over it.
However when i look through the logs i am getting the below:
As you can see, at this time the current underlying for spx is $4734.75. Since the strikes are in $5 increments the closest strike would be $4735. So i would expect to get 5 below that and 5 above but for some reason i am getting strikes starting at $4750 and going up.
Any help would be appricated.
Mia Alissi
Let's go through the code and see what might be causing the issue with the filtering of SPX options.
Adding the Index Option:
'SPXW'
as the ticker for same-day options, which is correct for SPX weekly options. Ensure that theResolution.HOUR
is appropriate for your strategy. If you need more frequent updates, consider usingResolution.MINUTE
.Filter Setup:
OnData Method:
SPXChain
and logging the contract details. Ensure that thecontract.Strike
andcontract.UnderlyingLastPrice
are being logged correctly.Potential Issues:
Debugging Steps:
SPXChain
is being populated with the expected contracts.Here's an updated version of your
OnData
method with additional logging:By logging the available strikes, you can verify if the data source is providing the expected strikes. If the issue persists, consider reaching out to the data provider to ensure that the expected strikes are available for the SPX options.
Sources: Greeks and IV Implementation, Basic Template S P X Weekly Index Options Algorithm, Automating the Wheel Strategy, Index Option Call I T M Greeks Expiry Regression Algorithm, Index Option Bull Put Spread Algorithm
The material on this website is provided for informational purposes only and does not constitute an offer to sell, a solicitation to buy, or a recommendation or endorsement for any security or strategy, nor does it constitute an offer to provide investment advisory services by QuantConnect. In addition, the material offers no opinion with respect to the suitability of any security or specific investment. QuantConnect makes no guarantees as to the accuracy or completeness of the views expressed in the website. The views are subject to change, and may have become unreliable for various reasons, including changes in market conditions or economic circumstances. All investments involve risk, including loss of principal. You should consult with an investment professional before making any investment decisions.
Ryan Klingert
So i know that there is more lower contracts available because if i change the -5 filter to -10 i get the below data. I would expect to then see 15 contracts from -10 to +5 but instead am getting 15 contracts from -3 to +12. Showing their is lower data than shown above.
Ryan Klingert
One more thing: the spacing appears to be random somewhat random between on data calls. For example above i am calling hourly. Changing the filters to -2 to +2 (so that i can fit more hours in one image) you see that from hour to hour it jumps around with no apparent pattern.
Shown above the first one is -2 to +1, then +1 to +3, then -2 to +1, then -8 to -5
Ryan Klingert
For those following along, i believe i have narrowed down the issue to be that the options filter appears to only be updating at the start of each day. Not hourly on each call. But i have not figured out how to fix that
Ryan Klingert
The material on this website is provided for informational purposes only and does not constitute an offer to sell, a solicitation to buy, or a recommendation or endorsement for any security or strategy, nor does it constitute an offer to provide investment advisory services by QuantConnect. In addition, the material offers no opinion with respect to the suitability of any security or specific investment. QuantConnect makes no guarantees as to the accuracy or completeness of the views expressed in the website. The views are subject to change, and may have become unreliable for various reasons, including changes in market conditions or economic circumstances. All investments involve risk, including loss of principal. You should consult with an investment professional before making any investment decisions.
To unlock posting to the community forums please complete at least 30% of Boot Camp.
You can continue your Boot Camp training progress from the terminal. We hope to see you in the community soon!