As an active Options trader, I realized lean framework still has some room of improvement with Options. I'm trying to automatize some of my strategies and one very useful way to write clean code is with the Algorithm Framework.
There is already a way to create Option Chains tied to a universe (https://www.quantconnect.com/docs/v2/writing-algorithms/algorithm-framework/universe-selection/options-universes#61-Option-Chained-Universe-Selection), but there was no way to tie those Option Chains to a UniverseSelectionModel. I wrote a new UniverseSelectionModel that can handle that. For example, now you can keep updated Option Chains tied to a Fundamental universe selection.
Feel free to use or adapt it if you find it useful.
.ekz.
Great work. I've got some options universe systems that would benefit from this architecture.
One issue I've had is Python's speed. Running a 1-year backtest in the cloud, with an options universe could take easily two hours.Â
You've written this demo in C#, which I understand should be much faster than Python. I know it's just a proof of concept, but it also seems to move a bit slowly, (in the cloud). Running this 1-month backtest took about 5 minutes, on a B8-16 node.
Are you running in the cloud or locally? Are you seeing the same speed? Any advice on how to optimize for backtest performance?
--
cc'ing some of our QC performance gurus and options rockstars for their thoughts: Fred Painchaud , Derek Melchin, Alexandre Catarino, Â Varad Kabade, Yayaya Â
Ivan Radigales Creus
Thanks .ekz. .
I think the problem is the resolution. In my example algorithm, I'm using Minute resolution and request the OptionChains for 100 underlings. I usually use Daily resolution in my algorithms, and it runs much faster.
However, any suggestions to make it more efficient will be appreciated 😊
And regarding the programming language, I also started in QC with Python, but I felt it was much easier to debug code in C# and algorithms ran a bit faster overall.
.ekz.
Thanks Ivan Radigales Creus, that was indeed my first thought, but looking through your code, I couldn't find where you specified your resolution. In your POC code, how would one change it to Daily resolution?--Additional context: I have limited experience with LEAN in C#, and Option Chain Universes.
Ivan Radigales Creus
.ekz. I was experimenting with Python and created the same class I did with C# in Python.
I also set the resolution to Daily there in the Initialize() function (as explained https://www.quantconnect.com/docs/v2/writing-algorithms/securities/subscriptions#03-Resolutions).
I was trying to experiment adding the Greeks to the algorithm, but I failed to do so. I tried to follow the suggestions on https://www.quantconnect.com/forum/discussion/3039/value-of-greeks-delta-is-always-0/p1 and https://www.quantconnect.com/docs/v2/writing-algorithms/reality-modeling/options-models/pricing but it didn't work. Greeks are always 0.
Not sure if someone can help with that? It would be great to be able to filter by Delta/Theta, etc.
At least I hope my Python version of the algorithm helps and also shows you how to change the default resolution (set to Minute).
.ekz.
Thanks for your response. Â
Here's some code I shared a little while ago that may be helpful in getting your Greeks initialized: https://www.quantconnect.com/forum/discussion/11691/sharing-selecting-options-contracts-using-delta/p1
Thanks for sharing the python version of your code. I actually want to make the transition to C# ha. It sounds like you're saying that in C# we just set the universe settings to Daily, as per usual. I should have tried the obvious. Will do.
One other question I have: can you share a use case in which  using your architecture would facilitate a strategy that would otherwise be harder/impossible on QC. I might have misunderstood the benefits of the functionality.
For example, A use case I have is to select individual contracts (with known DTE and strike offsets), after defining my equity universe. I currently do this without any options universes at all. Â It seems this architecture may be overkill for that. Â
Any thoughts? What's your use case?
Ivan Radigales Creus
Thanks .ekz. . Unfortunately the code you shared for the greeks only works when Adding Options manually on initialize with AddOption, but not if we use Universe Models. I think there is a bug in the framework and price models are not used when using the UniverseSelectionModel.
I agree it may be faster to add options manually for some cases if you need static strikes or expirations. However, using an OptionFilter makes it faster when you want to have dynamic option chains every day (i.e. always next Monthly expiration, and always the -5, +5 strikes closest to underlying price).
I use OptionFilter to select next monthly expiration options automatically every day, even that my fundamentals model updates only once a month.
.ekz.
Ah, I see. That is unfortunate. Perhaps the team has a bug out for it already. (cc: Martin Molinero re: options price models not used for UniverseSelectionModel.)
As for option filter, that is what I was using as well. After my equity universe had been identified, for each equity I would use an Option filter function to select contracts using DTE and Delta (similar to my standalone code I shared above), but I never use an Options universe.Â
I'll try to dig up that code, its been a while.
Â
Â
Louis Szeto
Hi Ivan and .ekz.
The Option subscriptions were not hooked with its underlying in your model, although you've subscribed to the underlying data. Thus the Greeks cannot be calculated properly. This should be done during creating security objects for the options.Â
Best
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.
.ekz.
Thanks for the comment Louis Szeto . Any chance you can share an example?
Louis Szeto
Hi .ekz.
There you go 😊
Best
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.
Ivan Radigales Creus
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!