stochastic_processes/
lib.rs

1//! Stochastic processes simluation toolkit.
2//!
3//! This crate provides utilities for simulating various stochastic processes.
4//!
5//! # Quick Start
6//!
7//! To create a process, call the `new` constructor for the desired process, and supply the
8//! constructor with the required parameters. To simulate a process, simply call `simulate`
9//! on the process.
10//!
11//! In the following example, a [Geometric Brownian motion](struct@gbm::GeometricBrownianMotion) is created with
12//! $\mu = \sigma = 1$. The processes is simluated using the
13//! [Euler-Maruyama](trait@EulerMaruyama::EulerMaruyama) method. The path is stored inside of a
14//! [`SimulatedPath`]. Finally, the path is exported to a pickle file (for use in Python).
15//!
16//! ```
17//! use stochastic_processes::prelude::*;
18//!
19//! let proc = GeometricBrownianMotion {
20//!     mu: 1.0,
21//!     sigma: 1.0,
22//! };
23//!
24//! let sim = proc.run_euler_maruyama(1.0, 0.0, 1.0, 20);
25//! let _ = export_to_pickle(sim, "/tmp/test.pickle").unwrap();
26//! ```
27
28pub mod processes;
29
30#[cfg(any(feature = "py", feature = "json"))]
31pub mod export;
32
33/// A convenience module appropriate for glob imports.
34pub mod prelude {
35    pub use crate::SimulatedPath;
36    pub use crate::processes::*;
37
38    #[cfg(feature = "py")]
39    pub use crate::export::py::*;
40
41    #[cfg(feature = "json")]
42    pub use crate::export::json::*;
43}
44
45/// Representation of a simluated path.
46///
47/// For $n$ time-steps, a simulated path is a $(n+1) \times 2$ matrix, where the first colum
48/// holds the time and the second column holds the process value.
49pub type SimulatedPath = nalgebra::Matrix<
50    f32,
51    nalgebra::Dynamic,
52    nalgebra::U2,
53    nalgebra::VecStorage<f32, nalgebra::Dynamic, nalgebra::U2>,
54>;