QuantConnect/Lean · error · RegressionTestException

Stock was not assigned

Error message

Stock was not assigned

What it means

Asserts _stockAssigned: the option assignment delivered the underlying stock into the portfolio. In Lean, assigning a short call delivers a short stock position (and a short put delivers long stock). If this is false, the assignment fired but the resulting stock position event was not captured by the test's handler.

Source

Thrown at Algorithm.CSharp/DuplicateOptionAssignmentRegressionAlgorithm.cs:167

                _optionDelisted = true;
            }
        }

        public override void OnEndOfAlgorithm()
        {
            if (!_optionSold)
            {
                throw new RegressionTestException("Option was not sold");
            }

            if (!_optionAssigned)
            {
                throw new RegressionTestException("Option was not assigned");
            }

            if (!_stockAssigned)
            {
                throw new RegressionTestException("Stock was not assigned");
            }

            if (!_optionDelistedWarningReceived)
            {
                throw new RegressionTestException("Option delisting warning was not received");
            }

            if (!_optionDelisted)
            {
                throw new RegressionTestException("Option was not delisted");
            }

            if (!_orderCanceled)
            {
                throw new RegressionTestException("Order was not canceled");
            }

            var openOrders = Transactions.GetOpenOrders();

View on GitHub (pinned to d2c3659f87)

Solutions

  1. Log all assignment/option events received to confirm whether the stock-delivery event fired.
  2. Compare the _stock Symbol against the symbol in the received event for SID equality.
  3. Check the SecurityPositionGroup/option assignment modeling for the stock-delivery step.
Defensive patterns

Strategy: validation

Validate before calling

// After option assignment, check the delivered stock position exists
var stock = Portfolio[_stock];
if (stock.Quantity == 0)
{
    Log($"No stock position after option assignment for {_option}. Assignment may not have delivered shares.");
}

Prevention

When it happens

Trigger: The assignment fired for the option but the paired stock assignment event did not arrive, or the handler that sets _stockAssigned did not match the stock symbol.

Common situations: Split between option-assignment and stock-delivery events changed; the underlying symbol object differs (SID mismatch) so the handler's symbol comparison fails; group/margin handling refactor.

Related errors


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