QuantConnect/Lean · error · AssertionError

Expected greeks to be accessed

Error message

Expected greeks to be accessed

What it means

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.

Source

Thrown at Algorithm.Python/OptionPriceModelForOptionStylesBaseRegressionAlgorithm.py:43

        self._tried_greeks_calculation = False
        self._option = None

    def on_data(self, slice: Slice) -> None:
        if self.is_warming_up:
            return

        for kvp in slice.option_chains:
            if not self._option or kvp.key != self._option.symbol:
                continue

            self.check_greeks([contract for contract in kvp.value])

    def on_end_of_day(self, symbol: Symbol) -> None:
        self._check_greeks = True

    def on_end_of_algorithm(self) -> None:
        if not self._tried_greeks_calculation:
            raise AssertionError("Expected greeks to be accessed")

    def init(self, option: Option, option_style_is_supported: bool) -> None:
        self._option = option
        self._option_style_is_supported = option_style_is_supported
        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

View on GitHub (pinned to d2c3659f87)

Solutions

  1. Confirm init(option, ...) was called and self._option matches the delivered chain's kvp.key in on_data.
  2. Ensure the algorithm exited warm-up before the option chain was delivered (check SetWarmUp / data span).
  3. Inspect that the option contract is subscribed and slice.option_chains is non-empty.
  4. Verify on_end_of_day re-arms _check_greeks so check_greeks does not permanently early-return.

Example fix

# before: option never matched, check_greeks skipped
if not self._option or kvp.key != self._option.symbol: continue
# after: ensure self._option is set and symbols match
self.init(option, option_style_is_supported=True)
# and confirm kvp.key == self._option.symbol
Defensive patterns

Strategy: validation

Validate before calling

# assert the greeks path was reached; surface why it was skipped
if not self._tried_greeks_calculation:
    self.debug(f"greeks never accessed: option_set={self._option is not None}, chains_seen={self._chains_seen}, warmed_up={self.is_warming_up}")

Prevention

When it happens

Trigger: 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.

Common situations: 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.

Related errors


AI-assisted analysis of QuantConnect/Lean@d2c3659f87 (2026-08-13). Data as JSON: /api/errors/68fdfee4b0640f0b. Report an issue: GitHub.