MatLogica | ORE LiveRisk Case Study: 100x Faster with AADC

ORE LiveRisk Case Study: 100x Faster with AADC

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

by Dmitri Goloubentsev, CEO MatLogica

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.

Not Approximation - Machine Precision

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)

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.

Code Complexity

  • Complex C++ class hierarchies - Deep inheritance structures requiring intimate knowledge
  • Template metaprogramming - Advanced C++ patterns throughout
  • Interconnected objects that must be precisely orchestrated

Configuration Burden

  • Intricate XML configuration requirements - Elaborate setup files for market data and trades
  • Elaborate initialization sequences - Precise order of object creation and dependencies
  • Hundreds of lines of setup code just to create TodaysMarket

Our Simple Goal

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

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.

Input Point: Market Data Entry

Market data enters through CSVLoader::loadFile:

const string key = tokens[1];
Real value = parseReal(tokens[2]);

Hook with AADC:

if (idouble::isRecording()) {
    auto aadc_arg = value.markAsInput();
    AADCKernelInputOutputRegistry
        Instance().inputs.push_back(
            (key, aadc_arg));
}

Output Point: NPV Extraction

The ReportWriter::writeNpv provides access to trade NPVs:

Real npv = trade->instrument()
    ->NPV();

Mark as AADC outputs:

auto npv_res = (npv * fx)
    .markAsOutput();
AADCKernelInputOutputRegistry
    Instance().outputs.push_back(
        (trade->id(), npv_res));

Handling Control Flow Branches

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.

Problem Identified

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)); 
    // ...
}
Simple Solution

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()

Performance Results: 100x Faster ORE with AADC

Testing 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
  • Production ready - Kernel can be serialized, cached, and deployed to cloud

The LiveRisk Approach

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:

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.

Additional AADC Capabilities for ORE

Advanced features for production risk systems

Delta Ladders

AVX2 vectorization enables parallel calculation of delta ladders and what-if scenarios across multiple market shifts simultaneously

Kernel Optimization

Generated machine code is optimized for your specific CPU architecture, maximizing performance on your hardware

Diagnostics Toolkit

AADC's diagnostic tools identify potential issues like control flow branches and active-to-passive conversions automatically

Learn More About AADC

Explore related resources and documentation

Three-phase process: Record computational graph once, JIT compile to optimized machine code, execute thousands of times with 6-1000x speedup.

Technical Findings
  • Near-instantaneous compilation (milliseconds)
  • Automatic vectorization (AVX2/AVX512)
  • Automatic multi-threading
  • Eliminates interpreter overhead

In-depth explanation of the compiler technology and optimization techniques that make MatLogica AADC significantly faster than traditional AAD approaches.

See how our clients transformed their quant libraries

Technical Findings
  • Revolutionary adjoint factor <1 achievement
  • 6-1000x performance improvements
  • Minimal code changes required
  • Production-proven at major banks

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.

100x Faster

0.4 seconds for 1M FX trades

Black Box Approach

No C++ hierarchy knowledge needed

Machine Precision

Exact results, not approximations

Complete code with detailed comments available in downloadable PDF and Jupyter notebook