Skip to content

PositionGroup

QuantConnect.Securities.Positions.PositionGroup

PositionGroup(
    buying_power_model: IPositionGroupBuyingPowerModel,
    quantity: float,
    *positions: Union[IPosition, Iterable[IPosition]]
)
PositionGroup(
    key: PositionGroupKey,
    quantity: float,
    *positions: Union[IPosition, Iterable[IPosition]]
)
PositionGroup(
    key: PositionGroupKey,
    quantity: float,
    positions: Dictionary[Symbol, IPosition],
)

Bases: Object, IPositionGroup, Iterable[IPosition]

Provides a default implementation of IPositionGroup

Initializes a new instance of the PositionGroup class

Parameters:

Name Type Description Default
buying_power_model Optional[IPositionGroupBuyingPowerModel]

The buying power model to use for this group

None
quantity float

The group quantity, which must be the ratio of quantity to unit quantity of each position

required
positions Union[IPosition, Iterable[IPosition]]

The positions comprising this group

()
key Optional[PositionGroupKey]

The deterministic key for this group

None

count

count: int

Gets the number of positions in the group

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

__iter__

__iter__() -> Iterator[IPosition]

empty

empty(
    buying_power_model: IPositionGroupBuyingPowerModel,
) -> PositionGroup

Instantiates a default empty position group instance

Parameters:

Name Type Description Default
buying_power_model IPositionGroupBuyingPowerModel

The buying power model to use for this group

required

get_enumerator

get_enumerator() -> IEnumerator[IPosition]

Returns an enumerator that iterates through the collection.

Returns:

Type Description
IEnumerator[IPosition]

An enumerator that can be used to iterate through the collection.

to_string

to_string() -> str

Returns a string that represents the current object.

Returns:

Type Description
str

A string that represents the current object.

try_get_position

try_get_position(
    symbol: Union[Symbol, str, BaseContract],
    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]

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.