QuantConnect/Lean · error · ValueError

Regression test failed: open interest is zero for all contra

Error message

Regression test failed: open interest is zero for all contracts

What it means

Guarantee check: it must never be the case that every contract in the option chain has zero open interest. If all(chain contract.open_interest == 0), open-interest data is entirely missing/zero for the whole chain, indicating a broad data or subscription failure (worse than a single-contract value error).

Source

Thrown at Algorithm.Python/OptionOpenInterestRegressionAlgorithm.py:61

                        history = self.history(OpenInterest, contract.symbol, timedelta(1))["openinterest"]
                        if len(history.index) == 0 or 0 in history.values:
                            raise ValueError("Regression test failed: open interest history request is empty")

                        security = self.securities[contract.symbol]
                        open_interest_cache = security.cache.get_data(OpenInterest)
                        if open_interest_cache == None:
                            raise ValueError("Regression test failed: current open interest isn't in the security cache")
                        if slice.time.date() == datetime(2014, 6, 5).date() and (contract.open_interest != 50 or security.open_interest != 50):
                            raise ValueError("Regression test failed: current open interest was not correctly loaded and is not equal to 50")
                        if slice.time.date() == datetime(2014, 6, 6).date() and (contract.open_interest != 70 or security.open_interest != 70):
                            raise ValueError("Regression test failed: current open interest was not correctly loaded and is not equal to 70")
                        if slice.time.date() == datetime(2014, 6, 6).date():
                            self.market_order(contract.symbol, 1)
                            self.market_on_close_order(contract.symbol, -1)

                if all(contract.open_interest == 0 for contract in chain.value):
                    raise ValueError("Regression test failed: open interest is zero for all contracts")

    def on_order_event(self, order_event):
        self.log(str(order_event))

View on GitHub (pinned to d2c3659f87)

Solutions

  1. Confirm open-interest data files exist for the option underlying/expiry on the regression dates.
  2. Verify the option subscription includes the OpenInterest data type (not just quote/trade).
  3. Trace the data feed for the option symbol to ensure OI points reach the chain contracts.

Example fix

// before: option subscription without open interest type
AddOptionContract(symbol, Resolution.MINUTE);  // OI not subscribed
// after: include open interest
AddOptionContract(symbol, new[] { typeof(OpenInterest) }, Resolution.MINUTE);
Defensive patterns

Strategy: validation

Validate before calling

# detect a fully-zero chain early instead of relying on per-contract checks
if chain.value and all(c.open_interest == 0 for c in chain.value):
    self.debug(f"all contracts zero OI for {kvp.key} at {slice.time}; check OI data files and subscription type")

Type guard

def chain_has_open_interest(chain) -> bool:
    return any(c.open_interest != 0 for c in chain.value)

Prevention

When it happens

Trigger: all(contract.open_interest == 0 for contract in chain.value) is True for a given slice's option chain.

Common situations: Open-interest data files missing for the whole chain date; the open-interest subscription type disabled/not registered for the option; data feed regression dropping all OI points.

Related errors


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