Skip to content

Position

QuantConnect.Securities.Positions.Position

Position(
    symbol: Union[Symbol, str, BaseContract, Security],
    quantity: float,
    unit_quantity: float,
)
Position(
    security: Security, quantity: Optional[float] = None
)

Bases: Object, IPosition

Defines a quantity of a security's holdings for inclusion in a position group

Signature descriptions:

  • Initializes a new instance of the Position class

  • Initializes a new instance of the Position class using the security's lot size as it's unit quantity. If quantity is null, then the security's holdings quantity is used.

Parameters:

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

The symbol

None
quantity float | Optional[float]

The quantity

None
unit_quantity Optional[float]

The position's unit quantity within its group

None
security Optional[Security]

The security

None

symbol

symbol: Symbol

The symbol

quantity

quantity: float

The quantity

unit_quantity

unit_quantity: float

The unit quantity. The unit quantities of a group define the group. For example, a covered call has 100 units of stock and -1 units of call contracts.

to_string

to_string() -> str

Returns a string that represents the current object.

Returns:

Type Description
str

A string that represents the current object.

combine

combine(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
other IPosition

The other position to add

required

Returns:

Type Description
IPosition

The combined position.

deduct

deduct(quantity_to_deduct: float) -> IPosition

Deducts the specified quantity_to_deduct from the specified position

Parameters:

Name Type Description Default
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() -> float

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

Returns:

Type Description
float

The group quantity.

with_lots

with_lots(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
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.