MatLogica | Code Generation AAD

Code Generation AAD

Code Generation AAD™: The Only Practical Solution

Combine ease of integration with high performance. AADC delivers adjoint factor <1, meaning your original function plus all derivatives compute faster than the original function alone.

The AAD Dilemma

Automatic Adjoint Differentiation (AAD) is highly desired by practitioners in finance and beyond. However, traditional approaches force you to choose:

Traditional AAD Approaches:

  • Complex and time-demanding integration - adding templates
  • Greek Performance - ~4x slower than original function but all sensitivities are computed
  • Accelerate Original Model - not available

Code Generation AAD™ - Get All Three:

  • ✓ Easy Integration: Operator overloading, no code refactoring
  • ✓ Fast Performance: 20-50x speedup, adjoint factor <1
  • ✓ Accelerates Original Function: MatLogica's optimised binary kernel is used for repetitive calculations

Code Generation AAD™ uses code generation and operator overloading to efficiently compute gradients by generating optimized machine code (kernels) at runtime. This results in faster computing of the model and its first and higher-order derivatives.

The approach is particularly useful for models with many parameters requiring frequent gradient updates, Monte Carlo simulations, and real-time risk calculations.

Read our detailed overview of AAD approaches here.

MatLogica's AADC: Practical Code Generation AAD

AADC Compiler

MatLogica has developed a specialized runtime compiler, AADC (AAD Compiler), that generates efficient binary kernels for execution of the original and adjoint functions on the fly.

Due to native CPU vectorization (AVX2/AVX512) and safe multithreading, AADC can speed up the AAD method itself and deliver pricing and scenario analysis simply and effectively, in a way that is unattainable with competing products.

Key Advantage: AADC enables efficient AAD calculations in legacy code without major refactoring, introduction of templates, or constraining control flow.

AADC Code Generation AAD Architecture

Second-Order Greeks

Gamma, cross-gamma, vanna, volga computed using bump-and-revalue of first-order AAD Greeks. Far more stable than double-bumping price, faster than alternatives.

Adjoint Factor <1

Using AADC, the original function and all its derivatives compute faster than the original function alone. This is unique to Code Generation AAD with JIT compilation.

Faster Simulations

Any types of simulations (what-if, stress test, backtesting, VaR, Monte Carlo) can be supercharged seamlessly with 20-50x speedup.

Debugging & Checkpointing

Our debugging and checkpointing toolkit makes integration and troubleshooting simpler, providing visibility into computational flow.

Code Simplification

MatLogica AADC acts as an abstraction layer between your business logic and hardware, optimizing for AVX2/AVX512 and multi-core automatically.

Benefits of MatLogica AADC Code Generation

Practice: AADC's Specialized JIT Compiler

For a practical Code Generation approach, not limited to synthetic benchmarks, a specialized Just-In-Time Compiler is essential.

Why AADC's JIT Compiler Is Different

Standard Compilers (LLVM, C++, etc.)
  • Optimized for compile-once, run-many-times scenarios
  • Compilation minutes - and sometimes hours
  • Too slow for runtime code generation
  • Not practical for changing portfolios or intraday pricing
AADC JIT Compiler
  • Optimized for runtime compilation - milliseconds to seconds
  • Direct machine code generation - no intermediate representations
  • Fast enough for practical use - new trades, portfolio changes
  • Maintains full optimization - AVX2/AVX512, multithreading, efficient memory use

No Functional Limitations

MatLogica AADC does not introduce limits on functionality such as branching, enabling smooth integration without loss of numerical precision or trade-offs in functionality or usability.

Key features supported:

  • Complex control flow (if/else, loops, recursion)
  • Function calls and callbacks
  • External library calls
  • Existing code patterns without refactoring
AADC Just-In-Time Compilation

Practice: AADC Just-In-Time Compilation

Code Generation AAD vs Other Approaches

Characteristic Tape-Based AAD Source Transformation Code Generation (AADC)
Integration Ease Hard - templates usually required Difficult (code rewrite) ✓ Easy (operator overloading)
Adjoint Factor 2-5x ~2x ✓ <1x< /span>
Speeding up Simulations No No ✓ Yes (20-50x faster)
Memory Overhead High (tape storage) Low ✓ Low
Control Flow Limited Full support ✓ Full support
Vectorization Difficult Possible ✓ Automatic (AVX2/512)
Multi-threading Difficult Manual ✓ Automatic (thread-safe)

When to Use Code Generation AAD

Ideal For:

  • Monte Carlo simulations: Especially those with continuous mathematical operations
  • Real-time risk systems (Live Risk)
  • Stress testing and scenario analysis
  • XVA calculations
  • Model calibration, curve construction
  • Quantitative finance models: Option pricing, risk calculations, portfolio optimization
  • Machine learning: Gradient-based optimization, neural network training
  • Analytical functions: Problems dominated by continuous mathematical expressions
  • Legacy code modernization: Improving and accelerating complex legacy analytics code, with AADC successfully applied to multi-million line of code projects
  • Fast prototyping or developing new quant systems

Consider Alternatives If:

  • Single-shot calculations with no sensitivities and no repeated runs
  • Building LLMs or other models with simple maths
  • Extremely simple models (no vectorization benefit)
  • Heavily branching algorithms: Code with extensive conditional logic based on computed values
  • Discrete state models: Algorithms that rely on complex discrete decision trees
  • String processing or symbolic computation: Non-numerical operations
  • Database operations or I/O intensive tasks: Operations outside mathematical computation

Note: For most production financial applications, Code Generation AAD is the optimal choice.

Experience Adjoint Factor <1

See how AADC delivers original function plus all derivatives faster than the original alone

Request Benchmark

info@matlogica.com

Related topics: code generation AAD vs tape-based, adjoint factor less than 1, JIT compiler automatic differentiation, operator overloading AAD, second-order Greeks bump-and-revalue, AVX2 AVX512 vectorization AAD, thread-safe automatic differentiation, runtime code generation AAD, binary kernel generation AAD, legacy code AAD integration, Monte Carlo Greeks acceleration