TensorQuantLib Documentation¶
TensorQuantLib is a comprehensive quantitative finance library with tensor-train compression, automatic differentiation, and stochastic models — built from scratch with NumPy and SciPy. 150+ public functions covering derivatives pricing, risk management, and portfolio analysis.
Contents
- Quickstart
- Installation
- Your First Surrogate
- Pricer Decision Guide
- Autodiff Greeks
- Second-Order Greeks
- Heston Stochastic Volatility
- American Options
- Implied Volatility
- Exotic Options
- Volatility Surface Models
- Interest Rate Models
- FX Options
- Credit Risk
- Jump-Diffusion Models
- IR Derivatives
- Variance Reduction
- Risk Metrics
- TT Compression
- CLI
- Performance & Production Guide
- At-a-Glance Latency Table
- Choosing the Right Pricer
- Batch / Vectorised Pricing
- TT-Rank and
n_pointsTuning - Heston Calibration: From 10 s to < 2 s
- Memory Profiling
- Monte Carlo Variance Reduction: Which Method When
- Parallelism: Pricing a Large Portfolio
- Production Configuration Checklist
- Interpreting
print_summary()Output - Profiling Your Own Workflow
- API Reference
- Theory & Background
- Tensor-Train Decomposition
- Reverse-Mode Automatic Differentiation
- Black-Scholes Model
- Heston Stochastic Volatility
- American Options — Longstaff-Schwartz
- Basket Options & Moment Matching
- SABR Model
- SVI Parameterization
- Vasicek Short-Rate Model
- CIR Model
- Merton Structural Credit Model
- Garman-Kohlhagen FX Model
- Merton Jump-Diffusion
- Black-76 for IR Derivatives
- Surrogate Pricing
- References
- Known Limitations
- Changelog
Note
Quant traders / fintech engineers: see the Performance & Production Guide guide for latency tables, Heston calibration speedups, TT-rank tuning, and the production configuration checklist.
Researchers: the Theory & Background page has full mathematical derivations for every model.
Quick Overview¶
from tensorquantlib import TTSurrogate
# Build a 3-asset basket option surrogate
surr = TTSurrogate.from_basket_analytic(
S0_ranges=[(80, 120)] * 3,
K=100, T=1.0, r=0.05,
sigma=[0.2, 0.25, 0.3],
weights=[1/3, 1/3, 1/3],
n_points=30,
)
surr.print_summary()
# Evaluate the surrogate — ~5 microseconds per eval
# (100-1000× faster than re-running Monte Carlo for repeated evals)
price = surr.evaluate([100.0, 100.0, 100.0])
greeks = surr.greeks([100.0, 100.0, 100.0])
Features¶
Reverse-mode autodiff: Tensor class with 23+ differentiable ops
Second-order autodiff: Hessians, HVPs, Gamma/Vanna/Volga
Black-Scholes engine: pricing + all analytical Greeks
Heston stochastic volatility: semi-analytic CF, QE Monte Carlo, calibration
American options: Longstaff-Schwartz LSM with exercise boundary
Exotic options: Asian, Digital, Barrier (8 types), Lookback, Cliquet, Rainbow
Volatility surface: SABR (Hagan 2002), SVI (Gatheral 2004) with calibration
Interest rates: Vasicek, CIR, Nelson-Siegel, yield curve bootstrapping
FX options: Garman-Kohlhagen, FX Greeks, forwards, quanto
Credit risk: Merton structural model, CDS pricing, hazard rates
Jump-diffusion: Merton jump-diffusion, Kou double-exponential
Local volatility: Dupire local vol, local vol Monte Carlo
IR derivatives: Black-76 caps/floors, swaptions, swap rate
Variance reduction: antithetic, control variate, QMC, importance sampling, stratified
Risk metrics: VaR (parametric/historical/MC), CVaR, scenario analysis
Backtesting: engine, strategies, performance metrics (Sharpe, Sortino, Calmar)
TT compression: TT-SVD, TT-cross, rounding, arithmetic, surrogate pricing
Basket options: correlated GBM Monte Carlo, analytic moment-matching
Visualization: pricing surfaces, Greek surfaces, TT-rank charts
CLI:
python -m tensorquantlib— info, price, greeks, demo