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.

y(t,T)=−log⁡P(t,T)T−t,P(t,T)=EQ ⁣[exp⁡(−∫tTrs ds)∣rt].y(t,T)=-\frac{\log P(t,T)}{T-t},\qquad P(t,T)=\mathbb E^{\mathbb Q}\!\left[\exp\left(-\int_t^T r_s\,ds\right)\mid r_t\right].

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, κ>0\kappa>0 measures the speed of mean reversion, θ\theta is the long-run level of the short rate, and σ\sigma controls the size of shocks.

drt=κ(θ−rt) dt+σ dWtQ.dr_t=\kappa(\theta-r_t)\,dt+\sigma\,dW_t^{\mathbb Q}.

Apply Itô’s product rule to eκt(rt−θ)e^{\kappa t}(r_t-\theta). The drift cancels, leaving a deterministic weight on the Brownian increment. Integrating gives the exact solution and makes the conditional mean and variance explicit.

rt+h=θ+(rt−θ)e−κh+σ∫tt+he−κ(t+h−u) dWu.r_{t+h}=\theta+(r_t-\theta)e^{-\kappa h}+\sigma\int_t^{t+h}e^{-\kappa(t+h-u)}\,dW_u.

mh=θ+(rt−θ)e−κh,qh=σ22κ(1−e−2κh).m_h=\theta+(r_t-\theta)e^{-\kappa h},\qquad q_h=\frac{\sigma^2}{2\kappa}(1-e^{-2\kappa h}).

The mean deviation halves after log⁡(2)/κ\log(2)/\kappa years. At very long horizons the distribution approaches N(θ,σ2/(2κ))\mathcal N(\theta,\sigma^2/(2\kappa)). As κ\kappa approaches zero with θ\theta fixed, the finite-horizon variance approaches σ2h\sigma^2 h.

Bond pricing from the integrated rate

Let τ=T−t\tau=T-t and B(τ)=(1−e−κτ)/κB(\tau)=(1-e^{-\kappa\tau})/\kappa. Integrating the SDE solution and exchanging the time and Brownian integrals under the square-integrable kernel gives:

I=∫tTrs ds=θτ+(rt−θ)B(τ)+σκ∫tT(1−e−κ(T−u)) dWu.I=\int_t^T r_s\,ds=\theta\tau+(r_t-\theta)B(\tau)+\frac{\sigma}{\kappa}\int_t^T(1-e^{-\kappa(T-u)})\,dW_u.

By Itô isometry, the stochastic integral is normal with zero mean and the following variance. The normal moment-generating function gives the bond price.

vI=σ2κ2[τ−2B(τ)+1−e−2κτ2κ],P(t,T)=e−E[I]+vI/2.v_I=\frac{\sigma^2}{\kappa^2}\left[\tau-2B(\tau)+\frac{1-e^{-2\kappa\tau}}{2\kappa}\right],\qquad P(t,T)=e^{-\mathbb E[I]+v_I/2}.

This has the affine form A(τ)e−B(τ)rtA(\tau)e^{-B(\tau)r_t}. A one-basis-point rise in the short rate changes log price by approximately −10−4B(τ)-10^{-4}B(\tau). 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-12

Historical estimation versus market calibration

Sample a historical proxy at equally spaced intervals of hh years. The physical-measure transition is ri+1=c+ϕri+εir_{i+1}=c+\phi r_i+\varepsilon_i with independent Gaussian innovations of variance qq. For this specification, ordinary least squares gives the unrestricted conditional maximum-likelihood coefficients, and the innovation variance uses the mean squared residual.

κ=−log⁡ϕh,θ=c1−ϕ,σ=2κq1−ϕ2.\kappa=-\frac{\log\phi}{h},\qquad \theta=\frac{c}{1-\phi},\qquad \sigma=\sqrt{\frac{2\kappa q}{1-\phi^2}}.

A slope outside (0,1)(0,1) 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 ∑iwi[Pmodel(0,Ti)−Pmarket(0,Ti)]2\sum_i w_i[P_{\text{model}}(0,T_i)-P_{\text{market}}(0,T_i)]^2. 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 e−Ie^{-I} 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.

Sources