diff --git a/Cargo.toml b/Cargo.toml index 84dbf87..2ed6994 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "stochastic-rs" -version = "0.6.2" +version = "0.6.3" edition = "2021" license = "MIT" description = "A Rust library for stochastic processes" diff --git a/src/jumps/jump_fou.rs b/src/jumps/jump_fou.rs index 7a2725c..f26cc23 100644 --- a/src/jumps/jump_fou.rs +++ b/src/jumps/jump_fou.rs @@ -1,9 +1,10 @@ use ndarray::Array1; use rand_distr::Distribution; -use crate::prelude::{ - cpoisson::{compound_poisson, CompoundPoisson}, - fou::{fou, Fou}, +use crate::{ + noises::fgn::FgnFft, + prelude::cpoisson::{compound_poisson, CompoundPoisson}, + utils::Generator, }; /// Generates a path of the jump fractional Ornstein-Uhlenbeck (FOU) process. @@ -56,17 +57,9 @@ pub fn jump_fou(params: &JumpFou, jump_distr: impl Distribution + Copy) -> t, } = *params; let dt = t.unwrap_or(1.0) / n as f64; - let fou = fou(&Fou { - hurst, - mu, - sigma, - theta, - n, - x0, - t, - }); + let fgn = FgnFft::new(hurst, n - 1, t, None).sample(); let mut jump_fou = Array1::::zeros(n); - jump_fou[0] = fou[0]; + jump_fou[0] = x0.unwrap_or(0.0); for i in 1..n { let [.., jumps] = compound_poisson( @@ -78,7 +71,8 @@ pub fn jump_fou(params: &JumpFou, jump_distr: impl Distribution + Copy) -> jump_distr, ); - jump_fou[i] = fou[i - 1] + jumps.sum(); + jump_fou[i] = + jump_fou[i - 1] + theta * (mu - jump_fou[i - 1]) * dt + sigma * fgn[i - 1] + jumps.sum(); } jump_fou diff --git a/src/main.rs b/src/main.rs index c503c3d..3e1e642 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,42 +1,35 @@ use std::time::Instant; use plotly::{common::Line, Plot, Scatter}; -use rand_distr::Normal; -use stochastic_rs::jumps::bates::{bates_1996, Bates1996}; +use rand_distr::Gamma; +use stochastic_rs::jumps::jump_fou::{jump_fou, JumpFou}; fn main() { let start = Instant::now(); let mut plot = Plot::new(); - let jump_distr = Normal::new(0.0, 0.07).unwrap(); - let params = Bates1996 { - mu: Some(0.05), - b: Some(0.05), - r: None, - r_f: None, - lambda: 0.01, - k: 0., - alpha: 0.0225, - beta: 4.0, - sigma: 0.1, - rho: 0.1, - n: 100, - s0: Some(40.), - v0: Some(0.025), - t: Some(25.0), - use_sym: Some(false), + let jump_distr = Gamma::new(2.0, 0.07).unwrap(); + let params = JumpFou { + hurst: 0.7, + mu: 1.0, + sigma: 4.0, + theta: 2.0, + lambda: 5.25, + n: 1000, + x0: Some(0.0), + t: Some(10.0), }; - println!("{:?}", params); - for _ in 0..10 { - let [s, _v] = bates_1996(¶ms, jump_distr); + + for _ in 0..1 { + let s = jump_fou(¶ms, jump_distr); let trace = Scatter::new((0..s.len()).collect::>(), s.to_vec()) .mode(plotly::common::Mode::Lines) .line( Line::new() .color("orange") - .shape(plotly::common::LineShape::Hv), + .shape(plotly::common::LineShape::Spline), ) .name("Bates"); plot.add_trace(trace);