stochastic_processes/processes/cir.rs
1use crate::processes::*;
2
3// TODO: Write test to make sure that the CIR process has the correct distribution.
4
5/// The [Cox-Ingersoll-Ross (CIR)](https://en.wikipedia.org/wiki/Cox%E2%80%93Ingersoll%E2%80%93Ross_model) 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 \sqrt{x_t} \textrm{d} W_t $$
9/// where $\theta$, $\mu$, and $\sigma$ are parameters of the process and $W_t$ is a standard Brownian motion.
10pub struct CIR {
11 /// $\theta$ is the speed of reversion.
12 pub theta: f32,
13
14 /// $\mu$ is the long-term mean.
15 pub mu: f32,
16
17 /// $\sigma$ is the instantaneous volatility.
18 pub sigma: f32,
19}
20
21impl CIR {
22 /// Create a new CIR process.
23 pub fn new(theta: f32, mu: f32, sigma: f32) -> Self {
24 Self { theta, mu, sigma }
25 }
26}
27
28impl StochasticProcess for CIR {}
29
30impl AutonomousStochasticProcess for CIR {
31 fn drift(&self, x: f32) -> f32 {
32 self.theta * (self.mu - x)
33 }
34
35 fn diffusion(&self, x: f32) -> f32 {
36 self.sigma * x.sqrt()
37 }
38}