Skip to content

NullBuyingPowerModel

QuantConnect.Securities.NullBuyingPowerModel

NullBuyingPowerModel()
NullBuyingPowerModel(
    initial_margin_requirement: float,
    maintenance_margin_requirement: float,
    required_free_buying_power_percent: float,
)
NullBuyingPowerModel(
    leverage: float,
    required_free_buying_power_percent: float = 0,
)

Bases: BuyingPowerModel

Provides a buying power model considers that there is sufficient buying power for all orders

Signature descriptions:

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

  • Initializes a new instance of the BuyingPowerModel

Parameters:

Name Type Description Default
initial_margin_requirement Optional[float]

The percentage of an order's absolute cost

None
maintenance_margin_requirement Optional[float]

The percentage of the holding's absolute

None
required_free_buying_power_percent Optional[float]

The percentage used to determine the required

0
leverage Optional[float]

The leverage

None

NULL

NULL: IBuyingPowerModel = ...

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

required_free_buying_power_percent

required_free_buying_power_percent: float

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

This codeEntityType is protected.

get_maintenance_margin

get_maintenance_margin(
    parameters: MaintenanceMarginParameters,
) -> MaintenanceMargin

Gets the margin currently allocated to the specified holding

Parameters:

Name Type Description Default
parameters MaintenanceMarginParameters

An object containing the security

required

Returns:

Type Description
MaintenanceMargin

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

has_sufficient_buying_power_for_order

has_sufficient_buying_power_for_order(
    parameters: HasSufficientBuyingPowerForOrderParameters,
) -> HasSufficientBuyingPowerForOrderResult

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

Parameters:

Name Type Description Default
parameters HasSufficientBuyingPowerForOrderParameters

An object containing the portfolio, the security and the order

required

Returns:

Type Description
HasSufficientBuyingPowerForOrderResult

Returns buying power information for an order.

get_buying_power

get_buying_power(
    parameters: BuyingPowerParameters,
) -> BuyingPower

Gets the buying power available for a trade

Parameters:

Name Type Description Default
parameters BuyingPowerParameters

A parameters object containing the algorithm's portfolio, security, and order direction

required

Returns:

Type Description
BuyingPower

The buying power available for the trade.

get_initial_margin_required_for_order

get_initial_margin_required_for_order(
    parameters: InitialMarginRequiredForOrderParameters,
) -> InitialMargin

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

Parameters:

Name Type Description Default
parameters InitialMarginRequiredForOrderParameters

An object containing the portfolio, the security and the order

required

Returns:

Type Description
InitialMargin

The total margin in terms of the currency quoted in the order.

get_initial_margin_requirement

get_initial_margin_requirement(
    parameters: InitialMarginParameters,
) -> InitialMargin

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

Parameters:

Name Type Description Default
parameters InitialMarginParameters

An object containing the security and quantity of shares

required

Returns:

Type Description
InitialMargin

The initial margin required for the provided security and quantity.

get_leverage

get_leverage(security: Security) -> float

Gets the current leverage of the security

Parameters:

Name Type Description Default
security Security

The security to get leverage for

required

Returns:

Type Description
float

The current leverage in the security.

get_maximum_order_quantity_for_delta_buying_power

get_maximum_order_quantity_for_delta_buying_power(
    parameters: GetMaximumOrderQuantityForDeltaBuyingPowerParameters,
) -> GetMaximumOrderQuantityResult

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:

Name Type Description Default
parameters GetMaximumOrderQuantityForDeltaBuyingPowerParameters

An object containing the portfolio, the security and the delta buying power

required

Returns:

Type Description
GetMaximumOrderQuantityResult

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

get_maximum_order_quantity_for_target_buying_power

get_maximum_order_quantity_for_target_buying_power(
    parameters: GetMaximumOrderQuantityForTargetBuyingPowerParameters,
) -> GetMaximumOrderQuantityResult

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:

Name Type Description Default
parameters GetMaximumOrderQuantityForTargetBuyingPowerParameters

An object containing the portfolio, the security and the target signed buying power percentage

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(
    parameters: ReservedBuyingPowerForPositionParameters,
) -> ReservedBuyingPowerForPosition

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

Parameters:

Name Type Description Default
parameters ReservedBuyingPowerForPositionParameters

A parameters object containing the security

required

Returns:

Type Description
ReservedBuyingPowerForPosition

The reserved buying power in account currency.

set_leverage

set_leverage(security: Security, leverage: float) -> None

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

Parameters:

Name Type Description Default
security Security
required
leverage float

The new leverage

required

get_amount_to_order

get_amount_to_order(
    security: Security,
    target_margin: float,
    margin_for_one_unit: float,
    final_margin: Optional[float],
) -> Tuple[float, float]

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:

Name Type Description Default
security Security

Security we are to determine order size for

required
target_margin float

Target margin allocated

required
margin_for_one_unit float

Margin requirement for one unit; used in our initial order guess

required
final_margin Optional[float]

Output the final margin allocated to this security

required

Returns:

Type Description
Tuple[float, float]

The size of the order to get safely to our target.

get_margin_remaining

get_margin_remaining(
    portfolio: SecurityPortfolioManager,
    security: Security,
    direction: OrderDirection,
) -> float

Gets the margin cash available for a trade

This codeEntityType is protected.

Parameters:

Name Type Description Default
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 margin available for the trade.