Skip to main content

Module simulation

Module simulation 

Source
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 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
  • 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§

SimulationStats
Statistics for tracking Short Put strategy performance across multiple simulations.
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§

Simulate
Trait for simulating trading strategies across multiple price paths.
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.
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.