volfi is a C++ research prototype for fast Black-Scholes implied variance. Untested Python and R translations are also available.
It implements an efficient implied-volatility solver based on the generalized-inverse-Gaussian quantile representation in An Explicit Solution to Black-Scholes Implied Volatility.
For out-of-the-money normalized calls with forward log-moneyness k > 0, normalized call price c, and total implied volatility v = sigma sqrt(T), the variance-space representation is
The formula above makes total variance the natural inversion variable. For fixed positive moneyness, write F_h for the corresponding GIG distribution function. Then the OTM inversion is simply the quantile problem w = F_h^{-1}(c_*).
volfi fits and corrects this variance quantile directly. A volatility-space method instead targets its square root. This difference matters because the square-root map is strongly curved near small variance, while the GIG representation is already expressed in w.
The same choice also gives a compact correction step. With residual R_h(w) = F_h(w) - c_*, density f_h(w) = F_h'(w), and log-density derivative ell_h(w) = f_h'(w) / f_h(w), one Halley correction is
For the GIG family used here,
Thus the correction is expressed through the GIG density and its logarithmic derivative in the native variable w. In volatility space, the corresponding residual is G(v) = F_h(v^2) - c_*, which introduces extra chain-rule terms from w = v^2.
The method still evaluates a residual. The point is that the residual is the GIG-CDF residual in total-variance space, evaluated through its equivalent closed form. In repeated inversions on fixed strike or moneyness grids, the moneyness-dependent quantities can also be precomputed in otm_context.
The normalized problem is
where c_* is the normalized OTM-call price and w is total implied variance.
For normalized calls, ITM prices are projected exactly to the OTM side before inversion:
At the forward strike the inversion reduces to
For put options, use put-call parity for a transformation into a call.
This v0.1.7 release is the wing-speed update: it extends the previous projected-OTM kernel with a precomputed log-c wing seed for the true raw OTM-call domain while keeping the projected ITM-to-OTM path.
- Keeps the precomputed
otm_contextfast path. - Adds a wing seed for the true OTM-call region.
- Adds explicit fixed-grid and randomized true-OTM tests.
- Preserves the projected call-delta benchmark path from the earlier release.
include/volfi/volfi.hpp flagship header
include/volfi/volfi_reorder.hpp alternate ordering helpers
include/volfi/volfi_logc_libm.hpp log-c wing support
tests/ projected-OTM and true-OTM tests
bench/bench_otm_grid.cpp fixed projected-grid benchmark
bench/bench_lbr_compare.cpp optional volfi vs LetsBeRational comparison driver
docs/technical_note/ technical documentation (.tex and .pdf)
Makefile simple build entry point
CMakeLists.txt optional CMake build for core tests and standalone benchmark
make
make test
make benchTo override the compiler:
make CXX=g++The optional CMake build covers the core tests and standalone volfi benchmark. The LetsBeRational comparison is a Makefile/manual target because it depends on a separately obtained local LetsBeRational build.
#include <volfi/volfi.hpp>
volfi::otm_context ctx(h);
double w = volfi::implied_variance_otm(ctx, c_otm);For normalized calls:
double w = volfi::implied_variance_call_normalised(k, c);The performance comparison was run against LetsBeRational through its native shared-library interface using NormalisedImpliedBlackVolatility.
The repository includes bench/bench_lbr_compare.cpp, but not the LetsBeRational source or binary. To reproduce the side-by-side comparison, fetch LetsBeRational.7z separately and build or link it locally.
Minimal setup used for the comparison:
- obtain the upstream LetsBeRational source from the archive above
- build LetsBeRational locally as a native library or compile its source into a local benchmark build
- point
bench/bench_lbr_compare.cppat that local copy and benchmarkNormalisedImpliedBlackVolatility
Example build command:
make bench_lbr_compare CXX=g++ \
LBR_INCLUDE=/path/to/LetsBeRational \
LBR_LIBDIR=/path/to/LetsBeRational/LinuxTest grids:
- Fixed grid:
- Random grid:
Benchmark setting:
cases: 451
repetitions per timing run: 5000
evaluations per timing run: 2255000
runs: 9
reported unit: nanoseconds per implied-volatility evaluation
Accuracy:
| method | mean abs vol error | max abs vol error | max rel vol error |
|---|---|---|---|
| volfi | 1.86e-16 |
1.33e-15 |
5.46e-14 |
| LetsBeRational | 1.64e-16 |
7.77e-16 |
2.32e-14 |
Timing:
| method | mean ns/eval | median ns/eval | min ns/eval | max ns/eval |
|---|---|---|---|---|
| volfi | 53.01 |
51.80 |
49.08 |
60.41 |
| LetsBeRational | 188.10 |
181.23 |
176.99 |
211.33 |
Median speed ratio:
Benchmark setting:
accuracy cases: 200000
random seed: 20260502
timing cases: 5000
repetitions per timing run: 1000
evaluations per timing run: 5000000
runs: 9
reported unit: nanoseconds per implied-volatility evaluation
Accuracy:
| method | mean abs vol error | max abs vol error | max rel vol error |
|---|---|---|---|
| volfi | 1.60e-16 |
1.55e-15 |
5.01e-14 |
| LetsBeRational | 1.72e-16 |
1.33e-15 |
3.68e-14 |
Timing:
| method | mean ns/eval | median ns/eval | min ns/eval | max ns/eval |
|---|---|---|---|---|
| volfi | 55.88 |
55.48 |
54.19 |
59.38 |
| LetsBeRational | 168.77 |
166.35 |
164.75 |
179.06 |
Median speed ratio:
On Black prices generated over these fixed and random grids, volfi v0.1.7 recovers the input volatility to near machine precision and is about 3x to 3.5x faster than LetsBeRational in this benchmark setup.
OS/kernel: Linux 6.6.87.2-microsoft-standard-WSL2 x86_64 GNU/Linux
compiler: g++ (Ubuntu 11.4.0-1ubuntu1~22.04.3) 11.4.0
CPU model: 11th Gen Intel(R) Core(TM) i5-1145G7 @ 2.60GHz
CPU cores reported: 8
Threads per core: 2
Cores per socket: 4
Socket count: 1
Hypervisor vendor: Microsoft
Memory reported: 7.60 GiB
- This is a research kernel, not a global replacement for LetsBeRational.
- The comparison is domain-specific.
- Timings vary across machines, compilers, libm implementations, and host scheduling.
- The current implementation targets GCC/Clang-like compilers.
volfi is source-available research software under the PolyForm Noncommercial License 1.0.0.
You may inspect, test, benchmark, reproduce, and evaluate the software for noncommercial research purposes.
Live trading, production pricing, risk management, execution systems, commercial analytics, or other commercial financial-service use is not permitted without a separate written license. See NOTICE.md.