Lean
$LEAN_TAG$
|
Provides a base class for all buying power models More...
Public Member Functions | |
BuyingPowerModel () | |
Initializes a new instance of the BuyingPowerModel with no leverage (1x) More... | |
BuyingPowerModel (decimal initialMarginRequirement, decimal maintenanceMarginRequirement, decimal requiredFreeBuyingPowerPercent) | |
Initializes a new instance of the BuyingPowerModel More... | |
BuyingPowerModel (decimal leverage, decimal requiredFreeBuyingPowerPercent=0) | |
Initializes a new instance of the BuyingPowerModel More... | |
virtual decimal | GetLeverage (Security security) |
Gets the current leverage of the security More... | |
virtual void | SetLeverage (Security security, decimal leverage) |
Sets the leverage for the applicable securities, i.e, equities More... | |
virtual InitialMargin | GetInitialMarginRequiredForOrder (InitialMarginRequiredForOrderParameters parameters) |
Gets the total margin required to execute the specified order in units of the account currency including fees More... | |
virtual MaintenanceMargin | GetMaintenanceMargin (MaintenanceMarginParameters parameters) |
Gets the margin currently allocated to the specified holding More... | |
virtual InitialMargin | GetInitialMarginRequirement (InitialMarginParameters parameters) |
The margin that must be held in order to increase the position by the provided quantity More... | |
virtual HasSufficientBuyingPowerForOrderResult | HasSufficientBuyingPowerForOrder (HasSufficientBuyingPowerForOrderParameters parameters) |
Check if there is sufficient buying power to execute this order. More... | |
virtual GetMaximumOrderQuantityResult | GetMaximumOrderQuantityForDeltaBuyingPower (GetMaximumOrderQuantityForDeltaBuyingPowerParameters parameters) |
Get the maximum market order quantity to obtain a delta in the buying power used by a security. The deltas sign defines the position side to apply it to, positive long, negative short. More... | |
virtual GetMaximumOrderQuantityResult | GetMaximumOrderQuantityForTargetBuyingPower (GetMaximumOrderQuantityForTargetBuyingPowerParameters parameters) |
Get the maximum market order quantity to obtain a position with a given buying power percentage. Will not take into account free buying power. More... | |
decimal | GetAmountToOrder ([NotNull]Security security, decimal targetMargin, decimal marginForOneUnit, out decimal finalMargin) |
Helper function that determines the amount to order to get to a given target safely. Meaning it will either be at or just below target always. More... | |
virtual ReservedBuyingPowerForPosition | GetReservedBuyingPowerForPosition (ReservedBuyingPowerForPositionParameters parameters) |
Gets the amount of buying power reserved to maintain the specified position More... | |
virtual BuyingPower | GetBuyingPower (BuyingPowerParameters parameters) |
Gets the buying power available for a trade More... | |
Static Public Attributes | |
static readonly IBuyingPowerModel | Null = new NullBuyingPowerModel() |
Gets an implementation of IBuyingPowerModel that does not check for sufficient buying power More... | |
Protected Member Functions | |
virtual decimal | GetMarginRemaining (SecurityPortfolioManager portfolio, Security security, OrderDirection direction) |
Gets the margin cash available for a trade More... | |
Properties | |
decimal | RequiredFreeBuyingPowerPercent [get, set] |
The percentage used to determine the required unused buying power for the account. More... | |
Provides a base class for all buying power models
Definition at line 27 of file BuyingPowerModel.cs.
QuantConnect.Securities.BuyingPowerModel.BuyingPowerModel | ( | ) |
Initializes a new instance of the BuyingPowerModel with no leverage (1x)
Definition at line 46 of file BuyingPowerModel.cs.
QuantConnect.Securities.BuyingPowerModel.BuyingPowerModel | ( | decimal | initialMarginRequirement, |
decimal | maintenanceMarginRequirement, | ||
decimal | requiredFreeBuyingPowerPercent | ||
) |
Initializes a new instance of the BuyingPowerModel
initialMarginRequirement | The percentage of an order's absolute cost that must be held in free cash in order to place the order |
maintenanceMarginRequirement | The percentage of the holding's absolute cost that must be held in free cash in order to avoid a margin call |
requiredFreeBuyingPowerPercent | The percentage used to determine the required unused buying power for the account. |
Definition at line 60 of file BuyingPowerModel.cs.
QuantConnect.Securities.BuyingPowerModel.BuyingPowerModel | ( | decimal | leverage, |
decimal | requiredFreeBuyingPowerPercent = 0 |
||
) |
Initializes a new instance of the BuyingPowerModel
leverage | The leverage |
requiredFreeBuyingPowerPercent | The percentage used to determine the required unused buying power for the account. |
Definition at line 92 of file BuyingPowerModel.cs.
|
virtual |
Gets the current leverage of the security
security | The security to get leverage for |
Implements QuantConnect.Securities.IBuyingPowerModel.
Reimplemented in QuantConnect.Securities.Future.FutureMarginModel, QuantConnect.Securities.PatternDayTradingMarginModel, QuantConnect.Securities.Option.OptionMarginModel, and QuantConnect.Securities.CashBuyingPowerModel.
Definition at line 114 of file BuyingPowerModel.cs.
|
virtual |
Sets the leverage for the applicable securities, i.e, equities
This is added to maintain backwards compatibility with the old margin/leverage system
security | |
leverage | The new leverage |
Implements QuantConnect.Securities.IBuyingPowerModel.
Reimplemented in QuantConnect.Securities.Future.FutureMarginModel, QuantConnect.Securities.Option.OptionMarginModel, QuantConnect.Securities.CashBuyingPowerModel, QuantConnect.Securities.PatternDayTradingMarginModel, and QuantConnect.Securities.ConstantBuyingPowerModel.
Definition at line 127 of file BuyingPowerModel.cs.
|
virtual |
Gets the total margin required to execute the specified order in units of the account currency including fees
parameters | An object containing the portfolio, the security and the order |
Implements QuantConnect.Securities.IBuyingPowerModel.
Reimplemented in QuantConnect.Securities.Future.FutureMarginModel, and QuantConnect.Securities.Option.OptionMarginModel.
Definition at line 144 of file BuyingPowerModel.cs.
|
virtual |
Gets the margin currently allocated to the specified holding
parameters | An object containing the security and holdings quantity/cost/value |
Implements QuantConnect.Securities.IBuyingPowerModel.
Reimplemented in QuantConnect.Securities.Future.FutureMarginModel, QuantConnect.Securities.Option.OptionMarginModel, QuantConnect.Securities.PatternDayTradingMarginModel, QuantConnect.Securities.Option.FuturesOptionsMarginModel, QuantConnect.Securities.ConstantBuyingPowerModel, QuantConnect.Securities.CryptoFuture.CryptoFutureMarginModel, and QuantConnect.Securities.NullBuyingPowerModel.
Definition at line 167 of file BuyingPowerModel.cs.
|
protectedvirtual |
Gets the margin cash available for a trade
portfolio | The algorithm's portfolio |
security | The security to be traded |
direction | The direction of the trade |
Reimplemented in QuantConnect.Securities.CryptoFuture.CryptoFutureMarginModel.
Definition at line 179 of file BuyingPowerModel.cs.
|
virtual |
The margin that must be held in order to increase the position by the provided quantity
parameters | An object containing the security and quantity of shares |
Implements QuantConnect.Securities.IBuyingPowerModel.
Reimplemented in QuantConnect.Securities.Future.FutureMarginModel, QuantConnect.Securities.Option.OptionMarginModel, QuantConnect.Securities.Option.FuturesOptionsMarginModel, QuantConnect.Securities.PatternDayTradingMarginModel, QuantConnect.Securities.CryptoFuture.CryptoFutureMarginModel, QuantConnect.Securities.CashBuyingPowerModel, and QuantConnect.Securities.ConstantBuyingPowerModel.
Definition at line 230 of file BuyingPowerModel.cs.
|
virtual |
Check if there is sufficient buying power to execute this order.
parameters | An object containing the portfolio, the security and the order |
Implements QuantConnect.Securities.IBuyingPowerModel.
Reimplemented in QuantConnect.Securities.CashBuyingPowerModel, and QuantConnect.Securities.NullBuyingPowerModel.
Definition at line 246 of file BuyingPowerModel.cs.
|
virtual |
Get the maximum market order quantity to obtain a delta in the buying power used by a security. The deltas sign defines the position side to apply it to, positive long, negative short.
parameters | An object containing the portfolio, the security and the delta buying power |
Used by the margin call model to reduce the position by a delta percent.
Implements QuantConnect.Securities.IBuyingPowerModel.
Reimplemented in QuantConnect.Securities.CashBuyingPowerModel.
Definition at line 333 of file BuyingPowerModel.cs.
|
virtual |
Get the maximum market order quantity to obtain a position with a given buying power percentage. Will not take into account free buying power.
parameters | An object containing the portfolio, the security and the target signed buying power percentage |
This implementation ensures that our resulting holdings is less than the target, but it does not necessarily maximize the holdings to meet the target. To do that we need a minimizing algorithm that reduces the difference between the target final margin value and the target holdings margin.
Implements QuantConnect.Securities.IBuyingPowerModel.
Reimplemented in QuantConnect.Securities.CashBuyingPowerModel, and QuantConnect.Securities.Future.FutureMarginModel.
Definition at line 366 of file BuyingPowerModel.cs.
decimal QuantConnect.Securities.BuyingPowerModel.GetAmountToOrder | ( | [NotNull] Security | security, |
decimal | targetMargin, | ||
decimal | marginForOneUnit, | ||
out decimal | finalMargin | ||
) |
Helper function that determines the amount to order to get to a given target safely. Meaning it will either be at or just below target always.
security | Security we are to determine order size for |
targetMargin | Target margin allocated |
marginForOneUnit | Margin requirement for one unit; used in our initial order guess |
finalMargin | Output the final margin allocated to this security |
Definition at line 480 of file BuyingPowerModel.cs.
|
virtual |
Gets the amount of buying power reserved to maintain the specified position
parameters | A parameters object containing the security |
Implements QuantConnect.Securities.IBuyingPowerModel.
Reimplemented in QuantConnect.Securities.CashBuyingPowerModel.
Definition at line 549 of file BuyingPowerModel.cs.
|
virtual |
Gets the buying power available for a trade
parameters | A parameters object containing the algorithm's portfolio, security, and order direction |
Implements QuantConnect.Securities.IBuyingPowerModel.
Reimplemented in QuantConnect.Securities.CashBuyingPowerModel.
Definition at line 560 of file BuyingPowerModel.cs.
|
static |
Gets an implementation of IBuyingPowerModel that does not check for sufficient buying power
Definition at line 33 of file BuyingPowerModel.cs.
|
getsetprotected |
The percentage used to determine the required unused buying power for the account.
Definition at line 41 of file BuyingPowerModel.cs.