stochastic_processes/processes/
ornstein_uhlenbeck.rs

1use crate::processes::*;
2
3// TODO: Write test to make sure that OU process has correct distribution.
4
5/// The [Ornstein-Uhlenbeck](https://en.wikipedia.org/wiki/Ornstein%E2%80%93Uhlenbeck_process) process.
6///
7/// This is a stochastic process given by the following stochastic differential equation:
8/// $$ \textrm{d}x_t = \theta (\mu - x_t) \textrm{d}t + \sigma \textrm{d} W_t $$
9/// where $\theta$, $\mu$, and $\sigma$ are parameters of the process and $W_t$ is a standard Brownian motion.
10
11pub struct OrnsteinUhlenbeck {
12    /// $\theta$ is the speed of reversion.
13    pub theta: f32,
14
15    /// $\mu$ is the long-term mean.
16    pub mu: f32,
17
18    /// $\sigma$ is the instantaneous volatility.
19    pub sigma: f32,
20}
21
22impl OrnsteinUhlenbeck {
23    /// Create a new Ornstein-Uhlenbeck process.
24    pub fn new(theta: f32, mu: f32, sigma: f32) -> Self {
25        Self { theta, mu, sigma }
26    }
27}
28
29impl StochasticProcess for OrnsteinUhlenbeck {}
30
31impl AutonomousStochasticProcess for OrnsteinUhlenbeck {
32    fn drift(&self, x: f32) -> f32 {
33        self.theta * (self.mu - x)
34    }
35
36    fn diffusion(&self, _x: f32) -> f32 {
37        self.sigma
38    }
39}