use ndarray::Array1;
use stochastic_rs_core::simd_rng::Deterministic;
use stochastic_rs_core::simd_rng::SeedExt;
use stochastic_rs_core::simd_rng::Unseeded;
use crate::diffusion::fou::Fou;
use crate::traits::FloatExt;
use crate::traits::ProcessExt;
pub struct FVasicek<T: FloatExt, S: SeedExt = Unseeded> {
pub hurst: T,
pub theta: T,
pub mu: T,
pub sigma: T,
pub n: usize,
pub x0: Option<T>,
pub t: Option<T>,
pub seed: S,
pub fou: Fou<T, S>,
}
impl<T: FloatExt> FVasicek<T> {
pub fn new(hurst: T, theta: T, mu: T, sigma: T, n: usize, x0: Option<T>, t: Option<T>) -> Self {
Self {
hurst,
theta,
mu,
sigma,
n,
x0,
t,
seed: Unseeded,
fou: Fou::new(hurst, theta, mu, sigma, n, x0, t),
}
}
}
impl<T: FloatExt> FVasicek<T, Deterministic> {
pub fn seeded(
hurst: T,
theta: T,
mu: T,
sigma: T,
n: usize,
x0: Option<T>,
t: Option<T>,
seed: u64,
) -> Self {
let s = Deterministic::new(seed);
let child = s.derive();
Self {
hurst,
theta,
mu,
sigma,
n,
x0,
t,
seed: Deterministic::new(seed),
fou: Fou::seeded(hurst, theta, mu, sigma, n, x0, t, child.current()),
}
}
}
impl<T: FloatExt, S: SeedExt> ProcessExt<T> for FVasicek<T, S> {
type Output = Array1<T>;
fn sample(&self) -> Array1<T> {
self.fou.sample()
}
}
py_process_1d!(PyFVasicek, FVasicek,
sig: (hurst, theta, mu, sigma, n, x0=None, t=None, seed=None, dtype=None),
params: (hurst: f64, theta: f64, mu: f64, sigma: f64, n: usize, x0: Option<f64>, t: Option<f64>)
);
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn sample_length_matches_n() {
let v = FVasicek::<f64>::new(0.7, 0.5, 0.04, 0.01, 64, Some(0.05), Some(1.0));
let path = v.sample();
assert_eq!(path.len(), 64);
}
}