QuantConnect/Lean · error · RegressionTestException

Expected subscriptions for the added index option contract

Error message

Expected subscriptions for the added index option contract

What it means

After AddIndexOptionContract(spxOption, Resolution.Minute), this asserts at least two subscriptions exist: the underlying index plus the option contract. A count < 2 means the option contract subscription was not created, so AddIndexOptionContract failed to register its data feed.

Source

Thrown at Algorithm.CSharp/DuplicatedIndexOptionSubscriptionRegressionAlgorithm.cs:57

            if (SubscriptionManager.Subscriptions.Single().Symbol != spx)
            {
                throw new RegressionTestException($"Expected a single subscription to exist ({spx})");
            }

            var spxOption = QuantConnect.Symbol.CreateOption(
                spx,
                Market.USA,
                OptionStyle.European,
                OptionRight.Call,
                3200m,
                new DateTime(2021, 1, 15));

            AddIndexOptionContract(spxOption, Resolution.Minute);

            if (SubscriptionManager.Subscriptions.Count() < 2)
            {
                throw new RegressionTestException("Expected subscriptions for the added index option contract");
            }

            if (SubscriptionManager.Subscriptions.Count(x => x.Symbol == spx) != 1)
            {
                throw new RegressionTestException("Expected a single subscription for the underlying index security");
            }

            // Quit early, we already tested what we wanted
            Quit();
        }

        /// <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.

View on GitHub (pinned to d2c3659f87)

Solutions

  1. List SubscriptionManager.Subscriptions after AddIndexOptionContract to confirm whether the option subscription exists.
  2. Trace AddIndexOptionContract into the SubscriptionManager to see where the option config is added.
  3. Verify the option symbol is valid and resolves to a contract in available data.
Defensive patterns

Strategy: validation

Validate before calling

var symbols = SubscriptionManager.Subscriptions.Select(s => s.Symbol).ToList();
if (symbols.Count < 2 || !symbols.Contains(spxOption))
{
    Log($"Index option contract subscription missing. Subs: {string.Join(", ", symbols)}");
}

Prevention

When it happens

Trigger: AddIndexOptionContract did not add the option's subscription, or it deduplicated against the underlying and removed itself. Subscription registration path for index options broken.

Common situations: Refactor of AddOption/AddIndexOptionContract not registering the contract's subscription; the option symbol resolution colliding with the index; fillForward/resolution handling change.

Related errors


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