Fix trade statistics for option assignment underlying fills#9627
Merged
jhonabreul merged 2 commits intoJul 20, 2026
Merged
Conversation
Resolve the security from each order event when updating TradeBuilder so physically settled underlying fills use the underlying multiplier and conversion rate. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> Copilot-Session: 716a0df4-0117-458b-b4ac-7d8aeeb9bf48
Option exercises emit the underlying fill under the option's order id, so resolving the security from the order symbol handed the option's contract multiplier and quote currency conversion rate to the underlying fill, inflating closed trade statistics. Extend the option assignment regression algorithm, in both C# and Python, to assert every closed trade's profit and loss against its own security's contract multiplier.
jhonabreul
approved these changes
Jul 20, 2026
jhonabreul
left a comment
Collaborator
There was a problem hiding this comment.
Thank you for your contribution!
I pushed a commit with a small change: just moved the solution up earlier in the method and updated the algorithms.
Martin-Molinero
approved these changes
Jul 20, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
Physical option settlement emits an option fill and an underlying fill with the same option exercise order ID.
BrokerageTransactionHandlerpreviously used the parent order's security when sending both events toTradeBuilder, so an underlying fill that closed a trade used the option contract multiplier and quote-currency conversion rate.For a standard US equity option, the existing
OptionAssignmentRegressionAlgorithmreproduced an expected underlying loss of $20,000 as $2,000,000. The underlying fill quantity already contains the contract unit of trade, so applying the option multiplier again inflated closed-trade P&L, MAE, MFE, and end-trade drawdown.This change resolves the security from
orderEvent.Symbol, matching portfolio fill processing. Normal fills are unchanged because their order and event symbols are identical.The existing option-assignment regression now verifies every closed underlying trade uses the underlying security's multiplier.
Tests
OptionAssignmentRegressionAlgorithm(fails before the fix, passes after)OptionAssignmentStatisticsRegressionAlgorithmOptionExerciseAssignRegressionAlgorithm