If you’ve ever tried to implement Automatic Adjoint Differentiation from scratch for a real derivatives pricing engine, you already know the gap between understanding the theory and shipping something that actually performs. Antoine Savine’s Modern Computational Finance is one of the few books that closes that gap honestly, and CompFinance is the companion code that makes it actionable. This isn’t a toy implementation tossed together to illustrate textbook concepts — it’s a reference codebase written by someone who built these systems professionally at Danske Bank, and it shows in every design decision.
GitHub: asavine/CompFinance — 194★, 69 forks
What makes this repository worth your time is its direct relevance to the problems that actually consume quant engineering teams: computing Greeks and XVA sensitivities at scale without crippling your Monte Carlo throughput. The AAD implementation here demonstrates the adjoint pattern applied to a realistic financial model, not a contrived academic example. Parallel simulation infrastructure is treated as a first-class concern, not an afterthought bolted on after the math was already written.
For intermediate-to-advanced C++ developers working in derivatives pricing or risk, this repo is the kind of reference you bookmark and return to repeatedly — not for copying, but for understanding how the pieces fit together when correctness, performance, and maintainability all have to coexist.
What Is CompFinance?
The CompFinance library is the production C++ implementation accompanying Antoine Savine‘s Modern Computational Finance: AAD and Parallel Simulations (Wiley, 2018).
It solves a core problem in quantitative finance: computing derivatives (sensitivities, or “Greeks”) of complex financial models efficiently and correctly, while also running Monte Carlo simulations at scale across multiple threads.
The library is split into two cooperating subsystems. The files prefixed AAD* form a self-contained, general-purpose Adjoint Algorithmic Differentiation (AAD) engine. Rather than relying on finite differences or hand-coded analytic gradients, AAD propagates derivatives backward through a recorded computation tape, yielding exact gradients at a cost roughly proportional to a single forward pass. The implementation incorporates advanced techniques from chapters 10, 14, and 15 of the book — including memory-efficient tape management via blocklist.h and analytic treatment of Gaussian functions via gaussians.h — making it notably faster than naive AAD approaches.
The files prefixed mc* constitute a generic parallel simulation framework for financial payoffs. It abstracts models, products, and random-number generation into composable components, with parallelism handled by threadPool.h, a custom thread pool developed in part I of the book.
The primary entry point is main.h, which exposes high-level functions combining both subsystems. A typical usage pattern wraps a computation in an AAD-aware type so the tape records operations automatically:
Number x = 1.5; // AAD active variable
Number y = exp(-x * x); // operations recorded on tape
y.propagateAdjoints(); // reverse pass
double dydx = x.adjoint();
The project targets C++17 and is configured for maximum optimization via an included Visual Studio 2017 project (xlComp.vcxproj).
How It Fits Into a Finance C++ Stack
In a derivatives desk risk engine, a quant developer needs to price thousands of European and barrier options across multiple underlyings every second as market data ticks in. The asavine/CompFinance library — based on Antoine Savine’s Modern Computational Finance — provides production-ready automatic differentiation (AAD) alongside Monte Carlo and finite difference solvers, making it a natural fit for real-time Greeks computation without finite-difference bumping overhead.
Consider a scenario where a risk engine reprices a vanilla European call and computes delta and vega analytically via AAD on each market data update:
#include "aad.h"
#include "gaussians.h"
double priceAndGreeks(double S, double K, double r, double vol, double T,
double& delta, double& vega) {
// Wrap inputs as AAD numbers
Number nS(S), nK(K), nR(r), nVol(vol), nT(T);
Number::tape->rewind();
double d1val = (log(S / K) + (r + 0.5 * vol * vol) * T) / (vol * sqrt(T));
Number d1(d1val);
Number price = nS * Number(normalCdf(d1val))
- nK * Number(exp(-r * T)) * Number(normalCdf(d1val - vol * sqrt(T)));
price.propagateToInputs();
delta = nS.adjoint();
vega = nVol.adjoint();
return price.value();
}
Rather than bumping each input independently — which costs O(n) pricings for n risk factors — AAD delivers all sensitivities in roughly the cost of two forward passes. Rolling your own AAD is notoriously error-prone, requiring careful tape management, memory pooling, and expression-template design. Alternatives like QuantLib lack first-class AAD integration, and commercial AD tools (NAG, dco/c++) add licensing cost and vendor lock-in. CompFinance ships with a battle-tested, open-source tape implementation tuned specifically for financial payoffs, letting a quant developer focus on model logic rather than infrastructure.
Project Health
The CompFinance library shows moderate but concerning signs of decline. With 194 stars and 69 forks, it has a reasonable user base, yet the last commit dates to September 2021—nearly three years ago—suggesting active maintenance has stalled. The four open issues remain unresolved, and recent commits reveal a pattern of minor fixes and documentation updates rather than feature development or security patches. The unknown license status is a red flag for production adoption, as it creates legal ambiguity. Commit messages indicate work on multi-asset support and numerical methods (Sobol points), suggesting the library targets quantitative finance, but the lack of recent activity means no assurance of compatibility with modern dependencies or security vulnerabilities. The project appears to be in maintenance limbo rather than active development.
Verdict: Not recommended for production without thorough code review, security audit, and confirmation that you can maintain it independently if the original authors don’t resume activity.
The Verdict
Use it if: you need to price complex derivatives and structured products with minimal setup—asavine’s computational finance framework handles multi-asset, multi-curve scenarios elegantly.
Skip it if: you’re building a real-time trading system where microsecond latency matters more than mathematical elegance.

