Skip to content

OptionStrategyMatcherOptions

QuantConnect.Securities.Option.StrategyMatcher.OptionStrategyMatcherOptions

OptionStrategyMatcherOptions(
    definitions: Sequence[OptionStrategyDefinition],
    maximum_count_per_leg: Sequence[int],
    maximum_duration: timedelta = ...,
    maximum_solution_count: int = 100,
    definition_enumerator: IOptionStrategyDefinitionEnumerator = None,
    objective_function: IOptionStrategyMatchObjectiveFunction = None,
    position_enumerator: IOptionPositionCollectionEnumerator = None,
)

Bases: Object

Defines options that influence how the matcher operates.

Initializes a new instance of the OptionStrategyMatcherOptions class, providing options that control the behavior of the OptionStrategyMatcher

maximum_duration

maximum_duration: timedelta

The maximum amount of time spent trying to find an optimal solution.

maximum_solution_count

maximum_solution_count: int

The maximum number of matches to evaluate for the entire portfolio.

maximum_count_per_leg

maximum_count_per_leg: Sequence[int]

Indexed by leg index, defines the max matches to evaluate per leg. For example, MaximumCountPerLeg<1> is the max matches to evaluate for the second leg (index=1).

definitions

definitions: Iterable[OptionStrategyDefinition]

The definitions to be used for matching.

objective_function

Objective function used to compare different match solutions for a given set of positions/definitions

enumerate

enumerate(
    positions: OptionPositionCollection,
) -> Iterable[OptionPosition]

Enumerates the specified positions according to the configured IOptionPositionCollectionEnumerator

get_maximum_leg_matches

get_maximum_leg_matches(leg_index: int) -> int

Gets the maximum number of leg matches to be evaluated. This is to limit evaluating exponential numbers of potential matches as a result of large numbers of unique option positions for the same underlying security.

with_definition_enumerator

with_definition_enumerator(
    enumerator: IOptionStrategyDefinitionEnumerator,
) -> OptionStrategyMatcherOptions

Specifies the order in which definitions are evaluated. Definitions evaluated sooner are more likely to find matches than ones evaluated later.

with_maximum_count_per_leg

with_maximum_count_per_leg(
    counts: Sequence[int],
) -> OptionStrategyMatcherOptions

Specifies the maximum number of solutions per leg index in a solution. Matching is a recursive process, for example, we'll find a very large number of positions to match the first leg. Matching the second leg we'll see less, and third still even less. This is because each subsequent leg must abide by all the previous legs. This parameter defines how many potential matches to evaluate at each leg. For the first leg, we'll evaluate counts<0> matches. For the second leg we'll evaluate counts<1> matches and so on. By decreasing this parameter we can evaluate more total, complete solutions for the entire portfolio rather than evaluation every single permutation of matches for a particular strategy definition, which grows in absurd exponential fashion as the portfolio grows.

with_maximum_duration

with_maximum_duration(
    duration: timedelta,
) -> OptionStrategyMatcherOptions

Specifies the maximum time provided for obtaining an optimal solution.

with_maximum_solution_count

with_maximum_solution_count(
    count: int,
) -> OptionStrategyMatcherOptions

Specifies the maximum number of solutions to evaluate via the objective function.

with_objective_function

Specifies a function used to evaluate how desirable a particular solution is. A good implementation for this would be to minimize the total margin required to hold all of the positions.

with_position_enumerator

with_position_enumerator(
    enumerator: IOptionPositionCollectionEnumerator,
) -> OptionStrategyMatcherOptions

Specifies the order in which positions are evaluated. Positions evaluated sooner are more likely to find matches than ones evaluated later. A good implementation for this is its stand-alone margin required, which would encourage the algorithm to match higher margin positions before matching lower margin positiosn.