QuantConnect / QuantConnect/Lean

Option Position Match Finds Optimal Strategy (Lowest Margin Required)

Open
#8,136 0 comments 1 reaction 0 assignees View on GitHub

Nobody has claimed this yet.

bug
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 master branch
  • I have confirmed that this is not a duplicate issue by searching issues
  • I have provided detailed steps to reproduce the issue

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. 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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.