{"record":{"id":"1435ddb505114dba","repo":"QuantConnect/Lean","slug":"expected-greeks-not-to-be-calculated-for-contract","errorCode":null,"errorMessage":"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","messagePattern":"Expected greeks not to be calculated for (.+?), an (.+?) style option, using (.+?), which does not support them, but they were","errorType":"exception","errorClass":"AssertionError","httpStatus":null,"severity":"error","filePath":"Algorithm.Python/OptionPriceModelForOptionStylesBaseRegressionAlgorithm.py","lineNumber":66,"sourceCode":"        self._check_greeks = True\n        self._tried_greeks_calculation = False\n\n    def check_greeks(self, contracts: list[OptionContract]) -> None:\n        if not self._check_greeks or len(contracts) == 0 or not self._option:\n            return\n\n        self._check_greeks = False\n        self._tried_greeks_calculation = True\n\n        for contract in contracts:\n            greeks = None\n            try:\n                greeks = contract.greeks\n\n                # Greeks should have not been successfully accessed if the option style is not supported\n                option_style_str = 'American' if self._option.style == OptionStyle.AMERICAN else 'European'\n                if not self._option_style_is_supported:\n                    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')\n            except ArgumentException:\n                # ArgumentException is only expected if the option style is not supported\n                if self._option_style_is_supported:\n                    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')\n\n            # Greeks should be valid if they were successfuly accessed for supported option style\n            # Delta can be {-1, 0, 1} if the price is too wild, rho can be 0 if risk free rate is 0\n            # Vega can be 0 if the price is very off from theoretical price, Gamma = 0 if Delta belongs to {-1, 1}\n            if (self._option_style_is_supported\n                and (not greeks\n                    or ((contract.right == OptionRight.CALL and (greeks.delta < 0.0 or greeks.delta > 1.0 or greeks.rho < 0.0))\n                        or (contract.right == OptionRight.PUT and (greeks.delta < -1.0 or greeks.delta > 0.0 or greeks.rho > 0.0))\n                        or greeks.theta == 0.0 or greeks.vega < 0.0 or greeks.gamma < 0.0))):\n                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}')\n\n\n\n","sourceCodeStart":48,"sourceCodeEnd":84,"githubUrl":"https://github.com/QuantConnect/Lean/blob/d2c3659f877bfc2b5d9dc0fc89a9c7566f45e892/Algorithm.Python/OptionPriceModelForOptionStylesBaseRegressionAlgorithm.py#L48-L84","documentation":"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.","triggerScenarios":"self._option_style_is_supported is False, but contract.greeks returned a value instead of throwing ArgumentException. The explicit raise at line 66 fires.","commonSituations":"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.","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."],"exampleFix":"// before: greeks returned without style guard\npublic Greek Greeks => CalculateGreeks();\n// after: throw for unsupported styles\npublic Greek Greeks\n{\n    get\n    {\n        if (!Supports(Style)) throw new ArgumentException($\"{GetType().Name} does not support {Style} style options\");\n        return CalculateGreeks();\n    }\n}","handlingStrategy":"try-catch","validationCode":"# declare model support explicitly and assert the contract before reading greeks\nsupported = self._option.price_model.supports(self._option.style)  # hypothetical\nif not supported:\n    self.debug(f\"{type(self._option.price_model).__name__} does not support {self._option.style}; expect ArgumentException on greeks\")","typeGuard":"def style_is_supported(price_model, style) -> bool:\n    # use the model's declared support matrix, not a hand-maintained flag\n    return price_model.supported_styles(style)","tryCatchPattern":"# expected: unsupported style must throw ArgumentException\ntry:\n    _ = contract.greeks\nexcept ArgumentException:\n    pass  # correct behavior for unsupported style\nelse:\n    raise AssertionError(\"greeks returned for unsupported option style\")","preventionTips":["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."],"tags":["quantconnect","lean","regression","options","greeks","option-pricing","option-style"],"backgroundTag":null,"analyzedSha":"d2c3659f877bfc2b5d9dc0fc89a9c7566f45e892","analyzedAt":"2026-08-13T13:52:21.013Z","schemaVersion":2},"datasetVersion":"2026-08-13T14:17:21.547Z"}