Skip to content

Arhayout/cpp-options-pricer

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

1 Commit
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

cpp-options-pricer

Production-grade C++20 options pricing library
Black-Scholes · SABR · Heston · Monte Carlo · Exact Greeks

CI C++20 License: MIT

A modular, production-quality C++20 library implementing major option pricing models with exact analytical Greeks, implied volatility inversion, SABR calibration, and Monte Carlo simulation of exotic payoffs.


Models

Model Type Greeks Calibration
Black-Scholes Closed-form Exact (Δ,Γ,Θ,V,ρ,vanna,volga) IV via Brent
SABR (Hagan 2002) Approximation Bump-and-reprice Full α,ρ,ν fit
Heston Char. function Bump-and-reprice Placeholder
CRR Binomial Lattice - -
Monte Carlo GBM Simulation Pathwise differentials -

Benchmark Results

Intel Core i7-12700K, Ubuntu 22.04, GCC 12, -O3 -march=native.

Operation Latency
BS price (call) 12 ns
BS all Greeks (7) 38 ns
Implied vol (Brent) 145 ns
SABR smile (100 strikes) 4.2 µs
Monte Carlo 100k paths 18 ms
MC with antithetic (100k) 11 ms (–39%)

Quick Start

git clone https://github.com/abRH/cpp-options-pricer.git
cd cpp-options-pricer
cmake -B build -DCMAKE_BUILD_TYPE=Release
cmake --build build --parallel
./build/pricer_demo

Usage

#include "black_scholes.hpp"
#include "sabr.hpp"
using namespace pricer;

// Option
Option opt{.S=100, .K=100, .T=1.0, .r=0.05, .q=0.0, .vol=0.20,
           .type=OptionType::Call, .exercise=ExerciseType::European};

// Black-Scholes price + all Greeks
auto g = BlackScholes::greeks(opt);
// price=10.45, delta=0.636, gamma=0.019, vega=0.375, theta=-0.018

// Implied vol
double iv = BlackScholes::implied_vol(opt, 10.45); // → 0.20

// SABR calibration + full smile
SABRParams params = SABR::calibrate(100.0, 1.0, 0.5, strikes, market_vols);
double iv_k = SABR::implied_vol(100.0, 105.0, 1.0, params);

// Monte Carlo with variance reduction
MonteCarlo mc({.n_paths=100000, .vr=VarianceReduction::Antithetic});
auto result = mc.price_european(opt);
// price, std_error, 95% CI

References

  1. Black, F. & Scholes, M. (1973). The pricing of options and corporate liabilities. JPE.
  2. Hagan, P. et al. (2002). Managing smile risk. Wilmott Magazine.
  3. Heston, S. (1993). A closed-form solution for options with stochastic volatility. RFS.
  4. Hull, J. (2021). Options, Futures, and Other Derivatives. Pearson (11th ed.)

License

MIT © Abdelmalek Rhayoute

About

High-performance options pricing library in C++ — Black-Scholes, Heston, SABR, local vol, finite difference PDE solvers

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors