Topic

Spot rates, forward rates and yield curves

One yield per bond hides the fact that money due in one year and money due in ten are discounted at different rates. The curve of those rates can be read off bond prices exactly.

const curve = bootstrap([
  { price: "97.5",  coupon: 0,      periods: 1 },
  { price: "100.2", coupon: "3%",   periods: 2 },
  { price: "101",   coupon: "3.5%", periods: 3 },
]);
curve.discountFactors;   // 39/40, 3891/4120, 194221/213210: exact
curve.spot(3);           // the 3-period spot rate
curve.forward(1, 2);     // the rate from period 1 to 2 implied today, exact
curve.parYield(3);       // the coupon that would price a 3-period bond at par

Discount factors

dkd_k is today's price of 1 paid at the end of period k. A bond is then worth ∑kckdk\sum_k c_k d_k, with no single yield involved. If there is a bond maturing at each of periods 1, 2, …, n, the factors can be found one at a time: the one-period bond gives d1d_1; the two-period bond's price, less its first coupon valued at d1d_1, gives d2d_2; and so on. This is bootstrapping. It is only division and subtraction, so the factors are exact fractions.

Spot and forward rates

The spot rate sks_k is the yield of a zero-coupon bond for k periods: dk=(1+sk/f)−kd_k = (1 + s_k/f)^{-k}. It needs a k-th root, so beyond one period it is usually an interval.

The forward rate from a to b is the rate you can lock in today for that future stretch, by buying one zero and selling another: (1+fa,b/f)b−a=da/db(1 + f_{a,b}/f)^{b-a} = d_a/d_b. One-period forwards are exact. An upward-sloping spot curve means forwards above spots.

The par yield for k periods is the coupon rate at which a bond would be priced at exactly its face value: (1−dk)/∑j≤kdj(1 - d_k)/\sum_{j\le k} d_j, exact.

yieldCurve({ spots }) or yieldCurve({ discountFactors }) makes a curve directly, and curve.price(bond) values any bond off it.

Immunisation

A liability of L due at time T has present value L(1+i)−fTL(1+i)^{-fT} and duration T. If the assets held against it have the same present value and the same duration, a small change in yield moves both by the same amount. If the assets are also more convex than the liability, any change in yield, up or down, leaves a surplus. immunise takes two bonds, one shorter and one longer than T, and solves for the split: two linear equations with an exact solution. surplusAt(yield) then shows, exactly, what is left if the yield jumps.

The protection is against one parallel shift of a flat curve, and the match must be renewed as time passes.

callreturns
bootstrap(bonds, { frequency })YieldCurve
yieldCurve({ spots | discountFactors, frequency })YieldCurve
curve.discount(k), .discountFactorsexact
curve.spot(k), .spots, .forward(a, b), .forwardsnominal annual rates; exact or intervals
curve.parYield(k), curve.price(bond)exact
immunise({ liability: { amount, time }, yield, bonds: [a, b] }){ presentValue, weights, amounts, units, durations, convexity, immunised, short, surplusAt }
Try itEdit the code and run it with @ratmath/finance and Core's Rational in scope. The last line's value is shown; PRINT(…) adds lines, TEX(…) typesets math.
Ctrl/⌘ + Enter runs