Skip to content

A high-performance C++ Monte Carlo pricer for options, supporting Asian, European, and Barrier options with price path simulation using SDEs (GBM, CEV) and Finite Difference Methods (Euler, Exact).

Notifications You must be signed in to change notification settings

pysojic/MCOptionPricer

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

6 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Monte Carlo Option Pricer (C++)

A modular Monte Carlo engine for pricing one-factor options by simulating paths of an underlying stochastic differential equation (SDE) and aggregating payoffs. The code is organized around a clean set of interfaces (SDE / RNG / FDM / Pricer) and two coordinating patterns:

  • Builder: assembles a consistent object network (model + discretization + RNG) from user/config choices.
  • Mediator: drives the simulation loop (path generation) and notifies pricers with generated paths.

The design follows a “plug-and-play” architecture: you can add new SDEs, time-stepping schemes, RNGs, or option pricers without touching the main simulation loop.


Architecture Overview

At a high level the program does:

  1. Choose and configure an SDE (e.g., GBM / CEV).
  2. Choose a finite-difference time-marching scheme (Euler / Milstein / predictor-corrector variants) to discretize the SDE.
  3. Choose an RNG to generate standard normal variates.
  4. Run a Monte Carlo loop that generates full price paths.
  5. Feed each path into one or more pricers (European / barrier / Asian / etc.) and finalize statistics.

The key idea is that the Mediator owns the simulation loop and is completely decoupled from the specific models, schemes, and products via abstract interfaces.


Project Structure

MonteCarloPricer/

├── build/                          # Build directory (generated after CMake)

├── include/

│   ├── FDMAbstract.hpp             # Base FDM interface / abstractions
│   ├── FDMDerived.hpp              # Concrete one-step schemes (Euler, Milstein, etc.)
│   ├── Interface.hpp               # High-level wiring / application interface
│   ├── MCBuilder.hpp               # Builder: constructs SDE + FDM + RNG configuration
│   ├── MCMediator.hpp              # Mediator: simulation driver (path generation + notifications)
│   ├── OptionData.hpp              # Option + market data container (S0, K, r, T, vol, etc.)
│   ├── PricerAbstract.hpp          # Pricer interface / base class
│   ├── PricerDerived.hpp           # Concrete pricers (European, Asian, Barrier, etc.)
│   ├── RNGAbstract.hpp             # RNG interface / base class
│   ├── RNGDerived.hpp              # Concrete RNGs (Box-Muller, Polar Marsaglia, etc.)
│   ├── SDEBase.hpp                 # SDE interface / base abstraction
│   ├── SDEConcrete.hpp             # Concrete SDEs (GBM, CEV, etc.)
│   ├── Singleton.hpp               # Utility singleton (if used for shared config/state)
│   └── StopWatch.hpp               # Timing utility

├── src/

│   ├── Interface.cpp               # Application wiring / glue implementation
│   ├── PricerDerived.cpp           # Pricer implementations
│   ├── RNGDerived.cpp              # RNG implementations
│   ├── SDEConcrete.cpp             # SDE implementations
│   ├── SDEConcrete.cpp             # SDE implementations
│   └── main.cpp                    # Program entry point


Requirements

  • A C++ compiler with C++17 support (Clang or GCC recommended)
  • CMake (3.14+)

Build

# from repo root
mkdir -p build
cmake -S . -B build
cmake --build build -j

The executable will be created in build/.


Run

./build/MonteCarloPricer

What’s Implemented (Conceptually)

SDE Layer

Concrete models in SDEConcrete.* implement an SDE interface (drift/diffusion, initial condition, expiry). Typical implementations include:

  • Geometric Brownian Motion (GBM):
    $$dS_t = \mu S_t,dt + \sigma S_t,dW_t$$
  • CEV:
    $$dS_t = \mu S_t,dt + \sigma S_t^\beta,dW_t$$

Time Discretization (FDM) Layer

One-step schemes in FDMDerived.hpp advance the process, e.g.:

  • Euler–Maruyama
  • Milstein
  • (Optional) Predictor–Corrector variants

The discretization does not generate randomness itself; it consumes Wiener increments / normal variates provided by the RNG module.

Random Number Generation

Concrete generators in RNGDerived.* typically produce standard normal $Z \sim \mathcal{N}(0,1)$, e.g.:

  • Box–Muller
  • Polar Marsaglia

Pricers

Concrete pricers in PricerDerived.* consume generated paths and compute discounted payoffs, e.g.:

  • European payoff using terminal value $S_T$
  • Barrier / Asian style logic

Extending the Project

Add a new SDE

  1. Create a new class in SDEConcrete.hpp/.cpp implementing the SDE interface.
  2. Register it in the builder (or factory selection) so it can be constructed from config.

Add a new time-stepping scheme

  1. Implement a new derived class in FDMDerived.hpp (or split into .cpp if desired).
  2. Ensure it conforms to the FDM interface and consumes RNG-provided increments.

Add a new pricer (new product)

  1. Implement a derived class in PricerDerived.hpp/.cpp.
  2. Plug it into the mediator subscription/wiring (one mediator run can feed multiple pricers).

References


About

A high-performance C++ Monte Carlo pricer for options, supporting Asian, European, and Barrier options with price path simulation using SDEs (GBM, CEV) and Finite Difference Methods (Euler, Exact).

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published