Equity
Local Volatility Model
- class rivapy.models.LocalVol(vol_param, x_strikes: array, time_grid: array, call_prices: ndarray = None, local_vol_grid: ndarray = None)[source]
Bases:
object
Local Volatility Class
- Parameters:
vol_param – a grid or a parametrisation of the volatility
x_strikes (np.array) – strikes
time_grid (np.array) – time_grid
call_param (np.ndarray, optional) – A grid of call prices. Not compatible with vol_param. Defaults to None.
- apply_mc_step(x: ndarray, t0: float, t1: float, rnd: ndarray, inplace: bool = True)[source]
Apply a MC-Euler step for the LV Model for n different paths.
- Parameters:
x (np.ndarray) – 2-d array containing the start values for the spot and variance. The first column contains the spot, the second the variance values.
t0 ([type]) – [description]
t1 ([type]) – [description]
rnd ([type]) – [description]
- static compute_local_var(vol_param, x_strikes: array, time_grid: array, call_param: ndarray = None, min_lv=0.01, max_lv=1.5)[source]
Calculate the local variance from vol_param or call_param for x_strikes on time_grid
- Parameters:
vol_param – a grid or a parametrisation of the volatility
x_strikes (np.array) – strikes
time_grid (np.array) – time_grid
call_param (np.ndarray, optional) – A grid of call prices. Not compatible with vol_param. Defaults to None.
- Returns:
local volatility surface on the grid
Heston Model
- class rivapy.models.HestonModel(long_run_variance, mean_reversion_speed, vol_of_vol, initial_variance, correlation)[source]
Bases:
object
_summary_
- Parameters:
long_run_variance (_type_) – _description_
mean_reversion_speed (_type_) – _description_
vol_of_vol (_type_) – _description_
initial_variance (_type_) – _description_
correlation (_type_) – _description_
- apply_mc_step(x: ndarray, t0: float, t1: float, rnd: ndarray, inplace: bool = True, slv: ndarray = None)[source]
Apply a MC-Euler step for the Heston Model for n different paths.
- Parameters:
x (np.ndarray) – 2-d array containing the start values for the spot and variance. The first column contains the spot, the second the variance values.
t0 (float) – The current time.
t1 (float) – The next timestep to be computed.
rnd (np.ndarray) – Two-dimensional array of shape (n_sims,2) containing the normal random numbers. Each row of the array is used to compute the correlated random numbers for the respective simulation.
slv (np.ndarray) – Stochastic local variance (for each path) to be multiplied with the heston variance. This is used by the StochasticVolatilityModel and can be ignored.
- call_price(s0: float, v0: float, K: ndarray | float, ttm: ndarray | float) ndarray | float [source]
Computes a call price for the Heston model via integration over characteristic function.
- Parameters:
s0 (float) – current spot
v0 (float) – current variance
K (float) – strike
ttm (float) – time to maturity
Scott Chesney
Scott Chesney Model is a stochastic volatility model of the form
\[dS = e^y S dW_S\]\[dy = \kappa (\theta-y)dt \alpha dW_y\]\[E[dW_S\dot dW_y] = \rho dt\]
- class rivapy.models.ScottChesneyModel(kappa: float, theta: float, alpha: float, correlation: float, y0: float)[source]
Bases:
object
Scott-Chesney Model Generates a timeseries according to
\[dS = e^y S dW_S\]\[dy = `{\kappa}` (`{ heta}`-y)dt `{lpha}` dW_y\]\[E[dW_s\dot dW_y] = \rho dt\]- Parameters:
kappa (float) – speed of mean reversion
theta (float) – mean reversion level
alpha (float) – vol of (log)vol
correlation (float) – correlation between (log)vol and spot
y0 – start value (float): (log) vol
- apply_mc_step(x: ndarray, t0: float, t1: float, rnd: ndarray, inplace: bool = True, slv: ndarray = None)[source]
Apply a MC-Euler step for the Scott-Chesney Model for n different paths.
- Parameters:
x (np.ndarray) – 2-d array containing the start values for the spot and variance. The first column contains the spot, the second the variance values.
t0 ([type]) – [description]
t1 ([type]) – [description]
rnd ([type]) – [description]
slv (np.ndarray) – Stochastic local variance (for each path) to be multiplied with the heston variance. This is used by the StochasticVolatilityModel.
Stochastic Local Volatility Model
- class rivapy.models.StochasticLocalVol(stoch_vol_model)[source]
Bases:
object
Stochastic Local Volatility model
- Parameters:
stochastic_vol_model (StochasticVolModel) – The underlying stochastic vol model
- apply_mc_step(x: ndarray, t0: float, t1: float, rnd: ndarray, inplace: bool = True)[source]
Apply a MC-Euler step for the Heston Local Vol Model for n different paths.
- Parameters:
x (np.ndarray) – 2-d array containing the start values for the spot and variance. The first column contains the spot, the second the variance values.
t0 ([type]) – [description]
t1 ([type]) – [description]
rnd ([type]) – [description]
- calibrate_MC(vol_param, x_strikes: ndarray, time_grid: ndarray, n_sims, local_var: ndarray = None, call_prices: ndarray = None)[source]
Calibrate the Heston Local Volatility Model using kernel regression.
This method calibrates the local volatility part of the Heston Model given a volatility parametrization so that the respective implied volatilities from the given vol parametrization are reproduced by the Heston Local Volatility model. The calibration is based on kernel regression as described in Applied Machine Learning for Stochastic Local Volatility Calibration.
- Parameters:
vol_param ([type]) – [description]
x_strikes (np.array) – [description]
time_grid (np.array) – [description]
n_sims ([type]) – [description]
local_var (np.ndarray, optional) – [description]. Defaults to None.
call_prices (np.ndarray, optional) – Defaults to None.