Skip to main content

market_model/
simulatable.rs

1/// The central trait for all market models.
2///
3/// Every model -- from a simple GBM to a full L3 order book simulator --
4/// implements this trait. The `SimulationRunner` consumes only this trait,
5/// so the hot path is monomorphized at compile time and pays zero overhead
6/// for unused complexity.
7///
8/// The runner clones the model for each parallel path, so implementations
9/// must be `Clone`.
10pub trait Simulatable: Clone + Send + Sync {
11    /// The type emitted at each step (e.g. `f64` for GBM, `BookSnapshot` for L3).
12    type Output: Clone + Send + Sync;
13
14    /// Dimensionality of the Brownian driver. Used by the runner to
15    /// pre-generate the correct number of random normals per step.
16    /// GBM is 1, Heston is 2, etc.
17    fn dim(&self) -> usize;
18
19    /// Advance the model by one step of size `dt`.
20    ///
21    /// `dw` is a slice of `dim()` independent standard normal increments,
22    /// pre-generated by the runner. `rng` is provided for jump components.
23    fn step(&mut self, dt: f64, dw: &[f64], rng: &mut impl rand::Rng) -> Self::Output;
24
25    /// The current state snapshot. Called once before simulation starts.
26    fn current(&self) -> Self::Output;
27}