QuantConnect/Lean · error · ValueError

Regression test failed: current open interest was not correc

Error message

Regression test failed: current open interest was not correctly loaded and is not equal to 50

What it means

Per-date open-interest value check for 2014-06-05: both contract.open_interest and security.open_interest must equal 50. If either differs, the open-interest value loaded from the data file (or cached) for that date is wrong, indicating a data or cache-value regression for that specific contract.

Source

Thrown at Algorithm.Python/OptionOpenInterestRegressionAlgorithm.py:53

    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. Inspect the option open-interest data file for the contract on 2014-06-05; it must resolve to 50.
  2. Check that the OptionContract.open_interest reflects the latest cached value and that security.open_interest reads the same cache.
  3. Ensure the open-interest subscription updates the cache before the chain contract is built.

Example fix

// before: chain contract and security cache out of sync
contract.open_interest;  // stale
// after: both read from the same cache point
security.SetOpenInterest(contract.open_interest);
Defensive patterns

Strategy: validation

Validate before calling

# check both sources agree and equal the expected value for the date
expected = 50 if slice.time.date() == datetime(2014,6,5).date() else None
if expected is not None and (contract.open_interest != expected or security.open_interest != expected):
    self.debug(f"OI mismatch on {slice.time.date()}: contract={contract.open_interest} security={security.open_interest} expected={expected}")

Prevention

When it happens

Trigger: slice.time.date() == 2014-06-05 and (contract.open_interest != 50 or security.open_interest != 50).

Common situations: The option open-interest data file for 2014-06-05 changed; the cache returns a stale/wrong value; contract.open_interest and security.open_interest diverge (cache vs chain contract object out of sync).

Related errors


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