QuantConnect/Lean · error · ValueError

Unexpected continuous future mapping event count: {len(conti

Error message

Unexpected continuous future mapping event count: {len(continuous_future_open_interest_mapping)}

What it means

Asserts a continuous-future symbol-change (mapping) history request returns exactly 9 mapping events for the E-mini S&P 500 (2007-2011) using DataMappingMode.OPEN_INTEREST. It pins the continuous-future mapping event count; divergence means the mapping (roll) data or the continuous-contract mapping logic changed.

Source

Thrown at Algorithm.Python/HistoryAuxiliaryDataRegressionAlgorithm.py:39

    def initialize(self):
        '''Initialise the data and resolution required, as well as the cash and start-end dates for your algorithm. All algorithms must initialized.'''

        self.set_start_date(2021, 1, 1)
        self.set_end_date(2021, 1, 5)

        aapl = self.add_equity("AAPL", Resolution.DAILY).symbol

        # multi symbol request
        spy = Symbol.create("SPY", SecurityType.EQUITY, Market.USA)
        multi_symbol_request = self.history(Dividend, [ aapl, spy ], 360, Resolution.DAILY)
        if len(multi_symbol_request) != 12:
                raise ValueError(f"Unexpected multi symbol dividend count: {len(multi_symbol_request)}")

        # continuous future mapping requests
        sp500 = Symbol.create(Futures.Indices.SP_500_E_MINI, SecurityType.FUTURE, Market.CME)
        continuous_future_open_interest_mapping = self.history(SymbolChangedEvent, sp500, datetime(2007, 1, 1), datetime(2012, 1, 1), data_mapping_mode = DataMappingMode.OPEN_INTEREST)
        if len(continuous_future_open_interest_mapping) != 9:
                raise ValueError(f"Unexpected continuous future mapping event count: {len(continuous_future_open_interest_mapping)}")
        continuous_future_last_trading_day_mapping = self.history(SymbolChangedEvent, sp500, datetime(2007, 1, 1), datetime(2012, 1, 1), data_mapping_mode = DataMappingMode.LAST_TRADING_DAY)
        if len(continuous_future_last_trading_day_mapping) != 9:
                raise ValueError(f"Unexpected continuous future mapping event count: {len(continuous_future_last_trading_day_mapping)}")

        dividend = self.history(Dividend, aapl, 360)
        self.debug(str(dividend))
        if len(dividend) != 6:
            raise ValueError(f"Unexpected dividend count: {len(dividend)}")
        for distribution in dividend.distribution:
            if distribution == 0:
                raise ValueError(f"Unexpected distribution: {distribution}")

        split = self.history(Split, aapl, 360)
        self.debug(str(split))
        if len(split) != 2:
            raise ValueError(f"Unexpected split count: {len(split)}")
        for splitfactor in split.splitfactor:
            if splitfactor == 0:

View on GitHub (pinned to d2c3659f87)

Solutions

  1. Verify the ES mapping files (CME future chain, symbol-change events) cover 2007-2011 and reconcile the event count to 9.
  2. Inspect continuous-future mapping selection (DataMappingMode.OPEN_INTEREST) code for changes.
  3. Confirm the request date range is unchanged.
  4. Rebaseline 9 if mapping data was legitimately corrected.

Example fix

# before
if len(continuous_future_open_interest_mapping) != 9:
# after: verified mapping-event count after a data refresh
if len(continuous_future_open_interest_mapping) != 9:  # verified against ES mapping files 2007-2012
Defensive patterns

Strategy: validation

Validate before calling

# log mapping-mode event counts side by side
oi = self.history(SymbolChangedEvent, sp500, datetime(2007,1,1), datetime(2012,1,1), data_mapping_mode=DataMappingMode.OPEN_INTEREST)
if len(oi) != 9:
    self.debug(f"OPEN_INTEREST mapping events: {len(oi)}\n{oi}")

Prevention

When it happens

Trigger: len(self.history(SymbolChangedEvent, sp500, datetime(2007,1,1), datetime(2012,1,1), data_mapping_mode=OPEN_INTEREST)) != 9.

Common situations: Future mapping (SymbolChangedEvent) data files changed for ES; the continuous-future mapping/resolution logic changed how OPEN_INTEREST rolls are counted; the date window changed.

Related errors


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