OptionStrategy
QuantConnect.Securities.Option.OptionStrategy
OptionStrategy(
name: str,
canonical_symbol: Union[
Symbol, str, BaseContract, Security
],
option_legs: List[OptionLegData] = None,
underlying_legs: List[UnderlyingLegData] = None,
)
OptionStrategy()
Bases: Object
Option strategy specification class. Describes option strategy and its parameters for trading.
Signature descriptions:
-
Creates a new instance of OptionStrategy with the specified parameters
-
Creates a new instance of OptionStrategy with default parameters
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
name
|
Optional[str]
|
The strategy name |
None
|
canonical_symbol
|
Optional[Union[Symbol, str, BaseContract, Security]]
|
The canonical option symbol |
None
|
option_legs
|
Optional[List[OptionLegData]]
|
The option legs data |
None
|
underlying_legs
|
Optional[List[UnderlyingLegData]]
|
The underlying legs data |
None
|
name
name: str
Option strategy name
underlying_legs
underlying_legs: List[UnderlyingLegData]
Option strategy underlying legs (usually 0 or 1 legs)
UnderlyingLegData
Bases: Leg
This class is a POCO containing basic data for the underlying leg of the strategy
quantity
quantity: int
Quantity multiplier used to specify proper scale (and direction) of the leg within the strategy
order_price
order_price: Optional[float]
Order limit price of the leg in case limit order is sent to the market on strategy execution
create
create(
quantity: int,
symbol: Union[Symbol, str, BaseContract, Security],
order_price: Optional[float] = None,
) -> UnderlyingLegData
create(
quantity: int, order_price: Optional[float] = None
) -> UnderlyingLegData
Creates a new instance of UnderlyingLegData for the specified quantity of underlying shares.
to_string
to_string() -> str
Returns a string that represents the underlying leg.
OptionLegData
Bases: Leg
This class is a POCO containing basic data for the option legs of the strategy
expiration
expiration: datetime
Expiration date of the leg
strike
strike: float
Strike price of the leg
quantity
quantity: int
Quantity multiplier used to specify proper scale (and direction) of the leg within the strategy
order_price
order_price: Optional[float]
Order limit price of the leg in case limit order is sent to the market on strategy execution
create
create(
quantity: int,
symbol: Union[Symbol, str, BaseContract, Security],
order_price: Optional[float] = None,
) -> OptionLegData
Creates a new instance of OptionLegData from the specified parameters
to_string
to_string() -> str
Returns a string that represents the option leg
create
create(name: str, legs: List[Leg]) -> OptionStrategy
Creates a new instance of OptionStrategy with the specified name and legs data. The method will try to infer the canonical symbol and underlying symbol from the legs data, but they can also be set manually after the strategy creation.
set_symbols
set_symbols() -> None
Sets the option legs symbols based on the canonical symbol and the leg data. If the canonical symbol is not set, it will be created using the underlying symbol.