Heston Model

class torchquantlib.models.stochastic_volatility.heston.Heston(kappa_init=1.0, theta_init=0.04, sigma_v_init=0.5, rho_init=-0.5, v0_init=0.04, mu_init=0.0)[source]

Bases: StochasticModel

Heston stochastic volatility model.

This model describes the evolution of an asset price and its variance using two coupled stochastic differential equations: dS = μSdt + √vSdW_S dv = κ(θ - v)dt + σ_v√vdW_v

where: S is the asset price v is the variance μ is the drift of the asset price κ is the rate of mean reversion of variance θ is the long-term mean of variance σ_v is the volatility of variance ρ is the correlation between the two Wiener processes W_S and W_v

__init__(kappa_init=1.0, theta_init=0.04, sigma_v_init=0.5, rho_init=-0.5, v0_init=0.04, mu_init=0.0)[source]

Initialize the Heston model.

Parameters:
  • kappa_init (float) – Initial value for rate of mean reversion of variance.

  • theta_init (float) – Initial value for long-term mean of variance.

  • sigma_v_init (float) – Initial value for volatility of variance.

  • rho_init (float) – Initial value for correlation between asset and variance processes.

  • v0_init (float) – Initial value for variance.

  • mu_init (float) – Initial value for drift of asset price.

simulate(S0, T, N, steps=100)[source]

Simulate asset price paths using the Heston model.

Parameters:
  • S0 (float) – Initial asset price.

  • T (float) – Time horizon for simulation.

  • N (int) – Number of simulation paths.

  • steps (int) – Number of time steps in each path.

Returns:

Simulated asset prices at time T.

Return type:

torch.Tensor

_apply_constraints()[source]

Apply constraints to model parameters to ensure they remain in valid ranges.

option_price(S0, K, T, r, option_type='call', N=10000, steps=100)[source]

Price a European option using Monte Carlo simulation under the Heston model.

Parameters:
  • S0 (float) – Initial asset price.

  • K (float) – Strike price.

  • T (float) – Time to maturity.

  • r (float) – Risk-free interest rate.

  • option_type (str) – ‘call’ or ‘put’.

  • N (int) – Number of simulation paths.

  • steps (int) – Number of time steps in simulation.

Returns:

Option price.

Return type:

float

simulate(S0, T, N, steps=100)[source]

Simulate asset price paths using the Heston model.

Parameters:
  • S0 (float) – Initial asset price.

  • T (float) – Time horizon for simulation.

  • N (int) – Number of simulation paths.

  • steps (int) – Number of time steps in each path.

Returns:

Simulated asset prices at time T.

Return type:

torch.Tensor

Class Methods

__init__(kappa_init=2.0, theta_init=0.04, sigma_init=0.3, rho_init=-0.7, v0_init=0.04)

Initialize the Heston model.

param float kappa_init:

Initial value for mean reversion speed of variance.

param float theta_init:

Initial value for long-term mean of variance.

param float sigma_init:

Initial value for volatility of variance.

param float rho_init:

Initial value for correlation between asset returns and variance.

param float v0_init:

Initial variance.

simulate(S0, T, N, steps=100)

Simulate asset price paths using the Heston model.

param float S0:

Initial asset price.

param float T:

Time horizon for simulation.

param int N:

Number of simulation paths.

param int steps:

Number of time steps in each path.

return:

Simulated asset prices at time T.

rtype:

torch.Tensor

_apply_constraints()

Apply constraints to model parameters to ensure they remain in valid ranges.

Model Description

The Heston model is a stochastic volatility model used in mathematical finance to model the evolution of asset prices and their volatility. It is particularly useful for pricing options and modeling the volatility smile observed in financial markets.

The model is described by two stochastic differential equations:

\[\begin{split}dS_t &= \mu S_t dt + \sqrt{v_t} S_t dW^1_t \\ dv_t &= \kappa(\theta - v_t) dt + \sigma \sqrt{v_t} dW^2_t\end{split}\]

where:

  • \(S_t\) is the asset price at time t

  • \(v_t\) is the instantaneous variance at time t

  • \(\mu\) is the drift of the asset price (often set to the risk-free rate)

  • \(\kappa\) is the rate of mean reversion of the variance

  • \(\theta\) is the long-term mean of the variance

  • \(\sigma\) is the volatility of volatility

  • \(\rho\) is the correlation between \(W^1_t\) and \(W^2_t\) (the two Wiener processes)

The Heston model allows for a more flexible and realistic representation of asset price dynamics compared to models with constant volatility, as it captures the stochastic nature of volatility and can reproduce observed market phenomena such as volatility clustering and leverage effects.