Lean  $LEAN_TAG$
QuantConnect.Securities.BuyingPowerModel Class Reference

Provides a base class for all buying power models More...

Inheritance diagram for QuantConnect.Securities.BuyingPowerModel:
[legend]

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...
 

Detailed Description

Provides a base class for all buying power models

Definition at line 27 of file BuyingPowerModel.cs.

Constructor & Destructor Documentation

◆ BuyingPowerModel() [1/3]

QuantConnect.Securities.BuyingPowerModel.BuyingPowerModel ( )

Initializes a new instance of the BuyingPowerModel with no leverage (1x)

Definition at line 46 of file BuyingPowerModel.cs.

◆ BuyingPowerModel() [2/3]

QuantConnect.Securities.BuyingPowerModel.BuyingPowerModel ( decimal  initialMarginRequirement,
decimal  maintenanceMarginRequirement,
decimal  requiredFreeBuyingPowerPercent 
)

Initializes a new instance of the BuyingPowerModel

Parameters
initialMarginRequirementThe percentage of an order's absolute cost that must be held in free cash in order to place the order
maintenanceMarginRequirementThe percentage of the holding's absolute cost that must be held in free cash in order to avoid a margin call
requiredFreeBuyingPowerPercentThe percentage used to determine the required unused buying power for the account.

Definition at line 60 of file BuyingPowerModel.cs.

◆ BuyingPowerModel() [3/3]

QuantConnect.Securities.BuyingPowerModel.BuyingPowerModel ( decimal  leverage,
decimal  requiredFreeBuyingPowerPercent = 0 
)

Initializes a new instance of the BuyingPowerModel

Parameters
leverageThe leverage
requiredFreeBuyingPowerPercentThe percentage used to determine the required unused buying power for the account.

Definition at line 92 of file BuyingPowerModel.cs.

Member Function Documentation

◆ GetLeverage()

virtual decimal QuantConnect.Securities.BuyingPowerModel.GetLeverage ( Security  security)
virtual

Gets the current leverage of the security

Parameters
securityThe security to get leverage for
Returns
The current leverage in the security

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.

Here is the caller graph for this function:

◆ SetLeverage()

virtual void QuantConnect.Securities.BuyingPowerModel.SetLeverage ( Security  security,
decimal  leverage 
)
virtual

Sets the leverage for the applicable securities, i.e, equities

This is added to maintain backwards compatibility with the old margin/leverage system

Parameters
security
leverageThe 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.

Here is the caller graph for this function:

◆ GetInitialMarginRequiredForOrder()

virtual InitialMargin QuantConnect.Securities.BuyingPowerModel.GetInitialMarginRequiredForOrder ( InitialMarginRequiredForOrderParameters  parameters)
virtual

Gets the total margin required to execute the specified order in units of the account currency including fees

Parameters
parametersAn object containing the portfolio, the security and the order
Returns
The total margin in terms of the currency quoted in 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.

Here is the call graph for this function:

◆ GetMaintenanceMargin()

virtual MaintenanceMargin QuantConnect.Securities.BuyingPowerModel.GetMaintenanceMargin ( MaintenanceMarginParameters  parameters)
virtual

Gets the margin currently allocated to the specified holding

Parameters
parametersAn object containing the security and holdings quantity/cost/value
Returns
The maintenance margin required for the provided 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.

Here is the caller graph for this function:

◆ GetMarginRemaining()

virtual decimal QuantConnect.Securities.BuyingPowerModel.GetMarginRemaining ( SecurityPortfolioManager  portfolio,
Security  security,
OrderDirection  direction 
)
protectedvirtual

Gets the margin cash available for a trade

Parameters
portfolioThe algorithm's portfolio
securityThe security to be traded
directionThe direction of the trade
Returns
The margin available for the trade

Reimplemented in QuantConnect.Securities.CryptoFuture.CryptoFutureMarginModel.

Definition at line 179 of file BuyingPowerModel.cs.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ GetInitialMarginRequirement()

virtual InitialMargin QuantConnect.Securities.BuyingPowerModel.GetInitialMarginRequirement ( InitialMarginParameters  parameters)
virtual

The margin that must be held in order to increase the position by the provided quantity

Parameters
parametersAn object containing the security and quantity of shares
Returns
The initial margin required for the provided security and quantity

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.

Here is the caller graph for this function:

◆ HasSufficientBuyingPowerForOrder()

virtual HasSufficientBuyingPowerForOrderResult QuantConnect.Securities.BuyingPowerModel.HasSufficientBuyingPowerForOrder ( HasSufficientBuyingPowerForOrderParameters  parameters)
virtual

Check if there is sufficient buying power to execute this order.

Parameters
parametersAn object containing the portfolio, the security and the order
Returns
Returns buying power information for an order

Implements QuantConnect.Securities.IBuyingPowerModel.

Reimplemented in QuantConnect.Securities.CashBuyingPowerModel, and QuantConnect.Securities.NullBuyingPowerModel.

Definition at line 246 of file BuyingPowerModel.cs.

Here is the call graph for this function:

◆ GetMaximumOrderQuantityForDeltaBuyingPower()

virtual GetMaximumOrderQuantityResult QuantConnect.Securities.BuyingPowerModel.GetMaximumOrderQuantityForDeltaBuyingPower ( GetMaximumOrderQuantityForDeltaBuyingPowerParameters  parameters)
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
parametersAn object containing the portfolio, the security and the delta buying power
Returns
Returns the maximum allowed market order quantity and if zero, also the reason

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.

Here is the call graph for this function:

◆ GetMaximumOrderQuantityForTargetBuyingPower()

virtual GetMaximumOrderQuantityResult QuantConnect.Securities.BuyingPowerModel.GetMaximumOrderQuantityForTargetBuyingPower ( GetMaximumOrderQuantityForTargetBuyingPowerParameters  parameters)
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
parametersAn object containing the portfolio, the security and the target signed buying power percentage
Returns
Returns the maximum allowed market order quantity and if zero, also the reason

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.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ GetAmountToOrder()

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.

Parameters
securitySecurity we are to determine order size for
targetMarginTarget margin allocated
marginForOneUnitMargin requirement for one unit; used in our initial order guess
finalMarginOutput the final margin allocated to this security
Returns
The size of the order to get safely to our target

Definition at line 480 of file BuyingPowerModel.cs.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ GetReservedBuyingPowerForPosition()

virtual ReservedBuyingPowerForPosition QuantConnect.Securities.BuyingPowerModel.GetReservedBuyingPowerForPosition ( ReservedBuyingPowerForPositionParameters  parameters)
virtual

Gets the amount of buying power reserved to maintain the specified position

Parameters
parametersA parameters object containing the security
Returns
The reserved buying power in account currency

Implements QuantConnect.Securities.IBuyingPowerModel.

Reimplemented in QuantConnect.Securities.CashBuyingPowerModel.

Definition at line 549 of file BuyingPowerModel.cs.

Here is the call graph for this function:

◆ GetBuyingPower()

virtual BuyingPower QuantConnect.Securities.BuyingPowerModel.GetBuyingPower ( BuyingPowerParameters  parameters)
virtual

Gets the buying power available for a trade

Parameters
parametersA parameters object containing the algorithm's portfolio, security, and order direction
Returns
The buying power available for the trade

Implements QuantConnect.Securities.IBuyingPowerModel.

Reimplemented in QuantConnect.Securities.CashBuyingPowerModel.

Definition at line 560 of file BuyingPowerModel.cs.

Here is the call graph for this function:

Member Data Documentation

◆ Null

readonly IBuyingPowerModel QuantConnect.Securities.BuyingPowerModel.Null = new NullBuyingPowerModel()
static

Gets an implementation of IBuyingPowerModel that does not check for sufficient buying power

Definition at line 33 of file BuyingPowerModel.cs.

Property Documentation

◆ RequiredFreeBuyingPowerPercent

decimal QuantConnect.Securities.BuyingPowerModel.RequiredFreeBuyingPowerPercent
getsetprotected

The percentage used to determine the required unused buying power for the account.

Definition at line 41 of file BuyingPowerModel.cs.


The documentation for this class was generated from the following file: