C++ implementations of classical Brownian motion processes and variants for stochastic simulation in finance, physics, and Monte Carlo methods. Includes a Python script for visualizing generated paths.
The random walk provides a simple discrete approximation to a standard Wiener process (Brownian motion), extended here to arithmetic Brownian motion with drift.
Stochastic Differential Equation (SDE):
-
$\mu$ (drift): Constant drift term. -
$\sigma$ (diffusion coefficient): Volatility scaling the Wiener increment. -
$W(t)$ : Standard Wiener process.
Simulation Method: Direct incremental construction using independent Gaussian increments (Euler discretization of the Wiener process):
where plot.csv.
Geometric Brownian motion is the continuous-time limit of a multiplicative random walk, widely used to model asset prices (e.g., stock prices under Black-Scholes).
Stochastic Differential Equation (SDE):
Exact Transition Formula: The code implements the closed-form solution over each time step (log-Euler scheme, which is exact for GBM):
Results are saved to plot.csv.
A Brownian bridge is a Wiener process conditioned to start and end at fixed points (typically
Stochastic Differential Equation (SDE):
Same as standard Brownian motion ($dB(t) = \sigma , dW(t)$), but subject to boundary conditions
Implementation Method: Dyadic (power-of-2) hierarchical construction for efficient path generation:
- Number of steps =
$2^n$ for refined resolution. - Incremental Gaussian sampling combined with bridge conditioning to enforce the endpoint.
- The construction fills intermediate points recursively while preserving the correct joint distribution.
Results are saved to plot.csv.
This method approximates Brownian motion paths using the first
Stochastic Differential Equation (SDE):
Eigen-decomposition (discrete sine basis):
Eigenvalues:
Eigenvectors:
Simulation Formula:
where plot.csv.
- Compile any
.cppfile (e.g.,g++ geometric_brownian_motion.cpp -o gbm). - Run the executable to generate
plot.csv. - Run
python plot.pyto visualize the simulated path.