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
|
var positionValue = security.Holdings.GetQuantityValue(quantity, security.Price); |
Potential Solution
Maybe the InitialMarginParameters should take the orderticket as an input?
|
public class InitialMarginParameters |
|
{ |
|
/// <summary> |
|
/// Gets the security |
|
/// </summary> |
|
public Security Security { get; } |
|
|
|
/// <summary> |
|
/// Gets the quantity |
|
/// </summary> |
|
public decimal Quantity { get; } |
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
Expected Behavior
GetInitialMarginRequirementcalculates 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
GetInitialMarginRequirementcalculates 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 hereLean/Common/Securities/CryptoFuture/CryptoFutureMarginModel.cs
Line 77 in 5611b55
Potential Solution
Maybe the
InitialMarginParametersshould take the orderticket as an input?Lean/Common/Securities/InitialMarginParameters.cs
Lines 23 to 33 in 6e2744a
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
masterbranch