{"record":{"id":"413e99c0d009cacf","repo":"QuantConnect/Lean","slug":"unexpected-number-of-symbol-changed-events-mappin","errorCode":null,"errorMessage":"Unexpected number of symbol changed events (mappings): {_mappingsCount}. Expected 1.","messagePattern":"Unexpected number of symbol changed events \\(mappings\\): (.+?)\\. Expected 1\\.","errorType":"exception","errorClass":"RegressionTestException","httpStatus":null,"severity":"error","filePath":"Algorithm.CSharp/BasicTemplateEurexFuturesAlgorithm.cs","lineNumber":165,"sourceCode":"            }\n        }\n\n        public override void OnSecuritiesChanged(SecurityChanges changes)\n        {\n            foreach (var addedSecurity in changes.AddedSecurities)\n            {\n                if (addedSecurity.Symbol.SecurityType == SecurityType.Future && addedSecurity.Symbol.IsCanonical())\n                {\n                    _mappedSymbol = _continuousContract.Mapped;\n                }\n            }\n        }\n\n        public override void OnEndOfAlgorithm()\n        {\n            if (_mappingsCount == 0)\n            {\n                throw new RegressionTestException($\"Unexpected number of symbol changed events (mappings): {_mappingsCount}. Expected 1.\");\n            }\n\n            if (!_delisted)\n            {\n                throw new RegressionTestException(\"Contract was not delisted\");\n            }\n\n            // Make sure we traded and that the position was liquidated on delisting\n            if (_boughtQuantity <= 0 || _liquidatedQuantity >= 0)\n            {\n                throw new RegressionTestException($\"Unexpected sold quantity: {_boughtQuantity} and liquidated quantity: {_liquidatedQuantity}\");\n            }\n        }\n\n        /// <summary>\n        /// This is used by the regression test system to indicate if the open source Lean repository has the required data to run this algorithm.\n        /// </summary>\n        public bool CanRunLocally { get; } = true;","sourceCodeStart":147,"sourceCodeEnd":183,"githubUrl":"https://github.com/QuantConnect/Lean/blob/d2c3659f877bfc2b5d9dc0fc89a9c7566f45e892/Algorithm.CSharp/BasicTemplateEurexFuturesAlgorithm.cs#L147-L183","documentation":"OnEndOfAlgorithm asserts that exactly one contract-mapping (SymbolChangedEvent) occurred during the run. _mappingsCount == 0 means no rollover happened at all — the continuous contract never remapped, so the rollover test path was never exercised. This is a terminal invariant check that the backtest actually exercised the mapping feature.","triggerScenarios":"OnEndOfAlgorithm runs with _mappingsCount == 0 — no SymbolChangedEvents were emitted across the entire 2024-05-30..2024-06-23 EuroStoxx50 window. The contract depth offset, date window, or data prevented a rollover.","commonSituations":"Backtest date window changed so it no longer spans a FirstDayMonth rollover boundary; contractDepthOffset altered so no remap occurs in-window; EUREX data missing the contract that would trigger the roll; mapping mode change suppresses the event.","solutions":["Confirm the date window (2024-05-30 to 2024-06-23) spans the expected FirstDayMonth rollover for EuroStoxx50.","Verify DataMappingMode.FirstDayMonth and contractDepthOffset: 0 produce a roll in-window.","Ensure the full EUREX contract chain data is present so a remapping candidate exists.","If the window genuinely has no roll, extend the end date or adjust contractDepthOffset to force one."],"exampleFix":null,"handlingStrategy":"validation","validationCode":"public override void OnEndOfAlgorithm()\n{\n    if (_mappingsCount != 1)\n    {\n        Log($\"Expected 1 mapping, got {_mappingsCount}. Check date window and mapping mode.\");\n    }\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Choose a backtest window that spans a FirstDayMonth rollover boundary.","Pin contractDepthOffset and DataMappingMode to values that yield a roll in-window.","Ensure the full contract chain data is present."],"tags":["futures","continuous-contract","symbol-mapping","regression-test","eurex","invariant"],"backgroundTag":null,"analyzedSha":"d2c3659f877bfc2b5d9dc0fc89a9c7566f45e892","analyzedAt":"2026-08-13T13:52:21.013Z","schemaVersion":2},"datasetVersion":"2026-08-13T14:17:21.547Z"}