Skip to content

Commit

Permalink
Update stochastic_new.rs
Browse files Browse the repository at this point in the history
  • Loading branch information
0xJepsen committed Jul 28, 2023
1 parent a0f9cf2 commit 71be366
Showing 1 changed file with 13 additions and 21 deletions.
34 changes: 13 additions & 21 deletions core/src/math/stochastic_new.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,9 @@ use anyhow::Result;
/// Type enum for process
pub enum StochasticProcessType {
/// Brownian motion
BrownianMotion,
BrownianMotion(BrownianMotion),
/// Ornstein-Uhlenbeck
OrnsteinUhlenbeck,
/// Poisson
Poisson,
OrnsteinUhlenbeck(OrnsteinUhlenbeck),
}
/// Struct for all processes init parameters.
pub struct EulerMaruyamaInput {
Expand All @@ -21,25 +19,19 @@ pub struct EulerMaruyamaInput {
pub parallel: bool, // run in parallel or not (recommended for > 1000 paths)
}

pub fn new_procces(proccess_type: StochasticProcessType, config: EulerMaruyamaInput) -> Result<()> {
/// Create new process and run euler maruyama.
pub fn new_procces(proccess_type: StochasticProcessType, config: EulerMaruyamaInput) -> Result<Trajectories> {

match proccess_type {
StochasticProcessType::BrownianMotion => {
let brownian_motion = BrownianMotion::new();
let trajectories = brownian_motion.euler_maruyama(config.x_0, config.t_0, config.t_n, config.n_steps, config.m_paths, config.parallel);
let trajectories: Trajectories = match proccess_type {
StochasticProcessType::BrownianMotion(process) => {
process.euler_maruyama(config.x_0, config.t_0, config.t_n, config.n_steps, config.m_paths, config.parallel)
},
StochasticProcessType::OrnsteinUhlenbeck(process) => {
process.euler_maruyama(config.x_0, config.t_0, config.t_n, config.n_steps, config.m_paths, config.parallel)
},
StochasticProcessType::OrnsteinUhlenbeck => {
let ornstein_uhlenbeck = OrnsteinUhlenbeck::new();
let trajectories = ornstein_uhlenbeck.euler_maruyama(config.x_0, config.t_0, config.t_n, config.n_steps, config.m_paths, config.parallel);
println!("{:?}", trajectories);
},
StochasticProcessType::Poisson => {
let poisson = Poisson::new();
let trajectories = poisson.euler_maruyama(config.x_0, config.t_0, config.t_n, config.n_steps, config.m_paths, config.parallel);
println!("{:?}", trajectories);
},
}
Ok(())
};

Ok(trajectories)
}

// impl StochasticProcess {
Expand Down

0 comments on commit 71be366

Please sign in to comment.