{"record":{"id":"8528aaef9294cca6","repo":"QuantConnect/Lean","slug":"unexpected-continuous-future-mapping-event-count","errorCode":null,"errorMessage":"Unexpected continuous future mapping event count: {len(continuous_future_open_interest_mapping)}","messagePattern":"Unexpected continuous future mapping event count: (.+?)","errorType":"exception","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"Algorithm.Python/HistoryAuxiliaryDataRegressionAlgorithm.py","lineNumber":39,"sourceCode":"    def initialize(self):\n        '''Initialise the data and resolution required, as well as the cash and start-end dates for your algorithm. All algorithms must initialized.'''\n\n        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:","sourceCodeStart":21,"sourceCodeEnd":57,"githubUrl":"https://github.com/QuantConnect/Lean/blob/d2c3659f877bfc2b5d9dc0fc89a9c7566f45e892/Algorithm.Python/HistoryAuxiliaryDataRegressionAlgorithm.py#L21-L57","documentation":"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.","triggerScenarios":"len(self.history(SymbolChangedEvent, sp500, datetime(2007,1,1), datetime(2012,1,1), data_mapping_mode=OPEN_INTEREST)) != 9.","commonSituations":"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.","solutions":["Verify the ES mapping files (CME future chain, symbol-change events) cover 2007-2011 and reconcile the event count to 9.","Inspect continuous-future mapping selection (DataMappingMode.OPEN_INTEREST) code for changes.","Confirm the request date range is unchanged.","Rebaseline 9 if mapping data was legitimately corrected."],"exampleFix":"# before\nif len(continuous_future_open_interest_mapping) != 9:\n# after: verified mapping-event count after a data refresh\nif len(continuous_future_open_interest_mapping) != 9:  # verified against ES mapping files 2007-2012","handlingStrategy":"validation","validationCode":"# log mapping-mode event counts side by side\noi = self.history(SymbolChangedEvent, sp500, datetime(2007,1,1), datetime(2012,1,1), data_mapping_mode=DataMappingMode.OPEN_INTEREST)\nif len(oi) != 9:\n    self.debug(f\"OPEN_INTEREST mapping events: {len(oi)}\\n{oi}\")","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Keep the continuous-future date window fixed in regression tests.","Compare mapping-mode counts against each other to detect mode-specific drift.","Version-pin the futures mapping data files used by CI."],"tags":["quantconnect","lean","regression","history","auxiliary-data","continuous-futures","symbol-mapping","futures"],"backgroundTag":null,"analyzedSha":"d2c3659f877bfc2b5d9dc0fc89a9c7566f45e892","analyzedAt":"2026-08-13T13:52:21.013Z","schemaVersion":2},"datasetVersion":"2026-08-13T14:17:21.547Z"}