QuantConnect/Lean · error · RegressionTestException

Option was not assigned

Error message

Option was not assigned

What it means

Postcondition: _optionAssigned must be true, meaning the short option was assigned (counterparty exercised it) and Lean fired the assignment event the test listens for. Assignment converts the short option into a stock position. Failure means the assignment/exercise pipeline never delivered the assignment event.

Source

Thrown at Algorithm.CSharp/DuplicateOptionAssignmentRegressionAlgorithm.cs:162

                if (!_optionSold || !_optionAssigned || !_stockAssigned || !_optionDelistedWarningReceived || _optionDelisted)
                {
                    throw new RegressionTestException($"Unexpected delisting event: {delisting}");
                }

                _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)

View on GitHub (pinned to d2c3659f87)

Solutions

  1. Confirm the algorithm's end date is on/after the option expiration so assignment can occur.
  2. Inspect Lean's exercise/assignment dispatch for the option and the matching handler in the test.
  3. Verify the option is ITM at expiration so the model triggers auto-exercise/assignment.
Defensive patterns

Strategy: validation

Validate before calling

// Validate assignment is feasible before asserting it occurred
var expiry = _option.ID.Date;
if (Time < expiry) Log("Algorithm ends before option expiry; assignment cannot occur");
var itm = IsOptionInTheMoney(_option, Securities[_underlying].Price);
if (!itm) Log("Option not ITM; auto-assignment unlikely");

Prevention

When it happens

Trigger: The option never reaches expiration in-the-money, the OptionAssignmentService did not run, or OnAssignment into the algorithm did not match the symbol. Also if the exercise logic changed.

Common situations: Data date range no longer spans the option expiration; option right/strike changes; refactor of how assignments are dispatched to algorithms (e.g. new OnAssignmentRendered vs OnOptionsAssigned).

Related errors


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