I am adding options to universe like this:
option = self.AddOption("AAPL", Resolution.Minute)
I want to filter options by the Strike relatively, e.g. +/- 10% of current price, I am trying to do something like this:
strike_dist = ceil(security.Price * 0.1 / option.StrikePrice)
option.SetFilter(minStrike=-strike_dist, maxStrike=strike_dist)
However, when I check in runtime, option.StrikePrice is 0, probably because there was no data loaded yet. So not sure how can I implement something like this here. I should I wait till I get any data first and call SetFilter? But this way filters may get wrong contracts for me until I do the rproper call. And in general this would result in quite messy code.
Yuri Lopukhov
Actually, I don't think I should use StrikePrice in the calculation. Basically, I need to know what strike distance to provide in SetFilter() function. For that I need to know the cost of 1 strike distance in quote currency. How can I do that? Can't seem to find the proper field.
Nico Xenox
Hey Yuri LopukhovÂ
I'm not sure if this would help you but maybe you could try to use ‘self.OptionChainProvider.GetOptionContractList’ and sort for strike prices that are within the +/- 10% range.Â
Â
I made the calculations for you. I checked the values in the debuger and it seems to work and also added a plot system that shows you with each buy where the max, min and current strike price is.
Hope it helps ;)
Yuri Lopukhov
Hi, Nico Xenox, yes, I am doing such filtering as well in my code (I have other conditions), but I need to limit amount of data I am getting in the algorithm. Unfiltered options may have hundreds of contracts, and I need to support multiple equity options, so I need to filter universe at least roughly, so I get less contracts selected and less data to process.
Derek Melchin
Hi Yuri,
To select all of the contracts within 1 strike distance of the underlying price, we can useÂ
To get the strike distance between the contracts or to select contracts based on a percentage distance from the underlying price, use a OptionFilterUniverse as the filter. Specifically, we can use the Symbol.Underlying property of the contracts to get the underlying price in the filter function.
Best,
Derek Melchin
Want to invest in QuantConnect as we build the Linux of quant finance? Checkout our Wefunder campaign to join the revolution.
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.
Yuri Lopukhov
Hi, Derek Melchin is there no way to find out how much 1 strike distance in USD in LEAN?
As I mentioned, I am filtering later when I have the price data, but I do not want to pipe all unfiltered options prices in the algorithm, I would like to filter it by strike, but relatively to the price.
Derek Melchin
Hi Yuri,
To find the strike distance, we at least need the Symbol objects of the Option contracts, which are passed to the contract filter method.Â
If we use the filter method and select a subset of the contracts, the OnData method won't receive prices for all of the Option contracts. It will only receive the prices for the contracts we select in the filter function.
See the attached backtest for an example that selects contracts at the filter level based on a percentage distance of their strike prices to the underlying.
Best,
Derek Melchin
Want to invest in QuantConnect as we build the Linux of quant finance? Checkout our Wefunder campaign to join the revolution.
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.
Yuri Lopukhov
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!