Skip to main content

Module simulation

Module simulation 

Source
Expand description

Random walks, stochastic processes, simulators, exit policies and the generic evaluation of simulated paths.

§Random Walk Simulation Library

This library provides tools for simulating and analyzing random walk processes and other stochastic models. It includes implementations of various random walk algorithms and statistical utilities; charts of a walk are drawn by the optionstratlib facade.

The library is organized into several modules:

  • model: Contains the data structures and types that represent stochastic processes
  • simulator: Provides simulation engines and algorithms for running the models
  • utils: Utility functions and helpers for statistical analysis and data manipulation
  • walk: Public API for creating and running random walk simulations

§Core Components

§Mathematical Background

The random walk implementation follows the geometric Brownian motion model with:

  1. Price changes: dS = μSdt + σSdW

    • S: Asset price
    • μ: Drift (mean return)
    • σ: Volatility
    • dW: Wiener process increment
  2. Volatility updates: σ(t) ~ N(σ, σ_change)

    • Stochastic volatility component
    • Updates based on volatility_window

§Features

  • Geometric Brownian motion simulation
  • Stochastic volatility modeling
  • Real-time volatility estimation
  • Integration with option pricing parameters
  • Iterator interface for sequential processing

§Performance Considerations

  • Time Complexity: O(n) for generation, where n is the number of steps
  • Space Complexity: O(n) for storing the price path
  • Volatility calculation: O(w) where w is the volatility window size

§Implementation Notes

  • All prices are strictly positive (enforced by Positive)
  • Volatility is estimated using rolling windows
  • The iterator provides option pricing parameters for each step
  • Thread-safe random number generation
  • Supports various time frames (daily, weekly, monthly)

Re-exports§

pub use exit::ExitPolicy;
pub use exit::check_exit_policy;
pub use ou::generate_ou_process;

Modules§

exit
Module containing exit policy definitions for option trading strategies.
ou
The Ornstein-Uhlenbeck path generator.
randomwalk
Random Walk Module
simulator
Provides simulation engines and algorithms for running stochastic models.
steps
Module containing functionality for stepping through data or calculations.

Structs§

PathOutcome
Outcome of evaluating one simulated price path.
PathStatistics
Summary statistics over a set of PathOutcomes.
WalkParams
Parameters for stochastic process simulations (random walks).
WalkPath
A simulated walk that exposes the per-step volatility path alongside the price path.

Enums§

WalkType
Enum defining different types of random walks

Traits§

PathEvaluator
Evaluates one simulated price path.
WalkTypeAble
Trait for implementing various random walk models and stochastic processes.
WalkTypeAbleClone
Object-safe helper trait that exposes a Clone-compatible operation for WalkTypeAble trait objects.

Functions§

custom_walk
Built-in Custom (mean-reverting volatility) walk kernel: simulates the price path together with the volatility path that drove it.
evaluate_paths
Runs evaluator over every walk in sim, in order.
expanding_window_vols
Per-step expanding-window volatility estimates for a price path, free of look-ahead bias: the estimate at index i uses only the log returns of prices[..=i].
garch_walk
Built-in GARCH(1,1) walk kernel: simulates the price path together with the volatility path that drove it.
generator_positive
Generates a vector of Steps containing Positive x-values and Positive y-values.
heston_walk
Built-in Heston walk kernel: simulates the price path together with the volatility path that drove it.
telegraph_walk
Built-in Telegraph (two-state regime switching) walk kernel: simulates the price path together with the volatility path that drove it.
walk_steps
Runs a walk and materializes it as a vector of Steps, delegating the construction of each y-value to next_y.
walk_steps_par
Parallel variant of walk_steps: identical contract and output, with the per-step next_y calls executed on the rayon thread pool.