Hello QC Community,
I would like to know whether it's possible to add the Delta variable in the OptionChainProvider at the filtering function of self.otm_puts and self.otm_calls.
def OptionsFilter(self,data,ticker):
contracts = self.OptionChainProvider.GetOptionContractList(ticker, data.Time)
self.UnderlyingPrice = self.Securities[ticker].Price
self.otm_puts = [x for x in contracts if self.UnderlyingPrice - x.ID.StrikePrice < 0 and x.ID.OptionRight == 1 and
self.DELTAX < (x.ID.Date - data.Time).days < self.DELTAY]
self.otm_calls = [x for x in contracts if self.UnderlyingPrice - x.ID.StrikePrice > 0 and x.ID.OptionRight == 0 and
self.DELTAX < (x.ID.Date - data.Time).days < self.DELTAY]
contracts = self.otm_calls + self.otm_puts
if len(contracts) == 0:
return None
for contract in contracts:
option = self.AddOptionContract(contract, Resolution.Minute)
option.PriceModel = OptionPriceModels.CrankNicolsonFD()
return self.otm_calls, self.otm_puts
Louis Szeto
Hi Thomas
Since you are not subscribed to the option Security object, I guess you cannot do it in this way?! but it's possible on slice.OptionChains method in OnData. Sadly it of course will be slower to call excessive security objects jammed your computational power.
Cheers
Louis
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.
Varad Kabade
Hi Thomas van Buuren and Louis,
The SetFilter helper method does not allow to filter contracts based on Greeks value. We recommend using the following code snippet to filter out various types of options(ITM, OTM, ATM).
We don't need to add contracts inside our OnSecuritiesChanged method. The algorithm has already subscribed to the contracts, and then it is sent to the given event handler.
Â
Best,
Varad Kabade
.ekz.
Hi Thomas van Buuren  and Louis Szeto .
I'm a discretionary options trader, so I understand the importance of selecting contracts using precise Deltas. I saw this thread and decided to write up a simple example that does so.
Louis: your example is a good one as well, though note that you need to warm up for at least 30 days for the correct greeks to be calculated --currently you are warming up for 7 days.Â
Hope this helps:Â
Â
Thomas van Buuren
Hi .ekz., Louis Szeto, and Varad kabade,
Thanks for the information and input. However, I only want to subscribe to option contracts that are specifically needed, for fifteen equity symbols. The backtest runs for four years. When using SetFilter, one backtest will cost 4/5 hours to complete. The ones that Lious and Varad are suggesting are about receiving the OptionChains without subscribing to the options in the Initialize method. Meaning that we only subscribe to the returned filtered option (Varad) or when the algorithm market orders an option (Lious), correct? Is there any documentation that elaborates these specific situations?
Â
Varad Kabade
Hi Thomas,
Â
The ones that Lious and Varad are suggesting are about receiving the OptionChains without subscribing to the options in the Initialize method
This is incorrect. We cannot use OptionChainProvider because we are trying to sort the contract by the delta values. To speed up the run-time, we can make the option filter more restrictive. For example, only subscribing to contracts within 5 strikes instead of 60 or contracts that expire within 30 days instead of 180. Also, please check this tutorial.
Best,
Varad Kabade
Thomas van Buuren
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!