{"record":{"id":"68fdfee4b0640f0b","repo":"QuantConnect/Lean","slug":"expected-greeks-to-be-accessed","errorCode":null,"errorMessage":"Expected greeks to be accessed","messagePattern":"Expected greeks to be accessed","errorType":"exception","errorClass":"AssertionError","httpStatus":null,"severity":"error","filePath":"Algorithm.Python/OptionPriceModelForOptionStylesBaseRegressionAlgorithm.py","lineNumber":43,"sourceCode":"        self._tried_greeks_calculation = False\n        self._option = None\n\n    def on_data(self, slice: Slice) -> None:\n        if self.is_warming_up:\n            return\n\n        for kvp in slice.option_chains:\n            if not self._option or kvp.key != self._option.symbol:\n                continue\n\n            self.check_greeks([contract for contract in kvp.value])\n\n    def on_end_of_day(self, symbol: Symbol) -> None:\n        self._check_greeks = True\n\n    def on_end_of_algorithm(self) -> None:\n        if not self._tried_greeks_calculation:\n            raise AssertionError(\"Expected greeks to be accessed\")\n\n    def init(self, option: Option, option_style_is_supported: bool) -> None:\n        self._option = option\n        self._option_style_is_supported = option_style_is_supported\n        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","sourceCodeStart":25,"sourceCodeEnd":61,"githubUrl":"https://github.com/QuantConnect/Lean/blob/d2c3659f877bfc2b5d9dc0fc89a9c7566f45e892/Algorithm.Python/OptionPriceModelForOptionStylesBaseRegressionAlgorithm.py#L25-L61","documentation":"OptionPriceModelForOptionStylesBase end-of-algorithm assertion: the algorithm must have attempted to compute option greeks at least once during the run (_tried_greeks_calculation stays False only if check_greeks never proceeded past its guard). This proves the on_data -> option_chains -> check_greeks path executed. If it never ran, the option chain was never delivered or check_greeks always hit an early-return guard.","triggerScenarios":"on_end_of_algorithm runs with self._tried_greeks_calculation == False. check_greeks returned early on every call because _check_greeks was False, contracts list was empty, or self._option was None.","commonSituations":"The option symbol/_option was never set (init not called / wrong symbol match in on_data); slice.option_chains never contained the expected chain; is_warming_up never became False so on_data skipped; the per-day _check_greeks re-arm in on_end_of_day never paired with delivered chains.","solutions":["Confirm init(option, ...) was called and self._option matches the delivered chain's kvp.key in on_data.","Ensure the algorithm exited warm-up before the option chain was delivered (check SetWarmUp / data span).","Inspect that the option contract is subscribed and slice.option_chains is non-empty.","Verify on_end_of_day re-arms _check_greeks so check_greeks does not permanently early-return."],"exampleFix":"# before: option never matched, check_greeks skipped\nif not self._option or kvp.key != self._option.symbol: continue\n# after: ensure self._option is set and symbols match\nself.init(option, option_style_is_supported=True)\n# and confirm kvp.key == self._option.symbol","handlingStrategy":"validation","validationCode":"# assert the greeks path was reached; surface why it was skipped\nif not self._tried_greeks_calculation:\n    self.debug(f\"greeks never accessed: option_set={self._option is not None}, chains_seen={self._chains_seen}, warmed_up={self.is_warming_up}\")","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Call init(option, ...) and ensure self._option matches the delivered chain symbol.","Exit warm-up before expecting greeks (extend the data span if needed).","Re-arm _check_greeks in on_end_of_day so each day gets a chance."],"tags":["quantconnect","lean","regression","options","greeks","option-pricing","option-chain"],"backgroundTag":null,"analyzedSha":"d2c3659f877bfc2b5d9dc0fc89a9c7566f45e892","analyzedAt":"2026-08-13T13:52:21.013Z","schemaVersion":2},"datasetVersion":"2026-08-13T14:17:21.547Z"}