{"record":{"id":"8c3d8bb986b54b4c","repo":"QuantConnect/Lean","slug":"stock-was-not-assigned","errorCode":null,"errorMessage":"Stock was not assigned","messagePattern":"Stock was not assigned","errorType":"exception","errorClass":"RegressionTestException","httpStatus":null,"severity":"error","filePath":"Algorithm.CSharp/DuplicateOptionAssignmentRegressionAlgorithm.cs","lineNumber":167,"sourceCode":"                _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)\n            {\n                throw new RegressionTestException(\"Order was not canceled\");\n            }\n\n            var openOrders = Transactions.GetOpenOrders();","sourceCodeStart":149,"sourceCodeEnd":185,"githubUrl":"https://github.com/QuantConnect/Lean/blob/d2c3659f877bfc2b5d9dc0fc89a9c7566f45e892/Algorithm.CSharp/DuplicateOptionAssignmentRegressionAlgorithm.cs#L149-L185","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","solutions":["Log all assignment/option events received to confirm whether the stock-delivery event fired.","Compare the _stock Symbol against the symbol in the received event for SID equality.","Check the SecurityPositionGroup/option assignment modeling for the stock-delivery step."],"exampleFix":null,"handlingStrategy":"validation","validationCode":"// After option assignment, check the delivered stock position exists\nvar stock = Portfolio[_stock];\nif (stock.Quantity == 0)\n{\n    Log($\"No stock position after option assignment for {_option}. Assignment may not have delivered shares.\");\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Compare SIDs (not just tickers) when matching the delivered stock to _stock.","Log all option/assignment events received so stock-delivery events are visible.","Validate the position-group model delivers the underlying on assignment."],"tags":["quantconnect","lean","regression-test","options","assignment","portfolio","postcondition"],"backgroundTag":null,"analyzedSha":"d2c3659f877bfc2b5d9dc0fc89a9c7566f45e892","analyzedAt":"2026-08-13T13:52:21.013Z","schemaVersion":2},"datasetVersion":"2026-08-13T14:17:21.547Z"}