Theory & Background¶
This page gives a brief summary of the mathematical ideas behind TensorQuantLib. For full details see the references.
Tensor-Train Decomposition¶
A d-dimensional tensor \(\mathbf{T} \in \mathbb{R}^{n_1 \times \cdots \times n_d}\) is represented in Tensor-Train (TT) format as:
where each core \(G_k(i_k)\) is an \(r_{k-1} \times r_k\) matrix (with \(r_0 = r_d = 1\)). The integers \(r_k\) are the TT-ranks.
Storage: \(\sum_k r_{k-1} \, n_k \, r_k\) — linear in d for bounded ranks, compared to \(\prod_k n_k\) for the full tensor.
TT-SVD Algorithm¶
We use the TT-SVD algorithm (Oseledets, 2011):
Reshape the tensor into a matrix \((n_1, n_2 \cdots n_d)\).
Compute a truncated SVD; keep singular values above threshold.
The left factor becomes core \(G_1\); the right factor is reshaped and the process repeats for the remaining dimensions.
The tolerance parameter \(\varepsilon\) controls the trade-off between compression and accuracy.
TT Arithmetic¶
TT format supports closed-form arithmetic:
Addition: rank-additive (\(r_k^{A+B} = r_k^A + r_k^B\))
Hadamard product: rank-multiplicative (\(r_k^{A \circ B} = r_k^A \cdot r_k^B\))
Scaling: no rank increase
Inner product: \(O(d \, r^2 \, n)\) via transfer-matrix contraction
Use tt_round() after addition / Hadamard to compress ranks back down.
Reverse-Mode Automatic Differentiation¶
TensorQuantLib implements reverse-mode autodiff (back-propagation) via a tape-based computational graph:
Each
Tensoroperation records its inputs and a_backwardclosure.backward()performs a topological sort (DFS) of the graph, then traverses in reverse, accumulating gradients via the chain rule.Gradients are un-broadcast where necessary.
This gives exact first-order derivatives (Delta, Vega) of any pricing function built from the supported operations.
Second-Order Automatic Differentiation¶
Second-order Greeks are computed via a 4-point finite-difference stencil on the forward pricing function:
All three Greeks share the same 4 corner evaluations, making the combined computation more efficient than separate calls.
Black-Scholes Model¶
For a European option on a single asset with spot \(S\), strike \(K\), risk-free rate \(r\), time to maturity \(T\), and volatility \(\sigma\):
where \(\Phi\) is the standard normal CDF.
Greeks are the partial derivatives:
Delta = \(\Phi(d_1)\)
Gamma = \(\phi(d_1) / (S \sigma \sqrt{T})\)
Vega = \(S \phi(d_1) \sqrt{T}\)
Theta = \(-\frac{S \phi(d_1) \sigma}{2\sqrt{T}} - r K e^{-rT} \Phi(d_2)\)
Rho = \(K T e^{-rT} \Phi(d_2)\)
Heston Stochastic Volatility¶
The Heston (1993) model augments Black-Scholes with a mean-reverting variance process:
where \(\kappa\) is the mean-reversion speed, \(\theta\) the long-run variance, \(\xi\) the vol-of-vol, and \(\rho\) the correlation.
The Feller condition \(2\kappa\theta > \xi^2\) ensures the variance process stays strictly positive.
Semi-analytic pricing uses Gil-Pelaez inversion of the Heston characteristic function:
where \(P_j\) are computed via numerical integration of the characteristic function \(\phi_j(u)\).
Monte Carlo uses the Quadratic-Exponential (QE) scheme (Andersen, 2008) for efficient discretisation of the CIR variance path.
American Options — Longstaff-Schwartz¶
The Longstaff-Schwartz (2001) algorithm prices American options via least-squares Monte Carlo (LSM):
Simulate \(N\) paths of the underlying asset.
At each exercise date (backwards from maturity), regress the continuation value on polynomial basis functions of the spot price.
Exercise if the immediate payoff exceeds the estimated continuation value.
Discount and average to obtain the option price.
The exercise boundary is implicitly determined by the regression. The library uses Laguerre polynomials for the basis functions.
Basket Options & Moment Matching¶
A basket call on \(d\) assets with weights \(w_i\) pays \(\max\!\bigl(\sum_i w_i S_i^T - K, \; 0\bigr)\).
Monte Carlo: simulate correlated geometric Brownian motions:
where \(Z \sim \mathcal{N}(0, \Sigma)\) and \(\Sigma\) is the correlation matrix (Cholesky-factored for sampling).
Analytic approximation (Gentle, 1993): match the first two moments of the basket to a lognormal distribution, then apply the Black-Scholes formula with the matched parameters \(\mu_B, \sigma_B\).
SABR Model¶
The SABR model (Hagan et al., 2002) for the forward rate \(F\) and stochastic volatility \(\alpha\):
The Hagan (2002) asymptotic approximation gives an implied Black volatility \(\sigma_B(K, F)\) in closed form:
ATM (\(K = F\)):
SVI Parameterization¶
The SVI (Stochastic Volatility Inspired) raw parameterization (Gatheral, 2004) for total implied variance \(w(k)\) as a function of log-moneyness \(k = \ln(K/F)\):
where \(a, b, \rho, m, \sigma\) are the 5 SVI parameters. Implied volatility is \(\sigma_B = \sqrt{w(k) / T}\).
Vasicek Short-Rate Model¶
The Vasicek (1977) model for the short rate:
Zero-coupon bond price \(P(0, T)\):
CIR Model¶
The Cox-Ingersoll-Ross (1985) model:
The square-root diffusion ensures non-negative rates when the Feller condition \(2\kappa\theta > \sigma^2\) holds.
Bond pricing is analytic with expressions involving \(\gamma = \sqrt{\kappa^2 + 2\sigma^2}\).
Merton Structural Credit Model¶
The Merton (1974) model treats firm equity as a call option on assets:
where \(V\) is the firm asset value, \(D\) the debt face value, and \(\sigma_V\) the asset volatility.
The credit spread is derived as: \(s = -\frac{1}{T}\ln\!\left(\frac{B}{D e^{-rT}}\right)\) where \(B = D e^{-rT} - \text{Put}(V, D, T)\).
Garman-Kohlhagen FX Model¶
The Garman-Kohlhagen (1983) model extends Black-Scholes for FX options, treating the foreign risk-free rate \(r_f\) as a continuous dividend yield:
Merton Jump-Diffusion¶
The Merton (1976) model adds Poisson jumps to GBM:
where \(N \sim \text{Poisson}(\lambda T)\) and \(\ln(1 + J) \sim \mathcal{N}(\mu_j, \sigma_j^2)\).
The price is a weighted sum of Black-Scholes prices:
Black-76 for IR Derivatives¶
Interest rate caps, floors, and swaptions are priced using the Black (1976) formula applied to forward rates:
A cap is a portfolio of caplets; a floor is a portfolio of floorlets. Swaptions use the same formula with the forward swap rate as the underlying.
Surrogate Pricing¶
The TTSurrogate workflow:
Build a pricing grid over spot prices (one axis per asset).
Compress the grid using TT-SVD — achieving 10–1000× compression.
Evaluate prices at new points via multi-linear interpolation on the compressed TT cores, avoiding full grid reconstruction.
Compute Greeks via finite differences on the surrogate.
This enables real-time pricing of 3–5 asset options on a laptop.
References¶
Oseledets, Tensor-Train Decomposition, SIAM J. Sci. Comput., 2011.
Heston, A Closed-Form Solution for Options with Stochastic Volatility, RFS, 1993.
Andersen, Efficient Simulation of the Heston Stochastic Volatility Model, J. Comp. Fin., 2008.
Longstaff and E. S. Schwartz, Valuing American Options by Simulation, RFS, 2001.
Hagan et al., Managing Smile Risk, Wilmott Magazine, 2002.
Gatheral, A Parsimonious Arbitrage-Free Implied Volatility Parameterization (SVI), 2004.
Vasicek, An Equilibrium Characterization of the Term Structure, J. Fin. Econ., 1977.
Cox, J. E. Ingersoll, S. A. Ross, A Theory of the Term Structure of Interest Rates, Econometrica, 1985.
Merton, On the Pricing of Corporate Debt, J. Finance, 1974.
Merton, Option Pricing When Underlying Stock Returns Are Discontinuous, J. Fin. Econ., 1976.
Garman and S. W. Kohlhagen, Foreign Currency Option Values, J. Int. Money & Finance, 1983.
Black, The Pricing of Commodity Contracts, J. Fin. Econ., 1976.
Black and M. Scholes, The Pricing of Options and Corporate Liabilities, J. Pol. Econ., 1973.
Glasserman, Monte Carlo Methods in Financial Engineering, Springer, 2003.