Hi,
It seems I need to call PriceModel.Evaluate() or EvaluatePriceModel() to get IV or Greeks for option contracts. I am trying with below code, but didn't get it work. What could be wrong? It seems I need to specify a PriceModel somewhere, how? Is there other thing I need to specify as well? Thanks.
qb = QuantBook()
sym_list = ['NVDA']
for sym_str in sym_list:
sym = qb.AddEquity(sym_str, Resolution.Daily).Symbol
op = qb.AddOption(sym_str, Resolution.Daily)
op.PriceModel = OptionPriceModels.BjerksundStensland();
def UniverseFunc(universe):
return universe.IncludeWeeklys().Strikes(-5, 5).Expiration(timedelta(25), timedelta(31)) # 28day +/-3
op.SetFilter(UniverseFunc)
op_his = qb.GetOptionHistory(sym, datetime(2023, 7, 27), datetime(2023, 7, 27), Resolution.Daily)
for slice in op_his:
for canonical_symbol, chain in slice.OptionChains.items():
for c in chain:
# approach 1:
# sec = qb.Securities[sym]
# res = sec.PriceModel.Evaluate(sec, None, c)
# approach 2:
# https://github.com/QuantConnect/Lean/issues/3083#issuecomment-1435123295
res = op.EvaluatePriceModel(slice, c)
if c.Right == OptionRight.Put:
# print("{}, {}, {}, {}, {}, {}, {}, ".format(c.Symbol, c.Strike, c.Expiry, c.ImpliedVolatility, c.Greeks.Delta, c.LastPrice, c.Volume))
print("{}, {}, {}, {}, {}, {}, {}, ".format(slice.Time, c.Strike, c.Expiry, res.ImpliedVolatility, res.Greeks.Delta, c.LastPrice, c.Volume))
Stanley
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!