Use option quotes for target margin pricing#9539
Open
scarab-systems wants to merge 1 commit into
Open
Conversation
Author
|
Closing this draft while I complete local verification against the project checklist. I’ll resubmit once I can satisfy the PR requirements cleanly. |
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
This updates option initial margin pricing to use available executable quote prices when calculating the premium/margin value for a target option quantity:
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.Percentdepends on the security buying power model's initial margin requirement when calculating target quantities. For options, the existing initial margin path priced the quantity withsecurity.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.slnpassed.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.QuantConnect.Tests.dllwith 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
masterat the same base commit and reproduced there as well in the same arm64 foundation-container environment:CompressionTests.ZipBytesReturnsByteArrayWithCorrectLengthfails on upstreammasterwith expected906121, actual905693.LiveTradingDataFeedTests.HandlesAllTypeshas local timeout behavior on upstreammasteras 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
Checklist:
master.bug-<issue#>-<description>orfeature-<issue#>-<description>