QuantConnect/Lean · error · RegressionTestException

Unexpected number of symbol changed events (mappings): {_map

Error message

Unexpected number of symbol changed events (mappings): {_mappingsCount}. Expected 1.

What it means

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.

Source

Thrown at Algorithm.CSharp/BasicTemplateEurexFuturesAlgorithm.cs:165

            }
        }

        public override void OnSecuritiesChanged(SecurityChanges changes)
        {
            foreach (var addedSecurity in changes.AddedSecurities)
            {
                if (addedSecurity.Symbol.SecurityType == SecurityType.Future && addedSecurity.Symbol.IsCanonical())
                {
                    _mappedSymbol = _continuousContract.Mapped;
                }
            }
        }

        public override void OnEndOfAlgorithm()
        {
            if (_mappingsCount == 0)
            {
                throw new RegressionTestException($"Unexpected number of symbol changed events (mappings): {_mappingsCount}. Expected 1.");
            }

            if (!_delisted)
            {
                throw new RegressionTestException("Contract was not delisted");
            }

            // Make sure we traded and that the position was liquidated on delisting
            if (_boughtQuantity <= 0 || _liquidatedQuantity >= 0)
            {
                throw new RegressionTestException($"Unexpected sold quantity: {_boughtQuantity} and liquidated quantity: {_liquidatedQuantity}");
            }
        }

        /// <summary>
        /// This is used by the regression test system to indicate if the open source Lean repository has the required data to run this algorithm.
        /// </summary>
        public bool CanRunLocally { get; } = true;

View on GitHub (pinned to d2c3659f87)

Solutions

  1. Confirm the date window (2024-05-30 to 2024-06-23) spans the expected FirstDayMonth rollover for EuroStoxx50.
  2. Verify DataMappingMode.FirstDayMonth and contractDepthOffset: 0 produce a roll in-window.
  3. Ensure the full EUREX contract chain data is present so a remapping candidate exists.
  4. If the window genuinely has no roll, extend the end date or adjust contractDepthOffset to force one.
Defensive patterns

Strategy: validation

Validate before calling

public override void OnEndOfAlgorithm()
{
    if (_mappingsCount != 1)
    {
        Log($"Expected 1 mapping, got {_mappingsCount}. Check date window and mapping mode.");
    }
}

Prevention

When it happens

Trigger: 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.

Common situations: 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.

Related errors


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