QuantConnect / QuantConnect/Lean
Option Position Match Finds Optimal Strategy (Lowest Margin Required)
Nobody has claimed this yet.
- Dominant language
- C#
- Stars
- 21.7k
- Forks
- 5.3k
- Avg merge
- 2d 22h
- Merged PRs (30d)
- 34
Description
Expected Behavior
LEAN matches options legs to find the combination that requires less margin.
Actual Behavior
LEAN matches options legs that don't have the minimum margin requirement.
Potential Solution
N/A
Reproducing the Problem
Buy two bear call spread with different strikes: Spread 1 (A > B) > Spread 2 (C > D). On OptionEquityBearCallSpreadRegressionAlgorithm, add:
callContracts = callContracts.Where(contract => contract.Strike > longCall.Strike && contract.Expiry == longCall.Expiry).ToList();
MarketOrder(callContracts[0].Symbol, -5);
AssertOptionStrategyIsPresent(OptionStrategyDefinitions.ShortButterflyCall.Name, 2);
MarketOrder(callContracts[1].Symbol, 5);
AssertOptionStrategyIsPresent(OptionStrategyDefinitions.BearCallSpread.Name, 10);
On OptionEquityBaseStrategyRegressionAlgorithm, we need to increase the strike range to +5:
u.Strikes(-2, +5)
We should have two bear call spread with 10 contracts, but we have:
2 Butterfly Calls
1 Short Butterfly Call
4 Bear Call Spread
And we used the Short Butterfly Call to get the margin.
The backtest on the following thread also reproduces the issue:
https://www.quantconnect.com/forum/discussion/17414/unexpected-remaining-margin-decrease/p1
Checklist
- I have completely filled out this template
- I have confirmed that this issue exists on the current
masterbranch - I have confirmed that this is not a duplicate issue by searching issues
- I have provided detailed steps to reproduce the issue
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with OptionEquityBearCallSpreadRegressionAlgorithm and OptionEquityBaseStrategyRegressionAlgorithm, applying the reproduction steps and the expanded u.Strikes(-2, +5) range. Compare the resulting strategy classifications and margin selection with the expected two bear call spreads. Done means the lowest-margin valid option strategy is selected and the regression assertions pass.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- csharp
- Domain
- fintech-quant
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 38/100