Skip to content

Use option quotes for target margin pricing#9539

Open
scarab-systems wants to merge 1 commit into
QuantConnect:masterfrom
scarab-systems:bug-6360-portfolio-target-option-quotes
Open

Use option quotes for target margin pricing#9539
scarab-systems wants to merge 1 commit into
QuantConnect:masterfrom
scarab-systems:bug-6360-portfolio-target-option-quotes

Conversation

@scarab-systems

@scarab-systems scarab-systems commented Jun 17, 2026

Copy link
Copy Markdown

Description

This updates option initial margin pricing to use available executable quote prices when calculating the premium/margin value for a target option quantity:

  • positive option quantities use the ask price when available
  • negative option quantities use the bid price when available
  • existing last/mark price behavior remains the fallback when quote prices are unavailable

This keeps the change local to the option margin model and avoids changing the generic buying power model behavior for other security types.

Related Issue

Closes #6360

Motivation and Context

PortfolioTarget.Percent depends on the security buying power model's initial margin requirement when calculating target quantities. For options, the existing initial margin path priced the quantity with security.Price. When quote data is available, that can size long option targets from a mid/last price instead of the ask, causing the filled position weight to exceed the requested target percentage by roughly the bid/ask spread.

Using the ask for increases and bid for reductions makes option target sizing line up with the executable side of the quote while retaining the previous fallback behavior when quote data has not been populated.

Requires Documentation Change

No.

How Has This Been Tested?

Tested in the QuantConnect foundation container on local Linux arm64:

  • dotnet build /p:Configuration=Release /v:quiet /p:WarningLevel=1 QuantConnect.Lean.sln passed.
  • dotnet test ./Tests/bin/Release/QuantConnect.Tests.dll --blame-hang-timeout 300seconds --blame-crash --filter "FullyQualifiedName~QuantConnect.Tests.Common.Securities.OptionMarginBuyingPowerModelTests" -- "TestRunParameters.Parameter(name=\"log-handler\", value=\"ConsoleErrorLogHandler\")" passed: 41 passed, 0 failed.
  • A full local arm64 foundation-container run of QuantConnect.Tests.dll with the repository CI filter completed with 35,966 passed, 26 skipped, and 2 failures.

The two local full-suite failures were checked against unchanged upstream master at the same base commit and reproduced there as well in the same arm64 foundation-container environment:

  • CompressionTests.ZipBytesReturnsByteArrayWithCorrectLength fails on upstream master with expected 906121, actual 905693.
  • LiveTradingDataFeedTests.HandlesAllTypes has local timeout behavior on upstream master as well.

So the option-margin change and its focused test coverage pass locally, while the full local arm64 suite has baseline failures that are not introduced by this branch. I am leaving the checklist item for all existing tests unchecked rather than claiming that local full-suite result passed.

Types of changes

  • Bug fix (non-breaking change which fixes an issue)
  • Refactor (non-breaking change which improves implementation)
  • Performance (non-breaking change which improves performance. Please add associated performance test and results)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to change)
  • Non-functional change (xml comments/documentation/etc)

Checklist:

  • My code follows the code style of this project.
  • I have read the CONTRIBUTING document.
  • I have added tests to cover my changes.
  • All new and existing tests passed. See testing note above: focused tests pass; two local arm64 full-suite failures reproduce on unchanged upstream master.
  • My branch follows the naming convention bug-<issue#>-<description> or feature-<issue#>-<description>

@scarab-systems

Copy link
Copy Markdown
Author

Closing this draft while I complete local verification against the project checklist. I’ll resubmit once I can satisfy the PR requirements cleanly.

@scarab-systems scarab-systems deleted the bug-6360-portfolio-target-option-quotes branch June 17, 2026 14:58
@scarab-systems scarab-systems restored the bug-6360-portfolio-target-option-quotes branch June 17, 2026 16:39
@scarab-systems scarab-systems marked this pull request as ready for review June 17, 2026 16:39
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.

Actual portfolio weight exceeds target percentage when using PortfolioTarget.Percent

1 participant