Diffusion Models¶
The stochastic.processes.diffusion
module provides classes for generating
discretely sampled continous-time diffusion processes using the
Euler–Maruyama method.
-
class
stochastic.processes.diffusion.
DiffusionProcess
(speed=1, mean=0, vol=1, volexp=0, t=1, rng=None)[source]¶ Generalized diffusion process.
A base process for more specific diffusion processes.
The process \(X_t\) that satisfies the following stochastic differential equation with Wiener process \(W_t\):
\[dX_t = \theta_t (\mu_t - X_t) dt + \sigma_t X_t^{\gamma_t} dW_t\]Realizations are generated using the Euler-Maruyama method.
Note
Since the family of diffusion processes have parameters which generalize to functions of
t
, parameter attributes will be returned as callables, even if they are initialized as constants. e.g. aspeed
parameter of 1 accessed from an instance attribute will return a function which accepts a single argument and always returns 1.- Parameters
speed (func) – the speed of reversion, or \(\theta_t\) above
mean (func) – the mean of the process, or \(\mu_t\) above
vol (func) – volatility coefficient of the process, or \(\sigma_t\) above
volexp (func) – volatility exponent of the process, or \(\gamma_t\) above
t (float) – the right hand endpoint of the time interval \([0,t]\) for the process
rng (numpy.random.Generator) – a custom random number generator
-
sample
(n, initial=1.0)[source]¶ Generate a realization.
- Parameters
n (int) – the number of increments to generate
initial (float) – the initial value of the process
-
property
t
¶ End time of the process.
-
times
(n)¶ Generate times associated with n increments on [0, t].
- Parameters
n (int) – the number of increments
-
class
stochastic.processes.diffusion.
ConstantElasticityVarianceProcess
(drift=1, vol=1, volexp=1, t=1, rng=None)[source]¶ Constant elasticity of variance process.
The process \(X_t\) that satisfies the following stochastic differential equation with Wiener process \(W_t\):
\[dX_t = \mu X_t dt + \sigma X_t^\gamma dW_t\]Realizations are generated using the Euler-Maruyama method.
Note
Since the family of diffusion processes have parameters which generalize to functions of
t
, parameter attributes will be returned as callables, even if they are initialized as constants. e.g. aspeed
parameter of 1 accessed from an instance attribute will return a function which accepts a single argument and always returns 1.- Parameters
drift (float) – the drift coefficient, or \(\mu\) above
vol (float) – the volatility coefficient, or \(\sigma\) above
volexp (float) – the volatility-price exponent, or \(\gamma\) above
t (float) – the right hand endpoint of the time interval \([0,t]\) for the process
rng (numpy.random.Generator) – a custom random number generator
-
sample
(n, initial=1.0)¶ Generate a realization.
- Parameters
n (int) – the number of increments to generate
initial (float) – the initial value of the process
-
property
t
¶ End time of the process.
-
times
(n)¶ Generate times associated with n increments on [0, t].
- Parameters
n (int) – the number of increments
-
class
stochastic.processes.diffusion.
CoxIngersollRossProcess
(speed=1, mean=0, vol=1, t=1, rng=None)[source]¶ Cox-Ingersoll-Ross process.
A model for instantaneous interest rate.
The process \(X_t\) that satisfies the following stochastic differential equation with Wiener process \(W_t\):
\[dX_t = \theta (\mu - X_t) dt + \sigma \sqrt{X_t} dW_t\]Realizations are generated using the Euler-Maruyama method.
Note
Since the family of diffusion processes have parameters which generalize to functions of
t
, parameter attributes will be returned as callables, even if they are initialized as constants. e.g. aspeed
parameter of 1 accessed from an instance attribute will return a function which accepts a single argument and always returns 1.- Parameters
speed (float) – the speed of reversion, or \(\theta\) above
mean (float) – the mean of the process, or \(\mu\) above
vol (float) – volatility coefficient of the process, or \(\sigma\) above
t (float) – the right hand endpoint of the time interval \([0,t]\) for the process
rng (numpy.random.Generator) – a custom random number generator
-
sample
(n, initial=1.0)¶ Generate a realization.
- Parameters
n (int) – the number of increments to generate
initial (float) – the initial value of the process
-
property
t
¶ End time of the process.
-
times
(n)¶ Generate times associated with n increments on [0, t].
- Parameters
n (int) – the number of increments
-
class
stochastic.processes.diffusion.
OrnsteinUhlenbeckProcess
(speed=1, vol=1, t=1, rng=None)[source]¶ Ornstein-Uhlenbeck process.
The process \(X_t\) that satisfies the following stochastic differential equation with Wiener process \(W_t\):
\[dX_t = - \theta X_t dt + \sigma dW_t\]Realizations are generated using the Euler-Maruyama method.
Note
Since the family of diffusion processes have parameters which generalize to functions of
t
, parameter attributes will be returned as callables, even if they are initialized as constants. e.g. aspeed
parameter of 1 accessed from an instance attribute will return a function which accepts a single argument and always returns 1.- Parameters
speed (float) – the speed of reversion, or \(\theta\) above
vol (float) – volatility coefficient of the process, or \(\sigma\) above
t (float) – the right hand endpoint of the time interval \([0,t]\) for the process
rng (numpy.random.Generator) – a custom random number generator
-
sample
(n, initial=1.0)¶ Generate a realization.
- Parameters
n (int) – the number of increments to generate
initial (float) – the initial value of the process
-
property
t
¶ End time of the process.
-
times
(n)¶ Generate times associated with n increments on [0, t].
- Parameters
n (int) – the number of increments
-
class
stochastic.processes.diffusion.
VasicekProcess
(speed=1, mean=1, vol=1, t=1, rng=None)[source]¶ Vasicek process.
A model for instantaneous interest rate.
The Vasicek process \(X_t\) that satisfies the following stochastic differential equation with Wiener process \(W_t\):
\[dX_t = \theta (\mu - X_t) dt + \sigma dW_t\]Realizations are generated using the Euler-Maruyama method.
Note
Since the family of diffusion processes have parameters which generalize to functions of
t
, parameter attributes will be returned as callables, even if they are initialized as constants. e.g. aspeed
parameter of 1 accessed from an instance attribute will return a function which accepts a single argument and always returns 1.- Parameters
speed (float) – the speed of reversion, or \(\theta\) above
mean (float) – the mean of the process, or \(\mu\) above
vol (float) – volatility coefficient of the process, or \(\sigma\) above
t (float) – the right hand endpoint of the time interval \([0,t]\) for the process
rng (numpy.random.Generator) – a custom random number generator
-
sample
(n, initial=1.0)¶ Generate a realization.
- Parameters
n (int) – the number of increments to generate
initial (float) – the initial value of the process
-
property
t
¶ End time of the process.
-
times
(n)¶ Generate times associated with n increments on [0, t].
- Parameters
n (int) – the number of increments