Skip to content

Natural cubic spline

Interpolate with zero endpoint second derivatives, and see why a natural boundary condition guarantees neither flat slopes, monotonicity nor linear extrapolation.

A natural cubic spline is a cubic spline whose second derivative is zero at both boundary knots. In exact interpolation, it passes through every supplied value, joins neighbouring cubic pieces with continuous first and second derivatives, and satisfies
S′′(x0)=S′′(xn)=0.S''(x_0)=S''(x_n)=0.

This gives a smooth curve without asking the user to supply endpoint slopes. For a quant filling gaps in a yield curve or volatility smile, however, “natural” describes a boundary assumption. It does not establish that the interpolated values are positive, monotone or financially admissible.

Zero curvature is not a flat endpoint

Here “curvature” means the second derivative, S′′S''. Setting it to zero says that the slope has zero instantaneous rate of change at the endpoint. It leaves the slope itself free. A clamped cubic spline, by contrast, prescribes the first derivative at each endpoint.
The natural conditions apply at two points. They do not force an entire outer interval to be linear. This is the numerical boundary condition used by SciPy's CubicSpline; its default boundary condition is not-a-knot, so natural interpolation must be selected explicitly.

A smooth curve that initially goes the wrong way

Take three synthetic, dimensionless knots:

(x0,y0)=(0,0),(x1,y1)=(1,1),(x2,y2)=(2,8).(x_0,y_0)=(0,0),\qquad(x_1,y_1)=(1,1),\qquad(x_2,y_2)=(2,8).

The supplied values increase. The natural interpolant is nevertheless negative just to the right of the first knot:

S(x)={−x2+3x32,0≤x≤1,1+4u+9u22−3u32,u=x−1,1≤x≤2.S(x)= \begin{cases} -\frac{x}{2}+\frac{3x^3}{2},&0\le x\le1,\\ 1+4u+\frac{9u^2}{2}-\frac{3u^3}{2},\quad u=x-1,&1\le x\le2. \end{cases}

At the join, both pieces have value 11, slope 44 and second derivative 99. At the two outer knots, the second derivative is zero, while the slopes are

S′(0)=−12,S′(2)=172=8.5.S'(0)=-\frac12,\qquad S'(2)=\frac{17}{2}=8.5.

The negative initial slope makes the curve fall before it rises. Its first-interval minimum occurs at x=1/3x=1/3, with value −1/9-1/9. In particular, S(0.5)=−1/16=−0.0625S(0.5)=-1/16=-0.0625; further along, S(1.5)=63/16=3.9375S(1.5)=63/16=3.9375.

For comparison, clamp the endpoint slopes to 00 and 1212. The unique interpolant through the same knots is then x3x^3, giving 1/81/8 at 0.50.5 and 27/827/8 at 1.51.5. Both curves hit all the data. Their disagreement between knots measures the effect of the boundary information.

Natural spline through (0,0), (1,1), (2,8) dips to minus 1/9 at x=1/3 and has value minus 1/16 at x=0.5, versus clamped value 1/8. Natural second derivatives at the knots are 0,9,0; endpoint slopes are minus 0.5 and 8.5.
Natural spline through (0,0), (1,1), (2,8) dips to minus 1/9 at x=1/3 and has value minus 1/16 at x=0.5, versus clamped value 1/8. Natural second derivatives at the knots are 0,9,0; endpoint slopes are minus 0.5 and 8.5.
Original synthetic example, with dimensionless coordinates and responses. The left panel magnifies the first interval; the right panel shows second derivatives over the whole domain. Filled markers denote attained values. The dashed comparison uses endpoint slopes 0 and 12.
The consequence for a financial application is concrete: nonnegative observations do not ensure a nonnegative interpolant, and increasing observations do not ensure a monotone curve. If the ordinate represents discount factors, option prices or implied volatilities, check the constraints appropriate to that quantity. Exact interpolation and smoothness alone do not provide an arbitrage-free construction.

How the boundary conditions enter the solve

One convenient construction solves for the knot second derivatives Mi=S′′(xi)M_i=S''(x_i). Write hi=xi+1−xih_i=x_{i+1}-x_i. Continuity of the first derivative gives the interior equations

hi−1Mi−1+2(hi−1+hi)Mi+hiMi+1=6(yi+1−yihi−yi−yi−1hi−1).h_{i-1}M_{i-1}+2(h_{i-1}+h_i)M_i+h_iM_{i+1} =6\left(\frac{y_{i+1}-y_i}{h_i}-\frac{y_i-y_{i-1}}{h_{i-1}}\right).

Natural boundaries supply M0=Mn=0M_0=M_n=0, completing a tridiagonal linear system. In the example, the only interior equation is 4M1=6(7−1)4M_1=6(7-1), hence M1=9M_1=9. Integrating the linear second derivative on each interval and matching the supplied values gives the pieces above. With only two knots, zero second derivatives at both ends force the single piece to reduce to the straight line between them.

Decide what happens outside the knots

Extrapolation is a separate decision. Extending the example's final cubic to x=3x=3 gives 1515. Extending its endpoint tangent line instead gives 8+8.5(3−2)=16.58+8.5(3-2)=16.5. Both extensions attach smoothly in value, slope and second derivative at x=2x=2, but they are different curves beyond it. SciPy's extrapolation guide explains why a natural boundary condition alone does not make polynomial-piece extrapolation linear.

In statistical modelling, “natural cubic spline” often denotes a regression basis with linear tails outside the boundary knots, as in Hastie, Tibshirani and Friedman, §5.2.1. Those linear tails are an explicit extension convention. Also distinguish exact interpolation from regression: fitting a natural-spline basis to noisy observations does not generally pass through every observation.

For the regression setting, Beyond Linearity: Splines, Local Regression, and Generalized Additive Models develops piecewise bases and their flexibility. The full lesson requires membership; the linked public page provides a preview.

Sources

Last updated
  • natural cubic spline
  • interpolation
  • boundary conditions
  • numerical methods
← Back to the glossaryBack to top ↑