Hello folks,
I'm trying to extract option chain using universal filter (not considering the optimization now). When I use `universe` function version vs `SetFunction`, strike prices are completely different. For instance:
def UniverseFunc(self, universe):
return universe.IncludeWeeklys().Strikes(-15, 15).Expiration(timedelta(20), timedelta(30))
If my equity is `TSLA` then I'll only get strike price five difference. Sample:
[170.0, 175.0, 180.0, 185.0, 190.0, 195.0, 200.0, 205.0, 210.0]
Again, this same code could produce:
[110.0, 111.0, 111.67, 112.0, 113.0, 113.33, 114.0, 115.0, 116.0, 116.67, 117.0, 118.0, 118.33, 119.0, 120.0, 121.0, 121.67, 122.0, 123.0, 123.33, 124.0, 125.0, 126.0, 126.67, 127.0, 128.33, 130.0]
strikes as well at the end time of the backtest. On the other hand if I use
option.SetFilter(-15, 15, timedelta(20), timedelta(30))
Then first couple of days of my backtesting, there won't be any option chain available. but looks like I always get all interval strike:
[115.0, 116.67, 118.33, 120.0, 121.67, 123.33, 125.0, 126.67, 128.33, 130.0, 131.67, 133.33, 135.0]
So, questions:
- Why `SetFilter` using `Universe` vs `SetFilter` function shows completely different data?
- How can I make sure I'll always get consistent data with all interval between min and max?
Looking forward for some help here. Btw, I'm a brand new person and I really appreciate your time and response.
Thanks
Mamun
I was also going through to find out, can `WarmUp` help here? My findings says no!
Setting warm up is only required when:
Then setting warm up will pump the data before the `SetStartDate` time arrive. It won't help with any option data.
Mamun
Here is the backtest code. If that helps to reply my issue.
Louis Szeto
Hi Md Al Mamum
We tried to run the exact backtest you've attached, but cannot reproduce the issue. The strike prices available were matching those by the universe filtering method:
Please tell us how do you derived those strike prices, so we can further assist.
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.
Mamun
Thank you so much Louis for replying.
First of all look at the output you got, everything is spaced 5 strike but TSLA has lot more strike in between. Those are one pt spaced. If output is
which mean it skipped all 0.33 and 0.67 strike in between. If you go further more date of my backtest, you will see strikes like:
TSLA split Aug 4, 2022 and my backtest running between Dec 2022 to Jan 23, and that's why my expectation is I would get all intermediate strikes in between 170 to 175. Not just 170 and 175, there should at least 6 more strikes.
My question was:
There are more case to discuss but let's what I'm missing here.
Mamun
Alight I figured a lot of things actually. Will try to explain and hopefully that helps other also.
Everything start with Time and then price. We also know `OnData` bring slice of data which is a super dictionary that's also known. We also know `OnData` will contain data based on your subscription resolution `Minute/Hour/Day` etc, but biggest missing part is how those data become available? Well, there is no guarantee that you will have your all data that you are looking at 9:31 opening minute and that's why documentation recommend keep checking the dictionary by the key.
Why is that? I think documentation also need to clear that underneath concept or some details which could help a lot. The reason is, all subscription data is asynchronous which mean I was subscribing for options data with following settings:
and exceptions was
But I was not getting all the data after opening. I was getting partial data. What is that partial data mean? It mean system was pulling data and it was receiving data in different time and that's why at the begging of each day I was getting contract list like:
where all intermediate strikes was missing but if you just keep waiting until your expected list come then after 10-15 minutes you will get all intermediate strikes. Then your possible list for my settings will look like:
Key take way:
There are many to solve that problem but we must accept the way LEAN built but providing updated documentation and videos will help.
Mamun
I think I'm wrong one part in my previous response.
that chain valid, that's a final list of the contract details in that day.
That mean I'm still not sure why:
Somehow I'm still stuck to get the contract list consistently.
Mamun
Ok, after crazy amount of research and looking in community, here is best outcome on option filtering so far.
Here is log of TSLA option contract with some conditions. Please check my backtest code attached here.
In a single snapshot you will see this:
Now all the returned contract list widely varies from day to day. Same expiration day but look at `2023-01-04` and `2023-01-05`. If I don't get consistent data then how can I build a strategy and make sure in forward it will work?
Please help me here what I'm missing. Really need some QC expert opinion here. Thanks
Louis Szeto
Hi Mamum
Sorry for the delay. You are right on “not every slice of data contains all contracts”. Indeed, only additional information are piped through the OnData slice handler. If a contract has no new quote/trade ticks, it won't be included in that particular time's OnData Slice. We recommend using self.OptionChainProvider.GetOptionContractList(underlyingSymbol, self.Time) (like what you've done!) to obtain symbol objects of all option contracts and further filter them with
And them subscribe their data through self.AddOptionContract(symbol)
You are not required or recommended to use AddOption() method in this way as it create much more extra subcription that might drag your backtest speed. Note that by this method, it is not possible to select contract by Greeks.
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.
Mamun
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!