Skip to content

Fix trade statistics for option assignment underlying fills#9627

Merged
jhonabreul merged 2 commits into
QuantConnect:masterfrom
YadavKapil:fix/option-assignment-trade-statistics
Jul 20, 2026
Merged

Fix trade statistics for option assignment underlying fills#9627
jhonabreul merged 2 commits into
QuantConnect:masterfrom
YadavKapil:fix/option-assignment-trade-statistics

Conversation

@YadavKapil

Copy link
Copy Markdown
Contributor

Description

Physical option settlement emits an option fill and an underlying fill with the same option exercise order ID. BrokerageTransactionHandler previously used the parent order's security when sending both events to TradeBuilder, 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 OptionAssignmentRegressionAlgorithm reproduced 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)
  • OptionAssignmentStatisticsRegressionAlgorithm
  • OptionExerciseAssignRegressionAlgorithm

Kapil Yadav and others added 2 commits July 19, 2026 15:26
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 jhonabreul left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

@jhonabreul
jhonabreul merged commit 4249165 into QuantConnect:master Jul 20, 2026
7 of 8 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants