Calibration¶
The calibration package provides tools for fitting financial models to
market data, estimating parameters from historical data, and calculating
implied volatility surfaces.
BSMIVSolver ¶
BSMIVSolver(max_iter: int = 20, tolerance: float = 1e-06, *, bisection_iter: int = 60, iv_bounds: tuple[float, float] = (0.0001, 5.0))
High-performance, vectorized implied-volatility solver.
Safeguarded Newton-Raphson (vega floor, step clipping, bracket tracking) on
every option at once, followed by bisection on the ones Newton did not
converge. Prices outside the no-arbitrage band (below the discounted
intrinsic value or above the forward/strike bound) get NaN.
Initializes the BSM implied volatility solver.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
max_iter
|
int
|
Newton iterations, by default 20. |
20
|
tolerance
|
float
|
Absolute price tolerance for convergence, by default 1e-6. |
1e-06
|
bisection_iter
|
int
|
Bisection iterations for options Newton could not solve, default 60. |
60
|
iv_bounds
|
tuple[float, float]
|
Search interval for the volatility, by default (1e-4, 5.0). |
(0.0001, 5.0)
|
Source code in src/optpricing/calibration/vectorized_bsm_iv.py
solve ¶
solve(target_prices: ndarray, options: DataFrame, stock: Stock, rate: Rate, *, initial_guess: ndarray | None = None) -> np.ndarray
Calculates implied volatility for an array of options.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
target_prices
|
ndarray
|
An array of market prices for which to find the implied volatility. |
required |
options
|
DataFrame
|
A DataFrame of option contracts, must include 'strike', 'maturity', and 'optionType' columns. |
required |
stock
|
Stock
|
The underlying asset's properties. |
required |
rate
|
Rate
|
The risk-free rate structure. |
required |
initial_guess
|
ndarray | None
|
Starting volatilities (e.g. yesterday's or the market's implied vols); defaults to 0.2 everywhere. |
None
|
Returns:
| Type | Description |
|---|---|
ndarray
|
Implied volatilities aligned with |
Source code in src/optpricing/calibration/vectorized_bsm_iv.py
75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 | |
CalibrationResult
dataclass
¶
CalibrationResult(params: dict[str, float], loss: float, rmse_iv: float, rmse_price: float, n_options: int, n_evaluations: int, n_starts: int, runtime: float, success: bool, message: str = '', starts: list[dict[str, Any]] = list())
Outcome of :meth:Calibrator.fit.
Attributes:
| Name | Type | Description |
|---|---|---|
params |
dict[str, float]
|
Calibrated (and frozen) parameters. |
loss |
float
|
Final weighted mean squared residual (IV² or price² units). |
rmse_iv |
float
|
Unweighted RMSE of the implied-volatility residuals at the optimum (NaN when no option admits an implied volatility). |
rmse_price |
float
|
Unweighted RMSE of the price residuals at the optimum. |
n_options |
int
|
Size of the calibration set. |
n_evaluations |
int
|
Objective evaluations (all starts). |
n_starts |
int
|
Starting points tried. |
runtime |
float
|
Wall-clock seconds. |
success |
bool
|
Whether at least one local optimisation converged. |
message |
str
|
Optimiser message of the best run. |
starts |
list[dict[str, Any]]
|
Per-start records ( |
CalibrationSettings
dataclass
¶
CalibrationSettings(liquidity: LiquidityFilter = LiquidityFilter(), objective: str = 'iv', weighting: str = 'spread', n_starts: int = 4, warm_start: bool = True, historical_prior: bool = True, feller_penalty: float = 0.0, time_budget: float | None = None, name: str = 'default')
Everything a calibration run needs besides the data and the model.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
liquidity
|
LiquidityFilter
|
Selection of the calibration set. |
LiquidityFilter()
|
objective
|
('iv', 'price')
|
Residuals in Black-Scholes implied-volatility or in price space. |
"iv"
|
weighting
|
('spread', 'vega', 'none')
|
Residual weights: inverse bid-ask spread, inverse vega (price space only; approximates the IV objective) or equal. |
"spread"
|
n_starts
|
int
|
Number of starting points (Latin hypercube in the bounds) besides the recipe's initial guess and the warm start; 1 = local optimisation only. |
4
|
warm_start
|
bool
|
Seed the optimiser with the previous calibration (when one is given). |
True
|
historical_prior
|
bool
|
Use historical-return estimates for jump parameters as a start point. |
True
|
feller_penalty
|
float
|
Soft penalty weight on |
0.0
|
time_budget
|
float | None
|
Wall-clock seconds per model (None = unlimited). |
None
|
name
|
str
|
Label used in tuning reports. |
'default'
|
replace ¶
A copy with some fields changed (liquidity may be a dict of
filter fields to update).
Source code in src/optpricing/calibration/market_filters.py
Calibrator ¶
Calibrator(model: BaseModel, market_data: DataFrame, stock: Stock, rate: Rate, *, objective: str = 'iv', weighting: str = 'spread', allow_mc: bool = False, feller_penalty: float = 0.0, mc_paths: int = 20000, mc_steps: int = 50, random_state: int = 0)
Fits a model's parameters to an option chain.
The residuals are taken in Black-Scholes implied-volatility space by
default (objective="iv"), which puts every strike and maturity on the
same footing; objective="price" uses price differences. Residuals can
be weighted by the inverse bid-ask spread (default), the inverse vega
(price space) or equally. Parameters are optimised in a unit cube mapped
onto the bounds with L-BFGS-B, from several starting points (initial
guess, optional warm start and Latin-hypercube samples); invalid parameter
sets (model ValueError) and optional Feller violations are penalised.
Initializes the Calibrator.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
model
|
BaseModel
|
The financial model to be calibrated (e.g., HestonModel). |
required |
market_data
|
DataFrame
|
Option quotes: 'strike', 'maturity', 'optionType', 'marketPrice' and optionally 'bid'/'ask' (for spread weights) and 'impliedVolatility' (warm start for the IV solver). |
required |
stock
|
Stock
|
The underlying asset's properties. |
required |
rate
|
Rate
|
The risk-free rate structure. |
required |
objective
|
('iv', 'price')
|
Residual space, by default "iv". |
"iv"
|
weighting
|
('spread', 'vega', 'none')
|
Residual weights, by default "spread". |
"spread"
|
allow_mc
|
bool
|
Permit Monte Carlo pricing for simulation-only models. |
False
|
feller_penalty
|
float
|
Weight of the soft Feller penalty (Heston/Bates), by default 0. |
0.0
|
mc_paths
|
int
|
Monte Carlo settings when |
20000
|
mc_steps
|
int
|
Monte Carlo settings when |
20000
|
random_state
|
int
|
Seed for the Latin-hypercube starting points, by default 0. |
0
|
Raises:
| Type | Description |
|---|---|
NotImplementedError
|
If the model cannot be priced on a chain (no closed form, no
characteristic function and |
Source code in src/optpricing/calibration/calibrator.py
91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 | |
fit ¶
fit(initial_guess: dict[str, float], bounds: dict[str, tuple], frozen_params: dict[str, float] | None = None, *, n_starts: int = 1, warm_start: dict[str, float] | None = None, n_local: int = 3, time_budget: float | None = None, maxiter: int = 200, log_scale: Iterable[str] = ()) -> dict[str, float]
Performs the calibration.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
initial_guess
|
dict[str, float]
|
Initial guesses for the parameters to be fitted. |
required |
bounds
|
dict[str, tuple]
|
(min, max) bounds per fitted parameter; missing bounds default to ±50 % around the guess. |
required |
frozen_params
|
dict[str, float] | None
|
Parameters held constant. Defaults to None. |
None
|
n_starts
|
int
|
Total starting points: the guess, the warm start (if given) and
Latin-hypercube samples filling up to |
1
|
warm_start
|
dict[str, float] | None
|
Previous calibration used as an extra start point. |
None
|
n_local
|
int
|
How many of the best-scoring starts get a full local optimisation. |
3
|
time_budget
|
float | None
|
Wall-clock seconds; further starts are skipped once exceeded. |
None
|
maxiter
|
int
|
L-BFGS-B iteration cap per start, by default 200. |
200
|
log_scale
|
Iterable[str]
|
Parameters mapped logarithmically onto their (positive) bounds, for
scales spanning orders of magnitude (e.g. the CEV |
()
|
Returns:
| Type | Description |
|---|---|
dict[str, float]
|
The full set of calibrated and frozen parameters. Details are in
|
Source code in src/optpricing/calibration/calibrator.py
281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 | |
loss ¶
Weighted mean squared residual (plus penalties) for a parameter set.
Source code in src/optpricing/calibration/calibrator.py
LiquidityFilter
dataclass
¶
LiquidityFilter(min_maturity_days: float = 7.0, max_maturity_years: float = 2.0, moneyness: tuple[float, float] = (0.7, 1.3), max_relative_spread: float = 0.25, min_open_interest: int = 1, require_bid: bool = True, otm_only: bool = True, iv_bounds: tuple[float, float] = (0.02, 3.0))
Rules selecting the options a model is fitted to (or evaluated on).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
min_maturity_days
|
float
|
Maturity window; default 7 days to 2 years. |
7.0
|
max_maturity_years
|
float
|
Maturity window; default 7 days to 2 years. |
7.0
|
moneyness
|
tuple[float, float]
|
Allowed forward moneyness |
(0.7, 1.3)
|
max_relative_spread
|
float
|
Maximum |
0.25
|
min_open_interest
|
int
|
Minimum open interest (or volume when open interest is missing); 1. |
1
|
require_bid
|
bool
|
Drop quotes with a zero bid; default True. |
True
|
otm_only
|
bool
|
Keep only out-of-the-money options (puts below the forward, calls above), the most liquid side of the chain; default True. |
True
|
iv_bounds
|
tuple[float, float]
|
Market implied volatilities outside this range are treated as data errors; default (0.02, 3.0). |
(0.02, 3.0)
|
evaluation ¶
The wider companion filter used to evaluate a fit: moneyness widened by 0.1 on each side and twice the spread tolerance, same maturity window, liquidity floor and OTM rule (in-the-money American puts carry an early-exercise premium no European model should be judged on).
Source code in src/optpricing/calibration/market_filters.py
to_dict ¶
JSON-ready dict (tuples become lists, as JSON would store them).
VectorizedIntegrationIVSolver ¶
VectorizedIntegrationIVSolver(max_iter: int = 20, tolerance: float = 1e-07, upper_bound: float = 1000.0)
A high-performance, vectorized Secant method solver for implied volatility for any model that supports a characteristic function.
Initializes the vectorized IV solver.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
max_iter
|
int
|
Maximum number of iterations for the Secant method, by default 20. |
20
|
tolerance
|
float
|
Error tolerance for convergence, by default 1e-7. |
1e-07
|
upper_bound
|
float
|
The upper limit for the numerical integration, by default 1000.0. |
1000.0
|
Source code in src/optpricing/calibration/vectorized_integration_iv.py
solve ¶
Calculates implied volatility for an array of options and prices.
This method uses a vectorized Secant root-finding algorithm. The pricing at each step is performed using a vectorized version of the Gil-Pelaez inversion formula.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
target_prices
|
ndarray
|
An array of market prices for which to find the implied volatility. |
required |
options
|
DataFrame
|
A DataFrame of option contracts. |
required |
model
|
BaseModel
|
The financial model to use for pricing. |
required |
rate
|
Rate
|
The risk-free rate structure. |
required |
Returns:
| Type | Description |
|---|---|
ndarray
|
An array of calculated implied volatilities. |
Source code in src/optpricing/calibration/vectorized_integration_iv.py
VolatilitySurface ¶
A class to compute and hold market and model-implied volatility surfaces.
This class takes a DataFrame of option market data and provides methods to calculate the Black-Scholes implied volatility (IV) for each option, either from its market price or from a price generated by a financial model.
Initializes the VolatilitySurface.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
option_data
|
DataFrame
|
A DataFrame containing market prices of options. Must include 'strike', 'maturity', 'marketPrice', 'optionType', and 'expiry' columns. |
required |
Raises:
| Type | Description |
|---|---|
ValueError
|
If any of the required columns are missing from |
Source code in src/optpricing/calibration/iv_surface.py
calculate_market_iv ¶
Calculates the market implied volatility surface from market prices.
This method inverts the Black-Scholes formula for each option's market
price to find the corresponding implied volatility. The results are
stored in the self.surface DataFrame.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
stock
|
Stock
|
The underlying asset's properties. |
required |
rate
|
Rate
|
The risk-free rate structure. |
required |
Returns:
| Type | Description |
|---|---|
VolatilitySurface
|
The same instance of the class, allowing for method chaining. |
Source code in src/optpricing/calibration/iv_surface.py
calculate_model_iv ¶
calculate_model_iv(stock: Stock, rate: Rate, model: BaseModel, technique: BaseTechnique = None, *, allow_mc: bool = False) -> VolatilitySurface
Calculates a model's implied volatility surface.
This method first prices every option in the dataset using the provided
model (vectorised closed form, characteristic function or, with
allow_mc, Monte Carlo). It then inverts the Black-Scholes formula
for each of these model prices to generate the model-implied
volatility surface.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
stock
|
Stock
|
The underlying asset's properties. |
required |
rate
|
Rate
|
The risk-free rate structure. |
required |
model
|
BaseModel
|
The financial model to generate prices from. |
required |
technique
|
BaseTechnique
|
Unused (kept for backwards compatibility); the chain pricer picks the fastest exact method itself. |
None
|
allow_mc
|
bool
|
Permit Monte Carlo pricing for simulation-only models. |
False
|
Returns:
| Type | Description |
|---|---|
VolatilitySurface
|
The same instance of the class, allowing for method chaining. |
Source code in src/optpricing/calibration/iv_surface.py
annotate_chain ¶
annotate_chain(df: DataFrame, stock: Stock, rate: Rate, *, iv_solver: BSMIVSolver | None = None) -> pd.DataFrame
Adds pricing helpers to a chain: forward, moneyness (K/F),
log_moneyness, relative_spread and iv_market (Black-Scholes
implied volatility of the mid, NaN where none exists).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
df
|
DataFrame
|
Options with |
required |
stock
|
(Stock, Rate)
|
Market parameters used for the forward and the implied volatilities. |
required |
rate
|
(Stock, Rate)
|
Market parameters used for the forward and the implied volatilities. |
required |
iv_solver
|
BSMIVSolver | None
|
Solver instance (default settings if omitted). |
None
|
Returns:
| Type | Description |
|---|---|
DataFrame
|
A copy of |
Source code in src/optpricing/calibration/market_filters.py
bucket_metrics ¶
RMSE of the IV and price errors by maturity and by moneyness bucket.
Returns:
| Type | Description |
|---|---|
DataFrame
|
Columns |
Source code in src/optpricing/calibration/metrics.py
evaluate_model ¶
evaluate_model(model: BaseModel, data: DataFrame, stock: Stock, rate: Rate, *, allow_mc: bool = False, **pricing_kwargs: Any) -> tuple[dict[str, float], pd.DataFrame, pd.DataFrame]
One-call evaluation: scalar metrics, bucket table and residual table.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
model
|
BaseModel
|
See :func: |
required |
data
|
BaseModel
|
See :func: |
required |
stock
|
BaseModel
|
See :func: |
required |
rate
|
BaseModel
|
See :func: |
required |
allow_mc
|
bool
|
Permit the Monte Carlo pricing route. |
False
|
Returns:
| Type | Description |
|---|---|
tuple[dict[str, float], DataFrame, DataFrame]
|
|
Source code in src/optpricing/calibration/metrics.py
filter_options ¶
filter_options(df: DataFrame, stock: Stock, rate: Rate, liquidity: LiquidityFilter | None = None) -> pd.DataFrame
Applies a :class:LiquidityFilter to a chain.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
df
|
DataFrame
|
Raw or annotated chain (see :func: |
required |
stock
|
(Stock, Rate)
|
Market parameters (forward, implied volatilities). |
required |
rate
|
(Stock, Rate)
|
Market parameters (forward, implied volatilities). |
required |
liquidity
|
LiquidityFilter | None
|
Rules to apply; defaults to |
None
|
Returns:
| Type | Description |
|---|---|
DataFrame
|
The surviving options, annotated, with a fresh integer index. |
Source code in src/optpricing/calibration/market_filters.py
find_atm_options ¶
Finds the closest at-the-money (ATM) call-put pair for each expiry.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
calls
|
DataFrame
|
A DataFrame of call options. |
required |
puts
|
DataFrame
|
A DataFrame of put options. |
required |
spot
|
float
|
The current spot price of the underlying. |
required |
Returns:
| Type | Description |
|---|---|
DataFrame
|
A DataFrame containing the merged ATM call-put pairs. |
Source code in src/optpricing/calibration/fit_market_params.py
fit_jump_params_from_history ¶
Estimates jump parameters and diffusion volatility from historical returns.
This function separates historical log returns into a "diffusion" component (normal daily movements) and a "jump" component (extreme movements) based on a standard deviation threshold. It then calculates the annualized parameters for a jump-diffusion model like Merton's.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
log_returns
|
Series
|
A pandas Series of daily log returns. |
required |
threshold_stds
|
float
|
The number of standard deviations to use as a threshold for identifying jumps, by default 3.0. |
3.0
|
Returns:
| Type | Description |
|---|---|
dict
|
A dictionary containing the estimated parameters: 'sigma', 'lambda', 'mu_j', and 'sigma_j'. |
Source code in src/optpricing/calibration/fit_jump_parameters.py
fit_rate_and_dividend ¶
fit_rate_and_dividend(calls: DataFrame, puts: DataFrame, spot: float, r_fixed: float | None = None, q_fixed: float | None = None) -> tuple[float, float]
Fits the risk-free rate (r) and dividend yield (q) from put-call parity.
With r_fixed given, the dividend yield comes from the implied forward
curve (:func:implied_dividend_yield). Otherwise the parity error of the
ATM call-put pair of every maturity is minimised over the free parameters
(note that parity identifies r - q well but r and q separately
only weakly, so supply one of them whenever possible).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
calls
|
DataFrame
|
A DataFrame of call options with 'strike', 'maturity', 'marketPrice'. |
required |
puts
|
DataFrame
|
A DataFrame of put options with 'strike', 'maturity', 'marketPrice'. |
required |
spot
|
float
|
The current spot price of the underlying. |
required |
r_fixed
|
float | None
|
If provided, the risk-free rate is held fixed at this value. Defaults to None. |
None
|
q_fixed
|
float | None
|
If provided, the dividend yield is held fixed at this value. Defaults to None. |
None
|
Returns:
| Type | Description |
|---|---|
tuple[float, float]
|
The estimated (or fixed) continuously compounded rate and dividend yield. |
Source code in src/optpricing/calibration/fit_market_params.py
implied_dividend_yield ¶
implied_dividend_yield(calls: DataFrame, puts: DataFrame, spot: float, rate: float, *, min_maturity_days: float = 14.0) -> float
Flat continuous dividend yield implied by the option chain for a given rate.
Aggregates :func:implied_forward_curve with a weighted median (weights
T * n_pairs, maturities shorter than min_maturity_days excluded when
longer ones exist) and falls back to zero when the result is implausible.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
calls
|
DataFrame
|
Option quotes (see :func: |
required |
puts
|
DataFrame
|
Option quotes (see :func: |
required |
spot
|
float
|
Spot price. |
required |
rate
|
float
|
Continuously compounded risk-free rate. |
required |
min_maturity_days
|
float
|
Maturities below this are ignored if longer ones exist, by default 14. |
14.0
|
Returns:
| Type | Description |
|---|---|
float
|
The implied continuous dividend yield. |
Source code in src/optpricing/calibration/fit_market_params.py
implied_forward_curve ¶
implied_forward_curve(calls: DataFrame, puts: DataFrame, spot: float, rate: float, *, moneyness_window: float = 0.03, min_pairs: int = 3) -> pd.DataFrame
Implied forward (and dividend yield) per maturity from put-call parity.
Each call-put pair gives F_i = K_i + (C_i - P_i) e^{rT}; the maturity's
forward is the bid-ask-weighted median over near-the-money pairs. Only
pairs close to the money are used because listed US equity and ETF options
are American: deep in-the-money puts carry an early-exercise premium that
biases parity (it is also why r cannot be inferred from the strike
slope of C - P and must be supplied).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
calls
|
DataFrame
|
Option quotes with |
required |
puts
|
DataFrame
|
Option quotes with |
required |
spot
|
float
|
Spot price used to pick near-the-money pairs and to convert the forward into a dividend yield. |
required |
rate
|
float
|
Continuously compounded risk-free rate. |
required |
moneyness_window
|
float
|
Pairs with |
0.03
|
min_pairs
|
int
|
Minimum number of pairs per maturity, by default 3. |
3
|
Returns:
| Type | Description |
|---|---|
DataFrame
|
One row per maturity: |
Source code in src/optpricing/calibration/fit_market_params.py
62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 | |
price_options_vectorized ¶
price_options_vectorized(options_df: DataFrame, stock: Stock, model: BaseModel, rate: Rate, *, upper_bound: float = 1000.0, method: str = 'cos', allow_mc: bool = False, mc_paths: int = 20000, mc_steps: int = 50, mc_seed: int = 0, **kwargs: Any) -> np.ndarray
Prices a chain of European options with the fastest exact method available.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
options_df
|
DataFrame
|
Must contain |
required |
stock
|
Stock
|
Underlying description. |
required |
model
|
BaseModel
|
A model with a vectorized closed form, a characteristic function or
(with |
required |
rate
|
Rate
|
Continuous zero-curve. |
required |
upper_bound
|
float
|
Integration truncation limit of the |
1000
|
method
|
('cos', 'gauss')
|
Characteristic-function pricer (see :class: |
"cos"
|
allow_mc
|
bool
|
Fall back to Monte Carlo for simulation-only models. |
False
|
mc_paths
|
int
|
Monte Carlo settings for that fallback (fixed seed: common random numbers across calls). |
20000
|
mc_steps
|
int
|
Monte Carlo settings for that fallback (fixed seed: common random numbers across calls). |
20000
|
mc_seed
|
int
|
Monte Carlo settings for that fallback (fixed seed: common random numbers across calls). |
20000
|
**kwargs
|
Any
|
Extra pricing arguments forwarded to the characteristic function or
simulation kernel (e.g. |
{}
|
Returns:
| Type | Description |
|---|---|
ndarray
|
Model prices - aligned with the row order of options_df. |
Raises:
| Type | Description |
|---|---|
NotImplementedError
|
If the model has neither a vectorized closed form nor a characteristic
function and |
Source code in src/optpricing/calibration/vectorized_pricer.py
residual_table ¶
residual_table(model: BaseModel, data: DataFrame, stock: Stock, rate: Rate, *, allow_mc: bool = False, iv_solver: BSMIVSolver | None = None, **pricing_kwargs: Any) -> pd.DataFrame
Prices every option in data with model and returns the residuals.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
model
|
BaseModel
|
The (calibrated) model. |
required |
data
|
DataFrame
|
Options with |
required |
stock
|
(Stock, Rate)
|
Market parameters. |
required |
rate
|
(Stock, Rate)
|
Market parameters. |
required |
allow_mc
|
bool
|
Permit the Monte Carlo pricing route, by default False. |
False
|
iv_solver
|
BSMIVSolver | None
|
Solver for the model implied volatilities. |
None
|
**pricing_kwargs
|
Any
|
Forwarded to :func: |
{}
|
Returns:
| Type | Description |
|---|---|
DataFrame
|
|
Source code in src/optpricing/calibration/metrics.py
select_fastest_technique ¶
Selects the fastest available pricing technique for a given model.
The function checks the capabilities of the model in a specific order of preference, which generally corresponds to computational speed.
The order of preference is: 1. Closed-Form 2. COS (Fang & Oosterlee 2008), for characteristic-function models: as accurate as FFT and 0.1-0.5 ms per option against 0.4-55 ms 3. Monte Carlo
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
model
|
BaseModel
|
The financial model for which to select a technique. |
required |
Returns:
| Type | Description |
|---|---|
BaseTechnique
|
An instance of the fastest suitable pricing technique. |
Raises:
| Type | Description |
|---|---|
TypeError
|
If no suitable pricing technique can be found for the model. |
Source code in src/optpricing/calibration/technique_selector.py
summarize_residuals ¶
Scalar metrics from a :func:residual_table.
Returns:
| Type | Description |
|---|---|
dict[str, float]
|
|
Source code in src/optpricing/calibration/metrics.py
supports_vectorized_pricing ¶
True if :func:price_options_vectorized can price a chain for model.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
model
|
BaseModel
|
The model to check. |
required |
allow_mc
|
bool
|
Count simulation-only models as supported, by default False. |
False
|