Skip to content

PositionExtensions

QuantConnect.Securities.Positions.PositionExtensions

Bases: Object

Provides extension methods for IPosition

combine

combine(position: IPosition, other: IPosition) -> IPosition

Combines the provided positions into a single position with the quantities added and the minimum unit quantity.

Parameters:

Name Type Description Default
position IPosition

The position

required
other IPosition

The other position to add

required

Returns:

Type Description
IPosition

The combined position.

consolidate

consolidate(
    positions: List[IPosition],
) -> Dictionary[Symbol, IPosition]

Consolidates the provided positions into a dictionary

Parameters:

Name Type Description Default
positions List[IPosition]

The positions to be consolidated

required

Returns:

Type Description
Dictionary[Symbol, IPosition]

A dictionary containing the consolidated positions.

deduct

deduct(
    position: IPosition, quantity_to_deduct: float
) -> IPosition

Deducts the specified quantity_to_deduct from the specified position

Parameters:

Name Type Description Default
position IPosition

The source position

required
quantity_to_deduct float

The quantity to deduct

required

Returns:

Type Description
IPosition

A new position with the same properties but quantity reduced by the specified amount.

get_group_quantity

get_group_quantity(position: IPosition) -> float

Gets the quantity a group would have if the given position were part of it.

Parameters:

Name Type Description Default
position IPosition

The position

required

Returns:

Type Description
float

The group quantity.

with_lots

with_lots(
    position: IPosition, number_of_lots: float
) -> IPosition

Creates a new IPosition with quantity equal to number_of_lots times its unit quantity

Parameters:

Name Type Description Default
position IPosition

The position

required
number_of_lots float

The number of lots for the new position

required

Returns:

Type Description
IPosition

A new position with the specified number of lots.