A small, production-ish Black-Scholes pricer in modern C++20 with a clean API, unit tests, and CI.
cmake -S . -B build -DCMAKE_BUILD_TYPE=Release -DBS_BUILD_TESTS=ON
cmake --build build -j
ctest --test-dir build --output-on-failure
./build/bs_cli --type call --S 100 --K 100 --r 0.05 --sigma 0.2 --T 1
price_call(const Params&)
,price_put(const Params&)
greeks_call(const Params&)
,greeks_put(const Params&)
Params{S,K,r,sigma,T}
withvalidate()
norm_pdf
,norm_cdf
helpers
see docs/NUMERICS.md
for formulas, units, and tolerances. Summary:
$C = S N(d_1) - K e^{-rT} N(d_2), \quad P = K e^{-rT} N(-d_2) - S N(-d_1)$ - Greeks:
$\Delta, \Gamma, \text{vega}, \Theta, \rho$
(vega per$1.0 , \sigma$ , theta per year)
Feature richness (e.g., constexpr
, library polish) with excellent toolchain maturity on Ubuntu 22.04 CI.
Built in Release on an Azure Standard B1s (1 vCPU, 1 GiB), gcc (Ubuntu 11.x), CMake Ninja.
./build/bs_bench --type call --iters 300000
./build/bs_bench --type put --iters 300000
Numbers vary with hardware/load; CI builds the bench but does not run it.
- Stage-2: Monte Carlo engine + variance reduction
- Stage-3: SIMD/AVX + cache-aware layouts + microbenchmarks