Skip to content

QLOptionPriceModel

QuantConnect.Securities.Option.QLOptionPriceModel

QLOptionPriceModel(
    pricing_engine_func: Callable[
        [GeneralizedBlackScholesProcess], IPricingEngine
    ],
    underlying_vol_estimator: IQLUnderlyingVolatilityEstimator = None,
    risk_free_rate_estimator: IQLRiskFreeRateEstimator = None,
    dividend_yield_estimator: IQLDividendYieldEstimator = None,
    allowed_option_styles: List[OptionStyle] = None,
)
QLOptionPriceModel(
    pricing_engine_func: Callable[
        [Symbol, GeneralizedBlackScholesProcess],
        IPricingEngine,
    ],
    underlying_vol_estimator: IQLUnderlyingVolatilityEstimator = None,
    risk_free_rate_estimator: IQLRiskFreeRateEstimator = None,
    dividend_yield_estimator: IQLDividendYieldEstimator = None,
    allowed_option_styles: List[OptionStyle] = None,
)

Bases: Object, IOptionPriceModel

Provides QuantLib(QL) implementation of IOptionPriceModel to support major option pricing models, available in QL.

Method constructs QuantLib option price model with necessary estimators of underlying volatility, risk free rate, and underlying dividend yield

Parameters:

Name Type Description Default
pricing_engine_func Callable[[GeneralizedBlackScholesProcess], IPricingEngine] | Callable[[Symbol, GeneralizedBlackScholesProcess], IPricingEngine]

Function modeled stochastic process, and returns new pricing engine to run calculations for that option

required
underlying_vol_estimator IQLUnderlyingVolatilityEstimator

The underlying volatility estimator

None
risk_free_rate_estimator IQLRiskFreeRateEstimator

The risk free rate estimator

None
dividend_yield_estimator IQLDividendYieldEstimator

The underlying dividend yield estimator

None
allowed_option_styles List[OptionStyle]

List of option styles supported by the pricing model. It defaults to both American and European option styles

None

enable_greek_approximation

enable_greek_approximation: bool

When enabled, approximates Greeks if corresponding pricing model didn't calculate exact numbers. The default value is true.

volatility_estimator_warmed_up

volatility_estimator_warmed_up: bool

True if volatility model is warmed up, i.e. has generated volatility value different from zero, otherwise false.

allowed_option_styles

allowed_option_styles: Sequence[OptionStyle]

List of option styles supported by the pricing model. By default, both American and European option styles are supported.

evaluate

evaluate(
    security: Security,
    slice: Slice,
    contract: OptionContract,
) -> OptionPriceModelResult

Evaluates the specified option contract to compute a theoretical price, IV and greeks

Parameters:

Name Type Description Default
security Security

The option security object

required
slice Slice

The current data slice. This can be used to access other information available to the algorithm

required
contract OptionContract

The option contract to evaluate

required

Returns:

Type Description
OptionPriceModelResult

An instance of OptionPriceModelResult containing the theoretical price of the specified option contract.

implied_volatility_estimation

implied_volatility_estimation(
    price: float,
    initial_guess: float,
    time_till_expiry: float,
    risk_free_discount: float,
    forward_price: float,
    payoff: Any,
    black: Optional[Any],
) -> Tuple[float, Any]

An implied volatility approximation by Newton-Raphson method. Return 0 if result is not converged

This codeEntityType is protected.

Parameters:

Name Type Description Default
price float

current price of the option

required
initial_guess float

initial guess of the IV

required
time_till_expiry float

time till option contract expiry

required
risk_free_discount float

risk free rate discount factor

required
forward_price float

future value of underlying price

required
payoff Any

payoff structure of the option contract

required
black Optional[Any]

black calculator instance

required

Returns:

Type Description
Tuple[float, Any]

implied volatility estimation.