quantlib_rs 0.1.0

A ground-up, idiomatic Rust quantitative finance library inspired by QuantLib.
Documentation

quantlib_rs

CI Crates.io Documentation License

A ground-up, idiomatic Rust quantitative finance library inspired by QuantLib.


Why quantlib_rs?

For over two decades, QuantLib has been the gold standard open-source library for quantitative finance modeling, trading, and risk management. However, its C++ architecture relies heavily on an Observer/Observable/Handle pattern that creates a mutable, cyclic object graph. In practice, this makes thread safety, parallel portfolio evaluation, and multi-core curve calibration notoriously difficult.

quantlib_rs is built from first principles in safe Rust to provide:

  1. Fearless Concurrency (Send + Sync): Designed from day one for multi-threaded pricing, calibration, and scenario analysis without mutex contention or borrow panics.
  2. Generational Handles & Immutable Snapshots: An arena/generational-index architecture instead of cyclic pointers, preventing memory leaks and dangling references.
  3. Exact Greeks via Automatic Differentiation: Forward-mode dual and hyper-dual numbers compute machine-precision Greeks ($\Delta, \Gamma, \mathcal{V}, \Theta, \rho$) in a single pass without step-size tuning or truncation error.
  4. Zero unsafe: Built under #![deny(unsafe_code)].
  5. Multi-Oracle Verification: Every numerical routine is cross-verified against multiple independent oracles (analytic formulas, put-call parity, Monte Carlo convergence, and QuantLib C++ published test cases).

Prior Art & Landscape

We build upon the collective wisdom of the Rust quantitative finance ecosystem:

Project Focus & Architecture Differentiator vs quantlib_rs
RustQuant Broad general-purpose quant crate (autodiff, ML, basic options) Generalist toolkit; not structured around term structures, schedules, and instrument/engine separation.
libitofin Methodical ground-up port of QuantLib following its layered L1–L11 architecture Directly uses QuantLib C++ test-suite as oracle; our architecture focuses on generational arenas, thread-safe snapshots, and forward-mode hyper-dual Greeks.
quantrs Lean derivatives pricing library focused on speed benchmarks Targeted primarily on options benchmarking; quantlib_rs aims for comprehensive institutional time, schedule, term structure, and instrument infrastructure.

Quickstart

Add quantlib_rs to your Cargo.toml:

[dependencies]
quantlib_rs = "0.1"

Price a European option and compute exact automatic differentiation Greeks:

use quantlib_rs::prelude::*;

fn main() -> Result<(), Box<dyn std::error::Error>> {
    let today = Date::from_ymd(2026, Month::September, 3)?;
    let maturity = Date::from_ymd(2027, Month::September, 3)?;

    let spot = 100.0;
    let strike = 100.0;
    let rate = 0.05;
    let div = 0.02;
    let vol = 0.20;

    let process = GeneralizedBlackScholesProcess::new(spot, rate, div, vol, today);
    let option = EuropeanOption::new(OptionType::Call, strike, maturity);
    let engine = AnalyticEuropeanEngine::new(process);

    let npv = engine.calculate(&option)?;
    let greeks = engine.calculate_greeks(&option)?;

    println!("Call NPV: {:.4}", npv);
    println!("Delta: {:.4}, Gamma: {:.4}, Vega: {:.4}", greeks.delta, greeks.gamma, greeks.vega);
    Ok(())
}

Current Scope & Status

quantlib_rs is in active early development:

  • Phase 0 — Foundation:
    • Date: Proleptic Gregorian calendar with $O(1)$ serial arithmetic and leap year logic.
    • Calendar: Trait, NullCalendar, WeekendsOnly, and UnitedStates (Federal and NYSE financial holidays).
    • DayCounter: Actual/360, Actual/365Fixed, Actual/Actual (ISDA), Thirty/360 (Bond Basis).
    • Schedule: Forward, backward, and coupon schedule generator.
    • Math: Linear interpolation, natural cubic splines ($C^2$ continuous), bisection and Newton-Raphson solvers, standard normal CDF/PDF and Peter Acklam inverse CDF.
  • Phase 1 — Vertical Slice (Options & Greeks):
    • Quote & MarketStore with generational indices and revision tracking.
    • FlatForward yield curve and BlackConstantVol volatility structure.
    • GeneralizedBlackScholesProcess.
    • EuropeanOption instrument and AnalyticEuropeanEngine.
    • Exact AD Greeks (Dual64, HyperDual64) and finite-difference bumps.
    • Multi-oracle verification tests (Hull reference, QuantLib C++ suite, put-call parity, Monte Carlo).
  • Phase 2 — Fixed Income Deep Vertical:
    • CashFlow trait, SimpleCashFlow, FixedRateCoupon with exact day count accruals, and Leg.
    • PiecewiseYieldCurve bootstrapped from money market deposits and par vanilla swaps with log-linear discount interpolation.
    • FixedRateBond and ZeroCouponBond with clean/dirty price conversion, accrued interest, and Yield to Maturity (YTM solver).
    • Bond Risk Analytics: Macaulay Duration, Modified Duration, Convexity, and DV01 / PV01.
    • VanillaSwap (fixed vs floating leg) with DiscountingSwapEngine supporting single-curve and modern dual-curve pricing and fair swap rate calculation.
    • Multi-oracle verification tests (Fabozzi 10th ed. textbook benchmarks, par bond and par swap model-free identities, and QuantLib C++ test-suite references).

See ROADMAP.md for future phases.


Contributing

We welcome contributions! Please see CONTRIBUTING.md and our CODE_OF_CONDUCT.md.


License

Dual-licensed under either:

at your option.