QuantConnect/Lean · error · ValueError

Regression test failed: current open interest isn't in the s

Error message

Regression test failed: current open interest isn't in the security cache

What it means

Option-open-interest regression: after fetching OpenInterest history for a specific ES-style option contract (72.5 call, 2016-01-15 expiry), it reads the security cache and asserts the current OpenInterest is cached. security.cache.get_data(OpenInterest) returning None means the open-interest data point was never registered into the security's cache, indicating the open-interest subscription/cache registration path regressed.

Source

Thrown at Algorithm.Python/OptionOpenInterestRegressionAlgorithm.py:51

        # use the underlying equity as the benchmark
        self.set_benchmark("TWX")

    def on_data(self, slice):
        if not self.portfolio.invested:
            for chain in slice.option_chains:
                for contract in chain.value:
                    if float(contract.symbol.id.strike_price) == 72.5 and \
                       contract.symbol.id.option_right == OptionRight.CALL and \
                       contract.symbol.id.date == datetime(2016, 1, 15):

                        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 the contract (72.5 call, 2016-01-15) is being subscribed/added (it must be in the chain and pass the filter).
  2. Inspect SecurityCache.GetData / RegisterNewData and the open-interest subscription registration in the data feed; ensure OpenInterest points are stored in the cache.
  3. Verify the open-interest data files for the option exist for 2014-06-05/06.
  4. Trace BaseDataCache for the OpenInterest type registration.

Example fix

// before: open interest not registered into the security cache
feed.Subscribe(contract, ...);  // OpenInterest type omitted
// after: ensure open-interest data is cached
security.Cache.AddData(openInterestPoint);
Defensive patterns

Strategy: validation

Validate before calling

# confirm the contract is subscribed and cache populated before asserting
security = self.securities[contract.symbol]
if security.cache.get_data(OpenInterest) is None:
    self.debug(f"no open-interest in cache for {contract.symbol}; subscribed={contract.symbol in self.portfolio.keys()}")

Type guard

def cache_has_open_interest(algo, symbol) -> bool:
    sec = algo.securities[symbol]
    return sec.cache.get_data(OpenInterest) is not None

Prevention

When it happens

Trigger: Inside on_data for the matching contract, security.cache.get_data(OpenInterest) == None. This fires before the per-date value checks (50/70), so the cache is empty.

Common situations: A refactor of Security.cache or the open-interest data registration in the data feed; open-interest subscription type no longer populating the cache; the option chain filter changed so the contract isn't actually subscribed.

Related errors


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