QuantConnect/Lean · error · ValueError
Unexpected continuous future mapping event count: {len(conti
Error message
Unexpected continuous future mapping event count: {len(continuous_future_last_trading_day_mapping)} What it means
Same continuous-future mapping check but with DataMappingMode.LAST_TRADING_DAY instead of OPEN_INTEREST. Asserts the ES symbol-change history returns 9 mapping events for 2007-2011 under the last-trading-day roll rule. Same meaning as 167 but for a different mapping mode, so a divergence specifically implicates the LAST_TRADING_DAY mapping path.
Source
Thrown at Algorithm.Python/HistoryAuxiliaryDataRegressionAlgorithm.py:42
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:
raise ValueError(f"Unexpected splitfactor: {splitfactor}")
symbol = Symbol.create("BTCUSD", SecurityType.CRYPTO_FUTURE, Market.BINANCE)View on GitHub (pinned to d2c3659f87)
Solutions
- Confirm the two mapping modes (OPEN_INTEREST vs LAST_TRADING_DAY) are both expected to yield 9 events for ES in this window.
- Inspect continuous-future mapping code for the LAST_TRADING_DAY branch.
- Reconcile ES mapping files and rebaseline if data was corrected.
Example fix
# before if len(continuous_future_last_trading_day_mapping) != 9: # after if len(continuous_future_last_trading_day_mapping) != 9: # matches OPEN_INTEREST count, verified
Defensive patterns
Strategy: validation
Validate before calling
ltd = self.history(SymbolChangedEvent, sp500, datetime(2007,1,1), datetime(2012,1,1), data_mapping_mode=DataMappingMode.LAST_TRADING_DAY)
if len(ltd) != 9:
self.debug(f"LAST_TRADING_DAY mapping events: {len(ltd)} (compare OPEN_INTEREST count)") Prevention
- Test all mapping modes together so a single-mode regression is caught.
- Document expected per-mode counts in the test comment.
- Re-run the continuous-future mapping regression after any mapping-code change.
When it happens
Trigger: len(self.history(SymbolChangedEvent, sp500, datetime(2007,1,1), datetime(2012,1,1), data_mapping_mode=LAST_TRADING_DAY)) != 9.
Common situations: The LAST_TRADING_DAY roll rule logic changed versus OPEN_INTEREST; mapping data changed; the two modes now disagree on event count.
Related errors
- Unexpected continuous future mapping event count: {len(conti
- Unexpected multi symbol dividend count: {len(multi_symbol_re
- Unexpected dividend count: {len(dividend)}
- Unexpected distribution: {distribution}
- Unexpected split count: {len(split)}
AI-assisted analysis of QuantConnect/Lean@d2c3659f87 (2026-08-13).
Data as JSON: /api/errors/2c2c2639b9151ee7.
Report an issue: GitHub.