Skip to content

OptionStrategyDefinition

QuantConnect.Securities.Option.StrategyMatcher.OptionStrategyDefinition

OptionStrategyDefinition(
    name: str,
    underlying_lots: int,
    legs: List[OptionStrategyLegDefinition],
)

Bases: Object, Iterable[OptionStrategyLegDefinition]

Provides a definitional object for an OptionStrategy. This definition is used to 'match' option positions via OptionPositionCollection. The OptionStrategyMatcher utilizes a full collection of these definitional objects in order to match an algorithm's option position holdings to the set of strategies in an effort to reduce the total margin required for holding the positions.

Initializes a new instance of the OptionStrategyDefinition class

Parameters:

Name Type Description Default
name str

The definition's name

required
underlying_lots int

The required number of underlying lots

required
legs List[OptionStrategyLegDefinition]

Definitions for each option leg

required

name

name: str

Gets the definition's name

underlying_lots

underlying_lots: int

Gets the number of underlying lots required to match this definition. A lot size is equal to the contract's multiplier and is usually equal to 100.

legs

Gets the option leg definitions. This list does NOT contain a definition for the required underlying lots, due to its simplicity. Instead the required underlying lots are defined via the underlying_lots property of the definition.

leg_count

leg_count: int

Gets the total number of legs, INCLUDING the underlying leg if applicable. This is used to perform a coarse filter as the minimum number of unique positions in the positions collection.

Builder

Builder(name: str)

Bases: Object

Builder class supporting fluent syntax in constructing OptionStrategyDefinition.

Initializes a new instance of the Builder class

build

Builds the OptionStrategyDefinition

with_call

with_call(
    quantity: int,
    *predicates: Union[Expression, Iterable[Expression]]
) -> Builder

Adds a call leg

with_put

with_put(
    quantity: int,
    *predicates: Union[Expression, Iterable[Expression]]
) -> Builder

Adds a put leg

with_underlying_lots

with_underlying_lots(lots: int) -> Builder

Sets the required number of underlying lots

__iter__

__iter__() -> Iterator[OptionStrategyLegDefinition]

call_leg

call_leg(
    quantity: int,
    *predicates: Union[Expression, Iterable[Expression]]
) -> OptionStrategyLegDefinition

Factory function for creating a call leg definition

create_strategy

create_strategy(
    legs: Sequence[OptionStrategyLegDefinitionMatch],
) -> OptionStrategy

Creates the OptionStrategy instance using this definition and the provided leg matches

get_enumerator

get_enumerator() -> (
    IEnumerator[OptionStrategyLegDefinition]
)

Returns an enumerator that iterates through the collection.

Returns:

Type Description
IEnumerator[OptionStrategyLegDefinition]

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

put_leg

put_leg(
    quantity: int,
    *predicates: Union[Expression, Iterable[Expression]]
) -> OptionStrategyLegDefinition

Factory function for creating a put leg definition

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_match_once

try_match_once(
    options: OptionStrategyMatcherOptions,
    positions: OptionPositionCollection,
    match: Optional[OptionStrategyDefinitionMatch],
) -> Tuple[bool, OptionStrategyDefinitionMatch]

Attempts to match the positions to this definition exactly once, by evaluating the enumerable and taking the first entry matched. If not match is found, then false is returned and match will be null.