Interpolation, Part 1: Flat, Linear & Cubic Methods#

Market data come at a few points, and a valuation needs the value in between. This page sets out the four methods that cover most of practice, in order of smoothness: flat (piecewise constant), linear, linear in a transformed variable, with variance and total variance as the case that matters for volatilities, and the cubic spline. Each has its formula, its error and its failure mode, and the cubic spline, the usual choice for a smooth curve, is set out in full: how it is built, what the boundary conditions do, how accurate it is, how far a change in one point is felt, and where it overshoots. It is the first of three pages on interpolation. Interpolation, Part 2: Extrapolation covers what happens beyond the data, and Interpolation, Part 3: Curves & Surfaces applies the methods to curves and surfaces.

Notation and what a method has to do#

The data are values \(y_0, \dots, y_n\) at nodes \(x_0 < x_1 < \dots < x_n\). Write \(h_i = x_{i+1} - x_i\) for the interval widths, \(\delta_i = (y_{i+1} - y_i)/h_i\) for the secant slopes, and for \(x_i \le x \le x_{i+1}\) write \(w = (x - x_i)/h_i\), which runs from 0 to 1 across the interval. An interpolant \(f\) passes through the data, \(f(x_i) = y_i\). Beyond that, a method is judged on:

  • Smoothness. Whether \(f\) is continuous (\(C^0\)), has a continuous slope (\(C^1\)) or a continuous curvature (\(C^2\)). A discontinuous slope in a discount curve is a jump in a forward rate.

  • Locality. How far a change in one data point is felt.

  • Shape preservation. Whether the interpolant stays within the range of the data, or overshoots.

  • Accuracy. How fast the error falls as the nodes are added, for smooth data.

Flat (piecewise constant)#

The value of one node is held until the next. With the previous (left-continuous) rule,

\[f(x) = y_i \quad \text{for } x_i \le x < x_{i+1}\]

The next rule takes \(y_{i+1}\), and nearest takes the closer of the two. The function jumps at the nodes, so it is not even continuous, and it never leaves the range of the data. It is the right choice when the quantity really is a step: a volatility that is constant between calibration expiries, as the \(\sigma(t)\) of the Hull-White model in Interest Rate Mean Reversion, Part 2: The Hull-White Model & Calibration, or a rate that applies from one fixing date to the next. As an approximation to a smooth function its error falls only in proportion to \(h\).

Linear#

A straight line between neighbouring points:

\[f(x) = y_i + \delta_i\,(x - x_i) = (1 - w)\,y_i + w\,y_{i+1}\]

It is continuous and local, and never leaves the range of the data. Its slope jumps at every node. For a function with a bounded second derivative the error is at most \(\tfrac{1}{8} h^2 \max|f''|\), so it falls with the square of the spacing. It is the default for a good reason, and the baseline for the other methods.

Linear in a transformed variable#

A method that is linear in a function \(g\) of the data gives

\[f(x) = g^{-1}\Big( (1 - w)\,g(y_i) + w\,g(y_{i+1}) \Big)\]

The choice of \(g\) changes the value between the nodes, and it changes it in a way that has financial meaning. The transformation \(g(y) = \ln y\) is log-linear interpolation, which for discount factors makes the forward rate constant between the pillars, and it is set out with the curves in Interpolation, Part 3: Curves & Surfaces. The one that matters for volatilities is the variance, \(g(\sigma) = \sigma^2\).

Linear in variance#

Interpolating a volatility \(\sigma\) linearly in its square, the variance, gives

\[f(x) = \sqrt{(1 - w)\,\sigma_i^2 + w\,\sigma_{i+1}^2}\]

Variances of independent increments add, so variance is the quantity that behaves linearly in the model, and a straight line in \(\sigma\) is not. In the expiry direction the quantity that adds is the total variance \(W(T) = \sigma(T)^2\,T\), and interpolating it linearly in \(T\) gives

\[W(T) = (1 - w)\,\sigma_i^2 T_i + w\,\sigma_{i+1}^2 T_{i+1}, \qquad \sigma(T) = \sqrt{W(T)/T}\]

Between two expiries the forward variance \((W_{i+1} - W_i)/(T_{i+1} - T_i)\) is then constant, which is the same as a piecewise constant forward volatility. It is also the form in which the calendar arbitrage condition is stated, since \(W\) must not fall with \(T\) (Interpolation, Part 3: Curves & Surfaces).

Cubic spline#

Definition. On each of the \(n\) intervals the spline is a cubic, which has four coefficients, so \(4n\) in all. The pieces pass through the data at both ends of each interval (\(2n\) conditions) and join with the same slope (\(n - 1\) conditions) and the same curvature (\(n - 1\) conditions) at the interior nodes. That is \(4n - 2\) conditions, so two more are needed, and they are the boundary conditions. The result is \(C^2\).

Construction. The second derivative of a cubic is a straight line, so on an interval it is fixed by its values \(M_i = f''(x_i)\) and \(M_{i+1}\) at the ends:

\[f''(x) = M_i \frac{x_{i+1} - x}{h_i} + M_{i+1} \frac{x - x_i}{h_i}\]

Integrating twice, and choosing the two constants so that \(f(x_i) = y_i\) and \(f(x_{i+1}) = y_{i+1}\), gives

\[f(x) = M_i \frac{(x_{i+1} - x)^3}{6 h_i} + M_{i+1} \frac{(x - x_i)^3}{6 h_i} + \left( \frac{y_i}{h_i} - \frac{M_i h_i}{6} \right)(x_{i+1} - x) + \left( \frac{y_{i+1}}{h_i} - \frac{M_{i+1} h_i}{6} \right)(x - x_i)\]

with slope

\[f'(x) = \frac{-M_i (x_{i+1} - x)^2 + M_{i+1} (x - x_i)^2}{2 h_i} + \delta_i - \frac{h_i}{6}\,(M_{i+1} - M_i)\]

The curvatures \(M_i\) are the only unknowns. Requiring the slope from the left and the right to agree at each interior node gives

\[h_{i-1} M_{i-1} + 2\,(h_{i-1} + h_i)\,M_i + h_i M_{i+1} = 6\,(\delta_i - \delta_{i-1}), \qquad i = 1, \dots, n-1\]

These are \(n - 1\) equations in \(n + 1\) unknowns. Written as a matrix, with the two boundary rows still to be chosen, the system is tridiagonal,

\[\begin{split}\begin{pmatrix} \ast & \ast & \ast & & \\ h_0 & 2(h_0 + h_1) & h_1 & & \\ & \ddots & \ddots & \ddots & \\ & & h_{n-2} & 2(h_{n-2} + h_{n-1}) & h_{n-1} \\ & & \ast & \ast & \ast \end{pmatrix} \begin{pmatrix} M_0 \\ M_1 \\ \vdots \\ M_{n-1} \\ M_n \end{pmatrix} = \begin{pmatrix} \ast \\ 6(\delta_1 - \delta_0) \\ \vdots \\ 6(\delta_{n-1} - \delta_{n-2}) \\ \ast \end{pmatrix}\end{split}\]

and the interior rows are diagonally dominant, so the solution exists and is unique, and the Thomas algorithm solves it in \(O(n)\) operations. The cost of fitting a spline is no more than a few passes through the data.

Boundary conditions. The starred rows are replaced by two of the following.

Boundary conditions#

Condition

First row (the last is the mirror image)

What it means

Natural

\(M_0 = 0\), \(M_n = 0\)

The curvature vanishes at the ends. The spline minimises \(\int (g'')^2\,dx\) over all smooth interpolants \(g\), the least bending energy

Clamped

\(2 h_0 M_0 + h_0 M_1 = 6\,(\delta_0 - s_0)\)

The end slopes \(f'(x_0) = s_0\) and \(f'(x_n) = s_n\) are given, so extra information is needed

Not-a-knot

\(h_1 M_0 - (h_0 + h_1)\,M_1 + h_0 M_2 = 0\)

The third derivative is continuous at \(x_1\) and \(x_{n-1}\), so the first two pieces are one cubic and so are the last two. It is the usual library default

Accuracy. For a function with a continuous fourth derivative, on a uniform grid with spacing \(h\), the clamped spline has an error of at most \(\tfrac{5}{384}\,h^4 \max|f^{(4)}|\), and the not-a-knot spline is of the same order, \(h^4\). The natural condition forces \(M_0 = 0\), which is wrong whenever the function has curvature at the end, and the error is then only \(h^2\) near the ends. The error spreads from the ends into the interior, with a decay that is geometric.

Locality. A cubic spline is not local, because the curvatures solve a linear system. For a uniform grid the interior equation is \(M_{i-1} + 4 M_i + M_{i+1} = 0\) away from the changed point, whose decaying solution is \(M_{i+1} = -(2 - \sqrt{3})\,M_i \approx -0.268\,M_i\). A change at one node is felt at every other, but it falls by a factor of 3.7 with each interval and changes sign. The effect on a non-uniform grid decays more slowly where the intervals are narrow compared with their neighbours.

Overshoot. The alternation of signs in the response to a single point is also the source of overshoot. Where the data change sharply, the spline swings past them on either side, and it does so by an amount that does not go to zero as the nodes are added.

The variable. A spline can be fitted to a rate or to a function of it. For a discount curve, a spline on the zero rate \(z(t)\) gives the forward rate \(f(t) = z(t) + t\,z'(t)\), and a spline on \(\ln D(t)\) gives \(f(t) = -\tfrac{d}{dt} \ln D(t)\). In both the forward rate is continuous, \(C^1\), where log-linear interpolation of the discount factor gives a forward rate that steps at every pillar.

Summary of the four methods#

Flat, linear and cubic#

Method

Smoothness

Local

Leaves the data range

Error for smooth data

Typical use

Flat

none (jumps in value)

yes

no

\(h\)

Step quantities, piecewise constant volatilities and rates

Linear

\(C^0\) (jumps in slope)

yes

no

\(h^2\)

The default, and the baseline

Linear in variance, total variance

\(C^0\)

yes

no

\(h^2\) in the transformed variable

Volatilities across strike and expiry

Cubic spline

\(C^2\)

no

yes

\(h^4\) (\(h^2\) near the ends for a natural spline)

Smooth curves and surfaces

Other methods exist, and they fill gaps between these. Monotone cubic (PCHIP) and Akima interpolation keep the \(C^1\) smoothness of a cubic and are local, and overshoot little or not at all. A single polynomial through all the points is exact for polynomial data and fails with many equally spaced nodes, where the error near the ends grows without bound (the Runge phenomenon). Smoothing splines and parametric families, such as Nelson-Siegel, do not pass through the data, and are the regression fits of Interest Rate Curves, Part 5: Regression Fits.

Worked example#

The example compares flat, linear and cubic interpolation on the accuracy and the smoothness of a known function. It then builds the cubic spline from the formulas above, solving the system for \(M_i\) directly, and checks it against a library routine. It compares the three boundary conditions on a zero curve, measures the order of the cubic error and the decay of a single point’s influence, and tests the overshoot of all the methods on step data. It fits a spline to a discount curve to compare the forward rates with those of log-linear interpolation, and ends with the interpolation of a volatility in variance.

Python code
"""Flat, linear and cubic interpolation: accuracy, smoothness, cubic splines built from the second-derivative system, overshoot, a discount curve and variance."""
import numpy as np
from scipy.interpolate import CubicSpline


def second_derivatives(x, y, bc="natural", slopes=(0.0, 0.0)):
    """Solve for the second derivatives M_i at the nodes. bc is natural, clamped or not-a-knot."""
    n = len(x) - 1
    h = np.diff(x)
    d = np.diff(y) / h
    a = np.zeros((n + 1, n + 1))
    b = np.zeros(n + 1)
    for i in range(1, n):
        a[i, i - 1], a[i, i], a[i, i + 1] = h[i - 1], 2 * (h[i - 1] + h[i]), h[i]
        b[i] = 6 * (d[i] - d[i - 1])
    if bc == "natural":
        a[0, 0] = a[n, n] = 1.0
    elif bc == "clamped":
        a[0, 0], a[0, 1], b[0] = 2 * h[0], h[0], 6 * (d[0] - slopes[0])
        a[n, n - 1], a[n, n], b[n] = h[-1], 2 * h[-1], 6 * (slopes[1] - d[-1])
    else:
        a[0, 0], a[0, 1], a[0, 2] = h[1], -(h[0] + h[1]), h[0]
        a[n, n - 2], a[n, n - 1], a[n, n] = h[-1], -(h[-2] + h[-1]), h[-2]
    return np.linalg.solve(a, b)


def spline(x, y, bc="natural", slopes=(0.0, 0.0)):
    """Return value, first and second derivative functions of the spline."""
    m = second_derivatives(x, y, bc, slopes)
    h = np.diff(x)

    def pieces(t):
        t = np.asarray(t, dtype=float)
        i = np.clip(np.searchsorted(x, t, side="right") - 1, 0, len(x) - 2)
        return t, i, h[i]

    def f(t):
        t, i, hi = pieces(t)
        return (m[i] * (x[i + 1] - t) ** 3 + m[i + 1] * (t - x[i]) ** 3) / (6 * hi) + (y[i] / hi - m[i] * hi / 6) * (x[i + 1] - t) + (y[i + 1] / hi - m[i + 1] * hi / 6) * (t - x[i])

    def f1(t):
        t, i, hi = pieces(t)
        return (-m[i] * (x[i + 1] - t) ** 2 + m[i + 1] * (t - x[i]) ** 2) / (2 * hi) + (y[i + 1] - y[i]) / hi - hi * (m[i + 1] - m[i]) / 6

    def f2(t):
        t, i, hi = pieces(t)
        return (m[i] * (x[i + 1] - t) + m[i + 1] * (t - x[i])) / hi

    return f, f1, f2, m


PILLARS = np.array([1.0, 2.0, 3.0, 5.0, 7.0, 10.0])
ZERO = np.array([3.10, 3.35, 3.50, 3.75, 3.90, 4.00]) / 100


def forward_rate(df, t, e=1e-5):
    return -(np.log(df(t + e)) - np.log(df(t - e))) / (2 * e)


def flat(x, y):
    """Piecewise constant, holding the previous node's value."""
    return lambda t: y[np.clip(np.searchsorted(x, np.asarray(t, dtype=float), side="right") - 1, 0, len(x) - 1)]


if __name__ == "__main__":
    print("1. Accuracy: f = exp(x) on [0, 2], largest error, and the observed order between successive halvings")
    fine = np.linspace(0, 2, 8001)
    print(f"   {'Intervals':>9} {'Flat':>10} {'order':>6} {'Linear':>10} {'order':>6} {'Natural cubic':>14} {'order':>6} {'Not-a-knot':>11} {'order':>6}")
    prev = None
    for n in (4, 8, 16, 32, 64):
        xs = np.linspace(0, 2, n + 1)
        ys = np.exp(xs)
        fns = (flat(xs, ys), lambda t: np.interp(t, xs, ys), spline(xs, ys)[0], spline(xs, ys, "not-a-knot")[0])
        row = [np.max(np.abs(g(fine) - np.exp(fine))) for g in fns]
        orders = ["" if prev is None else f"{np.log2(p / r):.2f}" for p, r in zip(prev or row, row)]
        print(f"   {n:9d} {row[0]:10.2e} {orders[0]:>6} {row[1]:10.2e} {orders[1]:>6} {row[2]:14.2e} {orders[2]:>6} {row[3]:11.2e} {orders[3]:>6}")
        prev = row

    print("\n2. Smoothness at the nodes of y = sin(x/2), x = 0, 1, ..., 12: largest jump in the value and in the derivatives")
    xk = np.arange(13.0)
    yk = np.sin(xk / 2)
    e = 1e-5
    print(f"   {'Method':<14} {'value':>10} {'first derivative':>18} {'second derivative':>19}")
    for name, g in (("Flat", flat(xk, yk)), ("Linear", lambda t: np.interp(t, xk, yk)), ("Natural cubic", spline(xk, yk)[0])):
        v = max(abs(g(k + 1e-9) - g(k - 1e-9)) for k in xk[1:-1])
        d1 = max(abs((g(k + e) - g(k + 2 * e)) / e - (g(k - 2 * e) - g(k - e)) / e) for k in xk[1:-1])
        d2 = max(abs((g(k + 3 * e) - 2 * g(k + 2 * e) + g(k + e)) / e**2 - (g(k - e) - 2 * g(k - 2 * e) + g(k - 3 * e)) / e**2) for k in xk[1:-1])
        print(f"   {name:<14} {v:10.2e} {d1:18.2e} {d2:19.2e}")
    print("\n3. The system for a natural spline: zero rates in % at the pillars")
    x, y = PILLARS, ZERO * 100
    f, f1, f2, m = spline(x, y)
    print("   interval widths h        ", np.round(np.diff(x), 2))
    print("   second derivatives M     ", np.round(m, 5))
    ref = CubicSpline(x, y, bc_type="natural")
    grid = np.linspace(1, 10, 901)
    print(f"   largest difference from scipy CubicSpline: {np.max(np.abs(f(grid) - ref(grid))):.1e}")
    for k in x[1:-1]:
        e = 1e-9
        print(f"   node {k:>4.0f}: value jump {f(k + e) - f(k - e):+.1e}, slope jump {f1(k + e) - f1(k - e):+.1e}, curvature jump {f2(k + e) - f2(k - e):+.1e}")

    print("\n4. The three boundary conditions: zero rate in % at 1.5, 4 and 8.5 years, and the end curvatures")
    print(f"   {'Condition':<30} {'1.5y':>8} {'4y':>8} {'8.5y':>8}   {'M_0':>8} {'M_n':>8}")
    for name, kw in (("Natural", {"bc": "natural"}), ("Clamped (end slopes 0.25, 0.03)", {"bc": "clamped", "slopes": (0.25, 0.03)}), ("Not-a-knot", {"bc": "not-a-knot"})):
        g, _, _, mm = spline(x, y, **kw)
        print(f"   {name:<30} " + " ".join(f"{float(g(t)):8.4f}" for t in (1.5, 4.0, 8.5)) + f"   {mm[0]:8.4f} {mm[-1]:8.4f}")

    print("\n5. Cubic accuracy: f = exp(x) on [0, 2], largest error, and the observed order between successive halvings")
    func, d1 = np.exp, np.exp
    fine = np.linspace(0, 2, 8001)
    inner = (fine >= 0.5) & (fine <= 1.5)
    print(f"   {'Intervals':>9} {'Natural':>10} {'order':>6} {'Natural, middle':>16} {'Clamped':>10} {'order':>6} {'Not-a-knot':>11} {'order':>6}")
    prev = None
    for n in (4, 8, 16, 32, 64):
        xs = np.linspace(0, 2, n + 1)
        errs = []
        for kw in ({"bc": "natural"}, {"bc": "clamped", "slopes": (1.0, np.exp(2))}, {"bc": "not-a-knot"}):
            g = spline(xs, func(xs), **kw)[0]
            errs.append(np.abs(g(fine) - func(fine)))
        row = [errs[0].max(), errs[1].max(), errs[2].max()]
        orders = ["" if prev is None else f"{np.log2(p / r):.2f}" for p, r in zip(prev or row, row)]
        print(f"   {n:9d} {row[0]:10.2e} {orders[0]:>6} {errs[0][inner].max():16.2e} {row[1]:10.2e} {orders[1]:>6} {row[2]:11.2e} {orders[2]:>6}")
        prev = row

    print("\n6. Locality: a unit value at one node of a uniform grid, zero elsewhere (natural spline)")
    xs = np.arange(-20.0, 21.0)
    ys = np.zeros_like(xs)
    ys[20] = 1.0
    g, _, _, mm = spline(xs, ys)
    print(f"   {'k':>3} {'M_k':>12} {'M_k / M_(k-1)':>14} {'largest |f| in interval k':>26}")
    prev_m = None
    for k in range(0, 8):
        interval = np.linspace(k, k + 1, 201)
        ratio = "" if prev_m is None else f"{mm[20 + k] / prev_m:.4f}"
        print(f"   {k:3d} {mm[20 + k]:12.3e} {ratio:>14} {np.max(np.abs(g(interval))):26.3e}")
        prev_m = mm[20 + k]
    print(f"   -(2 - sqrt(3)) = {-(2 - np.sqrt(3)):.4f}")

    print("\n7. Overshoot: data 0, 0, 0, 1, 1, 1 at x = 0..5, smallest and largest interpolated value")
    xs, ys = np.arange(6.0), np.array([0, 0, 0, 1, 1, 1.0])
    grid = np.linspace(0, 5, 2001)
    for name, kw in (("Natural", {"bc": "natural"}), ("Clamped, end slopes 0", {"bc": "clamped"}), ("Not-a-knot", {"bc": "not-a-knot"})):
        v = spline(xs, ys, **kw)[0](grid)
        print(f"   {name:<24} min {v.min():+.4f}  max {v.max():+.4f}")
    v = flat(xs, ys)(grid)
    print(f"   {'Flat':<24} min {v.min():+.4f}  max {v.max():+.4f}")
    v = np.interp(grid, xs, ys)
    print(f"   {'Linear':<24} min {v.min():+.4f}  max {v.max():+.4f}")

    print("\n8. A discount curve: forward rates in % from three ways of interpolating the zero rates")
    t0 = np.concatenate(([0.0], PILLARS))
    lnd = np.concatenate(([0.0], -ZERO * PILLARS))
    zero_spline = spline(PILLARS, ZERO)[0]
    lnd_spline = spline(t0, lnd)[0]
    methods = {
        "Log-linear discount factor": lambda t: np.exp(np.interp(t, t0, lnd)),
        "Natural spline, zero rate": lambda t: np.exp(-zero_spline(t) * t),
        "Natural spline, log discount": lambda t: np.exp(lnd_spline(t)),
    }
    times = (1.5, 2.5, 4.0, 6.0, 8.5)
    print(f"   {'Method':<30} " + " ".join(f"{str(t) + 'y':>7}" for t in times) + "   largest forward jump at a pillar")
    for name, df in methods.items():
        fwd = [forward_rate(df, t) * 100 for t in times]
        jump = max(abs(forward_rate(df, k + 1e-4) - forward_rate(df, k - 1e-4)) for k in PILLARS[:-1]) * 100
        print(f"   {name:<30} " + " ".join(f"{v:7.3f}" for v in fwd) + f"   {jump:.4f}")
    print(f"   {'Discount factor at 4y':<30} " + "  ".join(f"{df(4.0):.6f}" for df in methods.values()))

    print("\n9. Linear in variance: volatility 20% at 1 year and 30% at 2 years, value at 1.5 years")
    (t1, v1), (t2, v2), t = (1.0, 0.20), (2.0, 0.30), 1.5
    w = (t - t1) / (t2 - t1)
    linear_vol = (1 - w) * v1 + w * v2
    linear_var = np.sqrt((1 - w) * v1**2 + w * v2**2)
    total = (1 - w) * v1**2 * t1 + w * v2**2 * t2
    total_vol = np.sqrt(total / t)
    print(f"   Linear in volatility          {linear_vol:.4%}")
    print(f"   Linear in variance            {linear_var:.4%}")
    print(f"   Linear in total variance      {total_vol:.4%}   (total variance {total:.4f})")
    forward_var = (v2**2 * t2 - v1**2 * t1) / (t2 - t1)
    print(f"   Forward volatility between 1 and 2 years: {np.sqrt(forward_var):.4%}")
    for name, vol in (("Linear in volatility", linear_vol), ("Linear in variance", linear_var), ("Linear in total variance", total_vol)):
        fwd_var = (vol**2 * t - v1**2 * t1) / (t - t1)
        fwd_var2 = (v2**2 * t2 - vol**2 * t) / (t2 - t)
        print(f"   {name:<28} forward vol 1 to 1.5 years {np.sqrt(fwd_var):.4%}, 1.5 to 2 years {np.sqrt(fwd_var2):.4%}")

The output is:

1. Accuracy: f = exp(x) on [0, 2], largest error, and the observed order between successive halvings
   Intervals       Flat  order     Linear  order  Natural cubic  order  Not-a-knot  order
           4   2.91e+00          1.81e-01              8.79e-02           7.63e-03
           8   1.63e+00   0.83   5.10e-02   1.83       2.25e-02   1.97    6.31e-04   3.59
          16   8.66e-01   0.91   1.36e-02   1.91       5.66e-03   1.99    4.48e-05   3.82
          32   4.46e-01   0.96   3.50e-03   1.96       1.42e-03   2.00    2.99e-06   3.91
          64   2.25e-01   0.98   8.88e-04   1.98       3.54e-04   2.00    1.93e-07   3.95

2. Smoothness at the nodes of y = sin(x/2), x = 0, 1, ..., 12: largest jump in the value and in the derivatives
   Method              value   first derivative   second derivative
   Flat             4.92e-01           0.00e+00            0.00e+00
   Linear           9.49e-10           2.44e-01            1.11e-05
   Natural cubic    9.90e-10           7.64e-06            1.39e-05

3. The system for a natural spline: zero rates in % at the pillars
   interval widths h         [1. 1. 2. 2. 3.]
   second derivatives M      [ 0.      -0.15315  0.01259 -0.03621 -0.01776  0.     ]
   largest difference from scipy CubicSpline: 8.9e-16
   node    2: value jump +4.0e-10, slope jump -3.1e-10, curvature jump +1.3e-11
   node    3: value jump +2.6e-10, slope jump +2.5e-11, curvature jump +1.4e-10
   node    5: value jump +2.1e-10, slope jump -7.2e-11, curvature jump -1.5e-11
   node    7: value jump +1.0e-10, slope jump -3.6e-11, curvature jump +1.5e-11

4. The three boundary conditions: zero rate in % at 1.5, 4 and 8.5 years, and the end curvatures
   Condition                          1.5y       4y     8.5y        M_0      M_n
   Natural                          3.2346   3.6309   3.9600     0.0000   0.0000
   Clamped (end slopes 0.25, 0.03)   3.2305   3.6300   3.9574     0.0881   0.0065
   Not-a-knot                       3.2439   3.6327   3.9593    -0.2028   0.0025

5. Cubic accuracy: f = exp(x) on [0, 2], largest error, and the observed order between successive halvings
   Intervals    Natural  order  Natural, middle    Clamped  order  Not-a-knot  order
           4   8.79e-02                2.36e-02   1.08e-03           7.63e-03
           8   2.25e-02   1.97         1.58e-03   7.16e-05   3.91    6.31e-04   3.59
          16   5.66e-03   1.99         2.69e-05   4.59e-06   3.96    4.48e-05   3.82
          32   1.42e-03   2.00         1.71e-07   2.91e-07   3.98    2.99e-06   3.91
          64   3.54e-04   2.00         1.10e-08   1.83e-08   3.99    1.93e-07   3.95

6. Locality: a unit value at one node of a uniform grid, zero elsewhere (natural spline)
     k          M_k  M_k / M_(k-1)  largest |f| in interval k
     0   -4.392e+00                                 1.000e+00
     1    2.785e+00        -0.6340                  1.367e-01
     2   -7.461e-01        -0.2679                  3.663e-02
     3    1.999e-01        -0.2679                  9.815e-03
     4   -5.357e-02        -0.2679                  2.630e-03
     5    1.435e-02        -0.2679                  7.047e-04
     6   -3.846e-03        -0.2679                  1.888e-04
     7    1.031e-03        -0.2679                  5.059e-05
   -(2 - sqrt(3)) = -0.2679

7. Overshoot: data 0, 0, 0, 1, 1, 1 at x = 0..5, smallest and largest interpolated value
   Natural                  min -0.1092  max +1.1092
   Clamped, end slopes 0    min -0.1064  max +1.1064
   Not-a-knot               min -0.1283  max +1.1283
   Flat                     min +0.0000  max +1.0000
   Linear                   min +0.0000  max +1.0000

8. A discount curve: forward rates in % from three ways of interpolating the zero rates
   Method                            1.5y    2.5y    4.0y    6.0y    8.5y   largest forward jump at a pillar
   Log-linear discount factor       3.600   3.800   4.125   4.275   4.233   0.5000
   Natural spline, zero rate        3.619   3.792   4.147   4.279   4.224   0.0001
   Natural spline, log discount     3.629   3.789   4.147   4.282   4.229   0.0001
   Discount factor at 4y          0.863942  0.864818  0.864695

9. Linear in variance: volatility 20% at 1 year and 30% at 2 years, value at 1.5 years
   Linear in volatility          25.0000%
   Linear in variance            25.4951%
   Linear in total variance      27.0801%   (total variance 0.1100)
   Forward volatility between 1 and 2 years: 37.4166%
   Linear in volatility         forward vol 1 to 1.5 years 32.7872%, 1.5 to 2 years 41.5331%
   Linear in variance           forward vol 1 to 1.5 years 33.9116%, 1.5 to 2 years 40.6202%
   Linear in total variance     forward vol 1 to 1.5 years 37.4166%, 1.5 to 2 years 37.4166%
Left, step data interpolated by flat and linear methods and by natural, clamped and not-a-knot cubic splines, where only the splines overshoot. Right, forward rates from log-linear interpolation of the discount factor, which step at the pillars, and from two natural splines, which are continuous

Reading the output:

  • The orders are :math:`h`, :math:`h^2` and :math:`h^4`. For exp(x) on [0, 2], halving the spacing cuts the flat error by 2, the linear error by 4 and the not-a-knot spline error by 16 (observed orders 0.98, 1.98 and 3.95 at 64 intervals). At 64 intervals the errors are 0.225, 8.9e-4 and 1.9e-7: the flat interpolant is 250 times worse than the linear, which is 4,600 times worse than the spline. With only four intervals the spline is already 24 times better than linear. The natural spline is only of order 2, and the reason is in the boundary conditions below.

  • Each step up gains one degree of smoothness. At the nodes of sin(x/2) the flat interpolant jumps in value, by up to 0.49. The linear one is continuous and has a jump of 0.24 in the slope. The natural spline has no jump in the value, the slope or the curvature, and the 8e-6 and 1.4e-5 that are printed are the size of the finite-difference step. For a curve, a jump in the slope of the zero rate is a jump in the forward rate.

  • The system reproduces the library spline. Solving for the curvatures directly gives the same curve to 9e-16. At each interior node the value, slope and curvature jump by 1e-10 or less, which is the size of the finite-difference step, so the pieces join as \(C^2\). The curvatures of the zero curve are largest at the 2-year pillar (-0.153), where the slope falls from 0.25 to 0.15 per year.

  • The boundary condition matters near the ends. At 1.5 years the three conditions give 3.2346%, 3.2305% and 3.2439%, a range of 1.3 basis points. At 4 years the range is 0.27 basis points, and at 8.5 years 0.26. The end curvatures are 0 for the natural spline, 0.088 for the clamped and -0.203 for the not-a-knot spline, and the difference dies away from the ends.

  • The orders of convergence of the cubic splines are visible. For exp(x), halving the spacing cuts the natural spline error by 4 (orders 1.97, 1.99, 2.00), because the function has curvature at the end and the natural condition does not. The clamped and not-a-knot splines cut it by 16 (3.99 and 3.95). At 64 intervals the natural spline has an error of 3.5e-4 against 1.8e-8 for the clamped, about 19,000 times larger. Away from the ends the natural error is 1.1e-8, as small as the clamped, so the loss is all at the boundary.

  • The influence of a point decays by a factor of 0.268. From the second interval on, the ratio of successive curvatures is -0.2679, the value of \(-(2 - \sqrt{3})\), and the sign alternates. The largest value of the spline in each interval falls from 0.137 one interval away to 5e-5 seven intervals away. The change is small and it is never zero, and the alternation of the sign is the overshoot.

  • The cubic splines overshoot step data, and flat and linear do not. The natural spline goes from -0.109 to 1.109 on data between 0 and 1, the clamped spline to -0.106 and 1.106, and the not-a-knot spline to -0.128 and 1.128, an excess of 11 to 13% of the step. Flat and linear interpolation stay in [0, 1]. A discount factor above 1 is a negative rate, and a survival probability above 1 is a negative hazard rate.

  • A spline gives a continuous forward rate. Log-linear interpolation of the discount factor gives forward rates of 3.600, 3.800, 4.125, 4.275 and 4.233% at the five dates, with a step at each pillar of up to 0.5 percentage points. The two splines have no step, and differ from log-linear by up to 0.03 percentage points at these dates. They differ from each other by 0.010 at most, which is the effect of the variable that is fitted. The discount factor at 4 years is 0.863942, 0.864818 and 0.864695, a range of 0.0009, or about 88,000 on a payment of 100 million.

  • Linear in variance is not linear in volatility. Halfway between 20% and 30% volatility, linear gives 25.00%, linear in variance 25.50% and linear in total variance 27.08%, which puts the 1.5-year volatility 2 points above the straight line. Only total variance gives a constant forward volatility between the expiries, 37.42% in both halves. Linear in volatility gives 32.79% and 41.53%, a forward volatility that jumps at the interpolated date.

A valuation control view#

  • Record the method, the boundary condition and the variable, together: “cubic spline” or “linear” is not a specification. A natural and a not-a-knot spline on the same zero rates differ by over a basis point at the short end, and a spline on the zero rate and one on the log discount factor give different forwards.

  • Test for overshoot on the data actually used: a spline that is fine on a smooth curve can swing past the data at a kink or a sharp skew. Check the range of the interpolant against the range of the data, and check the forward rates for negative values.

  • Check that a risk bucket responds where the quote is: a spline is not local, so a quote moved at one maturity moves the curve at all the others, with a decaying and alternating effect. Risk reports then show sensitivities at maturities far from the quote.

  • Look at the derivative that the trade depends on: the slope of a discount curve is a forward rate, and the second derivative of a call price in the strike is a density. A spline that is smooth in the quantity that is fitted may not be smooth, or positive, in the one that is used.

  • Match the variable to the quantity that adds: interpolate volatilities in total variance across expiries, and check the result for a non-negative forward variance.

  • Quantify the spread between reasonable methods: price the book with two or more defensible choices. The difference is an estimate of interpolation uncertainty and an input to a valuation reserve. See Prudent Valuation: Requirements.

Next, Interpolation, Part 2: Extrapolation covers what to do beyond the last data point, where the choice matters most.