Quantij quantitative finance education and research
Vasicek Model: Mean Reversion, Bond Pricing and Calibration
Derive the Vasicek short-rate model, price discount bonds, and estimate its parameters in Python.
Published 27 November 2026 · 18 min read
What the short rate does
A discount bond pays one unit at maturity. A two-year bond priced at 0.90 has a continuously compounded yield of about 5.27%. Its yield is a single number that reproduces its discount factor; the short rate is the instantaneous discounting rate along a future path.
Price promised cash flows by multiplying each payment by the discount bond price for its date. This article uses decimal rates, continuously compounded yields and time measured in years.
Mean reversion and the SDE
Under the pricing measure, measures the speed of mean reversion, is the long-run level of the short rate, and controls the size of shocks.
Apply Itô’s product rule to . The drift cancels, leaving a deterministic weight on the Brownian increment. Integrating gives the exact solution and makes the conditional mean and variance explicit.
The mean deviation halves after years. At very long horizons the distribution approaches . As approaches zero with fixed, the finite-horizon variance approaches .
Bond pricing from the integrated rate
Let and . Integrating the SDE solution and exchanging the time and Brownian integrals under the square-integrable kernel gives:
By Itô isometry, the stochastic integral is normal with zero mean and the following variance. The normal moment-generating function gives the bond price.
This has the affine form . A one-basis-point rise in the short rate changes log price by approximately . This is a model-state sensitivity and differs from bumping the entire market curve.
The implementation below tests maturity and the constant-rate limit. For very small mean reversion times maturity, use a series expansion or integrate the squared kernel numerically to avoid cancellation in the variance.
from math import exp, expm1
def bond(r, tau, kappa, theta, sigma):
if tau < 0 or kappa <= 0 or sigma < 0:
raise ValueError("Invalid maturity or model parameters")
b = -expm1(-kappa * tau) / kappa
mean = theta*tau + (r-theta)*b
var = (sigma/kappa)**2 * (tau-2*b-expm1(-2*kappa*tau)/(2*kappa))
return exp(-mean + max(var, 0)/2)
assert bond(.04, 0, .3, .04, .01) == 1
assert abs(bond(.04, 5, .3, .04, 0) - exp(-.2)) < 1e-12Historical estimation versus market calibration
Sample a historical proxy at equally spaced intervals of years. The physical-measure transition is with independent Gaussian innovations of variance . For this specification, ordinary least squares gives the unrestricted conditional maximum-likelihood coefficients, and the innovation variance uses the mean squared residual.
A slope outside is incompatible with positive mean reversion. A slope near one makes the long-run level unstable. For irregular dates, use each observation’s own transition mean and variance in the likelihood. Short samples, rate regimes and the choice of historical proxy can dominate the estimates.
For pricing, estimate risk-neutral parameters against current market contracts. A market price of risk links physical and pricing dynamics. A good historical fit alone does not constrain option prices.
import numpy as np
def fit_history(rates, dt):
r = np.asarray(rates, dtype=float)
if r.ndim != 1 or r.size < 4 or dt <= 0 or not np.isfinite(r).all():
raise ValueError("Supply equally spaced rates and dt in years")
x = np.column_stack((np.ones(r.size-1), r[:-1]))
coef, _, rank, _ = np.linalg.lstsq(x, r[1:], rcond=None)
c, phi = coef
if rank != 2 or not 0 < phi < 1:
raise ValueError("Revisit the sample or use a constrained fit")
kappa = -np.log(phi)/dt
q = np.mean((r[1:]-x@coef)**2)
return kappa, c/(1-phi), np.sqrt(2*kappa*q/(1-phi**2))Calibrate a Vasicek curve in Python
With the starting short rate fixed, minimise . A practical workflow uses several starting points, price or bid–ask weights, and a maturity-by-maturity residual report. Adding option prices helps identify volatility. The synthetic example only checks that the optimiser recovers prices generated by the same model.
Run this after the bond function. Report residuals even when the optimiser declares success. A real curve will rarely fit as closely as synthetic data.
from scipy.optimize import least_squares
import numpy as np
tenors = np.array([.25, .5, 1, 2, 5, 10, 20])
r0 = .035
observed = np.array([bond(r0, t, .4, .05, .012) for t in tenors])
def residual(params):
model = np.array([bond(r0, t, *params) for t in tenors])
return 1e4 * (model - observed)
fit = least_squares(residual, [.25, .045, .015],
bounds=([.005, -.10, 0], [5, .20, .10]))
assert fit.success and np.max(np.abs(fit.fun)) < .01
print(fit.x, fit.fun)Simulate rates and verify a pricing identity
Simulate the exact Gaussian transition on each step. For discounting, even exact grid-point rates still require integrating the path. A trapezoid approximation should converge as you halve the step. Check that the mean of agrees with the analytic bond price within Monte Carlo error. For an exact one-step discount factor, sample the normally distributed integral using the mean and variance above; for a multi-step joint simulation, preserve its covariance with the ending short rate.
Separate sampling error from discretisation error. Increasing the path count shrinks the first, while refining the time grid shrinks the second.
Limits of the model
Gaussian shocks permit negative rates. A single factor restricts how yields across maturities move together. Constant coefficients generally cannot reproduce every point of an observed starting curve. Hull–White keeps the Gaussian dynamics and adds a deterministic shift to fit that curve.