How to Turn ORE/QuantLib into a LiveRisk Service for FX Products: 1 Million Trades Priced in 0.4 Seconds with Complete Delta Risk
Ever felt like you need a PhD just to navigate Open Risk Engine (ORE) and QuantLib's labyrinthine C++ hierarchy? You're not alone!
I'm excited to share this case study and Jupyter notebook demonstrating how we treated ORE as a complete black box and transformed it from a complexity monster into a lightning-fast LiveRisk service for FX linear products using MatLogica AADC.
1 million FX trades priced 100x faster
in just 0.4 seconds with complete delta risk in under 1 second!
This isn't AI magic or approximation - AADC delivers results accurate to machine precision while dramatically accelerating ORE/QuantLib calculations. We've simply eliminated the computational overhead while preserving the mathematical integrity of the derivatives pricing models.
No more hair-pulling sessions trying to connect all the dots in ORE - just a streamlined black box where market rates go in, and prices + sensitivities come out faster than you can say "template metaprogramming nightmare."
Powerful but complex - a formidable challenge for quants and developers
ORE (Open Risk Engine) built on top of QuantLib presents a formidable challenge for quants and developers. While powerful for derivatives pricing and risk management, its complexity can make even seemingly simple tasks like setting up a Monte Carlo model for FX products quite daunting.
Create a black box where market rates go in and FX trade prices come out as quickly as possible, with first-order sensitivities (delta risks) to all market rates via automatic adjoint differentiation (AAD).
The black box approach - identify entry and exit points only
Creating a `TodaysMarket` object in ORE typically requires extensive setup code spanning hundreds of lines. However, for our black box purposes, we need to identify where market data actually enters the system and where trade valuations exit—nothing more.
Market data enters through `CSVLoader::loadFile`:
const string key = tokens[1];
Real value = parseReal(tokens[2]);
if (idouble::isRecording()) {
auto aadc_arg = value.markAsInput();
AADCKernelInputOutputRegistry
Instance().inputs.push_back(
(key, aadc_arg));
}
The `ReportWriter::writeNpv` provides access to trade NPVs:
Real npv = trade->instrument()
->NPV();
auto npv_res = (npv * fx)
.markAsOutput();
AADCKernelInputOutputRegistry
Instance().outputs.push_back(
(trade->id(), npv_res));
Ensuring clean AAD recording for stable risk calculations
When recording with AADC, it's crucial to identify any branches that depend on input values, as these can create discontinuities leading to unstable risk calculations and P&L jumps in production systems.
AADC diagnostics found an issue in `Rounding::operator()`:
Decimal Rounding::operator()
(Decimal value) const {
if (type_ == None)
return value;
Real mult = std::pow(10.0,
precision_);
bool neg = AAD_PASSIVE(
(value < 0.0));
// ...
}
Bypass rounding when running under AADC:
if (idouble::isRecording())
return value;
Result - Clean recording confirmed: Number active to passive
conversions: 0
while recording OREApp::run()
Testing with 1 million randomly generated FX linear trades (forwards and swaps)
| Operation | Time (s) | Notes |
|---|---|---|
| Standard ORE NPV calculation (baseline) | 98 | Vanilla ORE/QuantLib performance |
| AADC recording (one-time) | 350 | Done pre-market, graph cached |
| NPV recalculation with AADC | 0.40 | 245x faster than baseline |
| NPV + all portfolio delta risks | ~1.0 | 100x+ faster with full sensitivities |
Practical production deployment for real-time risk management
The beauty of this AADC-powered ORE transformation lies in its efficiency and flexibility for production use:
Done before trading day begins
Cache and reuse compiled graph
Deploy AADC kernel to API
Rapid recalculation on market moves
Handle new trades efficiently
Trade cancellations without re-recording
Although this demonstration uses Open Risk Engine and QuantLib, the same black box technique can be applied to proprietary quant libraries without needing to understand their internal complexity. AADC's AVX2 vectorization capabilities can further accelerate calculations for delta ladders, scenario analysis, and what-if computations across any C++, C#, or Python quantitative library.
Ready to achieve 100x performance improvements in your risk systems? Whether you're using ORE, QuantLib, or proprietary quant libraries, MatLogica AADC can deliver sub-second LiveRisk capabilities without extensive refactoring.
Complete code with detailed comments available in downloadable PDF and Jupyter notebook