Skip to content

IPositionGroup

QuantConnect.Securities.Positions.IPositionGroup

Bases: Sequence[IPosition]

Defines a group of positions allowing for more efficient use of portfolio margin

key

Gets the key identifying this group

quantity

quantity: float

Gets the whole number of units in this position group

positions

positions: Iterable[IPosition]

Gets the positions in this group

buying_power_model

buying_power_model: IPositionGroupBuyingPowerModel

Gets the buying power model defining how margin works in this group

closes

closes(initial_group: IPositionGroup) -> bool

Checks whether the provided groups are closing/reducing each other, that is, each of their positions are in opposite sides.

Parameters:

Name Type Description Default
initial_group IPositionGroup

The initial position group before a trade

required

Returns:

Type Description
bool

Whether final resulting position group is a reduction of the initial one.

create_unit_group

create_unit_group(
    position_mananger: SecurityPositionGroupModel,
) -> IPositionGroup

Creates a new IPositionGroup with each position's quantity equaling it's unit quantity

Returns:

Type Description
IPositionGroup

A position group with the same position ratios as the template but with the specified group quantity.

get_position

get_position(
    symbol: Union[Symbol, str, BaseContract, Security],
) -> IPosition

Gets the position in the group matching the provided

Parameters:

Name Type Description Default
symbol Union[Symbol, str, BaseContract, Security]
required

get_user_friendly_name

get_user_friendly_name() -> str

Gets a user friendly name for the provided group

is_empty

is_empty() -> bool

Determines whether the position group is empty

Returns:

Type Description
bool

True if the position group is empty, that is, it has no positions, false otherwise.

is_inverted_of

is_inverted_of(other: IPositionGroup) -> bool

Checks whether the provided groups are in opposite sides, that is, each of their positions are in opposite sides.

Parameters:

Name Type Description Default
other IPositionGroup

The group to check against

required

Returns:

Type Description
bool

Whether the position groups are the inverted version of each other, that is, contain the same positions each on the opposite side.

try_get_position

try_get_position(
    symbol: Union[Symbol, str, BaseContract, Security],
    position: Optional[IPosition],
) -> Tuple[bool, IPosition]

Attempts to retrieve the position with the specified symbol

Parameters:

Name Type Description Default
symbol Union[Symbol, str, BaseContract, Security]

The symbol

required
position Optional[IPosition]

The position, if found

required

Returns:

Type Description
Tuple[bool, IPosition]

True if the position was found, otherwise false.

with_quantity

with_quantity(
    group_quantity: float,
    position_mananger: SecurityPositionGroupModel,
) -> IPositionGroup

Creates a new IPositionGroup with the specified group_quantity. If the quantity provided equals the template's quantity then the template is returned.

Parameters:

Name Type Description Default
group_quantity float

The quantity of the new group

required
position_mananger SecurityPositionGroupModel

The position manager to use to resolve positions

required

Returns:

Type Description
IPositionGroup

A position group with the same position ratios as the template but with the specified group quantity.