Skip to content

Cubic spline

Join cubic pieces with continuous slope and curvature, and see how endpoint conditions change an exact interpolation without guaranteeing financial validity.

A cubic spline is a function built from polynomial pieces of degree at most three, joined so that the value, first derivative and second derivative agree at each ordinary interior knot. The resulting curve is twice continuously differentiable, written C2C^2.

In quantitative finance, that extra smoothness matters when a calculation differentiates a fitted curve. Connecting quoted values by straight lines produces corners; differentiating a cubic spline gives a continuous slope. That is useful structure for a yield curve or volatility smile, but it does not establish that the fitted curve satisfies financial constraints.

Matching values and matching derivatives

For interpolation, start with distinct ordered knots x0<⋯<xnx_0<\cdots<x_n and observed values y0,…,yny_0,\ldots,y_n. On interval [xi,xi+1][x_i,x_{i+1}], write a local cubic
Si(x)=ai+bi(x−xi)+ci(x−xi)2+di(x−xi)3.S_i(x)=a_i+b_i(x-x_i)+c_i(x-x_i)^2+d_i(x-x_i)^3.
The interpolating spline must pass through both ends of each interval. At every interior knot, the left and right slopes must also match, as must the left and right curvatures. These conditions leave two degrees of freedom: there are 4n4n coefficients, 2n2n endpoint-value equations and 2(n−1)2(n-1) derivative-matching equations. Two suitable boundary conditions complete the construction.

“Cubic spline” therefore does not specify a unique interpolation rule on its own. Common choices include:

Boundary choiceWhat it specifies
NaturalThe second derivative is zero at both outer knots.
ClampedThe first derivative is prescribed at both outer knots. The slopes need not be zero.
Not-a-knotThe first two pieces share one cubic, and the last two pieces share one cubic, when there are enough knots.
These are conditions on the curve, not additional observations. Software defaults matter: SciPy's CubicSpline defaults to not-a-knot, rather than natural boundaries.

A three-point arch

Take the synthetic, dimensionless data (0,0)(0,0), (1,1)(1,1) and (2,0)(2,0). Impose natural boundaries S′′(0)=S′′(2)=0S''(0)=S''(2)=0. The resulting spline is

S(x)={3x2−x32,0≤x≤1,3(2−x)2−(2−x)32,1≤x≤2.S(x)= \begin{cases} \frac{3x}{2}-\frac{x^3}{2},&0\le x\le1,\\ \frac{3(2-x)}{2}-\frac{(2-x)^3}{2},&1\le x\le2. \end{cases}

At the middle knot, both expressions give value 11, slope 00 and second derivative −3-3. The join has no corner and no jump in curvature. The third derivative, however, jumps from −3-3 on the left to +3+3 on the right: a cubic spline need not be C3C^3.

At x=0.5x=0.5, the spline gives 11/16=0.687511/16=0.6875, while linear interpolation gives 1/21/2. Both curves pass through every supplied point. Their different answers between points come from their different construction rules, not from an error in matching the data.
Synthetic natural cubic through (0,0), (1,1), (2,0), with value 11/16 at x=0.5 versus the linear value 1/2. Slope joins at zero and curvature at minus 3 at x=1; endpoint curvature is zero.
Synthetic natural cubic through (0,0), (1,1), (2,0), with value 11/16 at x=0.5 versus the linear value 1/2. Slope joins at zero and curvature at minus 3 at x=1; endpoint curvature is zero.
Original dimensionless example. The solid curve is the natural cubic; the dashed line connects the same data linearly. Filled markers denote attained values. The derivative panels show the two smoothness conditions at the middle knot.

Natural does not mean flat. Here S′(0)=1.5S'(0)=1.5 and S′(2)=−1.5S'(2)=-1.5, despite zero endpoint curvature. Nor does zero curvature at the endpoint make the entire outer cubic segment a straight line.

What smoothness buys—and what still needs checking

A spline is a function class, not necessarily an exact fit. A regression spline estimates coefficients from noisy data, and a smoothing spline trades fit against a roughness penalty. Neither must pass through every observation. A B-spline is a basis for representing spline functions, rather than a competing requirement that every observation be interpolated. This distinction is developed in Hastie, Tibshirani and Friedman, Chapter 5.
For an implementation-oriented continuation, Beyond Linearity: Splines, Local Regression, and Generalized Additive Models uses a cubic spline basis in a fitted regression. The full lesson requires membership; its public page provides a preview.
Smoothness alone does not preserve monotonicity, positivity or convexity between knots. A cubic spline can overshoot; SciPy's interpolation guide illustrates this limitation. When interpolating financial quantities, specify whether the ordinate is a zero rate, discount factor, implied volatility or option price, then check the relevant pricing constraints. Changing that quantity changes the curve being constructed.
Finally, evaluating beyond the outer knots is extrapolation. Endpoint boundary conditions and the rule for extending the curve are separate choices. A smooth fit inside the observed range provides no automatic justification for its tail.

Sources

  • Hastie, T., Tibshirani, R. and Friedman, J. The Elements of Statistical Learning, second edition, corrected 12th printing (2017), Chapter 5, §§5.2–5.2.1 and §5.4: spline spaces, natural boundaries and smoothing splines.
  • SciPy documentation: CubicSpline: interpolation conditions, boundary choices and separate extrapolation control.
  • SciPy user guide: 1-D interpolation: derivative continuity, overshoot and B-spline representation.
Last updated
  • cubic spline
  • interpolation
  • numerical methods
  • curve fitting
← Back to the glossaryBack to top ↑