Processes
Equity, FX and generic
stochPathSim.processes.ArithmeticBrownianMotion
Bases: StochasticProcess
Exact simulation of dX = mu dt + sigma dW.
Values may be negative. mu is an absolute drift per year and sigma
is an absolute volatility per square-root year, both in the units of X.
For Bachelier pricing of a forward under its forward measure, use mu=0
and discount the payoff separately. Setting mu to the risk-free rate
does not produce a risk-neutral spot-price process.
The state is named spot for compatibility with the existing payoffs.
mean
mean(t)
Expected value x0 + mu*t.
variance
variance(t)
Variance sigma**2 * t.
stochPathSim.processes.FractionalBrownianMotion
Bases: StochasticProcess
Fractional Brownian motion with Hurst exponent 0 < H < 1.
X(t) = x0 + driftt + sigmaB_H(t), with covariance
Cov(B_H(t), B_H(s)) = (t**(2H)+s**(2H)-abs(t-s)**(2H))/2.
We Cholesky-factor the increment covariance on the requested grid, then cumulatively sum the correlated increments. This samples the exact finite-dimensional Gaussian law, including on non-uniform grids, subject to floating-point factorisation accuracy.
For H = 0.5 the increments reduce exactly to independent Brownian increments and supplied normals match standard Brownian simulation. For H != 0.5 the process is NOT a semimartingale; the resulting paths are intended for long-memory/roughness studies, NOT directly as an arbitrage-free traded-asset or derivative-pricing model.
The Cholesky decomposition requires O(n_steps3) preprocessing and O(n_steps2) memory; use modest grids (a few hundred observations).
increment_covariance
increment_covariance(grid)
Covariance matrix of unit-scale increments over a TimeGrid.
mean
mean(t)
Exact expected value at scalar or array times.
variance
variance(t)
Exact variance at scalar or array times.
stochPathSim.processes.GARCH11
Bases: StochasticProcess
GARCH(1,1) conditional volatility with lognormal price updates.
At observation k, the annualised conditional variance rate is v[k]. With a standard-normal innovation z[k]:
log(S[k+1]/S[k]) = (mu-q-v[k]/2)*dt[k] + sqrt(v[k]*dt[k])*z[k]
v[k+1] = omega + (alpha*z[k]**2 + beta)*v[k]
Parameters omega, alpha and beta are per observation, not per year: changing the number of observation steps changes the variance dynamics. Prices are simulated with exact conditional lognormal transitions, while the variance evolves by a discrete GARCH recursion. This is not a continuous-time diffusion and cannot be grid-refined without changing its interpretation. Non-uniform time grids are permitted as long as each interval represents one observation.
omega has units of annualised variance per observation; v0 is the annualised variance rate at t=0. Stationarity alpha+beta<1 is required. This is a statistical simulation, NOT automatically a risk-neutral option-pricing model; no variance risk premium is specified.
long_run_variance
property
long_run_variance
Unconditional stationary annualised variance rate.
expected_variance
expected_variance(n)
Expected variance rate at observation n, conditional on v0.
stochPathSim.processes.GJRGARCH11
Bases: GARCH11
GJR-GARCH(1,1) with asymmetric response to negative shocks.
v[k+1] = omega + (alpha + gamma*1[z[k]<0])*v[k]*z[k]**2 + beta*v[k]
Under symmetric standard-normal shocks the persistence coefficient is alpha + beta + gamma/2, which must be strictly below one. A positive gamma makes negative innovations cause more subsequent volatility. Like GARCH11 this is a per-observation discrete-time statistical model.
long_run_variance
property
long_run_variance
Stationary expected variance under symmetric innovations.
expected_variance
expected_variance(n)
Expected variance rate n observations ahead.
stochPathSim.processes.NormalInverseGaussian
Bases: StochasticProcess
An exponential NIG asset model with exact increments.
S_t = s0 * exp((mu - q - kappa(1))*t + L_t), where
kappa(z) = delta * (sqrt(alpha**2-beta**2) - sqrt(alpha**2-(beta+z)**2))
is the per-year cumulant of the NIG Levy process L. The compensator ensures
E[S_t] = s0*exp((mu-q)*t); use mu=r for risk-neutral spot pricing.
alpha controls tail decay, beta controls asymmetry, and delta
controls activity per year. Require alpha > abs(beta) and
alpha > abs(beta+1) so the model and its first exponential moment are
well-defined. delta=0 gives deterministic growth. Negative beta gives
negatively skewed log returns. The spot remains positive.
Each increment is beta*G + sqrt(G)*Z, with independent inverse Gaussian
clock G ~ IG(delta*dt/gamma, (delta*dt)**2) and gamma=sqrt(alpha**2-beta**2).
This matches SciPy's norminvgauss(a=alpha*delta*t, b=beta*delta*t,
scale=delta*t) parameterisation of L_t.
normals= controls only Z. Clock draws use seed; reuse both for
reproducibility. Antithetic sampling pairs Z only, not the clock draws.
compensator
property
compensator
Per-year correction kappa(1) for the exponential martingale.
mean
mean(t)
Expected spot s0*exp((mu-q)*t).
variance
variance(t)
Spot variance; requires alpha > abs(beta+2) when delta is positive.
Parameters outside that interior second-moment domain raise ValueError.
log_return_mean
log_return_mean(t)
Expected log return E[log(S_t/s0)].
log_return_variance
log_return_variance(t)
Variance of log returns, finite for every accepted parameter set.
stochPathSim.processes.GBM
Bases: StochasticProcess
Geometric Brownian motion
.. math:: dS_t = (\mu - q) S_t\,dt + \sigma S_t\,dW_t
simulated exactly on any grid, so there is no discretisation error.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
s0
|
float
|
Initial value. |
required |
mu
|
float
|
Drift (use the risk-free rate for risk-neutral pricing). |
required |
sigma
|
float
|
Volatility. |
required |
q
|
float
|
Continuous dividend yield. |
0.0
|
mean
mean(t)
Expected value E[S_t].
variance
variance(t)
Variance Var[S_t].
stochPathSim.processes.DisplacedDiffusion
Bases: StochasticProcess
Exact displaced diffusion of a forward or other shifted underlying.
The positive shifted variable X = S + shift follows
dX / X = (mu - q) dt + sigma dW.
Consequently S is bounded below by -shift but may be negative, and
E[S_t] = (s0 + shift) exp((mu - q) t) - shift.
For an undiscounted forward under its forward measure, set mu=q=0; the shifted process then is a martingale. mu is the drift of X, NOT the conventional proportional drift of S when shift is nonzero. Price a European option using displaced_diffusion_price(F, ...).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
s0
|
float
|
Initial forward/underlying, possibly negative. |
required |
mu
|
float
|
Annual proportional drift and carry of the shifted variable. |
required |
q
|
float
|
Annual proportional drift and carry of the shifted variable. |
required |
sigma
|
float
|
Annual lognormal volatility of the shifted variable. |
required |
shift
|
float
|
Displacement such that s0 + shift > 0. |
required |
mean
mean(t)
Exact E[S_t] for scalar or array times.
variance
variance(t)
Exact Var[S_t] for scalar or array times.
stochPathSim.processes.MultiAssetGBM
Bases: StochasticProcess
Correlated geometric Brownian motions, simulated exactly.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
s0
|
array_like
|
Initial values, drifts and volatilities, one per asset. |
required |
mu
|
array_like
|
Initial values, drifts and volatilities, one per asset. |
required |
sigma
|
array_like
|
Initial values, drifts and volatilities, one per asset. |
required |
correlation
|
array_like
|
Correlation matrix of the Brownian drivers. |
required |
q
|
float or array_like
|
Dividend yields. |
0.0
|
mean
mean(t)
Expected values, shape (..., n_assets).
stochPathSim.processes.MertonJumpDiffusion
Bases: StochasticProcess
Merton (1976) jump diffusion
.. math:: \frac{dS_t}{S_{t^-}} = (\mu - q - \lambda k)\,dt + \sigma\,dW_t + (e^{J} - 1)\,dN_t
with Poisson jumps of intensity lam and normal log-jumps
J ~ N(jump_mean, jump_std^2); k = E[e^J] - 1 compensates the jumps so
that E[S_t] = s0 exp((mu - q) t). Simulated exactly.
mean
mean(t)
Expected value E[S_t].
stochPathSim.processes.Heston
Bases: StochasticProcess
Heston (1993) stochastic volatility model
.. math:: dS_t &= (\mu - q) S_t\,dt + \sqrt{v_t} S_t\,dW^S_t \ dv_t &= \kappa(\theta - v_t)\,dt + \xi\sqrt{v_t}\,dW^v_t, \qquad d\langle W^S, W^v\rangle = \rho\,dt
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
s0
|
float
|
Initial spot, drift and dividend yield. |
required |
mu
|
float
|
Initial spot, drift and dividend yield. |
required |
q
|
float
|
Initial spot, drift and dividend yield. |
required |
v0
|
float
|
Initial variance, mean-reversion speed, long-run variance, vol of vol and correlation. |
required |
kappa
|
float
|
Initial variance, mean-reversion speed, long-run variance, vol of vol and correlation. |
required |
theta
|
float
|
Initial variance, mean-reversion speed, long-run variance, vol of vol and correlation. |
required |
xi
|
float
|
Initial variance, mean-reversion speed, long-run variance, vol of vol and correlation. |
required |
rho
|
float
|
Initial variance, mean-reversion speed, long-run variance, vol of vol and correlation. |
required |
scheme
|
('qe', 'euler')
|
|
"qe"
|
mean
mean(t)
Expected spot E[S_t].
variance_mean
variance_mean(t)
Expected variance E[v_t].
stochPathSim.processes.Bates
Bases: Heston
Bates (1996) model: Heston stochastic volatility plus compensated Merton log-normal jumps.
Parameters are those of :class:Heston plus lam, jump_mean and jump_std
(see :class:MertonJumpDiffusion).
stochPathSim.processes.SABR
Bases: StochasticProcess
SABR model (Hagan et al., 2002) for a forward
.. math:: dF_t &= \alpha_t F_t^\beta\,dW^F_t \ d\alpha_t &= \nu\,\alpha_t\,dW^\alpha_t, \qquad d\langle W^F, W^\alpha\rangle = \rho\,dt
The volatility is simulated exactly (lognormal); the forward uses an Euler step with absorption at zero.
stochPathSim.processes.CEV
Bases: StochasticProcess
Constant elasticity of variance model
.. math:: dS_t = \mu S_t\,dt + \sigma S_t^{\beta}\,dW_t
Simulated with an Euler scheme; paths that reach zero are absorbed there.
beta = 1 recovers GBM and beta = 0 an arithmetic model.
stochPathSim.processes.VarianceGamma
Bases: StochasticProcess
Variance gamma model (Madan, Carr and Chang, 1998)
.. math:: S_t = S_0 \exp\big((\mu + \omega) t + \theta G_t + \sigma W_{G_t}\big)
where G is a gamma subordinator with unit mean rate and variance rate nu, and
omega = ln(1 - theta nu - sigma^2 nu / 2) / nu makes E[S_t] = s0 exp(mu t).
Simulated exactly.
mean
mean(t)
Expected value E[S_t].
stochPathSim.processes.OrnsteinUhlenbeck
Bases: StochasticProcess
Ornstein-Uhlenbeck process
.. math:: dX_t = \kappa(\theta - X_t)\,dt + \sigma\,dW_t
simulated exactly from its Gaussian transition density.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
x0
|
float
|
Initial value. |
required |
kappa
|
float
|
Mean-reversion speed (> 0). |
required |
theta
|
float
|
Long-run mean. |
required |
sigma
|
float
|
Volatility. |
required |
mean
mean(t)
Expected value E[X_t].
variance
variance(t)
Variance Var[X_t].
stochPathSim.processes.RoughBergomi
Bases: StochasticProcess
Rough Bergomi model (Bayer, Friz and Gatheral, 2016)
.. math::
\frac{dS_t}{S_t} = \mu\,dt + \sqrt{V_t}\,dZ_t,\qquad
V_t = \xi_0 \exp\!\Big(\eta \tilde Y_t - \tfrac12 \eta^2 t^{2H}\Big),
\tilde Y_t = \sqrt{2H}\int_0^t (t-s)^{H-1/2}\,dW_s,
dZ_t = \rho\,dW_t + \sqrt{1-\rho^2}\,dW^\perp_t
with a flat forward variance curve xi0 and Hurst exponent 0 < H < 1/2
(rough volatility).
The Volterra process and the Brownian motion driving it are sampled
exactly on the grid from their joint Gaussian law (Cholesky factor of the
2n x 2n covariance), so E[V_t] = xi0 holds without discretisation bias.
The log-spot uses the left-point variance on each step, which keeps S an
exact martingale (E[S_T] = s0 exp(mu T)). Cost grows as n_steps^2, so
keep n_steps in the low hundreds.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
s0
|
float
|
Initial spot. |
required |
mu
|
float
|
Drift of the spot (risk-free rate minus dividend yield for pricing). |
required |
xi0
|
float
|
Flat forward variance. |
required |
eta
|
float
|
Volatility of volatility. |
required |
hurst
|
float
|
Hurst exponent |
required |
rho
|
float
|
Correlation between spot and volatility shocks. |
required |
mean
mean(t)
Expected spot E[S_t] = s0 exp(mu t).
variance_mean
variance_mean(t)
Expected instantaneous variance, equal to xi0 at every time.
stochPathSim.processes.KouJumpDiffusion
Bases: StochasticProcess
Kou (2002) double-exponential jump diffusion
.. math:: \frac{dS_t}{S_{t^-}} = (\mu - q - \lambda\zeta)\,dt + \sigma\,dW_t + (e^{Y} - 1)\,dN_t
with Poisson jumps of intensity lam. A log-jump Y is +Exp(eta_up)
with probability p_up and -Exp(eta_down) otherwise, so jumps are
asymmetric and heavy-tailed (unlike Merton's normal jumps).
zeta = E[e^Y] - 1 compensates the jumps so that E[S_t] = s0 exp((mu - q) t).
Simulated exactly: per step the up and down jump counts are binomial splits of a
Poisson count, and sums of exponentials are gamma distributed.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
eta_up
|
float
|
Rate of upward jumps; must exceed 1 for |
required |
eta_down
|
float
|
Rate of downward jumps (mean down-jump size |
required |
mean
mean(t)
Expected value E[S_t].
stochPathSim.processes.RegimeSwitchingGBM
Bases: StochasticProcess
GBM whose drift and volatility follow a continuous-time Markov chain
.. math:: \frac{dS_t}{S_t} = \mu_{R_t}\,dt + \sigma_{R_t}\,dW_t
where :math:R_t jumps between n regimes with generator matrix Q
(Q[i, j] is the rate of switching from i to j, rows sum to zero).
The regime chain is simulated exactly on the grid with the transition
matrices expm(Q dt). The spot uses the regime at the start of each step,
so it is exact when regimes only change on grid dates and has an O(dt)
error otherwise; use steps that are short compared with the mean regime
duration 1 / -Q[i, i].
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
s0
|
float
|
Initial spot. |
required |
mu
|
array_like
|
Drift and volatility in each regime. |
required |
sigma
|
array_like
|
Drift and volatility in each regime. |
required |
generator
|
array_like
|
|
required |
initial_regime
|
int
|
Regime at |
0
|
transition_matrix
transition_matrix(t)
Regime transition probabilities over a horizon t: expm(Q t).
mean
mean(t)
Expected spot E[S_t] = s0 e_i^T expm((Q + diag(mu)) t) 1 (Feynman-Kac).
Commodities
stochPathSim.processes.SchwartzOneFactor
Bases: StochasticProcess
Schwartz (1997) one-factor mean-reverting commodity model
.. math:: \frac{dS_t}{S_t} = \kappa(\mu - \ln S_t)\,dt + \sigma\,dW_t
so X = ln S is an Ornstein-Uhlenbeck process
:math:dX_t = \kappa(\alpha - X_t)dt + \sigma dW_t with
:math:\alpha = \mu - \sigma^2 / (2\kappa). Simulated exactly.
Parameters are taken as risk neutral, so :meth:futures_price is E[S_T].
alpha
property
alpha
Long-run mean of the log price.
log_mean
log_mean(t)
E[ln S_t].
log_variance
log_variance(t)
Var[ln S_t].
futures_price
futures_price(T)
Futures price for delivery at T: E[S_T].
stochPathSim.processes.SchwartzSmith
Bases: StochasticProcess
Schwartz-Smith (2000) two-factor commodity model
.. math::
\ln S_t = \chi_t + \xi_t,\qquad
d\chi_t = -\kappa \chi_t\,dt + \sigma_\chi\,dW^\chi_t,\qquad
d\xi_t = \mu_\xi\,dt + \sigma_\xi\,dW^\xi_t,\qquad
d\langle W^\chi, W^\xi\rangle_t = \rho\,dt
The short-term deviation chi mean-reverts to zero and the equilibrium level
xi is a Brownian motion with drift. Both factors are simulated exactly
from their joint Gaussian transition.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
chi0
|
float
|
Initial short-term deviation and equilibrium log price. |
required |
xi0
|
float
|
Initial short-term deviation and equilibrium log price. |
required |
log_mean
log_mean(t)
E[ln S_t].
log_variance
log_variance(t)
Var[ln S_t].
futures_price
futures_price(T)
Futures price E[S_T] (parameters taken as risk neutral).
Credit
stochPathSim.processes.ConstantIntensity
Bases: _IntensityModel
Constant default intensity lam: survival probability :math:e^{-\lambda t}.
stochPathSim.processes.CIRIntensity
Bases: _IntensityModel
Stochastic default intensity following a CIR process
.. math:: d\lambda_t = \kappa(\theta - \lambda_t)\,dt + \sigma\sqrt{\lambda_t}\,dW_t
The intensity is simulated exactly (non-central chi-square transitions, drawn
from the generator); the pathwise survival exp(-∫λ dt) uses the trapezoid
rule on the grid. Its expectation is the CIR bond price, see
:meth:survival_probability.
survival_probability
survival_probability(t)
Risk-neutral survival probability E[exp(-∫λ)] (the CIR bond formula).
Interest rates
stochPathSim.processes.Vasicek
Bases: StochasticProcess
Vasicek model :math:dr_t = \kappa(\theta - r_t)\,dt + \sigma\,dW_t.
Simulated exactly together with :math:\int_0^t r_s\,ds; uses two normals
per step (n_factors = 2).
mean
mean(t)
Expected short rate E[r_t].
variance
variance(t)
Variance Var[r_t].
stochPathSim.processes.CIR
Bases: StochasticProcess
Cox-Ingersoll-Ross model :math:dr_t = \kappa(\theta - r_t)\,dt + \sigma\sqrt{r_t}\,dW_t.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
scheme
|
('exact', 'euler')
|
|
"exact"
|
feller_satisfied
property
feller_satisfied
2 kappa theta >= sigma^2: the rate then never reaches zero.
mean
mean(t)
Expected short rate E[r_t].
variance
variance(t)
Variance Var[r_t].
stochPathSim.processes.CIRPlusPlus
Bases: StochasticProcess
Brigo-Mercurio CIR++ with exact underlying CIR transitions.
r_t = x_t + phi(t), where x is a standard CIR factor starting at x0, and phi(t) = f_market(0,t) - f_CIR(0,t) is a deterministic curve shift. This construction fits the initial market discount curve analytically.
States are rate, factor, discount. The factor is non-negative under the exact scheme; shifted short rates can be negative even if it is positive. Discount factors use a trapezoidal integral of x (as in CIR), plus the exact deterministic shift integral P_market(0,t)/P_CIR(0,t). Thus MC means of discounts approach the input curve with time-step refinement; individual discount paths are not continuous-time exact.
The exact scheme draws noncentral chi-square factors from the seeded generator; supplied normals and antithetic shocks do not affect them. Use scheme="euler" to drive a full-truncation factor with normals.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
x0
|
float
|
Parameters of the underlying CIR factor; all must be positive. |
required |
kappa
|
float
|
Parameters of the underlying CIR factor; all must be positive. |
required |
theta
|
float
|
Parameters of the underlying CIR factor; all must be positive. |
required |
sigma
|
float
|
Parameters of the underlying CIR factor; all must be positive. |
required |
curve
|
ZeroCurve or float
|
Target initial curve, or flat continuously compounded rate. |
required |
scheme
|
('exact', 'euler')
|
CIR factor transition scheme. |
"exact"
|
feller_satisfied
property
feller_satisfied
Whether the underlying CIR factor stays strictly above zero.
r0
property
r0
Initial short rate equals the market instantaneous forward at zero.
cir_forward_rate
cir_forward_rate(t)
Initial instantaneous forward f_CIR(0,t) from the CIR affine bond formula.
shift
shift(t)
Deterministic CIR++ shift phi(t) for the input zero curve.
mean
mean(t)
Exact expected short rate.
variance
variance(t)
Exact short-rate variance, equal to the CIR factor variance.
stochPathSim.processes.HullWhite
Bases: _CurveFittedGaussian
Hull-White one-factor model :math:dr_t = (\theta(t) - a r_t)\,dt + \sigma\,dW_t.
:math:\theta(t) is chosen so that the model reproduces curve exactly.
Uses two normals per step (n_factors = 2).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
curve
|
ZeroCurve or float
|
Initial zero curve, or a flat continuously compounded rate. |
required |
stochPathSim.processes.HoLee
Bases: _CurveFittedGaussian
Ho-Lee model :math:dr_t = \theta(t)\,dt + \sigma\,dW_t, fitted to curve.
Uses two normals per step (n_factors = 2).
stochPathSim.processes.G2pp
Bases: _CurveFittedGaussian
Two-factor Gaussian model G2++ (Brigo and Mercurio).
.. math:: r_t = x_t + y_t + \varphi(t),\quad dx_t = -a x_t\,dt + \sigma\,dW^1_t,\quad dy_t = -b y_t\,dt + \eta\,dW^2_t,\quad d\langle W^1, W^2\rangle_t = \rho\,dt
:math:\varphi(t) fits curve exactly. States: "rate", "x",
"y" and "discount". Uses four normals per step (n_factors = 4):
two for the factors and two for their integrals.
stochPathSim.processes.BlackKarasinski
Bases: StochasticProcess
Black-Karasinski model :math:d\ln r_t = (\theta(t) - a \ln r_t)\,dt + \sigma\,dW_t.
theta is a constant (simulated exactly) or a callable of time (the drift
integral over each step uses the mid-point value). Fitting theta exactly
to a yield curve needs a lattice and is not included.
log_rate_mean
log_rate_mean(t)
E[ln r_t] for a constant theta.
log_rate_variance
log_rate_variance(t)
Var[ln r_t].
stochPathSim.processes.BlackDermanToy
Bases: StochasticProcess
Continuous-time Black-Derman-Toy model with constant volatility.
.. math:: d\ln r_t = \theta(t)\,dt + \sigma\,dW_t
With a constant volatility the continuous-time BDT model has no mean
reversion. theta is a constant (simulated exactly) or a callable of
time (mid-point rule over each step).