QuantConnect/Lean · error · RegressionTestException

Unexpected order event symbol!

Error message

Unexpected order event symbol!

What it means

Thrown in OnOrderEvent when orderEvent.Symbol.ID.Symbol is not 'SPXW'. The algorithm trades SPXW (SPX weekly) index options exclusively via a Bear Call Spread strategy. Any order event from a different symbol (e.g., SPX, the underlying, or a non-weekly SPX option) indicates the option strategy generated legs on unexpected contracts.

Source

Thrown at Algorithm.CSharp/BasicTemplateSPXWeeklyIndexOptionsStrategyAlgorithm.cs:95

                if (contracts.Count > 1)
                {
                    var smallerStrike = contracts[0];
                    var higherStrike = contracts[1];

                    // if found, buy until it expires
                    var optionStrategy = OptionStrategies.BearCallSpread(_spxOption, smallerStrike.Strike, higherStrike.Strike, smallerStrike.Expiry);
                    Buy(optionStrategy, 1);
                }
            }
        }

        public override void OnOrderEvent(OrderEvent orderEvent)
        {
            Debug(orderEvent.ToString());
            if (orderEvent.Symbol.ID.Symbol != "SPXW")
            {
                throw new RegressionTestException("Unexpected order event symbol!");
            }
        }

        /// <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 virtual bool CanRunLocally { get; } = true;

        /// <summary>
        /// This is used by the regression test system to indicate which languages this algorithm is written in.
        /// </summary>
        public virtual List<Language> Languages { get; } = new() { Language.CSharp };

        /// <summary>
        /// Data Points count of all timeslices of algorithm
        /// </summary>
        public virtual long DataPoints => 26399;

View on GitHub (pinned to d2c3659f87)

Solutions

  1. Verify the AddIndexOption canonical symbol is 'SPXW' and the filter only returns weekly contracts.
  2. Log orderEvent.Symbol in OnOrderEvent to identify which unexpected symbol triggered the assertion.
  3. Check OptionStrategies.BearCallSpread leg resolution to confirm it only uses SPXW contracts from the chain.
  4. Inspect the option chain data for contamination with non-SPXW symbols.

Example fix

// before
public override void OnOrderEvent(OrderEvent orderEvent)
{
    if (orderEvent.Symbol.ID.Symbol != "SPXW")
    {
        throw new RegressionTestException("Unexpected order event symbol!");
    }
}

// after — diagnose the offending symbol
public override void OnOrderEvent(OrderEvent orderEvent)
{
    if (orderEvent.Symbol.ID.Symbol != "SPXW")
    {
        throw new RegressionTestException(
            $"Unexpected order event symbol: {orderEvent.Symbol.ID.Symbol} (full: {orderEvent.Symbol})");
    }
}
Defensive patterns

Strategy: validation

Validate before calling

// Validate symbol before asserting
if (orderEvent.Symbol.ID.Symbol != "SPXW")
{
    Log($"Unexpected symbol in order event: {orderEvent.Symbol} (canonical: {orderEvent.Symbol.ID.Symbol})");
}

Type guard

bool IsExpectedSymbol(OrderEvent ev) => ev.Symbol.ID.Symbol == "SPXW";

Prevention

When it happens

Trigger: The option filter returns non-SPXW contracts (standard SPX options), the BearCallSpread strategy resolves legs to the underlying, the option chain contains mixed SPX and SPXW contracts, or a symbol-creation change alters the ticker string.

Common situations: AddIndexOption filter not restrictive enough (missing IncludeWeeklys or strikes filter), option strategy leg resolution picks up non-weekly contracts, or data file changes introduce SPX contracts into the SPXW chain.

Related errors


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