Skip to content

BuyingPowerModelExtensions

QuantConnect.Securities.BuyingPowerModelExtensions

Bases: Object

Provides extension methods as backwards compatibility shims

above_minimum_order_margin_portfolio_percentage

above_minimum_order_margin_portfolio_percentage(
    model: IBuyingPowerModel,
    security: Security,
    quantity: float,
    portfolio_manager: SecurityPortfolioManager,
    minimum_order_margin_portfolio_percentage: float,
) -> bool
above_minimum_order_margin_portfolio_percentage(
    portfolio_manager: SecurityPortfolioManager,
    minimum_order_margin_portfolio_percentage: float,
    abs_final_order_margin: float,
) -> bool

Helper method to determine if the requested quantity is above the algorithm minimum order margin portfolio percentage

Parameters:

Name Type Description Default
model Optional[IBuyingPowerModel]

The buying power model

None
security Optional[Security]

The security

None
quantity Optional[float]

The quantity of shares

None
portfolio_manager SecurityPortfolioManager

The algorithm's portfolio

required
minimum_order_margin_portfolio_percentage float

Minimum order margin portfolio percentage to ignore bad orders, orders with unrealistic small sizes

required
abs_final_order_margin Optional[float]

The calculated order margin value

None

Returns:

Type Description
bool

True if this order quantity is above the minimum requested.

get_buying_power

get_buying_power(
    model: IBuyingPowerModel,
    portfolio: SecurityPortfolioManager,
    security: Security,
    direction: OrderDirection,
) -> float

Gets the buying power available for a trade

Parameters:

Name Type Description Default
model IBuyingPowerModel

The IBuyingPowerModel

required
portfolio SecurityPortfolioManager

The algorithm's portfolio

required
security Security

The security to be traded

required
direction OrderDirection

The direction of the trade

required

Returns:

Type Description
float

The buying power available for the trade.

get_initial_margin_requirement

get_initial_margin_requirement(
    model: IBuyingPowerModel,
    security: Security,
    quantity: float,
) -> float

Gets the margin currently allocated to the specified holding

Parameters:

Name Type Description Default
model IBuyingPowerModel

The buying power model

required
security Security

The security

required
quantity float

The quantity of shares

required

Returns:

Type Description
float

The initial margin required for the provided security and quantity.

get_maintenance_margin

get_maintenance_margin(
    model: IBuyingPowerModel, security: Security
) -> float

Gets the margin currently allocated to the specified holding

Parameters:

Name Type Description Default
model IBuyingPowerModel

The buying power model

required
security Security

The security

required

Returns:

Type Description
float

The maintenance margin required for the provided holdings quantity/cost/value.

get_maximum_order_quantity_for_target_buying_power

get_maximum_order_quantity_for_target_buying_power(
    model: IBuyingPowerModel,
    portfolio: SecurityPortfolioManager,
    security: Security,
    target: float,
    minimum_order_margin_portfolio_percentage: float,
) -> GetMaximumOrderQuantityResult

Get the maximum market order quantity to obtain a position with a given value in account currency

Parameters:

Name Type Description Default
model IBuyingPowerModel

The IBuyingPowerModel

required
portfolio SecurityPortfolioManager

The algorithm's portfolio

required
security Security

The security to be traded

required
target float

The target percent holdings

required
minimum_order_margin_portfolio_percentage float

Configurable minimum order margin portfolio percentage to ignore orders with unrealistic small sizes

required

Returns:

Type Description
GetMaximumOrderQuantityResult

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

get_reserved_buying_power_for_position

get_reserved_buying_power_for_position(
    model: IBuyingPowerModel, security: Security
) -> float

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

Parameters:

Name Type Description Default
model IBuyingPowerModel

The IBuyingPowerModel

required
security Security

The security

required

Returns:

Type Description
float

The reserved buying power in account currency.

has_sufficient_buying_power_for_order

has_sufficient_buying_power_for_order(
    model: IBuyingPowerModel,
    portfolio: SecurityPortfolioManager,
    security: Security,
    order: Order,
) -> HasSufficientBuyingPowerForOrderResult

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

Parameters:

Name Type Description Default
model IBuyingPowerModel

The IBuyingPowerModel

required
portfolio SecurityPortfolioManager

The algorithm's portfolio

required
security Security

The security to be traded

required
order Order

The order

required

Returns:

Type Description
HasSufficientBuyingPowerForOrderResult

Returns buying power information for an order.