Expand description
simulation- Simulation techniques for scenario analysis.
Framework for Monte Carlo and other simulation methods to model potential market scenarios and their impact on options strategies. Includes path generation algorithms and statistical analysis of simulation results.
§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, statistical utilities, and visualization capabilities.
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
- Visualization support
- 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;
Modules§
- exit
- Module containing exit policy definitions for option trading strategies.
- 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§
- Simulation
Stats - Statistics for tracking Short Put strategy performance across multiple simulations.
- 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§
- Simulate
- Trait for simulating trading strategies across multiple price paths.
- 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.
- 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.