Vol Model Calibration#

class quantflow.options.calibration.VolModelCalibration(*, pricer: ~quantflow.options.pricer.OptionPricer[TypeVar], vol_surface: ~quantflow.options.surface.VolSurface[~typing.Any], minimize_method: str | None = None, moneyness_weight: ~typing.Annotated[float, ~annotated_types.Ge(ge=0)] = 0.0, ttm_weight: ~typing.Annotated[float, ~annotated_types.Ge(ge=0.0), ~annotated_types.Le(le=1.0)] = 0.0, options: dict[~quantflow.options.calibration.ModelCalibrationEntryKey, ~quantflow.options.calibration.OptionEntry] = <factory>)#

Abstract class for calibration of a stochastic volatility model

Methods:

cost_function

Calculate the cost function from the model prices

cost_weight

Calculate the weight for the cost function for a given time to maturity and moneyness

fit

Fit the model

get_bounds

Get the parameter bounds for the calibration

get_constraints

Get the constraints for the calibration

get_params

Get the parameters of the model

implied_vol_range

Get the range of implied volatilities

model_post_init

Override this method to perform additional initialization after __init__ and model_construct.

penalize

Penalize the cost function

plot

Plot the implied volatility for market and model prices

set_params

Set the parameters of the model

Attributes:

minimize_method

The optimization method to use - if None, the default is used

model

Get the model

model_config

Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].

moneyness_weight

The weight for penalize options with moneyness as it moves away from 0

options

The options to calibrate

pricer

The OptionPricer for the model

ref_date

Get the reference date

ttm_weight

The weight for penalize options with ttm as it approaches 0

vol_surface

The VolSurface to calibrate the model with

cost_function(params: ndarray) float#

Calculate the cost function from the model prices

cost_weight(ttm: float, moneyness: float) float#

Calculate the weight for the cost function for a given time to maturity and moneyness

fit() OptimizeResult#

Fit the model

get_bounds() Bounds | None#

Get the parameter bounds for the calibration

get_constraints() Sequence[dict[str, Any]] | None#

Get the constraints for the calibration

abstract get_params() ndarray#

Get the parameters of the model

Must be implemented by the subclass

implied_vol_range() Bounds#

Get the range of implied volatilities

model_post_init(_ctx: Any) None#

Override this method to perform additional initialization after __init__ and model_construct. This is useful if you want to do some validation that requires the entire model to be initialized.

penalize() float#

Penalize the cost function

plot(index: int = 0, *, max_moneyness_ttm: float | None = 1.0, support: int = 51, **kwargs: Any) Any#

Plot the implied volatility for market and model prices

abstract set_params(params: ndarray) None#

Set the parameters of the model

Must be implemented by the subclass

minimize_method: str | None#

The optimization method to use - if None, the default is used

property model: M#

Get the model

model_config: ClassVar[ConfigDict] = {'arbitrary_types_allowed': True}#

Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].

moneyness_weight: float#

The weight for penalize options with moneyness as it moves away from 0

The weight is applied as exp(-moneyness_weight * moneyness), therefore a value of 0 won’t penalize moneyness at all

options: dict[ModelCalibrationEntryKey, OptionEntry]#

The options to calibrate

pricer: OptionPricer[M]#

The OptionPricer for the model

property ref_date: datetime#

Get the reference date

ttm_weight: float#

The weight for penalize options with ttm as it approaches 0

The weight is applied as 1 - ttm_weight*exp(-ttm), therefore a value of 0 won’t penalize ttm at all, a value of 1 will penalize options with ttm->0 the most

vol_surface: VolSurface[Any]#

The VolSurface to calibrate the model with

class quantflow.options.calibration.HestonCalibration(*, pricer: ~quantflow.options.pricer.OptionPricer[Heston], vol_surface: ~quantflow.options.surface.VolSurface[~typing.Any], minimize_method: str | None = None, moneyness_weight: ~typing.Annotated[float, ~annotated_types.Ge(ge=0)] = 0.0, ttm_weight: ~typing.Annotated[float, ~annotated_types.Ge(ge=0.0), ~annotated_types.Le(le=1.0)] = 0.0, options: dict[~quantflow.options.calibration.ModelCalibrationEntryKey, ~quantflow.options.calibration.OptionEntry] = <factory>, feller_penalize: float = 0.0)#

A VolModelCalibration for the Heston stochastic volatility model

Methods:

get_bounds

Get the parameter bounds for the calibration

get_params

Get the parameters of the model

penalize

Penalize the cost function

set_params

Set the parameters of the model

Attributes:

model_config

Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].

get_bounds() Sequence[Bounds] | None#

Get the parameter bounds for the calibration

get_params() ndarray#

Get the parameters of the model

Must be implemented by the subclass

penalize() float#

Penalize the cost function

set_params(params: ndarray) None#

Set the parameters of the model

Must be implemented by the subclass

minimize_method: str | None#

The optimization method to use - if None, the default is used

model_config: ClassVar[ConfigDict] = {'arbitrary_types_allowed': True}#

Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].

moneyness_weight: float#

The weight for penalize options with moneyness as it moves away from 0

The weight is applied as exp(-moneyness_weight * moneyness), therefore a value of 0 won’t penalize moneyness at all

options: dict[ModelCalibrationEntryKey, OptionEntry]#

The options to calibrate

pricer: OptionPricer[M]#

The OptionPricer for the model

ttm_weight: float#

The weight for penalize options with ttm as it approaches 0

The weight is applied as 1 - ttm_weight*exp(-ttm), therefore a value of 0 won’t penalize ttm at all, a value of 1 will penalize options with ttm->0 the most

vol_surface: VolSurface[Any]#

The VolSurface to calibrate the model with