Lean
$LEAN_TAG$
|
Provides a base class for implementations of IPositionGroupBuyingPowerModel More...
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... | |
Provides a base class for implementations of IPositionGroupBuyingPowerModel
Definition at line 29 of file PositionGroupBuyingPowerModel.cs.
|
protected |
Initializes a new instance of the PositionGroupBuyingPowerModel class
requiredFreeBuyingPowerPercent | The percentage of portfolio buying power to leave as a buffer |
Definition at line 40 of file PositionGroupBuyingPowerModel.cs.
|
pure virtual |
Gets the margin currently allocated to the specified holding
parameters | An object containing the security |
Implements QuantConnect.Securities.Positions.IPositionGroupBuyingPowerModel.
Implemented in QuantConnect.Securities.Option.OptionStrategyPositionGroupBuyingPowerModel, and QuantConnect.Securities.Positions.SecurityPositionGroupBuyingPowerModel.
|
pure 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 |
Implements QuantConnect.Securities.Positions.IPositionGroupBuyingPowerModel.
Implemented in QuantConnect.Securities.Option.OptionStrategyPositionGroupBuyingPowerModel, and QuantConnect.Securities.Positions.SecurityPositionGroupBuyingPowerModel.
|
pure 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.Positions.IPositionGroupBuyingPowerModel.
Implemented in QuantConnect.Securities.Option.OptionStrategyPositionGroupBuyingPowerModel, and QuantConnect.Securities.Positions.SecurityPositionGroupBuyingPowerModel.
|
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 | An object containing the portfolio and a position group containing the contemplated changes to the portfolio |
Implements QuantConnect.Securities.Positions.IPositionGroupBuyingPowerModel.
Definition at line 74 of file PositionGroupBuyingPowerModel.cs.
|
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.
|
virtual |
Check if there is sufficient buying power for the position group to execute this order.
parameters | An object containing the portfolio, the position group and the order |
Implements QuantConnect.Securities.Positions.IPositionGroupBuyingPowerModel.
Reimplemented in QuantConnect.Securities.Positions.SecurityPositionGroupBuyingPowerModel.
Definition at line 152 of file PositionGroupBuyingPowerModel.cs.
|
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.
|
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.
|
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 | An object containing the portfolio, the position group and the target signed buying power percentage |
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:
Implements QuantConnect.Securities.Positions.IPositionGroupBuyingPowerModel.
Reimplemented in QuantConnect.Securities.Positions.SecurityPositionGroupBuyingPowerModel.
Definition at line 238 of file PositionGroupBuyingPowerModel.cs.
|
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 | An object containing the portfolio, the position group and the delta buying power |
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.
PositionGroupBuyingPower QuantConnect.Securities.Positions.PositionGroupBuyingPowerModel.GetPositionGroupBuyingPower | ( | PositionGroupBuyingPowerParameters | parameters | ) |
Gets the buying power available for a position group trade
parameters | A parameters object containing the algorithm's portfolio, security, and order direction |
Implements QuantConnect.Securities.Positions.IPositionGroupBuyingPowerModel.
Definition at line 417 of file PositionGroupBuyingPowerModel.cs.
|
protectedvirtual |
Helper function to convert a CashAmount to the account currency
Definition at line 457 of file PositionGroupBuyingPowerModel.cs.
|
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.
|
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.
|
virtual |
Indicates whether the current object is equal to another object of the same type.
other | An object to compare with this object. |
Definition at line 526 of file PositionGroupBuyingPowerModel.cs.
override bool QuantConnect.Securities.Positions.PositionGroupBuyingPowerModel.Equals | ( | object | obj | ) |
Determines whether the specified object is equal to the current object.
obj | The object to compare with the current object. |
Definition at line 544 of file PositionGroupBuyingPowerModel.cs.
override int QuantConnect.Securities.Positions.PositionGroupBuyingPowerModel.GetHashCode | ( | ) |
Serves as the default hash function.
Definition at line 566 of file PositionGroupBuyingPowerModel.cs.
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.
portfolio | Current portfolio |
currentPositionGroup | Current position group |
currentUsedMargin | Current margin reserved for the position |
targetFinalMargin | The target margin |
groupUnit | Unit position group corresponding to the currentPositionGroup |
unitMargin | Margin required for the groupUnit |
finalMargin | Output the final margin allocated for the position group |
Definition at line 583 of file PositionGroupBuyingPowerModel.cs.
|
getprotected |
Gets the percentage of portfolio buying power to leave as a buffer
Definition at line 34 of file PositionGroupBuyingPowerModel.cs.