Skip to content

Commit

Permalink
fix: jump fou
Browse files Browse the repository at this point in the history
  • Loading branch information
dancixx committed Jul 30, 2024
1 parent 1be24f2 commit afaa41f
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 38 deletions.
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -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"
Expand Down
22 changes: 8 additions & 14 deletions src/jumps/jump_fou.rs
Original file line number Diff line number Diff line change
@@ -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.
Expand Down Expand Up @@ -56,17 +57,9 @@ pub fn jump_fou(params: &JumpFou, jump_distr: impl Distribution<f64> + 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::<f64>::zeros(n);
jump_fou[0] = fou[0];
jump_fou[0] = x0.unwrap_or(0.0);

for i in 1..n {
let [.., jumps] = compound_poisson(
Expand All @@ -78,7 +71,8 @@ pub fn jump_fou(params: &JumpFou, jump_distr: impl Distribution<f64> + 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
Expand Down
39 changes: 16 additions & 23 deletions src/main.rs
Original file line number Diff line number Diff line change
@@ -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(&params, jump_distr);

for _ in 0..1 {
let s = jump_fou(&params, jump_distr);

let trace = Scatter::new((0..s.len()).collect::<Vec<_>>(), 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);
Expand Down

0 comments on commit afaa41f

Please sign in to comment.