I can't get the option chains to work when I set the resolution to Hour in AddOption. It does work when I set it to Minute. However, I'd like to get my backtest resuls quickly, and I believe that an hourly resolution is good enough. Is there anything I'm missing here?
JayJayD
Hi Ken M, option data has minute resolution only.
In order to get hourly bars, you should use consolidators, one for each contract.
Here is an example with futures, the implementation for options is basically the same.
Mathieu Robitaille
How do we use the consolidator created for futures, but with option chains?
I would like to consolidate options chains to more than hourly, say every 4 hours.
Thanks
Jack Simonson
Hi Mathieu,
Â
It is certainly possible to use consolidators with options chains, and I've provided a link to an example here. Hopefully this will help you with you algorithm, and if there are additional issues that you encounter, post in the forum and the community can help you solve them!
Gil Sapir
Jack Simonson Consolidators are not good enough to use with options because we don't have access to the OptionChain from the consolidator.
We have it only in OnData (slice ).
Â
Alexandre Catarino
Hi Gil Sapir ,
What do you want to consolidate?
If we just want to consolidate price data, we can use consolidators as suggested by Jack.
We can assign an event to the consolidator and when it is triggered, the OptionsChains of the current Slice object can be accessed to find the option contract for the symbol:
self.Consolidate(optionContractSymbol, timedelta(hours=4), self.OnOptionConsolidated) def OnOptionConsolidated(self, consolidated): symbol = consolidated.Symbol chains = self.CurrentSlice.OptionChains # add logic to find symbol in chains
Â
Alberto Maria Bernardi
Hello Alexandre,
Thanks for your add on Jack's script for Options Consolidation, I am currently trying to use the same logic to obtain the Implied Volatility of different Option contracts with 2h and 3h frequency. I already have the whole Algo up and running at minute frequency,Â
I really cannot understand how to use Consolidators + Event Handler to solve my problem.
I was trying to combine Jack's example with your suggested lines to do the following:
1) Obtain Option Chain, filtered by strike and maturities range.
2) Isolate only Put contracts with specific expiries and moneyness
3) Obtain Implied Volatility for those contracts only (using Crank Nicolson model)
Is this actually feasible using the approach you suggeted or am I missing something?
Moreover, after checking Documentation I think I still need a clarification of the difference between the OnData() method and OnSecuritiesChanged() which Jack uses in his example above...
Thanks a lot.
Â
Derek Melchin
Hi Alberto,
Please attach a backtest which demonstrates the issue.
To clarify OnData and the OnSecuritiesChanged methods, OnData is called with every data slice passed to the algorithm while OnSecuritiesChanged is called whenever an option contract enters or leaves the universe.
Best,
Derek Melchin
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.
Alberto Maria Bernardi
Hi Derek,
Thank you for the clarification.
Before digging into the whole code let me just rephrase my question in simpler terms cause maybe there is no need for it:
I want to consolidate at Hourly frequecy the values of Implied Volatility only for specific options contracts of the same OptionChain (i.e. SPY OptionChain). Is it feasible using Consolidators (or anything else)?
Thanks a lot in advance,
Best,
Alberto
Â
Derek Melchin
Hi Alberto,
To consolidate the IV of option contracts, we can create a `BaseDataConsolidator` for each contract.
def OnSecuritiesChanged(self, changes): for security in changes.AddedSecurities: if security.Type == SecurityType.Option: symbol = security.Symbol consolidator = BaseDataConsolidator(timedelta(hours=1)) consolidator.DataConsolidated += self.OnIVConsolidated self.consolidators[symbol] = consolidator
We can then update the consolidator with the IV values passed to OnData.
def OnData(self, data): for symbol, chain in data.OptionChains.items(): for contract in chain: self.consolidators[contract.Symbol].Update(IndicatorDataPoint(self.Time, contract.ImpliedVolatility))
Consolidated IV bars are then passed to `OnIVConsolidated`. See the attached backtest for reference.
Best,
Derek Melchin
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.
Urban
Can consolidators decrease the time needed for a backtest since it means the engine calls OnData hourly instead of every minute?
Varad Kabade
Hi Urban,
The OnData method is the primary event handler that will be triggered at the resolution of our security if there is data available at the given time. Using a consolidator won't stop the engine from calling the event handler. We can potentially increase the speed of a backtest by completing all the calculations in the consolidator handler method and removing the OnData method.
We are currently working on adding Hourly and Daily resolutions for options. Subscribe to the following GH issue for updates:
https://github.com/QuantConnect/Lean/pull/6017
Best,
Varad Kabade
Â
Urban
Hope you don't mind the newbie question: is it possible to decrease the time needed for a backtest if a simple algorithm just wants to call OnData() at a fixed time daily e.g. at 10am?
Varad Kabade
Hi Urban,
Yes, the backtest will be significantly faster if our logic is restricted to a particular time in a day. We recommend using Scheduled events. Refer to the following doc for more information.
Best,
Varad Kabade
Ken M
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!