Lean  $LEAN_TAG$
QuantConnect.Securities.Positions.PositionGroupBuyingPowerModel Class Referenceabstract

Provides a base class for implementations of IPositionGroupBuyingPowerModel More...

Inheritance diagram for QuantConnect.Securities.Positions.PositionGroupBuyingPowerModel:
[legend]

Public Member Functions

abstract MaintenanceMargin GetMaintenanceMargin (PositionGroupMaintenanceMarginParameters parameters)
 Gets the margin currently allocated to the specified holding More...
 
abstract InitialMargin GetInitialMarginRequirement (PositionGroupInitialMarginParameters parameters)
 The margin that must be held in order to increase the position by the provided quantity More...
 
abstract InitialMargin GetInitialMarginRequiredForOrder (PositionGroupInitialMarginForOrderParameters parameters)
 Gets the total margin required to execute the specified order in units of the account currency including fees More...
 
virtual ReservedBuyingPowerImpact GetReservedBuyingPowerImpact (ReservedBuyingPowerImpactParameters parameters)
 Computes the impact on the portfolio's buying power from adding the position group to the portfolio. This is a 'what if' analysis to determine what the state of the portfolio would be if these changes were applied. The delta (before - after) is the margin requirement for adding the positions and if the margin used after the changes are applied is less than the total portfolio value, this indicates sufficient capital. More...
 
virtual HasSufficientBuyingPowerForOrderResult HasSufficientBuyingPowerForOrder (HasSufficientPositionGroupBuyingPowerForOrderParameters parameters)
 Check if there is sufficient buying power for the position group to execute this order. More...
 
virtual ReservedBuyingPowerForPositionGroup GetReservedBuyingPowerForPositionGroup (ReservedBuyingPowerForPositionGroupParameters parameters)
 Computes the amount of buying power reserved by the provided position group More...
 
virtual GetMaximumLotsResult GetMaximumLotsForTargetBuyingPower (GetMaximumLotsForTargetBuyingPowerParameters parameters)
 Get the maximum position group order quantity to obtain a position with a given buying power percentage. Will not take into account free buying power. More...
 
virtual GetMaximumLotsResult GetMaximumLotsForDeltaBuyingPower (GetMaximumLotsForDeltaBuyingPowerParameters parameters)
 Get the maximum market position group order quantity to obtain a delta in the buying power used by a position group. The deltas sign defines the position side to apply it to, positive long, negative short. More...
 
PositionGroupBuyingPower GetPositionGroupBuyingPower (PositionGroupBuyingPowerParameters parameters)
 Gets the buying power available for a position group trade More...
 
virtual bool Equals (IPositionGroupBuyingPowerModel other)
 Indicates whether the current object is equal to another object of the same type. More...
 
override bool Equals (object obj)
 Determines whether the specified object is equal to the current object. More...
 
override int GetHashCode ()
 Serves as the default hash function. More...
 
decimal GetPositionGroupOrderQuantity (SecurityPortfolioManager portfolio, IPositionGroup currentPositionGroup, decimal currentUsedMargin, decimal targetFinalMargin, IPositionGroup groupUnit, decimal unitMargin, out decimal finalMargin)
 Helper method 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...
 

Protected Member Functions

 PositionGroupBuyingPowerModel (decimal requiredFreeBuyingPowerPercent=0m)
 Initializes a new instance of the PositionGroupBuyingPowerModel class More...
 
virtual decimal GetContemplatedGroupsInitialMargin (SecurityPortfolioManager portfolio, PositionGroupCollection contemplatedGroups, List< IPosition > ordersPositions)
 Gets the initial margin required for the specified contemplated position group. Used by GetReservedBuyingPowerImpact to get the contemplated groups margin. More...
 
virtual HasSufficientBuyingPowerForOrderResult PassesPositionGroupSpecificBuyingPowerForOrderChecks (HasSufficientPositionGroupBuyingPowerForOrderParameters parameters, decimal availableBuyingPower)
 Provides a mechanism for derived types to add their own buying power for order checks without needing to recompute the available buying power. Implementations should return null if all checks pass and should return an instance of HasSufficientBuyingPowerForOrderResult with IsSufficient=false if it fails. More...
 
virtual decimal ToAccountCurrency (SecurityPortfolioManager portfolio, CashAmount cash)
 Helper function to convert a CashAmount to the account currency More...
 
virtual decimal GetOrderFeeInAccountCurrency (SecurityPortfolioManager portfolio, IPositionGroup positionGroup)
 Helper function to compute the order fees associated with executing market orders for the specified positionGroup More...
 

Static Protected Member Functions

static bool UnableToConverge (decimal currentMarginDifference, decimal lastMarginDifference, IPositionGroup groupUnit, SecurityPortfolioManager portfolio, decimal positionGroupQuantity, decimal targetMargin, decimal currentMargin, decimal absUnitMargin, out ArgumentException error)
 Checks if the margin difference is not growing in final margin calculation, just making sure we don't end up in an infinite loop. This function was split out to support derived types using the same error message as well as removing the added noise of the check and message creation. More...
 

Properties

decimal RequiredFreeBuyingPowerPercent [get]
 Gets the percentage of portfolio buying power to leave as a buffer More...
 

Detailed Description

Provides a base class for implementations of IPositionGroupBuyingPowerModel

Definition at line 29 of file PositionGroupBuyingPowerModel.cs.

Constructor & Destructor Documentation

◆ PositionGroupBuyingPowerModel()

QuantConnect.Securities.Positions.PositionGroupBuyingPowerModel.PositionGroupBuyingPowerModel ( decimal  requiredFreeBuyingPowerPercent = 0m)
protected

Initializes a new instance of the PositionGroupBuyingPowerModel class

Parameters
requiredFreeBuyingPowerPercentThe percentage of portfolio buying power to leave as a buffer

Definition at line 40 of file PositionGroupBuyingPowerModel.cs.

Member Function Documentation

◆ GetMaintenanceMargin()

abstract MaintenanceMargin QuantConnect.Securities.Positions.PositionGroupBuyingPowerModel.GetMaintenanceMargin ( PositionGroupMaintenanceMarginParameters  parameters)
pure virtual

Gets the margin currently allocated to the specified holding

Parameters
parametersAn object containing the security
Returns
The maintenance margin required for the

Implements QuantConnect.Securities.Positions.IPositionGroupBuyingPowerModel.

Implemented in QuantConnect.Securities.Option.OptionStrategyPositionGroupBuyingPowerModel, and QuantConnect.Securities.Positions.SecurityPositionGroupBuyingPowerModel.

Here is the caller graph for this function:

◆ GetInitialMarginRequirement()

abstract InitialMargin QuantConnect.Securities.Positions.PositionGroupBuyingPowerModel.GetInitialMarginRequirement ( PositionGroupInitialMarginParameters  parameters)
pure 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

Implements QuantConnect.Securities.Positions.IPositionGroupBuyingPowerModel.

Implemented in QuantConnect.Securities.Option.OptionStrategyPositionGroupBuyingPowerModel, and QuantConnect.Securities.Positions.SecurityPositionGroupBuyingPowerModel.

◆ GetInitialMarginRequiredForOrder()

abstract InitialMargin QuantConnect.Securities.Positions.PositionGroupBuyingPowerModel.GetInitialMarginRequiredForOrder ( PositionGroupInitialMarginForOrderParameters  parameters)
pure 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.Positions.IPositionGroupBuyingPowerModel.

Implemented in QuantConnect.Securities.Option.OptionStrategyPositionGroupBuyingPowerModel, and QuantConnect.Securities.Positions.SecurityPositionGroupBuyingPowerModel.

◆ GetReservedBuyingPowerImpact()

virtual ReservedBuyingPowerImpact QuantConnect.Securities.Positions.PositionGroupBuyingPowerModel.GetReservedBuyingPowerImpact ( ReservedBuyingPowerImpactParameters  parameters)
virtual

Computes the impact on the portfolio's buying power from adding the position group to the portfolio. This is a 'what if' analysis to determine what the state of the portfolio would be if these changes were applied. The delta (before - after) is the margin requirement for adding the positions and if the margin used after the changes are applied is less than the total portfolio value, this indicates sufficient capital.

Parameters
parametersAn object containing the portfolio and a position group containing the contemplated changes to the portfolio
Returns
Returns the portfolio's total portfolio value and margin used before and after the position changes are applied

Implements QuantConnect.Securities.Positions.IPositionGroupBuyingPowerModel.

Definition at line 74 of file PositionGroupBuyingPowerModel.cs.

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

◆ GetContemplatedGroupsInitialMargin()

virtual decimal QuantConnect.Securities.Positions.PositionGroupBuyingPowerModel.GetContemplatedGroupsInitialMargin ( SecurityPortfolioManager  portfolio,
PositionGroupCollection  contemplatedGroups,
List< IPosition ordersPositions 
)
protectedvirtual

Gets the initial margin required for the specified contemplated position group. Used by GetReservedBuyingPowerImpact to get the contemplated groups margin.

Reimplemented in QuantConnect.Securities.Option.OptionStrategyPositionGroupBuyingPowerModel.

Definition at line 133 of file PositionGroupBuyingPowerModel.cs.

Here is the caller graph for this function:

◆ HasSufficientBuyingPowerForOrder()

virtual HasSufficientBuyingPowerForOrderResult QuantConnect.Securities.Positions.PositionGroupBuyingPowerModel.HasSufficientBuyingPowerForOrder ( HasSufficientPositionGroupBuyingPowerForOrderParameters  parameters)
virtual

Check if there is sufficient buying power for the position group to execute this order.

Parameters
parametersAn object containing the portfolio, the position group and the order
Returns
Returns buying power information for an order against a position group

Implements QuantConnect.Securities.Positions.IPositionGroupBuyingPowerModel.

Reimplemented in QuantConnect.Securities.Positions.SecurityPositionGroupBuyingPowerModel.

Definition at line 152 of file PositionGroupBuyingPowerModel.cs.

Here is the call graph for this function:

◆ PassesPositionGroupSpecificBuyingPowerForOrderChecks()

virtual HasSufficientBuyingPowerForOrderResult QuantConnect.Securities.Positions.PositionGroupBuyingPowerModel.PassesPositionGroupSpecificBuyingPowerForOrderChecks ( HasSufficientPositionGroupBuyingPowerForOrderParameters  parameters,
decimal  availableBuyingPower 
)
protectedvirtual

Provides a mechanism for derived types to add their own buying power for order checks without needing to recompute the available buying power. Implementations should return null if all checks pass and should return an instance of HasSufficientBuyingPowerForOrderResult with IsSufficient=false if it fails.

Reimplemented in QuantConnect.Securities.Positions.SecurityPositionGroupBuyingPowerModel.

Definition at line 203 of file PositionGroupBuyingPowerModel.cs.

Here is the caller graph for this function:

◆ GetReservedBuyingPowerForPositionGroup()

virtual ReservedBuyingPowerForPositionGroup QuantConnect.Securities.Positions.PositionGroupBuyingPowerModel.GetReservedBuyingPowerForPositionGroup ( ReservedBuyingPowerForPositionGroupParameters  parameters)
virtual

Computes the amount of buying power reserved by the provided position group

Implements QuantConnect.Securities.Positions.IPositionGroupBuyingPowerModel.

Definition at line 214 of file PositionGroupBuyingPowerModel.cs.

Here is the call graph for this function:

◆ GetMaximumLotsForTargetBuyingPower()

virtual GetMaximumLotsResult QuantConnect.Securities.Positions.PositionGroupBuyingPowerModel.GetMaximumLotsForTargetBuyingPower ( GetMaximumLotsForTargetBuyingPowerParameters  parameters)
virtual

Get the maximum position group 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 position group and the target signed buying power percentage
Returns

Returns the maximum allowed market order quantity and if zero, also the reason.

Since there is no sense of "short" or "long" on position groups with multiple positions, the sign of the returned quantity will indicate the direction of the order regarding the reference position group passed in the parameters:

  • quantity > 0: the order should be placed in the same direction as the reference position group to increase it, without changing the positions' signs.
  • quantity < 0: the order should be placed in the opposite direction as the reference position group to reduce it, using each position's opposite sign.

Implements QuantConnect.Securities.Positions.IPositionGroupBuyingPowerModel.

Reimplemented in QuantConnect.Securities.Positions.SecurityPositionGroupBuyingPowerModel.

Definition at line 238 of file PositionGroupBuyingPowerModel.cs.

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

◆ GetMaximumLotsForDeltaBuyingPower()

virtual GetMaximumLotsResult QuantConnect.Securities.Positions.PositionGroupBuyingPowerModel.GetMaximumLotsForDeltaBuyingPower ( GetMaximumLotsForDeltaBuyingPowerParameters  parameters)
virtual

Get the maximum market position group order quantity to obtain a delta in the buying power used by a position group. The deltas sign defines the position side to apply it to, positive long, negative short.

Parameters
parametersAn object containing the portfolio, the position group 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.Positions.IPositionGroupBuyingPowerModel.

Reimplemented in QuantConnect.Securities.Positions.SecurityPositionGroupBuyingPowerModel.

Definition at line 382 of file PositionGroupBuyingPowerModel.cs.

Here is the call graph for this function:

◆ GetPositionGroupBuyingPower()

PositionGroupBuyingPower QuantConnect.Securities.Positions.PositionGroupBuyingPowerModel.GetPositionGroupBuyingPower ( PositionGroupBuyingPowerParameters  parameters)

Gets the buying power available for a position group 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.Positions.IPositionGroupBuyingPowerModel.

Definition at line 417 of file PositionGroupBuyingPowerModel.cs.

Here is the call graph for this function:

◆ ToAccountCurrency()

virtual decimal QuantConnect.Securities.Positions.PositionGroupBuyingPowerModel.ToAccountCurrency ( SecurityPortfolioManager  portfolio,
CashAmount  cash 
)
protectedvirtual

Helper function to convert a CashAmount to the account currency

Definition at line 457 of file PositionGroupBuyingPowerModel.cs.

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

◆ GetOrderFeeInAccountCurrency()

virtual decimal QuantConnect.Securities.Positions.PositionGroupBuyingPowerModel.GetOrderFeeInAccountCurrency ( SecurityPortfolioManager  portfolio,
IPositionGroup  positionGroup 
)
protectedvirtual

Helper function to compute the order fees associated with executing market orders for the specified positionGroup

Definition at line 465 of file PositionGroupBuyingPowerModel.cs.

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

◆ UnableToConverge()

static bool QuantConnect.Securities.Positions.PositionGroupBuyingPowerModel.UnableToConverge ( decimal  currentMarginDifference,
decimal  lastMarginDifference,
IPositionGroup  groupUnit,
SecurityPortfolioManager  portfolio,
decimal  positionGroupQuantity,
decimal  targetMargin,
decimal  currentMargin,
decimal  absUnitMargin,
out ArgumentException  error 
)
staticprotected

Checks if the margin difference is not growing in final margin calculation, just making sure we don't end up in an infinite loop. This function was split out to support derived types using the same error message as well as removing the added noise of the check and message creation.

Definition at line 488 of file PositionGroupBuyingPowerModel.cs.

Here is the caller graph for this function:

◆ Equals() [1/2]

virtual bool QuantConnect.Securities.Positions.PositionGroupBuyingPowerModel.Equals ( IPositionGroupBuyingPowerModel  other)
virtual

Indicates whether the current object is equal to another object of the same type.

Parameters
otherAn object to compare with this object.
Returns
true if the current object is equal to the other parameter; otherwise, false.

Definition at line 526 of file PositionGroupBuyingPowerModel.cs.

Here is the caller graph for this function:

◆ Equals() [2/2]

override bool QuantConnect.Securities.Positions.PositionGroupBuyingPowerModel.Equals ( object  obj)

Determines whether the specified object is equal to the current object.

Parameters
objThe object to compare with the current object.
Returns
true if the specified object is equal to the current object; otherwise, false.

Definition at line 544 of file PositionGroupBuyingPowerModel.cs.

Here is the call graph for this function:

◆ GetHashCode()

override int QuantConnect.Securities.Positions.PositionGroupBuyingPowerModel.GetHashCode ( )

Serves as the default hash function.

Returns
A hash code for the current object.

Definition at line 566 of file PositionGroupBuyingPowerModel.cs.

◆ GetPositionGroupOrderQuantity()

decimal QuantConnect.Securities.Positions.PositionGroupBuyingPowerModel.GetPositionGroupOrderQuantity ( SecurityPortfolioManager  portfolio,
IPositionGroup  currentPositionGroup,
decimal  currentUsedMargin,
decimal  targetFinalMargin,
IPositionGroup  groupUnit,
decimal  unitMargin,
out decimal  finalMargin 
)

Helper method 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
portfolioCurrent portfolio
currentPositionGroupCurrent position group
currentUsedMarginCurrent margin reserved for the position
targetFinalMarginThe target margin
groupUnitUnit position group corresponding to the currentPositionGroup
unitMarginMargin required for the groupUnit
finalMarginOutput the final margin allocated for the position group</param
Returns
The size of the order to get safely to our target

Definition at line 583 of file PositionGroupBuyingPowerModel.cs.

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

Property Documentation

◆ RequiredFreeBuyingPowerPercent

decimal QuantConnect.Securities.Positions.PositionGroupBuyingPowerModel.RequiredFreeBuyingPowerPercent
getprotected

Gets the percentage of portfolio buying power to leave as a buffer

Definition at line 34 of file PositionGroupBuyingPowerModel.cs.


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