Skip to content

PositionGroupExtensions

QuantConnect.Securities.Positions.PositionGroupExtensions

Bases: Object

Provides extension methods for IPositionGroup

closes

closes(
    final_group: IPositionGroup,
    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
final_group IPositionGroup

The final position group that would result from a trade

required
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(
    template: IPositionGroup,
    position_mananger: SecurityPositionGroupModel,
) -> IPositionGroup

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

Parameters:

Name Type Description Default
template IPositionGroup

The group template

required

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(
    group: IPositionGroup,
    symbol: Union[Symbol, str, BaseContract],
) -> IPosition

Gets the position in the group matching the provided

Parameters:

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

get_user_friendly_name

get_user_friendly_name(group: IPositionGroup) -> str

Gets a user friendly name for the provided group

is_empty

is_empty(position_group: IPositionGroup) -> bool

Determines whether the position group is empty

Parameters:

Name Type Description Default
position_group IPositionGroup

The position group

required

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(
    group: IPositionGroup, 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
group IPositionGroup

The group to check

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

with_quantity

with_quantity(
    template: IPositionGroup,
    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
template IPositionGroup

The group template

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