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
- Confirm the algorithm's end date is on/after the option expiration so assignment can occur.
- Inspect Lean's exercise/assignment dispatch for the option and the matching handler in the test.
- 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
- Ensure the backtest end date covers the option expiration for assignment to occur.
- Confirm the option is ITM at expiry so auto-exercise/assignment triggers.
- Log every assignment event as it arrives so missing ones are obvious.
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
- Stock was not assigned
- Option was not sold
- Option delisting warning was not received
- Option was not delisted
- Expected option assignment but got: {orderEvent}
AI-assisted analysis of QuantConnect/Lean@d2c3659f87 (2026-08-13).
Data as JSON: /api/errors/1bf339fdf4ea441c.
Report an issue: GitHub.