Barndorff-Nielson & Shephard process¶
quantflow.sp.bns.BNS
pydantic-model
¶
Bases: StochasticProcess1D
Barndorff-Nielson & Shephard (BNS) stochastic volatility model.
This is a stochastic volatility model where the variance process is given by a non-Gaussian Ornstein-Uhlenbeck process driven by a pure-jump Lévy process. The BNS model is defined by the following system of SDEs:
The model is flexible and can capture various stylized facts of financial markets, such as volatility clustering and leverage effects.
This implementation uses a GammaOU process for the variance, which is a common choice in the BNS model.
Fields:
-
variance_process(GammaOU) -
rho(float)
create
classmethod
¶
Convenience constructor for BNS process with parameters of the variance process
Source code in quantflow/sp/bns.py
characteristic_exponent
¶
Characteristic exponent of the BNS process with Gamma-OU variance.
with
where \(v_0\) is the initial variance, \(\kappa\) is the mean-reversion speed, \(\rho\) is the leverage parameter, and \((\lambda, \beta)\) are the intensity and exponential-jump rate of the background driving Lévy process.
Source code in quantflow/sp/bns.py
sample
¶
| PARAMETER | DESCRIPTION |
|---|---|
n
|
Number of paths
TYPE:
|
time_horizon
|
Time horizon
TYPE:
|
time_steps
|
Number of time steps to arrive at horizon
TYPE:
|
Source code in quantflow/sp/bns.py
sample_from_draws
¶
| PARAMETER | DESCRIPTION |
|---|---|
draws
|
Pre-drawn standard normal increments for the Brownian motion
TYPE:
|
*args
|
Optional pre-drawn subordinator paths; new draws are generated if omitted
TYPE:
|
Source code in quantflow/sp/bns.py
characteristic
¶
Characteristic function at time t for a given input parameter u
The characteristic function represents the Fourier transform of the probability density function
where \(\phi\) is the characteristic exponent, which can be more easily computed for many processes.
| PARAMETER | DESCRIPTION |
|---|---|
t
|
Time horizon
TYPE:
|
u
|
Characteristic function input parameter
TYPE:
|
Source code in quantflow/sp/base.py
convexity_correction
¶
analytical_std
¶
Analytical standard deviation of the process at time t
This has a closed form solution if the process has an analytical variance
analytical_mean
¶
analytical_variance
¶
analytical_pdf
¶
Analytical pdf of the process at time t
Implement if available
analytical_cdf
¶
Analytical cdf of the process at time t
Implement if available
marginal
¶
domain_range
¶
frequency_range
¶
Maximum frequency when calculating characteristic functions
Source code in quantflow/sp/base.py
support
¶
Support of the process at time t
Source code in quantflow/sp/base.py
quantflow.sp.bns.BNS2
pydantic-model
¶
Bases: StochasticProcess1D
Two-factor Barndorff-Nielson & Shephard stochastic volatility model.
The original multi-factor BNS extension drives a single log-price with a single Brownian motion against a convex combination of independent Gamma-OU variances. With weight \(w \in [0, 1]\) for the first factor:
A fast and a slow factor combined this way add flexibility to the term structure of volatility while retaining the analytic tractability of BNS.
Fields:
weight
pydantic-field
¶
Weight \(w\) of the first variance factor in the convex combination; the second factor receives weight \(1 - w\)
characteristic_exponent
¶
Characteristic exponent as the sum of two weighted BNS exponents.
Conditional on the variance paths the diffusion is Gaussian with variance \(w \int v^1_s\,ds + (1-w) \int v^2_s\,ds\). Independence of the two BDLPs then factorises the unconditional expectation into a product, giving
where the substitution applies only to the diffusion term (\(u^2\)) and leaves the leverage term (\(i u \rho_i\)) unchanged.
| PARAMETER | DESCRIPTION |
|---|---|
t
|
Time horizon or array of evaluation times
TYPE:
|
u
|
Characteristic exponent argument
TYPE:
|
Source code in quantflow/sp/bns.py
sample
¶
| PARAMETER | DESCRIPTION |
|---|---|
n
|
Number of sample paths
TYPE:
|
time_horizon
|
Time horizon
TYPE:
|
time_steps
|
Number of discrete time steps
TYPE:
|
Source code in quantflow/sp/bns.py
sample_from_draws
¶
| PARAMETER | DESCRIPTION |
|---|---|
draws
|
Single Brownian motion driving both factors
TYPE:
|
*args
|
Optional pre-drawn BDLP paths for bns1 and bns2 (in that order)
TYPE:
|
Source code in quantflow/sp/bns.py
characteristic
¶
Characteristic function at time t for a given input parameter u
The characteristic function represents the Fourier transform of the probability density function
where \(\phi\) is the characteristic exponent, which can be more easily computed for many processes.
| PARAMETER | DESCRIPTION |
|---|---|
t
|
Time horizon
TYPE:
|
u
|
Characteristic function input parameter
TYPE:
|
Source code in quantflow/sp/base.py
convexity_correction
¶
analytical_std
¶
Analytical standard deviation of the process at time t
This has a closed form solution if the process has an analytical variance
analytical_mean
¶
analytical_variance
¶
analytical_pdf
¶
Analytical pdf of the process at time t
Implement if available
analytical_cdf
¶
Analytical cdf of the process at time t
Implement if available
marginal
¶
domain_range
¶
frequency_range
¶
Maximum frequency when calculating characteristic functions
Source code in quantflow/sp/base.py
support
¶
Support of the process at time t