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
- 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.
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
- 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.
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
- {Time} - Unexpected symbol changed event old symbol: {change
- {Time} - Unexpected symbol changed event new symbol: {change
- Contract was not delisted
- Unexpected sold quantity: {_boughtQuantity} and liquidated q
- {Time} unexpected symbol changed event {changedEvent}!
AI-assisted analysis of QuantConnect/Lean@d2c3659f87 (2026-08-13).
Data as JSON: /api/errors/413e99c0d009cacf.
Report an issue: GitHub.