{"record":{"id":"1bf339fdf4ea441c","repo":"QuantConnect/Lean","slug":"option-was-not-assigned","errorCode":null,"errorMessage":"Option was not assigned","messagePattern":"Option was not assigned","errorType":"exception","errorClass":"RegressionTestException","httpStatus":null,"severity":"error","filePath":"Algorithm.CSharp/DuplicateOptionAssignmentRegressionAlgorithm.cs","lineNumber":162,"sourceCode":"                if (!_optionSold || !_optionAssigned || !_stockAssigned || !_optionDelistedWarningReceived || _optionDelisted)\n                {\n                    throw new RegressionTestException($\"Unexpected delisting event: {delisting}\");\n                }\n\n                _optionDelisted = true;\n            }\n        }\n\n        public override void OnEndOfAlgorithm()\n        {\n            if (!_optionSold)\n            {\n                throw new RegressionTestException(\"Option was not sold\");\n            }\n\n            if (!_optionAssigned)\n            {\n                throw new RegressionTestException(\"Option was not assigned\");\n            }\n\n            if (!_stockAssigned)\n            {\n                throw new RegressionTestException(\"Stock was not assigned\");\n            }\n\n            if (!_optionDelistedWarningReceived)\n            {\n                throw new RegressionTestException(\"Option delisting warning was not received\");\n            }\n\n            if (!_optionDelisted)\n            {\n                throw new RegressionTestException(\"Option was not delisted\");\n            }\n\n            if (!_orderCanceled)","sourceCodeStart":144,"sourceCodeEnd":180,"githubUrl":"https://github.com/QuantConnect/Lean/blob/d2c3659f877bfc2b5d9dc0fc89a9c7566f45e892/Algorithm.CSharp/DuplicateOptionAssignmentRegressionAlgorithm.cs#L144-L180","documentation":"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.","triggerScenarios":"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.","commonSituations":"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).","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."],"exampleFix":null,"handlingStrategy":"validation","validationCode":"// Validate assignment is feasible before asserting it occurred\nvar expiry = _option.ID.Date;\nif (Time < expiry) Log(\"Algorithm ends before option expiry; assignment cannot occur\");\nvar itm = IsOptionInTheMoney(_option, Securities[_underlying].Price);\nif (!itm) Log(\"Option not ITM; auto-assignment unlikely\");","typeGuard":null,"tryCatchPattern":null,"preventionTips":["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."],"tags":["quantconnect","lean","regression-test","options","assignment","postcondition"],"backgroundTag":null,"analyzedSha":"d2c3659f877bfc2b5d9dc0fc89a9c7566f45e892","analyzedAt":"2026-08-13T13:52:21.013Z","schemaVersion":2},"datasetVersion":"2026-08-13T14:17:21.547Z"}