Case Study

ORE LiveRisk Case Study: 100x Faster

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

Executive Summary

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!

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`:

Original:
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:

Original:
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 (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

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 under 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:

1. Pre-market Recording

Done before trading day begins

  • 350s one-time recording cost
  • Executed before market open
  • Full computational graph captured
  • No impact on trading hours

2. Graph Serialization

Cache and reuse compiled graph

  • Serialize computational graph
  • Cache for rapid redeployment
  • No re-recording needed
  • Version control friendly

3. Cloud Deployment

Deploy AADC kernel to API

  • Deploy to cloud API endpoint
  • Scalable infrastructure
  • High availability setup
  • Load balancing support

4. Intraday Updates

Rapid recalculation on market moves

  • Sub-second recalculation
  • Each market data update
  • Prices AND sensitivities
  • Real-time risk view

5. Incremental Recording

Handle new trades efficiently

  • New trades: incremental recording only
  • No full re-record needed
  • Fast trade onboarding
  • Maintains performance

6. Weight Adjustment

Trade cancellations without re-recording

  • Adjust weight parameters
  • No re-recording required
  • Instant portfolio updates
  • Efficient trade management

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.

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