pub struct CIR {
pub S0: f64,
pub T: f64,
pub steps: usize,
pub sigma: f64,
pub mu: f64,
pub kappa: f64,
}
impl Stochastic for CIR {
fn gen_path(&self) -> Vec<f64> {
let dt = self.T / self.steps as f64;
let mut res = Vec::new();
let mut x = self.S0;
res.push(x);
for step in 0..self.steps {
let z = random_from_stdnorm();
let n1 = self.kappa * (self.mu - x) * dt;
let n2 = self.sigma * x.sqrt() * dt.sqrt() * z;
x = x + n1 + n2;
res.push(x);
}
res
}
}