A high-performance Monte Carlo simulation engine designed to price Path-Dependent Exotic Options (specifically Down-and-Out Barrier Call Options).
Unlike standard Black-Scholes implementations that assume a static time-step (
- Path Dependency: Simulates 252 discrete time-steps per path to enforce barrier conditions.
- Stochastic Accuracy: Utilizes
std::mt19937(Mersenne Twister) for high-fidelity normal distribution generation, avoiding the biases ofrand(). - Latency Optimization: Implements "Early Exit" logic; paths that breach the barrier are terminated immediately, reducing CPU cycles by ~30% in high-volatility scenarios.
- Drift/Diffusion Pre-calculation: Mathematical constants are computed outside the hot loops to minimize redundant FLOPs.
- Data Serialization: Exports simulation paths to
.csvfor downstream analysis in Python (Pandas/Matplotlib).
The asset price trajectories are modeled using the discrete form of Geometric Brownian Motion:
Where:
-
$S_t$ : Stock Price at time$t$ -
$r$ : Risk-free interest rate -
$\sigma$ : Volatility -
$Z$ : Standard Normal Random Variable$\sim N(0,1)$
- Simulations: 100,000 Paths
- Steps per Path: 252 (Total ~25.2 Million Steps)
- Execution Time: ~1.74 seconds (on standard hardware)
- Throughput: ~57,000 simulations/second
Dependencies: Standard C++ Library (STL) only. No external dependencies required.
# Compile using g++ with optimization flags
g++ -O3 -o option_pricer main.cpp
# Run the executable
./engine
Starting Simulation for AAPL...
--------------------------------
Theoretical Option Price: 10.425
Time Taken: 1.74484 seconds
Simulations per Second: 57312
Data saved to 'simulation_data.csv'