QuantConnect/Lean · error · AssertionError
Expected greeks not to be calculated for {contract.symbol.va
Error message
Expected greeks not to be calculated for {contract.symbol.value}, an {option_style_str} style option, using {type(self._option.price_model).__name__}, which does not support them, but they were What it means
check_greeks raises inside the try block when the option style is NOT supported by the price model but contract.greeks was accessed without throwing. It proves the unsupported-style contract: an IOptionPriceModel that does not support the option's style (e.g. European model on an American option) must throw ArgumentException when greeks are read. If greeks are silently returned, the price model's style guard regressed. NOTE: this raise is inside try which only catches ArgumentException, so the AssertionError correctly propagates.
Source
Thrown at Algorithm.Python/OptionPriceModelForOptionStylesBaseRegressionAlgorithm.py:66
self._check_greeks = True
self._tried_greeks_calculation = False
def check_greeks(self, contracts: list[OptionContract]) -> None:
if not self._check_greeks or len(contracts) == 0 or not self._option:
return
self._check_greeks = False
self._tried_greeks_calculation = True
for contract in contracts:
greeks = None
try:
greeks = contract.greeks
# Greeks should have not been successfully accessed if the option style is not supported
option_style_str = 'American' if self._option.style == OptionStyle.AMERICAN else 'European'
if not self._option_style_is_supported:
raise AssertionError(f'Expected greeks not to be calculated for {contract.symbol.value}, an {option_style_str} style option, using {type(self._option.price_model).__name__}, which does not support them, but they were')
except ArgumentException:
# ArgumentException is only expected if the option style is not supported
if self._option_style_is_supported:
raise AssertionError(f'Expected greeks to be calculated for {contract.symbol.value}, an {option_style_str} style option, using {type(self._option.price_model).__name__}, which supports them, but they were not')
# Greeks should be valid if they were successfuly accessed for supported option style
# Delta can be {-1, 0, 1} if the price is too wild, rho can be 0 if risk free rate is 0
# Vega can be 0 if the price is very off from theoretical price, Gamma = 0 if Delta belongs to {-1, 1}
if (self._option_style_is_supported
and (not greeks
or ((contract.right == OptionRight.CALL and (greeks.delta < 0.0 or greeks.delta > 1.0 or greeks.rho < 0.0))
or (contract.right == OptionRight.PUT and (greeks.delta < -1.0 or greeks.delta > 0.0 or greeks.rho > 0.0))
or greeks.theta == 0.0 or greeks.vega < 0.0 or greeks.gamma < 0.0))):
raise AssertionError(f'Expected greeks to have valid values. Greeks were: Delta: {greeks.delta}, Rho: {greeks.rho}, Theta: {greeks.theta}, Vega: {greeks.vega}, Gamma: {greeks.gamma}')
View on GitHub (pinned to d2c3659f87)
Solutions
- Inspect the price model's SupportFor(OptionStyle) / greeks accessor; it must throw ArgumentException when the style is unsupported.
- Confirm the regression subclass set the correct option_style_is_supported flag matching the model's actual support.
- Re-run the specific style/model combination in the regression matrix to isolate which model stopped guarding.
Example fix
// before: greeks returned without style guard
public Greek Greeks => CalculateGreeks();
// after: throw for unsupported styles
public Greek Greeks
{
get
{
if (!Supports(Style)) throw new ArgumentException($"{GetType().Name} does not support {Style} style options");
return CalculateGreeks();
}
} Defensive patterns
Strategy: try-catch
Validate before calling
# declare model support explicitly and assert the contract before reading greeks
supported = self._option.price_model.supports(self._option.style) # hypothetical
if not supported:
self.debug(f"{type(self._option.price_model).__name__} does not support {self._option.style}; expect ArgumentException on greeks") Type guard
def style_is_supported(price_model, style) -> bool:
# use the model's declared support matrix, not a hand-maintained flag
return price_model.supported_styles(style) Try / catch
# expected: unsupported style must throw ArgumentException
try:
_ = contract.greeks
except ArgumentException:
pass # correct behavior for unsupported style
else:
raise AssertionError("greeks returned for unsupported option style") Prevention
- Keep the price model's style-support check centralized and authoritative.
- Mirror the model's actual support matrix in regression flags, not a divergent hand list.
- Test each model/style pair in isolation.
When it happens
Trigger: self._option_style_is_supported is False, but contract.greeks returned a value instead of throwing ArgumentException. The explicit raise at line 66 fires.
Common situations: The price model's style-support check was removed/weakened so it no longer throws on unsupported styles; the style (American/European) was misconfigured so a supported model is treated as unsupported while still computing greeks; OptionStyle argument validation changed.
Related errors
- Expected greeks to be calculated for {contract.symbol.value}
- Expected greeks to be accessed
- Regression test failed: current open interest isn't in the s
- Regression test failed: current open interest was not correc
- Regression test failed: current open interest was not correc
AI-assisted analysis of QuantConnect/Lean@d2c3659f87 (2026-08-13).
Data as JSON: /api/errors/1435ddb505114dba.
Report an issue: GitHub.