Skip to content

OptionPositionCollection

QuantConnect.Securities.Option.StrategyMatcher.OptionPositionCollection

OptionPositionCollection(
    positions: ImmutableDictionary[Symbol, OptionPosition],
    rights: ImmutableDictionary[
        OptionRight, ImmutableHashSet[Symbol]
    ],
    sides: ImmutableDictionary[
        PositionSide, ImmutableHashSet[Symbol]
    ],
    strikes: ImmutableSortedDictionary[
        float, ImmutableHashSet[Symbol]
    ],
    expirations: ImmutableSortedDictionary[
        datetime, ImmutableHashSet[Symbol]
    ],
)

Bases: Object, Iterable[OptionPosition]

Provides indexing of option contracts

Initializes a new instance of the OptionPositionCollection class

Parameters:

Name Type Description Default
positions ImmutableDictionary[Symbol, OptionPosition]

All positions

required
rights ImmutableDictionary[OptionRight, ImmutableHashSet[Symbol]]

Index of position symbols by option right

required
sides ImmutableDictionary[PositionSide, ImmutableHashSet[Symbol]]

Index of position symbols by position side (short/long/none)

required
strikes ImmutableSortedDictionary[float, ImmutableHashSet[Symbol]]

Index of position symbols by strike price

required
expirations ImmutableSortedDictionary[datetime, ImmutableHashSet[Symbol]]

Index of position symbols by expiration

required

EMPTY

Gets an empty instance of OptionPositionCollection

underlying

underlying: Symbol

Gets the underlying security's symbol

count

count: int

Gets the total count of unique positions, including the underlying

is_empty

is_empty: bool

Gets whether or not there's any positions in this collection.

underlying_quantity

underlying_quantity: int

Gets the quantity of underlying shares held TODO : Change to UnderlyingLots

unique_puts

unique_puts: int

Gets the number of unique put contracts held (long or short)

unique_expirations

unique_expirations: int

Gets the unique number of expirations

unique_calls

unique_calls: int

Gets the number of unique call contracts held (long or short)

has_underlying

has_underlying: bool

Determines if this collection contains a position in the underlying

underlying_position

underlying_position: OptionPosition

Gets the underlying position

strikes

strikes: Iterable[float]

Gets all unique strike prices in the collection, in ascending order.

expirations

expirations: Iterable[datetime]

Gets all unique expiration dates in the collection, in chronological order.

__add__

__add__(
    position: OptionPosition,
) -> OptionPositionCollection

OptionPositionCollection + Operator

Parameters:

Name Type Description Default
position OptionPosition

OptionPosition to add

required

Returns:

Type Description
OptionPositionCollection

OptionPositionCollection with the new position added.

__iadd__

__iadd__(
    position: OptionPosition,
) -> OptionPositionCollection

OptionPositionCollection + Operator

Parameters:

Name Type Description Default
position OptionPosition

OptionPosition to add

required

Returns:

Type Description
OptionPositionCollection

OptionPositionCollection with the new position added.

__isub__

__isub__(
    position: OptionPosition,
) -> OptionPositionCollection

OptionPositionCollection - Operator

Parameters:

Name Type Description Default
position OptionPosition

OptionPosition to remove

required

Returns:

Type Description
OptionPositionCollection

OptionPositionCollection with the position removed.

__iter__

__iter__() -> Iterator[OptionPosition]

__sub__

__sub__(
    position: OptionPosition,
) -> OptionPositionCollection

OptionPositionCollection - Operator

Parameters:

Name Type Description Default
position OptionPosition

OptionPosition to remove

required

Returns:

Type Description
OptionPositionCollection

OptionPositionCollection with the position removed.

add

Creates a new collection that is the result of adding the specified position to this collection.

create

create(
    underlying: Union[Symbol, str, BaseContract],
    contract_multiplier: float,
    holdings: List[SecurityHolding],
) -> OptionPositionCollection

Creates a new OptionPositionCollection from the specified holdings, filtering based on the underlying

for_expiration

for_expiration(
    expiration: Union[datetime, date],
) -> Iterable[OptionPosition]

Returns the set of OptionPosition with the specified expiration

for_right

for_right(right: OptionRight) -> Iterable[OptionPosition]

Returns the set of OptionPosition with the specified right

for_side

for_side(side: PositionSide) -> Iterable[OptionPosition]

Returns the set of OptionPosition with the specified side

for_strike

for_strike(strike: float) -> Iterable[OptionPosition]

Returns the set of OptionPosition with the specified strike

for_symbols

for_symbols(
    symbols: List[Symbol],
) -> Iterable[OptionPosition]

Returns the set of OptionPosition with the specified symbols

get_enumerator

get_enumerator() -> IEnumerator[OptionPosition]

Returns an enumerator that iterates through the collection.

Returns:

Type Description
IEnumerator[OptionPosition]

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

has_position

has_position(
    symbol: Union[Symbol, str, BaseContract],
) -> bool

Determines if a position is held in the specified symbol

remove

remove(
    position: OptionPosition,
) -> OptionPositionCollection

Creates a new collection that is the result of removing the specified position

remove_range

remove_range(
    positions: List[OptionPosition],
) -> OptionPositionCollection

Creates a new collection that is the result of removing the specified positions

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[OptionPosition],
) -> Tuple[bool, OptionPosition]

Retrieves the OptionPosition for the specified symbol if one exists in this collection.