{"record":{"id":"2c2c2639b9151ee7","repo":"QuantConnect/Lean","slug":"unexpected-continuous-future-mapping-event-count-2c2c26","errorCode":null,"errorMessage":"Unexpected continuous future mapping event count: {len(continuous_future_last_trading_day_mapping)}","messagePattern":"Unexpected continuous future mapping event count: (.+?)","errorType":"exception","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"Algorithm.Python/HistoryAuxiliaryDataRegressionAlgorithm.py","lineNumber":42,"sourceCode":"        self.set_start_date(2021, 1, 1)\n        self.set_end_date(2021, 1, 5)\n\n        aapl = self.add_equity(\"AAPL\", Resolution.DAILY).symbol\n\n        # multi symbol request\n        spy = Symbol.create(\"SPY\", SecurityType.EQUITY, Market.USA)\n        multi_symbol_request = self.history(Dividend, [ aapl, spy ], 360, Resolution.DAILY)\n        if len(multi_symbol_request) != 12:\n                raise ValueError(f\"Unexpected multi symbol dividend count: {len(multi_symbol_request)}\")\n\n        # continuous future mapping requests\n        sp500 = Symbol.create(Futures.Indices.SP_500_E_MINI, SecurityType.FUTURE, Market.CME)\n        continuous_future_open_interest_mapping = self.history(SymbolChangedEvent, sp500, datetime(2007, 1, 1), datetime(2012, 1, 1), data_mapping_mode = DataMappingMode.OPEN_INTEREST)\n        if len(continuous_future_open_interest_mapping) != 9:\n                raise ValueError(f\"Unexpected continuous future mapping event count: {len(continuous_future_open_interest_mapping)}\")\n        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)\n        if len(continuous_future_last_trading_day_mapping) != 9:\n                raise ValueError(f\"Unexpected continuous future mapping event count: {len(continuous_future_last_trading_day_mapping)}\")\n\n        dividend = self.history(Dividend, aapl, 360)\n        self.debug(str(dividend))\n        if len(dividend) != 6:\n            raise ValueError(f\"Unexpected dividend count: {len(dividend)}\")\n        for distribution in dividend.distribution:\n            if distribution == 0:\n                raise ValueError(f\"Unexpected distribution: {distribution}\")\n\n        split = self.history(Split, aapl, 360)\n        self.debug(str(split))\n        if len(split) != 2:\n            raise ValueError(f\"Unexpected split count: {len(split)}\")\n        for splitfactor in split.splitfactor:\n            if splitfactor == 0:\n                raise ValueError(f\"Unexpected splitfactor: {splitfactor}\")\n\n        symbol = Symbol.create(\"BTCUSD\", SecurityType.CRYPTO_FUTURE, Market.BINANCE)","sourceCodeStart":24,"sourceCodeEnd":60,"githubUrl":"https://github.com/QuantConnect/Lean/blob/d2c3659f877bfc2b5d9dc0fc89a9c7566f45e892/Algorithm.Python/HistoryAuxiliaryDataRegressionAlgorithm.py#L24-L60","documentation":"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.","triggerScenarios":"len(self.history(SymbolChangedEvent, sp500, datetime(2007,1,1), datetime(2012,1,1), data_mapping_mode=LAST_TRADING_DAY)) != 9.","commonSituations":"The LAST_TRADING_DAY roll rule logic changed versus OPEN_INTEREST; mapping data changed; the two modes now disagree on event count.","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."],"exampleFix":"# before\nif len(continuous_future_last_trading_day_mapping) != 9:\n# after\nif len(continuous_future_last_trading_day_mapping) != 9:  # matches OPEN_INTEREST count, verified","handlingStrategy":"validation","validationCode":" ltd = self.history(SymbolChangedEvent, sp500, datetime(2007,1,1), datetime(2012,1,1), data_mapping_mode=DataMappingMode.LAST_TRADING_DAY)\n if len(ltd) != 9:\n     self.debug(f\"LAST_TRADING_DAY mapping events: {len(ltd)} (compare OPEN_INTEREST count)\")","typeGuard":null,"tryCatchPattern":null,"preventionTips":["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."],"tags":["quantconnect","lean","regression","history","auxiliary-data","continuous-futures","symbol-mapping","futures","last-trading-day"],"backgroundTag":null,"analyzedSha":"d2c3659f877bfc2b5d9dc0fc89a9c7566f45e892","analyzedAt":"2026-08-13T13:52:21.013Z","schemaVersion":2},"datasetVersion":"2026-08-13T14:17:21.547Z"}