Skip to content

Piecewise cubic Hermite interpolation

Build cubic pieces from endpoint values and slopes, see how PCHIP selects shape-preserving slopes, and understand why continuous first derivatives do not imply continuous curvature.

Piecewise cubic Hermite interpolation joins neighbouring data points with cubic polynomials that match both a value and a chosen slope at each endpoint. Adjacent pieces share the same knot slope, so the fitted curve has a continuous first derivative. In numerical libraries, PCHIP usually names a particular shape-preserving choice of those slopes.

This distinction matters when filling gaps between financial observations. A curve can pass through every quoted value and still introduce an unwanted hump between them. The cubic basis determines how values and slopes fit together; the slope rule determines much of the curve's behaviour between observations.

Four constraints determine each piece

Take ordered knots x0<⋯<xnx_0<\cdots<x_n, values yiy_i, and knot slopes mim_i. On [xi,xi+1][x_i,x_{i+1}], put hi=xi+1−xih_i=x_{i+1}-x_i and t=(x−xi)/hit=(x-x_i)/h_i. The Hermite piece is

Pi(x)=H00(t)yi+H10(t)himi+H01(t)yi+1+H11(t)himi+1,P_i(x)=H_{00}(t)y_i+H_{10}(t)h_i m_i +H_{01}(t)y_{i+1}+H_{11}(t)h_i m_{i+1},

where

H00(t)=2t3−3t2+1,H10(t)=t3−2t2+t,H01(t)=−2t3+3t2,H11(t)=t3−t2.\begin{aligned} H_{00}(t)&=2t^3-3t^2+1, & H_{10}(t)&=t^3-2t^2+t,\\ H_{01}(t)&=-2t^3+3t^2, & H_{11}(t)&=t^3-t^2. \end{aligned}

The four basis functions enforce Pi(xi)=yiP_i(x_i)=y_i, Pi(xi+1)=yi+1P_i(x_{i+1})=y_{i+1}, Pi′(xi)=miP_i'(x_i)=m_i and Pi′(xi+1)=mi+1P_i'(x_{i+1})=m_{i+1}. The factors hih_i are essential: mim_i is a derivative with respect to the original coordinate xx, rather than the normalized coordinate tt.

These are polynomials of degree at most three. A constant segment or straight line is allowed. The formula itself makes no promise of monotone interpolation: arbitrary endpoint slopes can make a cubic reverse direction even between increasing values.

PCHIP chooses the slopes from the data

For the shape-preserving PCHIP convention used by SciPy, define each secant slope as

δi=yi+1−yihi.\delta_i=\frac{y_{i+1}-y_i}{h_i}.

At an interior knot, set mi=0m_i=0 if either adjacent secant is zero or their signs differ. Otherwise use a weighted harmonic mean:

mi=w1+w2w1/δi−1+w2/δi,w1=2hi+hi−1,w2=hi+2hi−1.\begin{aligned} m_i&=\frac{w_1+w_2}{w_1/\delta_{i-1}+w_2/\delta_i},\\ w_1&=2h_i+h_{i-1},\qquad w_2=h_i+2h_{i-1}. \end{aligned}

A flat interval therefore has zero slopes at both ends, and a change of direction has zero slope at its turning knot. When both secants have the same sign, the harmonic mean moderates the slope without changing that sign.

Endpoints need their own rule. With at least three knots, the left endpoint candidate is

m~0=(2h0+h1)δ0−h0δ1h0+h1.\widetilde m_0=\frac{(2h_0+h_1)\delta_0-h_0\delta_1}{h_0+h_1}.

Set it to zero if its sign differs from δ0\delta_0. Otherwise, when the first two secants have different signs, limit its magnitude to 3∣δ0∣3|\delta_0|, retaining the sign of δ0\delta_0. Reflect this procedure at the right endpoint. With only two knots, use the single secant at both ends, reproducing the line.

This algorithm preserves each data interval's direction and stays within its two endpoint values. Globally increasing data remain increasing in the non-strict sense; data that change direction retain those turns. It does not smooth noisy observations: interpolation still reproduces the supplied values.

A plateau exposes the continuity tradeoff

Use the synthetic, dimensionless data

(xi,yi)=(0,0), (1,1), (2,1).(x_i,y_i)=(0,0),\ (1,1),\ (2,1).

The secants are 11 and 00. PCHIP assigns slopes (m0,m1,m2)=(3/2,0,0)(m_0,m_1,m_2)=(3/2,0,0) and produces

P(x)={32x−12x3,0≤x≤1,1,1≤x≤2.P(x)= \begin{cases} \frac32x-\frac12x^3,&0\le x\le1,\\ 1,&1\le x\le2. \end{cases}

Thus P(0.5)=11/16=0.6875P(0.5)=11/16=0.6875 and P(1.5)=1P(1.5)=1. On the first interval, P′(x)=32(1−x2)≥0P'(x)=\frac32(1-x^2)\ge0; on the second it is zero. The curve rises into the plateau without overshooting it.

At x=1x=1, both pieces have value 11 and slope 00. Their second derivatives disagree:

lim⁡x↑1P′′(x)=−3,lim⁡x↓1P′′(x)=0.\lim_{x\uparrow1}P''(x)=-3, \qquad \lim_{x\downarrow1}P''(x)=0.
PCHIP is therefore C1C^1 here, but not C2C^2: its first derivative is continuous, while the ordinary second derivative does not exist at this knot. A cubic spline with the usual simple-knot C2C^2 conditions solves a different joining problem. Both are piecewise cubics; their slope choices and smoothness requirements differ.
Three panels show PCHIP through synthetic knots (0,0), (1,1), (2,1). The response joins at 1 and the first derivative joins at 0. At x=1 the second derivative has left limit -3 and right limit 0; open circles mark these limits.
Three panels show PCHIP through synthetic knots (0,0), (1,1), (2,1). The response joins at 1 and the first derivative joins at 0. At x=1 the second derivative has left limit -3 and right limit 0; open circles mark these limits.
Original synthetic example with dimensionless coordinates and responses. Matching values and slopes does not require matching curvature. Open circles in the last panel are one-sided limits, rather than an attained second derivative at the join.

Choose the interpolated quantity as well as the method

PCHIP can be useful when preserving the ordering of supplied values matters more than continuous curvature. Positive knot values also yield positive values between knots, because each interval stays within its endpoint range. These statements apply inside the knot domain. They do not establish a sensible extrapolation rule.

For a financial curve, specify whether the interpolated quantity is a discount factor, its logarithm, or a rate with a stated compounding convention. PCHIP's shape guarantee concerns that chosen quantity. It supplies no general convexity or financial no-arbitrage guarantee, and a quantity involving second derivatives may have jumps or be undefined at knots.

The Object-Oriented Model Design lesson (membership; public preview available) gives a useful implementation setting: its curve object interpolates log discount factors and rejects maturities outside its pillars. That example uses a different interpolation rule, but makes the choice of variable and domain explicit—the same decisions a PCHIP curve needs.

Sources

  • Cleve Moler, Numerical Computing with MATLAB, chapter 3, §§3.3–3.5 — Hermite endpoint constraints, shape-preserving slope construction and the distinction from C2C^2 cubic splines; electronic chapter dated 16 September 2013.
  • SciPy documentation: PchipInterpolator — weighted harmonic interior slopes, monotonicity preservation and first- versus second-derivative continuity.
  • F. N. Fritsch, SLATEC DPCHIM — endpoint limiting, direction switches and the two-knot linear case.
  • Gérard Cornuéjols, Javier Peña and Reha Tütüncü, Optimization Methods in Finance, 2nd edition, Cambridge University Press, 2018, §3.4, pp. 42–43 — interpolation between term-structure observations.
Last updated
  • interpolation
  • hermite basis
  • pchip
  • shape preservation
  • numerical methods
← Back to the glossaryBack to top ↑