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:
Calculate the cost function from the model prices
Calculate the weight for the cost function for a given time to maturity and moneyness
Fit the model
Get the parameter bounds for the calibration
Get the constraints for the calibration
Get the parameters of the model
Get the range of implied volatilities
Override this method to perform additional initialization after __init__ and model_construct.
Penalize the cost function
Plot the implied volatility for market and model prices
Set the parameters of the model
Attributes:
The optimization method to use - if None, the default is used
Get the model
Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].
The weight for penalize options with moneyness as it moves away from 0
The options to calibrate
The
OptionPricer
for the modelGet the reference date
The weight for penalize options with ttm as it approaches 0
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 theHeston
stochastic volatility modelMethods:
Get the parameter bounds for the calibration
Get the parameters of the model
Penalize the cost function
Set the parameters of the model
Attributes:
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