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. 

 

  1. qb = QuantBook()
  2. sym_list = ['NVDA']
  3. for sym_str in sym_list:
  4. sym = qb.AddEquity(sym_str, Resolution.Daily).Symbol
  5. op = qb.AddOption(sym_str, Resolution.Daily)
  6. op.PriceModel = OptionPriceModels.BjerksundStensland();
  7. def UniverseFunc(universe):
  8. return universe.IncludeWeeklys().Strikes(-5, 5).Expiration(timedelta(25), timedelta(31)) # 28day +/-3
  9. op.SetFilter(UniverseFunc)
  10. op_his = qb.GetOptionHistory(sym, datetime(2023, 7, 27), datetime(2023, 7, 27), Resolution.Daily)
  11. for slice in op_his:
  12. for canonical_symbol, chain in slice.OptionChains.items():
  13. for c in chain:
  14. # approach 1:
  15. # sec = qb.Securities[sym]
  16. # res = sec.PriceModel.Evaluate(sec, None, c)
  17. # approach 2:
  18. # https://github.com/QuantConnect/Lean/issues/3083#issuecomment-1435123295
  19. res = op.EvaluatePriceModel(slice, c)
  20. if c.Right == OptionRight.Put:
  21. # print("{}, {}, {}, {}, {}, {}, {}, ".format(c.Symbol, c.Strike, c.Expiry, c.ImpliedVolatility, c.Greeks.Delta, c.LastPrice, c.Volume))
  22. print("{}, {}, {}, {}, {}, {}, {}, ".format(slice.Time, c.Strike, c.Expiry, res.ImpliedVolatility, res.Greeks.Delta, c.LastPrice, c.Volume))
+ Expand

Author

Stanley

August 2023