Skip to content

Commit

Permalink
feat: rename heston params
Browse files Browse the repository at this point in the history
  • Loading branch information
dancixx committed Sep 27, 2024
1 parent 4f11a0d commit e22d0d7
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 46 deletions.
1 change: 1 addition & 0 deletions stochastic-rs-core/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ keywords = ["stochastic", "process", "random", "simulation", "monte-carlo"]
ndarray = { version = "0.16.1", features = [
"rayon",
"matrixmultiply-threading",
"blas"
] }
num-complex = { version = "0.4.6", features = ["rand"] }
rand = "0.8.5"
Expand Down
63 changes: 21 additions & 42 deletions stochastic-rs-core/src/main.rs
Original file line number Diff line number Diff line change
@@ -1,50 +1,29 @@
use stochastic_rs::{process::fbm::Fbm, Sampling};
use stochastic_rs::{noise::fgn::Fgn, Sampling};

fn main() {
// let fbm = Fbm::new(&Fbm {
// hurst: 0.9,
// n: 10000,
// t: None,
// m: Some(100),
// ..Default::default()
// });
let fbm = Fgn::new(0.9, 10000, None, Some(10000));

// let mut runs = Vec::new();

// for _ in 0..20 {
// let start = std::time::Instant::now();
// for _ in 0..1000 {
// let _ = fbm.sample_par();
// }
let start = std::time::Instant::now();
for _ in 0..10000 {
let _ = fbm.sample();
}

// let duration = start.elapsed();
// println!(
// "Time elapsed in expensive_function() is: {:?}",
// duration.as_secs_f32()
// );
// runs.push(duration.as_secs_f32());
// }
let duration = start.elapsed();
println!(
"Time elapsed in expensive_function() is: {:?}",
duration.as_secs_f32()
);

// let sum: f32 = runs.iter().sum();
// let average = sum / runs.len() as f32;
// println!("Average time: {}", average);
let fbm = Fbm::new(&Fbm {
hurst: 0.9,
n: 10000,
t: None,
m: Some(100),
..Default::default()
});
let fbm = Fgn::new(0.9, 10000, None, Some(10000));

for _ in 0..10 {
let start = std::time::Instant::now();
for _ in 0..1000 {
let _ = fbm.sample();
}
let duration = start.elapsed();
println!(
"Time elapsed in expensive_function() is: {:?}",
duration.as_secs_f32()
);
let start = std::time::Instant::now();
for _ in 0..10000 {
let _ = fbm.sample();
}

let duration = start.elapsed();
println!(
"Time elapsed in expensive_function() is: {:?}",
duration.as_secs_f32()
);
}
8 changes: 4 additions & 4 deletions stochastic-rs-core/src/volatility/heston.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ pub struct Heston {
pub mu: f64,
pub kappa: f64,
pub theta: f64,
pub eta: f64,
pub sigma: f64,
pub rho: f64,
pub n: usize,
pub s0: Option<f64>,
Expand All @@ -33,7 +33,7 @@ impl Heston {
mu: params.mu,
kappa: params.kappa,
theta: params.theta,
eta: params.eta,
sigma: params.sigma,
rho: params.rho,
n: params.n,
s0: params.s0,
Expand Down Expand Up @@ -61,8 +61,8 @@ impl Sampling2D<f64> for Heston {
s[i] = s[i - 1] + self.mu * s[i - 1] * dt + s[i - 1] * v[i - 1].sqrt() * cgn1[i - 1];

let random: f64 = match self.use_sym.unwrap_or(false) {
true => self.eta * (v[i - 1]).abs().sqrt() * cgn2[i - 1],
false => self.eta * (v[i - 1]).max(0.0).sqrt() * cgn2[i - 1],
true => self.sigma * (v[i - 1]).abs().sqrt() * cgn2[i - 1],
false => self.sigma * (v[i - 1]).max(0.0).sqrt() * cgn2[i - 1],
};
v[i] = v[i - 1] + self.kappa * (self.theta - v[i - 1]) * dt + random;
}
Expand Down

0 comments on commit e22d0d7

Please sign in to comment.