Skip to content

BuyingPowerModelPythonWrapper

QuantConnect.Python.BuyingPowerModelPythonWrapper

BuyingPowerModelPythonWrapper(model: Any)

Bases: BasePythonWrapper[IBuyingPowerModel], IBuyingPowerModel

Wraps a PyObject object that represents a security's model of buying power

Constructor for initializing the BuyingPowerModelPythonWrapper class with wrapped PyObject object

Parameters:

Name Type Description Default
model Any

Represents a security's model of buying power

required

instance

instance: Any

Gets the underlying python instance

This codeEntityType is protected.

PythonRuntimeChecker

Bases: Object

Set of helper methods to invoke Python methods with runtime checks for return values and out parameter's conversions.

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 potrfolio, 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

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

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.

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.

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

The security to set leverage for

required
leverage float

The new leverage

required

equals

equals(obj: Any) -> bool
equals(
    other: BasePythonWrapper[
        QuantConnect_Python_BasePythonWrapper_TInterface
    ],
) -> bool

Signature descriptions:

  • Determines whether the specified object is an instance of BasePythonWrapper{TInterface} and wraps the same Python object reference as this instance, which would indicate that they are equal.

  • Determines whether the specified instance wraps the same Python object reference as this instance, which would indicate that they are equal.

Parameters:

Name Type Description Default
obj Optional[Any]

The other object to compare this with

None
other Optional[BasePythonWrapper[QuantConnect_Python_BasePythonWrapper_TInterface]]

The other object to compare this with

None

Returns:

Type Description
bool

True if both instances are equal, that is if both wrap the same Python object reference.

set_python_instance

set_python_instance(instance: Any) -> None
set_python_instance(
    instance: Any, validate_interface: bool
) -> None

Signature descriptions:

  • Sets the python instance

  • Sets the python instance and sets the validate interface flag

Parameters:

Name Type Description Default
instance Any

The underlying python instance

required
validate_interface Optional[bool]

Whether to perform validations for interface implementation

None

dispose

dispose() -> None

Dispose of this instance

get_event

get_event(name: str) -> Any

Gets the Python instance event with the specified name

Parameters:

Name Type Description Default
name str

The name of the event

required

get_hash_code

get_hash_code() -> int

Gets the hash code for the current instance

Returns:

Type Description
int

The hash code of the current instance.

get_method

get_method(
    method_name: str, python_only: bool = False
) -> Any

Gets the Python instances method with the specified name and caches it

Parameters:

Name Type Description Default
method_name str

The name of the method

required
python_only bool

Whether to only return python methods

False

Returns:

Type Description
Any

The matched method.

get_property

get_property(property_name: str) -> Any

Gets the Python instance property with the specified name

Parameters:

Name Type Description Default
property_name str

The name of the property

required

has_attr

has_attr(name: str) -> bool

Determines whether the Python instance has the specified attribute

Parameters:

Name Type Description Default
name str

The attribute name

required

Returns:

Type Description
bool

Whether the Python instance has the specified attribute.

invoke_method

invoke_method(
    method_name: str, *args: Union[Object, Iterable[Object]]
) -> Any

Invokes the specified method with the specified arguments

Parameters:

Name Type Description Default
method_name str

The name of the method

required
args Union[Object, Iterable[Object]]

The arguments to call the method with

()

invoke_void_method

invoke_void_method(
    method_name: str, *args: Union[Object, Iterable[Object]]
) -> None

Invokes the specified method with the specified arguments without returning a value

Parameters:

Name Type Description Default
method_name str

The name of the method

required
args Union[Object, Iterable[Object]]

The arguments to call the method with

()

set_property

set_property(property_name: str, value: Any) -> None

Sets the Python instance property with the specified name

Parameters:

Name Type Description Default
property_name str

The name of the property

required
value Any

The property value

required