Stochastic Processes¶
This page gives an overview of all stochastic processes available in the library.
Available processes¶
Diffusion¶
| Process | Description |
|---|---|
| WienerProcess | Standard Brownian motion |
Mean-reverting (intensity)¶
| Process | Description |
|---|---|
| CIR | Cox-Ingersoll-Ross square-root diffusion |
| Vasicek | Gaussian Ornstein-Uhlenbeck process |
| NGOU | Generic non-Gaussian OU process driven by a pure-jump Lévy process |
| GammaOU | Non-Gaussian OU process with Gamma stationary marginal |
Jump processes¶
| Process | Description |
|---|---|
| PoissonProcess | Homogeneous Poisson process |
| CompoundPoissonProcess | Poisson process with random jump sizes |
| DSP | Doubly stochastic (Cox) Poisson process |
Stochastic volatility¶
| Process | Description |
|---|---|
| Heston | Classical square-root stochastic volatility model |
| HestonJ | Heston model with compound Poisson jumps |
| DoubleHeston | Two independent Heston variance processes |
| DoubleHestonJ | Double Heston with compound Poisson jumps on the first component |
| BNS | Barndorff-Nielsen and Shephard model with Gamma-OU variance |
| BNS2 | Two-factor BNS with convex-combination variance |
Jump diffusion¶
| Process | Description |
|---|---|
| JumpDiffusion | Diffusion with compound Poisson jumps |
Copulas¶
| Process | Description |
|---|---|
| Copula | Abstract base class for bivariate copulas |
| IndependentCopula | Independence copula \(C(u, v) = u v\) |
| FrankCopula | Archimedean Frank copula |
Base classes¶
quantflow.sp.base.StochasticProcess
pydantic-model
¶
Bases: BaseModel, ABC
Base class for stochastic processes in continuous time
sample_from_draws
abstractmethod
¶
sample
abstractmethod
¶
Generate random Paths from the process.
| 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/base.py
characteristic_exponent
abstractmethod
¶
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_cdf
¶
quantflow.sp.base.StochasticProcess1D
pydantic-model
¶
Bases: StochasticProcess
Base class for 1D stochastic process in continuous time
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
sample_from_draws
abstractmethod
¶
sample
abstractmethod
¶
Generate random Paths from the process.
| 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/base.py
characteristic_exponent
abstractmethod
¶
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_cdf
¶
quantflow.sp.base.IntensityProcess
pydantic-model
¶
Bases: StochasticProcess1D
Base class for mean reverting 1D processes which can be used as stochastic intensity
Fields:
integrated_log_laplace
abstractmethod
¶
The log-Laplace transform of the cumulative process:
| PARAMETER | DESCRIPTION |
|---|---|
t
|
time horizon
TYPE:
|
u
|
frequency
TYPE:
|
Source code in quantflow/sp/base.py
domain_range
¶
ekt
¶
sample_from_draws
abstractmethod
¶
sample
abstractmethod
¶
Generate random Paths from the process.
| 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/base.py
characteristic_exponent
abstractmethod
¶
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_cdf
¶
marginal
¶
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.base.StochasticProcess1DMarginal
pydantic-model
¶
Bases: Marginal1D, Generic[P]
Fields:
-
process(P) -
t(FloatArrayLike)
model_config
class-attribute
instance-attribute
¶
std_norm
¶
characteristic
¶
domain_range
¶
frequency_range
¶
pdf
¶
cdf
¶
mean
¶
variance
¶
support
¶
call_option_carr_madan_alpha
¶
Option alpha parameter for integrability of call option transform in the Carr-Madan formula.
The choice of alpha is crucial for the numerical stability of the Carr-Madan formula. A common choice is to set alpha to a value that ensures the integrand decays sufficiently fast at high frequencies. The maturity-dependent heuristic below (high alpha for short maturities, decaying to a 0.5 floor for long ones) has been found to work well in practice across the processes in this library; override on a per-process basis if needed.
Source code in quantflow/sp/base.py
call_option
¶
call_option(n=None, *, pricing_method=CARR_MADAN, cos_moneyness_std_precision=12, max_moneyness=1.5, max_frequency=None, alpha=None, simpson_rule=False, use_fft=False)
Price call options via one of the available Fourier-based methods, as a function of log-strike
| PARAMETER | DESCRIPTION |
|---|---|
n
|
Number of discretization points for the transform. Defaults to 128.
TYPE:
|
pricing_method
|
Method to use for option pricing via Fourier transform of the call option price. Defaults to Lewis.
TYPE:
|
cos_moneyness_std_precision
|
Truncation parameter for COS: the integration interval is set to [-cos_moneyness_std_precisionstd, cos_moneyness_std_precisionstd].
TYPE:
|
max_moneyness
|
Maximum moneyness to calculate prices. The log-strike grid is set to [-max_moneynessstd, max_moneynessstd]. Used by Lewis and Carr & Madan methods only.
TYPE:
|
max_frequency
|
Maximum frequency for the transform grid. Defaults to frequency_range().
TYPE:
|
alpha
|
Damping parameter for integrability of the Carr-Madan integrand, it is ignored if not applicable.
TYPE:
|
simpson_rule
|
Use Simpson's rule for integration. Default is False.
TYPE:
|
use_fft
|
Use FFT for the transform rather than FRFT. Default is False.
TYPE:
|
Source code in quantflow/utils/marginal.py
156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 | |
call_option_carr_madan
¶
call_option_carr_madan(n=None, *, max_moneyness=1.5, max_frequency=None, alpha=None, simpson_rule=False, use_fft=False)
Call option price via Carr & Madan method
| PARAMETER | DESCRIPTION |
|---|---|
n
|
Number of discretization points for the transform. Defaults to 128.
TYPE:
|
max_moneyness
|
Maximum moneyness to calculate prices. The log-strike grid is set to [-max_moneynessstd, max_moneynessstd].
TYPE:
|
max_frequency
|
Maximum frequency for the transform grid. Defaults to frequency_range().
TYPE:
|
alpha
|
Damping parameter for integrability of the Carr-Madan integrand. Defaults to call_option_carr_madan_alpha.
TYPE:
|
simpson_rule
|
Use Simpson's rule for integration. Default is False.
TYPE:
|
use_fft
|
Use FFT for the transform. Default is False.
TYPE:
|
Source code in quantflow/utils/marginal.py
call_option_cos
¶
Call option price via the COS method (Fang & Oosterlee 2008).
The call price at log-strike \(k\) is approximated by the cosine series
where the prime denotes a half weight on the \(j=0\) term, \([a,b]\) is the truncation interval, and \(V_j\) are the cosine payoff coefficients for the normalised call payoff \((e^y - 1)^+\) integrated over \([0, b]\). The \(e^k\) factor converts from strike-normalised to forward-space pricing.
Returns an OptionPricingCosResult with the precomputed coefficient vector. Use call_price to evaluate at arbitrary log-strikes in \(O(N)\) per strike.
| PARAMETER | DESCRIPTION |
|---|---|
n
|
Number of cosine series terms. Defaults to 128.
TYPE:
|
moneyness_std_precision
|
Truncation parameter: the integration interval is set to [-moneyness_std_precisionstd, moneyness_std_precisionstd].
TYPE:
|
Source code in quantflow/utils/marginal.py
call_option_lewis
¶
call_option_lewis(n=None, *, max_moneyness=1.5, max_frequency=None, simpson_rule=False, use_fft=False)
Call option price via the Lewis (2001) formula
| PARAMETER | DESCRIPTION |
|---|---|
n
|
Number of discretization points for the transform. Defaults to 128.
TYPE:
|
max_moneyness
|
Maximum moneyness to calculate prices. The log-strike grid is set to [-max_moneynessstd, max_moneynessstd].
TYPE:
|
max_frequency
|
Maximum frequency for the transform grid. Defaults to frequency_range().
TYPE:
|
simpson_rule
|
Use Simpson's rule for integration. Default is False.
TYPE:
|
use_fft
|
Use FFT for the transform. Default is False.
TYPE:
|
Source code in quantflow/utils/marginal.py
call_option_transform
¶
Call option transform
| PARAMETER | DESCRIPTION |
|---|---|
u
|
Frequency domain points (possibly complex-shifted).
TYPE:
|
Source code in quantflow/utils/marginal.py
cdf_from_characteristic
¶
cdf_from_characteristic(n=None, *, max_frequency=None, simpson_rule=False, use_fft=False, frequency_n=None)
| PARAMETER | DESCRIPTION |
|---|---|
n
|
Number of discretization points for the transform. Defaults to 128.
TYPE:
|
max_frequency
|
Maximum frequency for the transform grid. Defaults to frequency_range().
TYPE:
|
simpson_rule
|
Use Simpson's rule for integration. Default is False.
TYPE:
|
use_fft
|
Use FFT for the transform. Default is False.
TYPE:
|
frequency_n
|
Number of points for the frequency grid. Overrides n if provided.
TYPE:
|
Source code in quantflow/utils/marginal.py
cdf_jacobian
¶
Jacobian of the cdf with respect to the parameters of the process. It is useful for optimization purposes if necessary.
Optional to implement, otherwise raises NotImplementedError if called.
| PARAMETER | DESCRIPTION |
|---|---|
x
|
Location in the state space of the process.
TYPE:
|
Source code in quantflow/utils/marginal.py
characteristic_corrected
¶
Characteristic function corrected for the convexity of the log-price distribution
| PARAMETER | DESCRIPTION |
|---|---|
u
|
Frequency domain points.
TYPE:
|
Source code in quantflow/utils/marginal.py
characteristic_df
¶
Compute the characteristic function with n discretization points and a max frequency
| PARAMETER | DESCRIPTION |
|---|---|
n
|
Number of discretization points for the transform. Defaults to 128.
TYPE:
|
max_frequency
|
Maximum frequency for the transform grid. Defaults to frequency_range().
TYPE:
|
simpson_rule
|
Use Simpson's rule for integration. Default is False.
TYPE:
|
Source code in quantflow/utils/marginal.py
get_transform
¶
| PARAMETER | DESCRIPTION |
|---|---|
n
|
Number of discretization points. Defaults to 128.
TYPE:
|
support
|
Function returning the space domain grid given the number of points.
TYPE:
|
max_frequency
|
Maximum frequency for the transform grid. Defaults to frequency_range().
TYPE:
|
simpson_rule
|
Use Simpson's rule for integration. Default is False.
TYPE:
|
use_fft
|
Use FFT for the transform. Default is False.
TYPE:
|
Source code in quantflow/utils/marginal.py
lewis_transform
¶
Lewis (2001) call option transform - no damping parameter required
| PARAMETER | DESCRIPTION |
|---|---|
u
|
Frequency domain points.
TYPE:
|
mean_from_characteristic
¶
Calculate mean as first derivative of characteristic function at 0
| PARAMETER | DESCRIPTION |
|---|---|
d
|
Step size for finite-difference approximation of the derivative.
TYPE:
|
Source code in quantflow/utils/marginal.py
option_support
¶
Compute the x axis.
| PARAMETER | DESCRIPTION |
|---|---|
points
|
Number of support points.
TYPE:
|
max_log_strike
|
Maximum absolute log-strike.
TYPE:
|
Source code in quantflow/utils/marginal.py
option_time_value
¶
option_time_value(n=128, *, max_frequency=None, max_log_strike=1, alpha=1.1, simpson_rule=False, use_fft=False)
Option time value
| PARAMETER | DESCRIPTION |
|---|---|
n
|
Number of discretization points for the transform.
TYPE:
|
max_frequency
|
Maximum frequency for the transform grid. Defaults to frequency_range().
TYPE:
|
max_log_strike
|
Maximum absolute log-strike for the output grid.
TYPE:
|
alpha
|
Contour shift parameter controlling the integration strip.
TYPE:
|
simpson_rule
|
Use Simpson's rule for integration. Default is False.
TYPE:
|
use_fft
|
Use FFT for the transform. Default is False.
TYPE:
|
Source code in quantflow/utils/marginal.py
option_time_value_transform
¶
Option time value transform
This transform does not require any additional correction since the integrand is already bounded for positive and negative moneyness
| PARAMETER | DESCRIPTION |
|---|---|
u
|
Frequency domain points.
TYPE:
|
alpha
|
Contour shift parameter controlling the integration strip.
TYPE:
|
Source code in quantflow/utils/marginal.py
pdf_from_characteristic
¶
pdf_from_characteristic(n=None, *, max_frequency=None, simpson_rule=False, use_fft=False, frequency_n=None)
Compute the probability density function from the characteristic function.
| PARAMETER | DESCRIPTION |
|---|---|
n
|
Number of discretization points to use in the transform. If None, use 128.
TYPE:
|
max_frequency
|
The maximum frequency to use in the transform. If not provided, the value from the frequency_range method is used. Only needed for special cases/testing.
TYPE:
|
simpson_rule
|
Use Simpson's rule for integration. Default is False.
TYPE:
|
use_fft
|
Use FFT for the transform. Default is False.
TYPE:
|
frequency_n
|
Number of points for the frequency grid. Overrides n if provided.
TYPE:
|
Source code in quantflow/utils/marginal.py
pdf_jacobian
¶
Jacobian of the pdf with respect to the parameters of the process. It has a base implementation that computes it from the cdf_jacobian method, but a subclass should overload this method if a more optimized way of computing it is available.
| PARAMETER | DESCRIPTION |
|---|---|
x
|
Location in the state space of the process.
TYPE:
|
Source code in quantflow/utils/marginal.py
std
¶
std_validated
¶
Float standard deviation, raising if it is not finite or non-positive.
Used by the Fourier-based pricing methods to set the log-strike grid range; degenerate parameter samples (e.g. during calibration) can produce a non-finite std and would otherwise crash deep in the transform with a confusing error.
Source code in quantflow/utils/marginal.py
std_from_characteristic
¶
variance_from_characteristic
¶
Calculate variance as second derivative of characteristic function at 0
| PARAMETER | DESCRIPTION |
|---|---|
d
|
Step size for finite-difference approximation of the derivative.
TYPE:
|