Handle insufficient margin for option exercise #7828
Merged
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
Handling insufficient margin for automatic option exercise, which was causing the "Duplicated option assignment..." exception mentioned in the related issue #7815.
With these changes, simulated option exercises are handled using the
Brokerage.OptionNofication
event to create the option exercise order instead of going through the order processor, so that the margin check is bypassed and the order is placed and filled. After this, we expect a margin call like shown in the new regression algorithmInsufficientBuyingPowerForAutomaticExerciseRegressionAlgorithm
.Note: about algorithm's stats change (orders hash): since simulated options exercises are now handled like expired options exercise, without going throught the order processor to place them, some order properties are not populated, like
OrderSubmissionData
andPriceCurrency
, but this should be taclked in a separate PR to keep this clean.Related Issue
Close #7815
Motivation and Context
Requires Documentation Change
How Has This Been Tested?
Regression algorithm
Types of changes
Checklist:
bug-<issue#>-<description>
orfeature-<issue#>-<description>