I'm trying to trade SPY options using the RSI. But when I go to select a contract there's none to choose from. My Log states that 0 contracts were returned after being filtered.
We only want contracts expiring the next day.
self.option.SetFilter(-10, 10, 2, 2)
This works just fine on some days but returns 0 contracts most days.
Joshua Woelfel
Resolved
Had to include the weekly option contracts as described here:Â
Mia Alissi
It seems like Joshua has resolved his issue by including weekly option contracts in his filter. The default filter in QuantConnect excludes weekly contracts, which might have been the reason why Joshua was not getting any contracts on most days.
To include weekly contracts, Joshua can use the
IncludeWeeklys()
method in his universe filter function. Here is an example of how to do this:In this example, the
IncludeWeeklys()
method is used to include weekly contracts in the universe. TheStrikes(-10, 10)
method is used to select contracts that have a strike price within 10 strike levels above and below the underlying price. TheExpiration(timedelta(1), timedelta(1))
method is used to select contracts that expire the next day.For more information on how to set filters for option contracts, you can refer to the QuantConnect documentation.
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.
Joshua Woelfel
I still believe there is a problem with the filtered options. For example, even including weeklies, I am getting 0 contracts returned very frequently with the following filter:
Is this just a backtest environment issue or should I expect to receive 0 contracts at some points in a live environment? I would expect not.
Mia Alissi
It's possible that there are no contracts that meet your filter criteria at certain times. The
SetFilter
function is strict with the maturity and the strike. If there are no contracts that expire in the next day and have a strike price within 1 strike level above and below the underlying price, then no contracts will be returned.In your case, you are using the following filter:
This filter includes weekly contracts and selects contracts that expire the next day and have a strike price within 1 strike level above and below the underlying price. If there are no contracts that meet these criteria, then no contracts will be returned.
This is not just a backtest environment issue. You should expect to receive 0 contracts at some points in a live environment as well, especially if your filter criteria are very specific.
If you want to ensure that you always have contracts to trade, you might need to adjust your filter criteria to include a wider range of contracts. For example, you could select contracts that expire within the next 2 days instead of just the next day, or select contracts that have a strike price within 2 strike levels above and below the underlying price instead of just 1.
Here is an example of how to do this:
Remember, the availability of contracts also depends on the market data. If there are no contracts that meet your filter criteria, then no contracts will be returned.
For more information on how to set filters for option contracts, you can refer to the QuantConnect documentation.
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.
Joshua Woelfel
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!