Jump to content

Connect Leeroopedia MCP: Equip your AI agents to search best practices, build plans, verify code, diagnose failures, and look up hyperparameter defaults.

Implementation:Avhz RustQuant StochasticProcess generate

From Leeroopedia


Knowledge Sources
Domains Stochastic_Processes, Numerical_Methods, Simulation
Last Updated 2026-02-07 20:00 GMT

Overview

Concrete tool for generating sample paths of stochastic processes provided by the RustQuant stochastics crate.

Description

The StochasticProcess trait defines generate(&self, config: &StochasticProcessConfig) -> Trajectories as a default method that delegates to simulate_stochatic_process. The simulation engine supports Euler-Maruyama, Milstein, and Strang Splitting schemes, with optional Rayon parallelism and seeded RNG.

The StochasticProcessConfig struct bundles all simulation parameters. The Trajectories struct holds the output: a time grid and a vector of path vectors.

Available process types implementing this trait include: GeometricBrownianMotion, BrownianMotion, ArithmeticBrownianMotion, CoxIngersollRoss, OrnsteinUhlenbeck, HullWhite, HoLee, MertonJumpDiffusion, FractionalBrownianMotion, SABR, Heston, and more.

Usage

Call generate() on any struct that implements the StochasticProcess trait after creating a StochasticProcessConfig.

Code Reference

Source Location

  • Repository: RustQuant
  • File: crates/RustQuant_stochastics/src/process.rs
  • Lines: L22-231 (Trajectories, StochasticProcessConfig, StochasticProcess trait)
  • File: crates/RustQuant_stochastics/src/simulation.rs
  • Lines: L22-165 (simulate_stochatic_process implementation)

Signature

pub struct Trajectories {
    pub times: Vec<f64>,
    pub paths: Vec<Vec<f64>>,
}

pub struct StochasticProcessConfig {
    pub x_0: f64,
    pub t_0: f64,
    pub t_n: f64,
    pub n_steps: usize,
    pub scheme: StochasticScheme,
    pub m_paths: usize,
    pub parallel: bool,
    pub seed: Option<u64>,
}

impl StochasticProcessConfig {
    pub fn new(
        x_0: f64, t_0: f64, t_n: f64, n_steps: usize,
        scheme: StochasticScheme, m_paths: usize,
        parallel: bool, seed: Option<u64>,
    ) -> Self
}

pub trait StochasticProcess: Sync {
    fn drift(&self, x: f64, t: f64) -> f64;
    fn diffusion(&self, x: f64, t: f64) -> f64;
    fn jump(&self, x: f64, t: f64) -> Option<f64>;
    fn generate(&self, config: &StochasticProcessConfig) -> Trajectories;
}

pub enum StochasticScheme {
    EulerMaruyama,
    Milstein,
    StrangSplitting,
}

Import

use RustQuant::stochastics::{
    StochasticProcess, StochasticProcessConfig,
    StochasticScheme, Trajectories,
};

I/O Contract

Inputs

Name Type Required Description
x_0 f64 Yes Initial process value
t_0 f64 Yes Start time
t_n f64 Yes End time
n_steps usize Yes Number of discretization steps
scheme StochasticScheme Yes EulerMaruyama, Milstein, or StrangSplitting
m_paths usize Yes Number of simulation paths
parallel bool Yes Enable Rayon parallelism (recommended for >1000 paths)
seed Option<u64> No Optional RNG seed for reproducibility

Outputs

Name Type Description
trajectories.times Vec<f64> Time grid from t_0 to t_n with n_steps+1 points
trajectories.paths Vec<Vec<f64>> m_paths simulated paths, each with n_steps+1 values

Usage Examples

GBM Path Generation

use RustQuant::stochastics::{
    GeometricBrownianMotion, StochasticProcess,
    StochasticProcessConfig, StochasticScheme,
};

let gbm = GeometricBrownianMotion::new(0.05, 0.20);

let config = StochasticProcessConfig::new(
    100.0,  // x_0: initial price
    0.0,    // t_0: start time
    1.0,    // t_n: end time (1 year)
    252,    // n_steps: daily resolution
    StochasticScheme::EulerMaruyama,
    10_000, // m_paths: 10k paths
    true,   // parallel
    Some(42), // seed for reproducibility
);

let output = gbm.generate(&config);

// Access results
let final_prices: Vec<f64> = output.paths
    .iter()
    .filter_map(|path| path.last().copied())
    .collect();

println!("Mean final price: {:.2}", final_prices.iter().sum::<f64>() / final_prices.len() as f64);

Ornstein-Uhlenbeck Process

use RustQuant::stochastics::{
    OrnsteinUhlenbeck, StochasticProcessConfig, StochasticScheme,
};

let ou = OrnsteinUhlenbeck::new(0.1, 0.5, 0.3); // mu, sigma, theta

let config = StochasticProcessConfig::new(
    0.0, 0.0, 5.0, 500,
    StochasticScheme::EulerMaruyama,
    1000, true, None,
);

let output = ou.generate(&config);

Related Pages

Implements Principle

Requires Environment

Uses Heuristic

Page Connections

Double-click a node to navigate. Hold to expand connections.
Principle
Implementation
Heuristic
Environment