quantlib_rs
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:
- Fearless Concurrency (
Send + Sync): Designed from day one for multi-threaded pricing, calibration, and scenario analysis without mutex contention or borrow panics. - Generational Handles & Immutable Snapshots: An arena/generational-index architecture instead of cyclic pointers, preventing memory leaks and dangling references.
- 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.
- Zero
unsafe: Built under#![deny(unsafe_code)]. - 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:
[]
= "0.1"
Price a European option and compute exact automatic differentiation Greeks:
use *;
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, andUnitedStates(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&MarketStorewith generational indices and revision tracking.FlatForwardyield curve andBlackConstantVolvolatility structure.GeneralizedBlackScholesProcess.EuropeanOptioninstrument andAnalyticEuropeanEngine.- 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:
CashFlowtrait,SimpleCashFlow,FixedRateCouponwith exact day count accruals, andLeg.PiecewiseYieldCurvebootstrapped from money market deposits and par vanilla swaps with log-linear discount interpolation.FixedRateBondandZeroCouponBondwith 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) withDiscountingSwapEnginesupporting 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:
- Apache License, Version 2.0 (LICENSE-APACHE or http://www.apache.org/licenses/LICENSE-2.0)
- MIT license (LICENSE-MIT or http://opensource.org/licenses/MIT)
at your option.