QuantConnect / QuantConnect/Lean

CryptoFutureMarginModel - GetInitialMarginRequirement doesn't consider order type

Open
#7,726 3 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

bug impact-low
Dominant language
C#
Stars
21.7k
Forks
5.3k
Avg merge
2d 22h
Merged PRs (30d)
34

Description

Expected Behavior

GetInitialMarginRequirement calculates the margin required to open a position and in cases of a limit order, it should calculate the position value based on the limit price instead of the security's current price.

Actual Behavior

GetInitialMarginRequirement calculates the margin based on the security's latest price, which leads to inaccurate buying power calculation, especially when the order type is a limit order where the limit price is much lower than the current price. See here https://github.com/QuantConnect/Lean/blob/5611b5508ada70dda96cc2b917e9475400f781e3/Common/Securities/CryptoFuture/CryptoFutureMarginModel.cs#L77

Potential Solution

Maybe the InitialMarginParameters should take the orderticket as an input?https://github.com/QuantConnect/Lean/blob/6e2744af7cf46090bafb166be016ea350df2cb8f/Common/Securities/InitialMarginParameters.cs#L23-L33

Reproducing the Problem

N/A (can provide a failing limit order due to insufficient buying power due to this issue if needed, but the link to the implementation code explains the issue)

System Information

N/A

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 in Common/Securities/CryptoFuture/CryptoFutureMarginModel.cs at GetInitialMarginRequirement, then read Common/Securities/InitialMarginParameters.cs. Trace how the order type and price reach the margin calculation, and verify that limit orders use their limit price while other orders retain the appropriate current-price behavior.

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.