OptionStrategyLegDefinition
QuantConnect.Securities.Option.StrategyMatcher.OptionStrategyLegDefinition
OptionStrategyLegDefinition(
right: OptionRight,
quantity: int,
predicates: List[OptionStrategyLegPredicate],
)
Bases: Object, Iterable[OptionStrategyLegPredicate]
Defines a single option leg in an option strategy. This definition supports direct match (does position X match the definition) and position collection filtering (filter collection to include matches)
Initializes a new instance of the OptionStrategyLegDefinition class
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
right
|
OptionRight
|
The leg's contract right |
required |
quantity
|
int
|
The leg's unit quantity |
required |
predicates
|
List[OptionStrategyLegPredicate]
|
The conditions a position must meet in order to match this definition |
required |
quantity
quantity: int
Gets the unit quantity
create
create(
right: OptionRight,
quantity: int,
predicates: List[Expression],
) -> OptionStrategyLegDefinition
Creates a new OptionStrategyLegDefinition matching the specified parameters
filter
filter(
legs: Sequence[OptionPosition],
positions: OptionPositionCollection,
include_underlying: bool = True,
) -> OptionPositionCollection
Filters the provided positions collection such that any remaining positions are all valid options that match this leg definition instance.
get_enumerator
get_enumerator() -> IEnumerator[OptionStrategyLegPredicate]
Returns an enumerator that iterates through the collection.
Returns:
| Type | Description |
|---|---|
IEnumerator[OptionStrategyLegPredicate]
|
An enumerator that can be used to iterate through the collection. |
match
match(
options: OptionStrategyMatcherOptions,
legs: Sequence[OptionPosition],
positions: OptionPositionCollection,
) -> Iterable[OptionStrategyLegDefinitionMatch]
Yields all possible matches for this leg definition held within the collection of positions
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
options
|
OptionStrategyMatcherOptions
|
Strategy matcher options guiding matching behaviors |
required |
legs
|
Sequence[OptionPosition]
|
The preceding legs already matched for the parent strategy definition |
required |
positions
|
OptionPositionCollection
|
The remaining, unmatched positions available to be matched against |
required |
Returns:
| Type | Description |
|---|---|
Iterable[OptionStrategyLegDefinitionMatch]
|
An enumerable of potential matches. |
try_match
try_match(
position: OptionPosition, leg: Optional[LegData]
) -> Tuple[bool, LegData]
Determines whether or not this leg definition matches the specified position, and if so, what the resulting quantity of the OptionStrategy.OptionLegData should be.