Skip to main content

Simulatable

Trait Simulatable 

Source
pub trait Simulatable:
    Clone
    + Send
    + Sync {
    type Output: Clone + Send + Sync;

    // Required methods
    fn dim(&self) -> usize;
    fn step(&mut self, dt: f64, dw: &[f64], rng: &mut impl Rng) -> Self::Output;
    fn current(&self) -> Self::Output;
}
Expand description

The central trait for all market models.

Every model – from a simple GBM to a full L3 order book simulator – implements this trait. The SimulationRunner consumes only this trait, so the hot path is monomorphized at compile time and pays zero overhead for unused complexity.

The runner clones the model for each parallel path, so implementations must be Clone.

Required Associated Types§

Source

type Output: Clone + Send + Sync

The type emitted at each step (e.g. f64 for GBM, BookSnapshot for L3).

Required Methods§

Source

fn dim(&self) -> usize

Dimensionality of the Brownian driver. Used by the runner to pre-generate the correct number of random normals per step. GBM is 1, Heston is 2, etc.

Source

fn step(&mut self, dt: f64, dw: &[f64], rng: &mut impl Rng) -> Self::Output

Advance the model by one step of size dt.

dw is a slice of dim() independent standard normal increments, pre-generated by the runner. rng is provided for jump components.

Source

fn current(&self) -> Self::Output

The current state snapshot. Called once before simulation starts.

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety".

Implementors§