Skip to content

SecurityPositionGroupResolver

QuantConnect.Securities.Positions.SecurityPositionGroupResolver

SecurityPositionGroupResolver(
    buying_power_model: IPositionGroupBuyingPowerModel,
)

Bases: Object, IPositionGroupResolver

Provides an implementation of IPositionGroupResolver that places all positions into a default group of one security.

Initializes a new instance of the SecurityPositionGroupResolver class

Parameters:

Name Type Description Default
buying_power_model IPositionGroupBuyingPowerModel

The buying power model to use for created groups

required

get_impacted_groups

get_impacted_groups(
    groups: PositionGroupCollection,
    positions: Sequence[IPosition],
) -> Iterable[IPositionGroup]

Determines the position groups that would be evaluated for grouping of the specified positions were passed into the IPositionGroupresolver.resolve method.

Parameters:

Name Type Description Default
groups PositionGroupCollection

The existing position groups

required
positions Sequence[IPosition]

The positions being changed

required

Returns:

Type Description
Iterable[IPositionGroup]

An enumerable containing the position groups that could be impacted by the specified position changes.

resolve

resolve(
    positions: PositionCollection,
) -> PositionGroupCollection

Resolves the position groups that exist within the specified collection of positions.

Parameters:

Name Type Description Default
positions PositionCollection

The collection of positions

required

Returns:

Type Description
PositionGroupCollection

An enumerable of position groups.

try_group

try_group(
    new_positions: Sequence[IPosition],
    current_positions: PositionGroupCollection,
    group: Optional[IPositionGroup],
) -> Tuple[bool, IPositionGroup]

Attempts to group the specified positions into a new IPositionGroup using an appropriate IPositionGroupBuyingPowerModel for position groups created via this resolver.

Parameters:

Name Type Description Default
new_positions Sequence[IPosition]

The positions to be grouped

required
current_positions PositionGroupCollection

The currently grouped positions

required
group Optional[IPositionGroup]

The grouped positions when this resolver is able to, otherwise null

required

Returns:

Type Description
Tuple[bool, IPositionGroup]

True if this resolver can group the specified positions, otherwise false.