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 processessimulator: Provides simulation engines and algorithms for running the modelsutils: Utility functions and helpers for statistical analysis and data manipulationwalk: Public API for creating and running random walk simulations
§Core Components
§Mathematical Background
The random walk implementation follows the geometric Brownian motion model with:
-
Price changes: dS = μSdt + σSdW
- S: Asset price
- μ: Drift (mean return)
- σ: Volatility
- dW: Wiener process increment
-
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§
- Path
Outcome - Outcome of evaluating one simulated price path.
- Path
Statistics - Summary statistics over a set of
PathOutcomes. - Walk
Params - Parameters for stochastic process simulations (random walks).
- Walk
Path - A simulated walk that exposes the per-step volatility path alongside the price path.
Enums§
- Walk
Type - Enum defining different types of random walks
Traits§
- Path
Evaluator - Evaluates one simulated price path.
- Walk
Type Able - Trait for implementing various random walk models and stochastic processes.
- Walk
Type Able Clone - Object-safe helper trait that exposes a
Clone-compatible operation forWalkTypeAbletrait 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
evaluatorover every walk insim, in order. - expanding_
window_ vols - Per-step expanding-window volatility estimates for a price path, free of
look-ahead bias: the estimate at index
iuses only the log returns ofprices[..=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 containingPositivex-values andPositivey-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 tonext_y. - walk_
steps_ par - Parallel variant of
walk_steps: identical contract and output, with the per-stepnext_ycalls executed on the rayon thread pool.