market_model/process/
mod.rs1pub mod bates;
2pub mod cir;
3pub mod gbm;
4pub mod hawkes;
5pub mod heston;
6pub mod jump_diffusion;
7pub mod ou;
8pub mod rough_ou;
9
10pub use self::bates::BatesProcess;
11pub use self::cir::CoxIngersollRoss;
12pub use self::gbm::GeometricBrownianMotion;
13pub use self::hawkes::HawkesProcess;
14pub use self::heston::HestonProcess;
15pub use self::jump_diffusion::JumpDiffusion;
16pub use self::ou::OrnsteinUhlenbeck;
17pub use self::rough_ou::RoughOUState;
18pub use self::rough_ou::RoughOrnsteinUhlenbeck;
19
20use rand::Rng;
21use rayon::prelude::*;
22
23pub trait StochasticProcess {
30 type State;
31 type Diffusion;
32 type BrownianIncrement;
33
34 fn drift(&self, x: &Self::State, t: f64) -> Self::State;
35 fn diffusion(&self, x: &Self::State, t: f64) -> Self::Diffusion;
36
37 fn jump_intensity(&self, _x: &Self::State, _t: f64) -> f64 {
38 0.0
39 }
40 fn jump_size<R: Rng + ?Sized>(&self, _x: &Self::State, _t: f64, _rng: &mut R) -> Self::State;
41
42 fn expected_value(&self, x0: &Self::State, t: f64) -> Self::State;
43 fn variance(&self, x0: &Self::State, t: f64) -> Self::State;
44
45 fn step<R: Rng + ?Sized>(
46 &self,
47 x: &Self::State,
48 t: f64,
49 dt: f64,
50 dw: &Self::BrownianIncrement,
51 rng: &mut R,
52 ) -> Self::State;
53
54 fn generate_increment<R: Rng + ?Sized>(&self, rng: &mut R, dt: f64) -> Self::BrownianIncrement;
55
56 fn simulate<R: Rng + ?Sized>(
57 &self,
58 x0: Self::State,
59 t0: f64,
60 t_end: f64,
61 dt: f64,
62 rng: &mut R,
63 ) -> Vec<(f64, Self::State)>;
64
65 fn simulate_paths(
66 &self,
67 x0: Self::State,
68 t0: f64,
69 t_end: f64,
70 dt: f64,
71 num_paths: usize,
72 ) -> Vec<Vec<(f64, Self::State)>>
73 where
74 Self: Sync,
75 Self::State: Send + Sync + Clone,
76 {
77 (0..num_paths)
78 .into_par_iter()
79 .map(|_| {
80 let mut rng = rand::rng();
81 self.simulate(x0.clone(), t0, t_end, dt, &mut rng)
82 })
83 .collect()
84 }
85}