MatLogica | ORE LiveRisk Case Study: 100x Faster with AADC - by Dmitri Goloubentsev

ORE LiveRisk Case Study: 100x Faster with AADC - by Dmitri Goloubentsev

Transforming Open Risk Engine into a Lightning-Fast LiveRisk Service

How to Turn ORE/QuantLib into a LiveRisk Service for FX Products: 1 Million Trades Priced in 0.4 Seconds with Complete Delta Risk

Request a demo

ORE LiveRisk Transformation with MatLogica AADC

This technical case study demonstrates how to transform Open Risk Engine (ORE) built on QuantLib into a high-performance LiveRisk service using MatLogica AADC, without needing to understand the full C++ hierarchy. The challenge: ORE/QuantLib presents formidable complexity with intricate class hierarchies, XML configuration requirements, and elaborate initialization sequences, making even simple tasks daunting for quants and developers. The solution: Treat ORE as a complete black box. Identify where market data enters (CSVLoader::loadFile) and where valuations exit (ReportWriter::writeNpv), then hook AADC at these points using markAsInput() and markAsOutput(). No need to understand the internal complexity. Performance results for 1 million FX linear trades: - Baseline ORE: 98 seconds for NPV calculation - AADC recording: 350 seconds (one-time, done pre-market) - AADC NPV recalculation: 0.4 seconds (245x faster than baseline) - AADC NPV + all delta risks: <1 second (100x+ faster with sensitivities) The LiveRisk workflow: Record computational graph once before market open, serialize and cache the kernel, deploy to cloud API, then process each market data update in sub-second time with both prices and sensitivities. New trades require only incremental recording, and trade cancellations handled via weight parameters without re-recording. Technical implementation: Hook into CSVLoader for inputs, ReportWriter for outputs, handle control flow branches (e.g., Rounding operator), ensure clean recording with zero active-to-passive conversions. The approach delivers machine precision accuracy (not approximation) while eliminating computational overhead. This black box technique works with any proprietary quant library, not just ORE/QuantLib. AVX2 vectorization capabilities further accelerate delta ladder and what-if scenario calculations.

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.

The results? 1 million FX trades priced 100x faster - in just 0.4 seconds with complete delta risk in under 1 second! No need to understand the full C++ hierarchy - we simply identify the inputs and outputs and let AADC handle everything in between.

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."

The Challenge with Open Risk Engine (ORE)

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. This case study demonstrates how we can transform ORE into a streamlined LiveRisk service for basic FX linear products using AADC without extensive refactoring.

When working with ORE/QuantLib, development teams often face a steep learning curve:

  • Complex C++ class hierarchies - Deep inheritance structures requiring intimate knowledge
  • Intricate XML configuration requirements - Elaborate setup files for market data and trades
  • Elaborate initialization sequences - Precise order of object creation and dependencies
  • Interconnected objects that must be precisely orchestrated for proper functioning

Our goal is simple: 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).

Finding the Input/Output Points in ORE

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.

After investigation, we found that market data enters through CSVLoader::loadFile with this simple pattern:

const string key = tokens[1];
Real value = parseReal(tokens[2]);
Market data entry point in ORE CSVLoader

This is where we hook into AADC by marking these values as inputs:

if (idouble::isRecording()) {
    auto aadc_arg = value.markAsInput();
    AADCKernelInputOutputRegistryInstance().inputs.push_back((key, aadc_arg));
    AADCKernelInputOutputRegistryInstance().input_values.push_back(value.val);
}
Hooking AADC inputs at market data entry point

For outputs, the ReportWriter::writeNpv method provides access to trade NPVs:

Real npv = trade->instrument()->NPV();
NPV output extraction point

Which we mark as outputs for AADC:

auto npv_res = (npv * fx).markAsOutput();
AADCKernelInputOutputRegistryInstance().outputs.push_back((trade->id(), npv_res));
Marking NPVs as AADC outputs for automatic differentiation

Handling Control Flow Branches for Clean AAD Recording

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.

In our ORE setup, AADC's diagnostics toolkit identified a potential 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)); 
    // ...
}
Original rounding operator with problematic branch

To resolve this branch handling issue, we modified the method to bypass rounding when running under AADC:

if (idouble::isRecording()) return value;
Simple fix: bypass rounding during AADC recording

After these changes, the AADC diagnostics report confirms clean recording:

Number active to passive conversions: 0 while recording OREApp::run()
AADC diagnostics confirming clean computational graph

The complete implementation code with detailed comments is available in our downloadable PDF documentation and Jupyter notebook.

Performance Results: 100x Faster ORE with AADC

We tested the LiveRisk solution with 1 million randomly generated FX linear trades (forwards and swaps):

Operation Time (seconds) 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
Table 1: ORE Performance Comparison - 1 Million FX Trades

Key Performance Insights:

  • 245x faster NPV calculation after one-time recording (0.4s vs 98s)
  • Sub-second complete risk - NPV plus all delta sensitivities in <1 second
  • Recording overhead amortized - 350s one-time cost pays off after just 4 market updates
  • Intraday viability - sub-second updates enable true LiveRisk services
  • Machine precision - AADC delivers exact results, not approximations

The LiveRisk Approach: Practical Production Deployment

The beauty of this AADC-powered ORE transformation lies in its efficiency and flexibility for production use:

  1. Pre-market recording: Recording can be done before the trading day begins (350s one-time cost)
  2. Graph serialization: The computational graph can be serialized and cached for reuse
  3. Cloud deployment: The resulting AADC kernel can be deployed to a cloud API endpoint
  4. Intraday updates: Each market data update triggers rapid recalculation (<1 second)
  5. Instant sensitivities: You get both prices AND delta risks almost instantaneously
  6. Incremental recording: For new trades, only incremental recording is needed (not full re-record)
  7. Weight adjustment: For trade cancellations, weight parameters can be adjusted without re-recording
  8. Delta ladders: AVX2 vectorization enables parallel what-if scenarios and risk ladder calculations

Beyond ORE/QuantLib:

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.

Transform Your ORE/QuantLib Implementation

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.