Skip to content

Repository files navigation

DAL - Derivatives Algorithms Library

CMake Linux CI CMake Windows CI Codacy Grade Coverage Status

A C++17 quantitative finance library with built-in Automatic Adjoint Differentiation (AAD). Features include yield curve construction, cross-currency pricing and calibration, Monte Carlo simulation, finite difference PDE solvers, a scripting engine for exotic payoffs with tree-walk and compiled evaluators, and parallel model evaluation.

CI

Pull requests with source, configuration, or build changes build and test the full compiler × AAD-backend matrix below. Documentation-only changes run the documentation integrity check and stable Linux/Windows gates without starting the compile, sanitizer, or benchmark jobs. Pushes to master (merges and direct master pushes) run a lean GCC 14 + Clang 20 subset across all four backends, because the pull request already covered every combination. GitHub publishes one status badge per workflow; open a workflow run for per-job results.

Platform Compiler AADet XAD CoDiPack Adept
Ubuntu (ubuntu-latest) GCC 13
Ubuntu (ubuntu-latest) GCC 14
Ubuntu (ubuntu-latest) GCC 15
Ubuntu (ubuntu-latest) Clang 18
Ubuntu (ubuntu-latest) Clang 19
Ubuntu (ubuntu-latest) Clang 20
Windows (windows-latest) MSVC
  • The GCC 14 + AADet leg additionally runs gcov coverage, tracked by Coveralls.
  • Windows legs additionally build the dal-python bindings and the dal-excel add-in.
  • Separate Linux jobs cover CoDiPack thread isolation, Python bindings with generated-source verification, documentation integrity, a warning-clean build, ASan/UBSan/TSan spot tests, and benchmark regression gating.

Quick Start

git clone --recursive git@github.com:wegamekinglc/Derivatives-Algorithms-Lib.git
cd Derivatives-Algorithms-Lib
bash build_linux.sh

The Linux default builds/tests core and public C++ and stages the install under build/stage/Release-linux; use --full for Python plus benchmarks. For the supported profiles, Windows workflow, Python bindings, and troubleshooting, see the installation guide.

Architecture

dal-cpp (DAL::cpp)
  └─ dal-public (DAL::public)
       ├─ dal-python
       └─ dal-excel

The native dependency graph is dal-cpp ← dal-public ← {dal-python, dal-excel}. dal-public is a developer-facing convenience facade over core DAL types; it is not an ABI-isolated compatibility boundary.

Sub-project Purpose
dal-cpp/ Core library: math, curves, models, scripting, AAD
dal-public/ Public C++ convenience facade over DAL::cpp
dal-python/ pybind11 Python bindings
dal-excel/ Excel .xll add-in (Windows-only)

Core domains in dal-cpp/dal/:

  • math/ — Interpolation, optimization, PDE solvers, random numbers, matrix ops
  • math/aad/ — Automatic Adjoint Differentiation (native, XAD, Adept, CoDiPack backends)
  • curve/ — Yield curve construction, piecewise forward rates, calibration
  • script/ — Expression scripting engine for exotic payoffs, with tree-walk and compiled evaluation modes
  • model/ — Financial models (Black-Scholes, Dupire local volatility, etc.)
  • time/ — Dates, calendars, schedules, and day-count bases
  • protocol/, currency/, indice/ — Market/contract conventions, currency data, and index/fixing management
  • risk/ — Risk report types and aggregation
  • storage/ — Storable objects, archives, and repository integration
  • concurrency/ — Thread pool for parallel Monte Carlo
  • platform/, io/, string/, utilities/ — Infrastructure: configuration, host init, Excel I/O helpers, strings, dictionaries
  • auto/ — Machinist-generated enums and serialization (do not hand-edit)

Examples

Python

from dal import *

today = Date_(2022, 9, 15)
EvaluationDate_Set(today)

spot, vol, rate, div = 100.0, 0.15, 0.0, 0.0
strike = 120.0
maturity = Date_(2025, 9, 15)

events = [f"call pays MAX(spot() - {strike}, 0.0)"]
product = Product_New([maturity], events)
model = BSModelData_New(spot, vol, rate, div)

res = MonteCarlo_Value(
    product,
    model,
    2**20,
    method="sobol",
    enable_aad=True,
    compiled=True,
)
for k, v in res.items():
    print(f"{k:<8}: {v:>10.4f}")

Output:

PV      :     4.0389
d_div   :   -85.2290
d_rate  :    73.1011
d_spot  :     0.2838
d_vol   :    58.7140

More examples: Python, Excel, C++. The C++ Monte Carlo script examples show both tree-walk and compiled evaluator output where applicable.

Cross-currency examples:

Quote-space DV01 examples:

The quote-risk workflow freezes exact single-curve, joint-XCCY, or staged-XCCY- basis calibration provenance and aggregates true portfolio price-per-decimal quote sensitivity plus DV01. Fingerprints reject stale curve state, and results remain separated by actual PV currency without FX conversion.

Script Engine Modes

Monte Carlo script valuation defaults to the tree-walk evaluator (compiled=false). Pass compiled=True in Python or compiled=true in C++ to select the flat-stream evaluator. The compiled mode is a performance option; payoff values and AAD risks are expected to match tree-walk results up to normal floating-point noise.

For implementation details and parity coverage, see Script Engine methodology. To compare runtime locally, build and run the script_mc_perf benchmark target:

bash ./build_linux.sh --benchmarks
./build/Release-linux/dal-cpp/benchmarks/script_mc_perf/script_mc_perf

Script Product Debug Dumps

Script products dump three ways: the legacy s-expression listing (DebugScriptProduct in C++, Product_Debug in Python), a versioned JSON AST for machine consumers (DebugScriptProductJson / Product_DebugJson, schema dal.script-product/1), and a width-aware Unicode tree with an ASCII fallback (DebugScriptProductTree / Product_DebugTree). See Product Debug Outputs for the formats.

Excel

=PRODUCT.NEW("my_product", A2, B2)
=BSMODELDATA.NEW("model", 100, 0.15, 0.0, 0.0)
=MONTECARLO.VALUE(A5, C7, 2^20, "sobol", FALSE, TRUE, 0.01)

Web UI

The portfolio management web UI moved to its own repository: wegamekinglc/dal-web.

Documentation

Methodology notes (see the index above for the full list):

  • AAD — Automatic adjoint differentiation: expression templates, tape, propagation
  • Yield Curve and Yield-Curve Jacobian — discount curves, calibration, inverse-Jacobian transforms, and production quote-space DV01
  • Cross-Currency Pricing and Calibration — fixed, resettable, and MTM swaps; immutable fixing snapshots; staged basis and simultaneous domestic/foreign/basis calibration
  • Interpolation — linear, log-linear, cubic interpolators
  • PDE — PDE framework, grid construction, and coordinate maps
  • Script Engine — expression scripting, fuzzy AAD evaluation, and compiled evaluator parity
  • Random — random number generation and path construction
  • Black / Bachelier — vanilla option pricing
  • Matrix — matrix and linear algebra

License

MIT License — see LICENSE

References

  • Tom Hyer, Derivatives Algorithms: Volume 1: Bones (repo)
  • Antoine Savine, Modern Computational Finance: AAD and Parallel Simulations (repo)
  • Antoine Savine, Modern Computational Finance: Scripting for Derivatives and xVA (repo)
  • Brian Huge and Jesper Andreasen, Finite Difference Methods for Financial PDEs (repo)

About

AAD enabled and scripting included derivatives modeling.

Topics

Resources

Contributing

Stars

27 stars

Watchers

1 watching

Forks

Releases

Packages

Used by

Contributors

Languages