Hi, Folks:
I am a newbie with QC and am building a backtester for weekly covered calls. Because of the weekly calls, I have to access the option chain from the Slice argument in OnData(), using the following code snippet that I found in a QC thread:
OptionChain otmCalls;
if (slice.OptionChains.TryGetValue(_equitySymbol.Value, out otmCalls)) {
// do something
}
It turns out that TryGetValue is always returns nothing because the AMD option chain is actually named "?AMD" instead of "AMD". So for now, I can get it to work by prepending "?" to the equity name, but this feels like a hack. Is this a bug in OptionChains, or am I doing something wrong here?
To give you the whole picture, algo.Initialize() contains the following code that sets up the equity and option for the covered call:
UniverseSettings.DataNormalizationMode = DataNormalizationMode.Raw;
var equity = AddEquity("AMD", Resolution.Minute);
equity.SetDataNormalizationMode(DataNormalizationMode.Raw);
_equitySymbol = equity.Symbol;
var option = AddOption(_equitySymbol.Value, Resolution.Minute, /* market */ null, /* fill forward */ true, /* leverage */ 0m);
// option coarse filter
option.SetFilter
(
universe =>
(
from symbol in universe
.IncludeWeeklys()
.Strikes(-3, 3)
.Expiration(TimeSpan.FromDays(4), TimeSpan.FromDays(10))
where
symbol.ID.OptionRight == OptionRight.Call
&& symbol.ID.StrikePrice - universe.Underlying.Price > 0
select symbol
)
);
Your comments and suggestions will be much appreciated.
Thank you,
Yigal
Derek Melchin
Hi Yigal,
To resolve the issue, we need to pass the option's Symbol to `TryGetValue` instead of `_equitySymbol`. 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.
Yigal Rachman
Thank you, Derek. Works like a charm :). It seems so obvious now..
Yigal Rachman
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!