Interest Rate Curve Build, Part 3: Global Solver & Jacobian#
See also
Hagan and West, “Interpolation methods for curve construction”, Applied Mathematical Finance, 2006
Interest Rate Curve Build, Part 1: Instruments & Bootstrapping solves for one discount factor at a time and Interest Rate Curve Build, Part 2: Multi-Curve & Basis extends it to several curves. Both assume that each instrument adds exactly one new unknown, that every quote is repriced exactly, and that the curves depend on each other in one direction only. Production curve sets break those assumptions. The first reason is the instruments themselves: much of the swap market is quoted in curve spreads, such as switches and flies, and a spread involves several maturities at once, so it cannot be bootstrapped. There are also more quotes than unknowns, the quotes contain noise, the curves depend on each other, and the desk needs the risk to each input. This page starts with the spreads, and then covers the tool for these cases, a global solver, and the Jacobian that drives it. The Jacobian does two jobs in a curve build: it is the engine of the solver, and it turns into the risk of every trade to every input quote. The page ends by returning to the spreads, with a worked example of what they add to the accuracy, the checking and the risk of a curve. Interest Rate Curve Build, Part 4: Regression Fits then covers a different approach, which does not reprice the inputs exactly.
Why a global solver: curve spreads#
So far every input has been an outright swap rate, and each one has brought in exactly one new unknown. That is not how all of the swap market is quoted. Much of the trading, especially in the less liquid tenors, is done in curve spreads, and a production curve uses those quotes as inputs. They are the clearest example of why a bootstrap is not enough.
What they are#
A switch is the spread between two swap rates, the long end less the short end. A fly (butterfly) is the belly of three swap rates against its two wings. With \(s(T)\) the par swap rate for maturity \(T\):
They are named by their tenors, so “2s10s” is the switch between the 2 year and the 10 year, and “5s7s10s” is the fly with the 7 year as the belly. Both are quoted in basis points. Each is a linear combination of outright swap rates, so its value is a weighted sum of par rates with the weights \(c_k\):
Conventions differ in the sign and the weights. Packages are often traded with weights that make the two legs equal in risk, not 1, 2 and 1, so the fly above is a simplified form. The name “swap spread” is not used here, as in some markets it means the swap rate less a government bond yield, which is a different thing.
Why they are used#
They trade as one package. A switch or a fly is executed in a single trade at one price, so the dealer has no exposure to the overall level of rates while quoting it. The bid-offer is quoted on the spread, and it can be tighter than the bid-offers on two or three outrights together.
The less liquid tenors trade mostly in spreads. An outright 7, 15 or 20 year swap is traded less often than the 2, 5, 10 and 30 year benchmarks, so its outright quote can be wide or stale. A fly such as 5s7s10s is how the 7 year is priced against two benchmark tenors that are liquid.
They carry information that the outrights do not. The slope and the curvature of the curve are what the market trades, and a spread quote is a direct measurement of them.
These statements depend on the market. In a market where the outrights are the liquid quote, a spread is no better than the two outrights that it is made from. The worked example later on this page shows how much depends on the relative bid-offer.
Why they cannot be bootstrapped#
The bootstrap needs each instrument to bring in one new unknown, using only unknowns that were found earlier. A switch or a fly breaks that. The 5s7s10s fly is there to fix the 7 year point, but it also contains the 10 year, which is not known until the 7 year is. The 7 and 10 year unknowns have to be solved together. The same is true in the long end, where the 15, 20 and 30 year points depend on each other through the flies that fix them.
An older workaround is to convert each spread into a synthetic outright. With the 5 and 10 year rates known, the 5s7s10s fly gives \(s(7) = \tfrac{1}{2}\,(\text{fly} + s(5) + s(10))\), and the bootstrap can then continue. It works when the set is exactly determined, but the noise in each quote is carried along the chain, it cannot weight the quotes by their reliability, and it cannot use a spread and an outright that overlap.
This is the main reason for a global solver. It treats every quote, whatever its type, as one equation in the full set of unknowns, and solves the whole set at once. The next sections describe how that works, and a later section returns to the spreads with numbers.
Sequential bootstrap and global solve#
The bootstrap solves for one unknown at a time and never revisits a pillar, which is why it cannot use the spreads above. A global solver treats all the discount factors as one vector of unknowns \(x\) and solves for them together. The unknowns are normally the log discount factors, \(x_j = \ln D(T_j)\), which keeps the discount factors positive. For each instrument \(i\), the residual is the difference between the quote that the curve implies and the quote in the market:
where \(q_i\) is the market quote and \(m\) is the number of instruments. A curve that reprices every input has \(r(x) = 0\). The solver has to find that \(x\). It cannot solve the equations directly, because the par rates are nonlinear functions of the discount factors, so it starts from a guess and improves it. To improve a guess it needs to know how the residuals change when the unknowns change. That is the Jacobian, described in the next section.
Aspect |
Sequential bootstrap |
Global solve |
|---|---|---|
Unknowns |
One at a time, shortest first. |
All at once. |
Instruments and knots |
One instrument per knot, with an exact fit. |
Any number of instruments, which can be more than the knots. |
Curve spreads (switches and flies) |
Cannot be used directly, because one quote involves several maturities. |
One more equation in the system, with its own weight. |
When quotes disagree |
Cannot say. It reprices each in turn, and a bad quote spreads along the curve. |
Gives a best fit in the least-squares sense, and the residuals show which quotes are out of line. |
Interpolation |
Local rules only, such as log-linear or monotone convex. |
Any rule, including smooth splines that depend on all the knots. |
Curves that depend on each other |
Only in one direction, solved in order. |
Any dependency, because every curve is in the same system. |
Speed |
Fast and simple. |
Slower, and needs a good starting point, but also gives the Jacobian as a by-product. |
Typical use |
Prototype, or a liquid curve with one clean instrument per pillar. |
Production curve sets, especially with several curves that depend on each other. |
When the number of instruments equals the number of knots, the two methods give the same curve. When there are more instruments than knots, the problem is over-determined, and the solver minimises a weighted sum of squares:
The weights \(w_i\) reflect the bid-offer spread or the reliability of each quote, so a liquid quote counts for more than a wide one. The optional term \(\lambda R(x)\) is a penalty for roughness, such as the integral of the squared change in the forward rate, and it trades fit for smoothness. This is a form of regularisation, and the amount \(\lambda\) is a methodology choice that should be documented.
The Jacobian#
What it is#
The Jacobian is the table of all the first derivatives of the residuals with respect to the unknowns:
It has one row for each instrument and one column for each unknown. The entry in row \(i\) and column \(j\) answers one question: if the log discount factor at knot \(j\) rises by a small amount, by how much does the par rate of instrument \(i\) change? For a curve with nine swaps and nine knots, \(J\) is a 9 by 9 table of numbers.
A small example#
Take two annual swaps, a 1 year at 4.00% and a 2 year at 3.80%, and two unknowns, \(x_1 = \ln D(1)\) and \(x_2 = \ln D(2)\). The par rate of the 1 year swap is \((1 - D_1)/D_1\), and the par rate of the 2 year swap is \((1 - D_2)/(D_1 + D_2)\), so the residuals are
and the Jacobian is the 2 by 2 matrix of their derivatives:
The first row is the 1 year swap. It has \(\partial r_1 / \partial x_1 = -1/D_1\) and a zero in the second column, because the 1 year swap does not depend on \(D(2)\) at all. The second row is the 2 year swap, which depends on both discount factors. The sign is negative throughout: raising a discount factor lowers a par rate.
Using it to solve#
Near the current guess, each residual is approximately a straight line in the unknowns, and the Jacobian is the slope:
The solver sets the right side to zero to find the step that would take the residuals to zero if the lines were exact:
This is Newton’s method. In the example, the starting guess is a flat discount rate of 3.5%, which gives \(D_1 = 0.9656\) and \(D_2 = 0.9324\). The residuals are -43.8 and -23.8 basis points, and the Jacobian at that point is
The first number says that a rise of 0.01 in \(\ln D(1)\) lowers the 1 year par rate by 1.04%. Solving \(J \Delta x = -r\) gives a step of \((-0.00423, -0.00453)\), so both log discount factors fall by about 0.4%. After one step the residuals are 0.09 and 0.05 basis points. After two they are zero to four decimal places. Newton’s method converges very fast near the solution, because each step removes most of the remaining error.
The solver repeats the same three actions at each iteration: reprice the instruments to get \(r\), compute \(J\), and solve for \(\Delta x\). The Jacobian is rebuilt each time, since the slopes change as the guess moves. It can be calculated by bumping each unknown and repricing, which is what the example does, or from analytic derivatives, or by automatic differentiation. The cost matters when a curve set has hundreds of unknowns.
When there are more instruments than unknowns, \(J\) is not square and the step solves the least-squares problem instead. With the weights \(W\), and a damping term \(\mu I\):
With \(\mu = 0\) this is Gauss-Newton, and when \(J\) is square and \(W\) is the identity it reduces to the Newton step above. With \(\mu > 0\) it is Levenberg-Marquardt, which adds damping so that the step stays stable when the starting point is poor. The damping is reduced as the iterations converge.
The shape of the Jacobian#
Which entries of \(J\) are not zero shows how the instruments depend on the knots. The example prints the pattern for the nine-swap curve, with a star where the entry is not zero:
Jacobian at the solution, '*' where the entry is not zero:
1Y 2Y 3Y 5Y 7Y 10Y 15Y 20Y 30Y <- unknown ln D(T)
1Y swap * . . . . . . . .
2Y swap * * . . . . . . .
3Y swap * * * . . . . . .
5Y swap * * * * . . . . .
7Y swap * * * * * . . . .
10Y swap * * * * * * . . .
15Y swap * * * * * * * . .
20Y swap * * * * * * * * .
30Y swap * * * * * * * * *
A swap depends on the discount factors up to its own maturity and on no later one, so everything above the diagonal is zero. The matrix is lower triangular. That has a useful consequence. A triangular system \(J \Delta x = -r\) can be solved from the top row down: the first equation has one unknown, the second has that one and one more, and so on. That is the bootstrap. The sequential bootstrap is the Newton step for a triangular Jacobian, solved one pillar at a time.
The global solver is needed when the Jacobian is not triangular. That happens when an instrument depends on a knot beyond its own maturity, which is the case for a spline that spreads the effect of each knot over its neighbours, and for curve sets where the curves depend on each other in both directions, as in Interest Rate Curve Build, Part 2: Multi-Curve & Basis. The entries above the diagonal are then not zero, and the equations have to be solved together.
The Jacobian also says how well-determined the curve is. The condition number of \(J\), which measures how much a small change in the quotes can change the solution, is 45 here, which is a healthy value. A very large number means that some instruments are nearly redundant or that the curve is barely pinned down by the data, and the solution is then unstable.
Worked example: the global fit#
The example runs in five parts. Parts 1 and 2 are the Newton iterations that are described above, first for the two-swap toy and then for the nine-swap curve. Part 3 solves the nine-swap problem with a least-squares solver and compares it with the bootstrap. Part 4 adds two quotes, at 4 and 6 years, that are slightly out of line with the others, and fits eleven quotes with the same nine knots. Part 5 uses the Jacobian for risk, in the next section.
Python code
"""Global solver for the curve, and curve risk from the Jacobian."""
import numpy as np
from scipy.optimize import least_squares
from curve_example import PAR_RATES, PILLARS, Curve, bootstrap, forward_swap
N = 100e6
def curve_from(x, knots=PILLARS):
"""A curve whose unknowns are the log discount factors at the knots."""
return Curve(np.array(knots, dtype=float), np.exp(x))
def par_rates(curve, maturities):
return np.array([forward_swap(curve, 0, int(m))[0] for m in maturities])
def solve_global(maturities, quotes, knots=PILLARS):
"""Fit every quote at once. With more quotes than knots this is a least-squares fit."""
residuals = lambda x: par_rates(curve_from(x, knots), maturities) - quotes
fit = least_squares(residuals, -0.035 * np.array(knots, dtype=float), method="lm", xtol=1e-14, ftol=1e-14)
return fit.x, fit.fun
def jacobian(function, x, step=1e-6):
"""Central-difference Jacobian of a vector function."""
columns = []
for i in range(len(x)):
up, down = x.copy(), x.copy()
up[i] += step
down[i] -= step
columns.append((function(up) - function(down)) / (2 * step))
return np.array(columns).T
def payer_pv(curve, maturity, strike):
"""PV of paying fixed against an overnight floating leg, per unit notional."""
return (1.0 - curve.df(maturity)) - strike * curve.df(np.arange(1, maturity + 1)).sum()
def newton(maturities, quotes, knots, iterations=6, verbose=False):
"""Newton's method on r(x) = par rates(x) - quotes. Each step solves J dx = -r with the Jacobian J."""
x = -0.035 * np.array(knots, dtype=float) # a flat 3.5% guess for the log discount factors
quote_fn = lambda v: par_rates(curve_from(v, knots), maturities)
worst = []
for k in range(iterations + 1):
r = quote_fn(x) - quotes
worst.append(np.max(np.abs(r)) * 1e4)
if verbose and k < 2:
j = jacobian(quote_fn, x)
print(f" iteration {k}: residuals {np.round(r * 1e4, 2)} bp")
print(f" Jacobian (rows: instruments, columns: ln D(1Y), ln D(2Y)):\n{np.round(j, 4)}")
print(f" step dx = -J^-1 r = {np.round(-np.linalg.solve(j, r), 5)}")
if k < iterations:
x = x - np.linalg.solve(jacobian(quote_fn, x), r)
return x, worst
if __name__ == "__main__":
quotes = np.array(PAR_RATES)
base = bootstrap()
# 1. A toy with two instruments, to show what the Jacobian is and what a Newton step does.
print("1. Two swaps (1Y at 4.00%, 2Y at 3.80%), two unknowns (ln D(1Y), ln D(2Y)):")
toy_x, toy_worst = newton([1, 2], np.array([0.0400, 0.0380]), [1, 2], iterations=4, verbose=True)
print(f" largest residual by iteration (bp): {np.round(toy_worst, 4)}")
print(f" solution: D(1Y) {np.exp(toy_x[0]):.6f}, D(2Y) {np.exp(toy_x[1]):.6f}\n")
# 2. The nine-swap curve: the shape of the Jacobian, and how fast Newton's method converges.
quote_fn = lambda v: par_rates(curve_from(v), PILLARS)
x_newton, worst = newton(PILLARS, quotes, PILLARS)
j_full = jacobian(quote_fn, x_newton)
print("2. Nine swaps, nine unknowns. Jacobian at the solution, '*' where the entry is not zero:")
print(" " + " ".join(f"{p:>3}Y" for p in PILLARS) + " <- unknown ln D(T)")
for i, p in enumerate(PILLARS):
print(f" {p:>3}Y swap " + " ".join(f"{'*' if abs(j_full[i, k]) > 1e-9 else '.':>4}" for k in range(len(PILLARS))))
print(f" largest residual by Newton iteration (bp): {np.array2string(np.array(worst), precision=2, suppress_small=True)}")
print(f" largest difference from the bootstrap: {np.max(np.abs(np.exp(x_newton) - base.df(np.array(PILLARS)))):.1e}")
print(f" condition number of the Jacobian: {np.linalg.cond(j_full):.1f}\n")
# 3. The same problem with the least-squares solver, then with more quotes than knots.
x, residual = solve_global(PILLARS, quotes)
largest = np.max(np.abs(np.exp(x) - base.df(np.array(PILLARS))))
print(f"3. Least-squares solver vs bootstrap: largest DF difference {largest:.1e}\n")
extra_maturities = [4, 6]
implied = par_rates(base, extra_maturities)
extra_quotes = implied + np.array([0.00015, -0.00010])
all_maturities = list(PILLARS) + extra_maturities
all_quotes = np.concatenate([quotes, extra_quotes])
x_fit, residual = solve_global(all_maturities, all_quotes)
order = np.argsort(all_maturities)
print("4. Eleven quotes, nine knots (4Y and 6Y quoted 1.5bp high and 1.0bp low):")
for i in order:
print(f" {all_maturities[i]:>3}Y residual {residual[i] * 1e4:+6.2f} bp")
# 5. Curve risk from the Jacobian, in the three steps, checked against a full rebuild for every quote.
# A 6Y swap is not one of the inputs, so its risk falls on the 5Y and 7Y quotes either side.
j_x = jacobian(quote_fn, x) # step 1: d(par rates)/d(log DFs)
d_x_d_quote = np.linalg.inv(j_x) # step 2: d(log DFs)/d(quotes), by the implicit function theorem
strike = forward_swap(base, 0, 6)[0]
pv_fn = lambda x_: N * payer_pv(curve_from(x_), 6, strike)
d_pv_d_x = jacobian(lambda x_: np.array([pv_fn(x_)]), x)[0] # step 3: d(trade PV)/d(log DFs)
jacobian_risk = d_pv_d_x @ d_x_d_quote * 1e-4 # per +1bp in each quote
print(f"\n5. Risk of a 6Y payer swap struck at par (PV {pv_fn(x):,.0f}), in three steps:")
print(" Step 2: how each log discount factor moves when one quote rises 1bp (bp of ln D)")
print(" Step 3: how the swap's PV moves when each log discount factor rises 1bp")
print(f" {'Pillar':>7} {'5Y quote bump':>14} {'7Y quote bump':>14} {'Swap PV per 1bp of ln D':>25}")
for k, p in enumerate(PILLARS):
print(f" {p:>6}Y {d_x_d_quote[k, 3]:14.3f} {d_x_d_quote[k, 4]:14.3f} {d_pv_d_x[k] * 1e-4:25,.1f}")
print(f" Risk to the 5Y quote = sum of (column 1 x column 3) = {np.sum(d_x_d_quote[:, 3] * d_pv_d_x * 1e-4):,.0f}")
print(f" Risk to the 7Y quote = sum of (column 2 x column 3) = {np.sum(d_x_d_quote[:, 4] * d_pv_d_x * 1e-4):,.0f}")
bumped_risk = []
for i in range(len(PILLARS)):
bumped = quotes.copy()
bumped[i] += 1e-4
bumped_curve = bootstrap(PILLARS, bumped)
bumped_risk.append(N * payer_pv(bumped_curve, 6, strike) - pv_fn(x))
print("\n Risk per +1bp in each input, against bumping the quote and rebuilding the curve:")
print(f" {'Input':>6} {'Jacobian':>11} {'Rebuild':>11}")
for maturity, jac, bump in zip(PILLARS, jacobian_risk, bumped_risk):
print(f" {maturity:>5}Y {jac:11,.1f} {bump:11,.1f}")
print(f" {'Total':>6} {jacobian_risk.sum():11,.1f} {np.sum(bumped_risk):11,.1f}")
The output for parts 1 to 4 is:
1. Two swaps (1Y at 4.00%, 2Y at 3.80%), two unknowns (ln D(1Y), ln D(2Y)):
iteration 0: residuals [-43.8 -23.8] bp
Jacobian (rows: instruments, columns: ln D(1Y), ln D(2Y)):
[[-1.0356 0. ]
[-0.0181 -0.5087]]
step dx = -J^-1 r = [-0.00423 -0.00453]
iteration 1: residuals [0.09 0.05] bp
Jacobian (rows: instruments, columns: ln D(1Y), ln D(2Y)):
[[-1.04 0. ]
[-0.0193 -0.5098]]
step dx = -J^-1 r = [1.e-05 1.e-05]
largest residual by iteration (bp): [43.8029 0.0928 0. 0. 0. ]
solution: D(1Y) 0.961538, D(2Y) 0.928190
2. Nine swaps, nine unknowns. Jacobian at the solution, '*' where the entry is not zero:
(the pattern shown above)
largest residual by Newton iteration (bp): [43.8 0.17 0. 0. 0. 0. 0. ]
largest difference from the bootstrap: 4.5e-13
condition number of the Jacobian: 45.0
3. Least-squares solver vs bootstrap: largest DF difference 4.5e-13
4. Eleven quotes, nine knots (4Y and 6Y quoted 1.5bp high and 1.0bp low):
1Y residual -0.00 bp
2Y residual -0.00 bp
3Y residual +0.42 bp
4Y residual -1.12 bp
5Y residual +0.35 bp
6Y residual +0.85 bp
7Y residual -0.50 bp
10Y residual +0.00 bp
15Y residual +0.00 bp
20Y residual +0.00 bp
30Y residual +0.00 bp
Reading the output:
The toy converges in two steps. The largest residual falls from 43.8 basis points to 0.09 after one Newton step, and is zero to the precision shown after two. The solution is \(D(1) = 0.961538\) and \(D(2) = 0.928190\), which are the discount factors of the swap-only curve from Interest Rate Curve Build, Part 1: Instruments & Bootstrapping.
The nine-swap curve converges just as fast, from 43.8 basis points to 0.17 after one step and below 0.01 after the next. The answer matches the bootstrap to \(10^{-12}\), as it should, since it is the same problem.
With extra quotes the curve no longer reprices everything. The misfit of the two extra quotes is shared with their neighbours, from 3 to 7 years. The residuals tell the curve owner which quotes to examine. A fit that leaves a residual is not an error. The question for control is whether the residuals are within the quote’s bid-offer spread.
Using it for risk#
Once the curve is solved, the same Jacobian gives the risk of a trade to every input quote. A trader wants to know how the value of a trade changes when each input quote moves, for example by one basis point. That is a bucketed, or key-rate, risk, and it is also what a hedge is built from, because each input is an instrument that can be traded. There are three steps.
Step 1: the Jacobian at the solution. \(J\) is the matrix that the solver already has.
Step 2: how the curve moves when a quote moves. The curve is defined implicitly by \(r(x, q) = 0\). If a quote \(q_k\) rises by a small amount, the unknowns must change to keep every residual at zero. The implicit function theorem gives the answer. Because each residual is the repriced rate less its own quote, the derivative of the residual with respect to its quote is the identity, and
Column \(k\) of the inverse is the change in every log discount factor when quote \(k\) rises by one unit, with the other quotes held fixed.
Step 3: how the trade’s value moves when the curve moves. The trade has a value \(V(x)\) that depends on the discount factors. Its derivative \(\partial V / \partial x\) has one number per knot. It can be calculated by bumping each discount factor, or analytically.
Combine them with the chain rule. The risk to quote \(k\) is the sum, over all the knots, of the trade’s sensitivity to a knot times the movement of that knot when the quote changes:
One matrix inverse serves every trade. Each trade only needs its own \(\partial V / \partial x\). This is much faster than one curve rebuild per input when there are hundreds of inputs, and it is exact, not a finite difference. Automatic differentiation computes the same quantities faster still in large systems.
For several curves, \(J\) covers the whole set. If the curves depend on each other in both directions, \(J\) is not triangular, and one inverse still gives the risk of every trade to every input in every curve.
Worked example: bucketed risk#
The example values a 6-year payer swap, struck at the 6-year par rate, for 100 million on the swap-only curve. A 6-year swap is not one of the inputs, so its risk falls on the quotes on either side. The first table gives the numbers for steps 2 and 3, for the 5 and 7 year quotes:
5. Risk of a 6Y payer swap struck at par (PV 0), in three steps:
Step 2: how each log discount factor moves when one quote rises 1bp (bp of ln D)
Step 3: how the swap's PV moves when each log discount factor rises 1bp
Pillar 5Y quote bump 7Y quote bump Swap PV per 1bp of ln D
1Y -0.000 -0.000 -352.6
2Y -0.000 -0.000 -340.4
3Y -0.000 -0.000 -487.7
5Y -5.087 -0.000 -4,642.3
7Y 0.382 -7.404 -4,176.9
10Y 0.391 0.715 0.0
15Y 0.408 0.745 0.0
20Y 0.398 0.727 0.0
30Y 0.361 0.659 0.0
Risk to the 5Y quote = sum of (column 1 x column 3) = 22,019
Risk to the 7Y quote = sum of (column 2 x column 3) = 30,926
Reading the table:
Step 2, the first two columns. A 1 basis point rise in the 5 year quote lowers \(\ln D(5)\) by 5.09 basis points and does not move the earlier pillars at all, since the Jacobian is triangular. It raises the later pillars by about 0.4 basis points, because the 7 year and longer quotes are held fixed and the curve has to compensate. This is the sawtooth from Interest Rate Curve Build, Part 1: Instruments & Bootstrapping seen in the discount factors. A 1 basis point rise in the 7 year quote lowers \(\ln D(7)\) by 7.40 basis points.
Step 3, the last column. The 6 year swap is sensitive to the discount factors up to 7 years, and not beyond, since its last payment is at 6 years. It is most sensitive to the 5 and 7 year pillars, whose discount factors the 6 year payment dates are interpolated from.
The combination. The risk to the 5 year quote is \((-5.087 \times -4642.3) + (0.382 \times -4176.9) \approx 23{,}616 - 1{,}596 = 22{,}020\), in agreement with the 22,019 in the output. The risk to the 7 year quote is \(-7.404 \times -4176.9 \approx 30{,}926\), since the 5 year pillar does not move when the 7 year quote changes.
The Jacobian risk is then compared with bumping each quote by 1 basis point and rebuilding the curve:
Risk per +1bp in each input, against bumping the quote and rebuilding the curve:
Input Jacobian Rebuild
1Y 0.2 0.2
2Y 0.4 0.4
3Y 1.0 1.0
5Y 22,019.1 22,019.0
7Y 30,925.5 30,926.7
10Y 0.0 -0.0
15Y 0.0 -0.0
20Y 0.0 -0.0
30Y 0.0 -0.0
Total 52,946.3 52,947.3
The Jacobian and the bump-and-rebuild agree on the bucketed risk of the 6 year swap.#
The risk sits on the 5-year and 7-year inputs, with 22,019 on the 5-year and 30,926 on the 7-year. A trader would hedge with 5-year and 7-year swaps in those amounts.
The Jacobian and the rebuild agree. They differ by about one part in 50,000, because the Jacobian is the exact derivative and the bump is a finite 1 basis point change, which includes a small amount of convexity in the trade’s value.
The short pillars have a small risk, because the 5-year discount factor depends on the earlier ones through the bootstrap.
The Jacobian is also used for scenario analysis, for hedging (solve for the amounts of the input instruments that offset the risk), and in XVA, where the sensitivities to the curve inputs of a whole portfolio are needed.
Switches and flies in the solver#
The first section of this page, Why a global solver: curve spreads, explained what switches and flies are and why they cannot be bootstrapped. Now that the solver and the Jacobian are in place, this section shows what spreads look like in the Jacobian, how the solver uses them, and what they add to the accuracy, the checking and the risk of a curve.
The shape of the Jacobian with spreads#
The Jacobian shows the problem exactly. The pattern below is for a curve with nine knots that is quoted with three outrights (1, 2 and 10 year), two switches (2s5s and 10s30s) and four flies. Compare it with the triangular pattern of nine outrights shown earlier:
Jacobian pattern, three outrights, two switches, four flies (condition number 58.0)
1Y 2Y 3Y 5Y 7Y 10Y 15Y 20Y 30Y
1Y * . . . . . . . .
2Y * * . . . . . . .
10Y * * * * * * . . .
2s5s * * * * . . . . .
10s30s * * * * * * * * *
2s3s5s * * * * . . . . .
5s7s10s * * * * * * . . .
10s15s20s * * * * * * * * .
15s20s30s * * * * * * * * *
Each row only reaches out as far as its longest tenor, but the matrix as a whole is not lower triangular. The rows that fix the 3 and 5 year knots both reach out to 5 years, the rows for the 7 and 10 year both reach out to 10 years, and the three rows that fix the 15, 20 and 30 year knots reach out to 20 or 30 years. The unknowns come in blocks of 2, 2 and 3 that have to be solved together. The matrix is block triangular, and that is the reason to solve for all the unknowns at once. The condition number rises from 45 to 58, so the problem is slightly more sensitive to the data.
How a global solver uses them#
In a global solver every quote, whatever its type, is one more residual. For an instrument with weights \(c\), the residual and its row of the Jacobian are
so the Jacobian row of a switch is the row of the long swap less the row of the short swap, and the row of a fly is twice the row of the belly less the rows of the wings. Nothing else changes in the solver. The residuals are divided by the noise \(\sigma_i\) of each quote, which is the weight \(w_i = 1/\sigma_i^2\) in the least-squares problem from the start of the page. A quote with a wide bid-offer counts for little, and a tight one counts for a lot.
This also makes it possible to combine quotes. If a tenor has an outright quote and is also in a fly, both are used, each with its weight. There are then more quotes than unknowns, and the solver gives the best compromise and the residuals that show where the quotes disagree.
Worked example#
The example uses the swap-only curve from Interest Rate Curve Build, Part 1: Instruments & Bootstrapping as the true curve, with nine knots. It builds three sets of quotes, adds simulated noise to every quote in proportion to its assumed bid-offer, and solves for the curve each time. The noise levels are invented to show the mechanics:
Quote |
Noise (bp) |
Comment |
|---|---|---|
Outrights 1, 2, 5, 10 and 30 year |
0.5 |
Liquid benchmarks |
Outrights 3, 7, 15 and 20 year |
1.5 |
Less liquid, so wide or stale |
Switches (2s5s, 5s10s, 10s30s) and flies (2s3s5s, 5s7s10s, 10s15s20s, 15s20s30s) |
0.25 |
Assumed tighter, because they trade as packages |
The three sets are:
A, nine outrights. The standard input. This is the same as a bootstrap.
B, three outrights and six spreads. The 1, 2 and 10 year outrights, the switches 2s5s and 10s30s, and the four flies. It has nine quotes for nine unknowns, so the fit is exact, but the less liquid tenors are set by the flies.
C, everything. The nine outrights, three switches and four flies, which is 16 quotes for nine unknowns. They are weighted by \(1/\sigma^2\).
Python code
"""Curve switches and flies as inputs to a global solver, and what they do to accuracy, structure and risk."""
import numpy as np
from scipy.optimize import least_squares
from curve_example import PAR_RATES, PILLARS, bootstrap
from curve_global_example import N, curve_from, jacobian, par_rates, payer_pv
PIL = list(PILLARS) # the nine knots: 1, 2, 3, 5, 7, 10, 15, 20, 30
TRUE_PAR = np.array(PAR_RATES)
# name: (tenors, coefficients, assumed bid-offer noise in bp). The value of an instrument is sum(coef x par rate).
# outright : the par swap rate. switch: long end less short end. fly: 2 x belly less the two wings.
INSTRUMENTS = {
"1Y": ((1,), (1,), 0.5), "2Y": ((2,), (1,), 0.5), "5Y": ((5,), (1,), 0.5),
"10Y": ((10,), (1,), 0.5), "30Y": ((30,), (1,), 0.5),
"3Y": ((3,), (1,), 1.5), "7Y": ((7,), (1,), 1.5), "15Y": ((15,), (1,), 1.5), "20Y": ((20,), (1,), 1.5),
"2s5s": ((2, 5), (-1, 1), 0.25), "5s10s": ((5, 10), (-1, 1), 0.25), "10s30s": ((10, 30), (-1, 1), 0.25),
"2s3s5s": ((2, 3, 5), (-1, 2, -1), 0.25), "5s7s10s": ((5, 7, 10), (-1, 2, -1), 0.25),
"10s15s20s": ((10, 15, 20), (-1, 2, -1), 0.25), "15s20s30s": ((15, 20, 30), (-1, 2, -1), 0.25),
}
SET_A = ["1Y", "2Y", "3Y", "5Y", "7Y", "10Y", "15Y", "20Y", "30Y"] # nine outrights
SET_B = ["1Y", "2Y", "10Y", "2s5s", "10s30s", "2s3s5s", "5s7s10s", "10s15s20s", "15s20s30s"] # spreads for the rest
SET_C = SET_A + ["2s5s", "5s10s", "10s30s", "2s3s5s", "5s7s10s", "10s15s20s", "15s20s30s"] # everything, 16 quotes
def coefficients(names):
c = np.zeros((len(names), len(PIL)))
for i, name in enumerate(names):
for tenor, coef in zip(*INSTRUMENTS[name][:2]):
c[i, PIL.index(tenor)] = coef
return c
def noise_bp(names, scale=1.0, spread_noise=None):
out = []
for name in names:
sigma = INSTRUMENTS[name][2]
if spread_noise is not None and name[0].isdigit() and "s" in name:
sigma = spread_noise
out.append(sigma * scale)
return np.array(out)
def solve(names, quotes, sigma_bp):
"""Weighted least squares, each residual divided by its noise. Exactly determined sets give a zero fit."""
c = coefficients(names)
sigma = sigma_bp / 1e4
fun = lambda x: (c @ par_rates(curve_from(x), PIL) - quotes) / sigma
fit = least_squares(fun, -0.035 * np.array(PIL, float), method="lm", xtol=1e-13, ftol=1e-13)
return fit.x, fit.fun * sigma
def run(names, trials, rng, spread_noise=None):
"""Monte Carlo: simulate noisy quotes around the true curve, solve, and return the par rate errors in bp."""
c_all = coefficients(list(INSTRUMENTS))
all_names = list(INSTRUMENTS)
exact = dict(zip(all_names, c_all @ TRUE_PAR))
sigma_all = dict(zip(all_names, noise_bp(all_names, spread_noise=spread_noise)))
errors = np.zeros((trials, len(PIL)))
for t in range(trials):
noisy = np.array([exact[n] + rng.normal(0.0, sigma_all[n] / 1e4) for n in names])
x, _ = solve(names, noisy, np.array([sigma_all[n] for n in names]))
errors[t] = (par_rates(curve_from(x), PIL) - TRUE_PAR) * 1e4
return errors
if __name__ == "__main__":
base = bootstrap()
x_true = np.log(base.df(np.array(PIL, float)))
print("Assumed noise (bp): outrights 1Y 2Y 5Y 10Y 30Y 0.5, outrights 3Y 7Y 15Y 20Y 1.5, switches and flies 0.25\n")
# 1. Structure: which knots each instrument depends on. Exactly determined sets A and B.
for label, names in (("A: nine outrights", SET_A), ("B: three outrights, two switches, four flies", SET_B)):
c = coefficients(names)
j = jacobian(lambda x_: c @ par_rates(curve_from(x_), PIL), x_true)
print(f"1. Jacobian pattern, set {label} (condition number {np.linalg.cond(j):.1f})")
print(" " + " ".join(f"{p:>3}Y" for p in PIL))
for i, name in enumerate(names):
print(f" {name:>10} " + " ".join(f"{'*' if abs(j[i, k]) > 1e-9 else '.':>4}" for k in range(len(PIL))))
print()
# 2. Accuracy: the error in each par rate over 300 simulated quote snapshots.
rng = np.random.default_rng(11)
trials = 300
res = {label: run(names, trials, rng) for label, names in (("A", SET_A), ("B", SET_B), ("C", SET_C))}
print(f"2. RMS error of each par rate against the true curve, {trials} simulated snapshots (bp):")
print(f" {'Tenor':>6} {'A: outrights':>13} {'B: spreads':>11} {'C: all 16':>10}")
for k, tenor in enumerate(PIL):
print(f" {tenor:>5}Y " + " ".join(f"{np.sqrt(np.mean(res[s][:, k] ** 2)):>{w}.2f}" for s, w in (("A", 13), ("B", 11), ("C", 10))))
print(f" {'All':>6} " + " ".join(f"{np.sqrt(np.mean(res[s] ** 2)):>{w}.2f}" for s, w in (("A", 13), ("B", 11), ("C", 10))))
# 3. It depends on how tight the spread quotes are.
print("\n3. RMS error of the 7Y par rate (bp) as the bid-offer on switches and flies changes (outrights unchanged):")
print(f" {'Spread noise':>13} {'A: outrights':>13} {'B: spreads':>11} {'C: all 16':>10}")
k7 = PIL.index(7)
for spread_noise in (0.25, 0.5, 1.0, 1.5, 3.0):
row = [np.sqrt(np.mean(run(names, 120, rng, spread_noise)[:, k7] ** 2)) for names in (SET_A, SET_B, SET_C)]
print(f" {spread_noise:>10.2f}bp {row[0]:13.2f} {row[1]:11.2f} {row[2]:10.2f}")
# 4. Using the extra quotes to catch a bad one: the 7Y outright is 5bp stale, everything else is exact.
c_all = coefficients(SET_C)
quotes = c_all @ TRUE_PAR
quotes[SET_C.index("7Y")] += 5e-4
x_fit, residual = solve(SET_C, quotes, noise_bp(SET_C))
print("\n4. Sixteen quotes where the 7Y outright is 5bp stale: fitted less quoted, in bp and in noise units")
print(f" {'Quote':>10} {'Residual':>9} {'In sigmas':>10}")
for name, r in zip(SET_C, residual):
print(f" {name:>10} {r * 1e4:+8.2f} {r * 1e4 / INSTRUMENTS[name][2]:+9.1f}")
# 5. Curve risk in the spread quotes: a 6Y payer swap, set B. Jacobian against bump-and-rebuild.
cb = coefficients(SET_B)
quote_fn = lambda x_: cb @ par_rates(curve_from(x_), PIL)
j_b = jacobian(quote_fn, x_true)
strike = par_rates(base, [6])[0]
pv_fn = lambda x_: N * payer_pv(curve_from(x_), 6, strike)
d_pv_d_x = jacobian(lambda x_: np.array([pv_fn(x_)]), x_true)[0]
risk_jac = d_pv_d_x @ np.linalg.inv(j_b) * 1e-4
exact_b = cb @ TRUE_PAR
risk_bump = []
for i in range(len(SET_B)):
bumped = exact_b.copy()
bumped[i] += 1e-4
x_b, _ = solve(SET_B, bumped, noise_bp(SET_B))
risk_bump.append(pv_fn(x_b) - pv_fn(x_true))
print(f"\n5. Risk of a 6Y payer swap struck at par (PV {pv_fn(x_true):,.0f}) per +1bp in each set B quote:")
print(f" {'Quote':>10} {'Jacobian':>11} {'Rebuild':>11}")
for name, jac, bump in zip(SET_B, risk_jac, risk_bump):
print(f" {name:>10} {jac:11,.1f} {bump:11,.1f}")
The first test repeats the experiment 300 times with different random noise and measures the error of each par rate against the true curve:
RMS error of each par rate against the true curve, 300 simulated snapshots (bp):
Tenor A: outrights B: spreads C: all 16
1Y 0.52 0.50 0.53
2Y 0.47 0.53 0.30
3Y 1.48 0.55 0.29
5Y 0.50 0.57 0.27
7Y 1.53 0.39 0.28
10Y 0.48 0.48 0.27
15Y 1.59 0.53 0.30
20Y 1.52 0.56 0.32
30Y 0.52 0.56 0.31
All 1.09 0.52 0.33
The outrights give the curve the error of their worst quotes. In A, the 3, 7, 15 and 20 year points have an error of about 1.5 basis points, which is the noise on those outrights, and the benchmarks about 0.5.
The spreads fix the less liquid tenors. In B, the error at those tenors falls from about 1.5 to about 0.5 basis points, and the overall error from 1.09 to 0.52. The benchmark tenors are slightly worse, at 0.5 to 0.6 against 0.5, since they are now set from an outright plus a switch, and the noise of the two adds up.
Using everything is best. In C, the error is 0.33 overall, and under 0.35 at every tenor but the 1 year. The extra quotes average out the noise, and the 1 year, which has only one quote, is unchanged.
The second test changes how tight the spread quotes are, with the outrights unchanged, and shows the 7 year point:
RMS error of the 7Y par rate (bp) as the bid-offer on switches and flies changes (outrights unchanged):
Spread noise A: outrights B: spreads C: all 16
0.25bp 1.60 0.36 0.26
0.50bp 1.53 0.51 0.39
1.00bp 1.58 0.79 0.56
1.50bp 1.60 1.08 0.78
3.00bp 1.41 2.28 1.04
The benefit depends on the spread bid-offer. At 0.25 basis points the spreads give an error of 0.36, against 1.60 for the outright. The benefit fades as the spread noise grows: at 1.5 basis points, the same as the outright’s noise, set B is still better, at 1.08, because the tight benchmark outrights anchor it, but the gain is much smaller.
A badly quoted spread is worse than the outright. At 3 basis points, set B has an error of 2.28, which is more than the 1.41 of the outright, because the noise in each spread is carried down the chain of knots. The combined set C is still better than A, since the weights give a noisy quote little say.
The weights have to be right. The solver can only down-weight a noisy quote if it knows it is noisy, so the bid-offers that set the weights are an input that has to be maintained.
The third test uses the extra quotes as a check. In set C every quote is exact except that the 7 year outright is 5 basis points stale:
Sixteen quotes where the 7Y outright is 5bp stale: fitted less quoted, in bp and in noise units
Quote Residual In sigmas
1Y -0.00 -0.0
2Y +0.11 +0.2
3Y +0.12 +0.1
5Y +0.14 +0.3
7Y -4.83 -3.2
10Y +0.14 +0.3
15Y +0.12 +0.1
20Y +0.11 +0.1
30Y +0.11 +0.2
2s5s +0.03 +0.1
5s10s -0.00 -0.0
10s30s -0.03 -0.1
2s3s5s -0.00 -0.0
5s7s10s +0.07 +0.3
10s15s20s -0.00 -0.0
15s20s30s -0.00 -0.0
The fitted curve ignores the stale quote, since the 5s7s10s fly and the benchmark outrights say what the 7 year should be. Only the 7 year outright has a large residual, which is 4.8 basis points or 3.2 times its noise, and everything else is within 0.3. A residual of three or more noise units is a flag for review. Without the overlap, a stale quote would look like any other quote and go straight into the curve.
The last test is risk. For the set B, the Jacobian is square and the risk to every quote comes from \(\partial V/\partial q = \partial V/\partial x \, J^{-1}\), as in the previous section. The trade is the 6 year payer swap, and the risk is the change in PV for a rise of 1 basis point in each quote with the others held fixed:
Risk of a 6Y payer swap struck at par (PV 0) per +1bp in each set B quote:
Quote Jacobian Rebuild
1Y 0.2 0.2
2Y 37,483.3 37,473.3
10Y 15,462.8 15,463.1
2s5s 37,482.3 37,474.9
10s30s 0.0 0.0
2s3s5s 0.5 0.5
5s7s10s 15,462.8 15,463.1
10s15s20s 0.0 0.0
15s20s30s 0.0 0.0
The risk is in the instruments that set the 5 and 7 year rates. In this set, the 5 year rate is the 2 year outright plus the 2s5s switch, and the 7 year rate is half of the sum of the 5s7s10s fly and the 5 and 10 year rates. The 6 year swap depends on the 5 and 7 year rates, so its risk is on the 2 year, 2s5s, 10 year and 5s7s10s quotes.
It is the same risk in a different basis. From the outright risk in the previous section, 22,019 to the 5 year and 30,926 to the 7 year, the 2 year and 2s5s risk is \(22{,}019 + \tfrac{1}{2} \times 30{,}926 = 37{,}482\), and the 10 year and 5s7s10s risk is \(\tfrac{1}{2} \times 30{,}926 = 15{,}463\). The Jacobian is what converts the risk from one set of instruments to another.
It is the hedge in the instruments that trade. A trader who hedges with switches and flies can read the amounts directly. The Jacobian and the rebuild agree to within 0.03%.
Practical points
Practical points#
Starting point: a global solve needs one. The sequential bootstrap is often used to supply it, and the quality of the start decides how many iterations are needed.
Convergence: the solver stops when the residuals and the step are below a tolerance. A tolerance that is too loose leaves a repricing error, and a failure to converge is a sign of a bad quote or a bad set-up.
Computing the Jacobian: bumping each unknown is simple, but costs one repricing per unknown at every iteration. Analytic derivatives or automatic differentiation are faster for large curve sets.
Weights and penalty: these are methodology choices. They should be set from the bid-offer spreads and documented, since they decide how a conflict between quotes is resolved.
Snapshots: all the quotes must come from the same time. A stale quote in a global fit spreads its error into the neighbours.
Extrapolation: beyond the last liquid pillar the curve is an assumption, such as a flat last forward rate or a convergence to a long-run forward rate, and it needs its own control.
A valuation control view#
Independent rebuild: rebuild the curve with a different solver or tool, and compare the discount factors and the par rates. The third part of the output above is a small version of this test, as it compares a global solve with a bootstrap.
Review the residuals: for a global fit, the residual by instrument is reviewed against a tolerance based on the bid-offer. A growing residual on one quote is an input problem to investigate.
Reconcile the risk: compare the Jacobian risk of a test trade with the risk from bumping, as in the output above, and with the risk system. A break points to a different interpolation, a different set of inputs, or a bug.
Check the Jacobian itself: its pattern should match the curve’s structure, triangular for a bootstrap, block triangular when spreads are used, and with known off-diagonal blocks for linked curves. Its condition number should be stable from day to day, and a jump is a sign of redundant or conflicting inputs.
Cross-check outrights against spreads: where a tenor has both an outright quote and a switch or fly, the residual in a combined fit is a ready-made test of the outright. A residual of three or more noise units is reviewed, as in the stale 7 year example above.
Maintain the bid-offers: the weights come from the bid-offer of each quote, and a spread is only worth using if it is tighter than the outrights it replaces. The bid-offers are reviewed against the market, and a change is a change to the methodology.
Know which quotes are observable: a tenor set only by a fly is only as observable as the fly and the benchmarks around it. That feeds the level judgement for long-dated trades.
Document the choices: the instruments in each pillar, the weights, the penalty, the interpolation and the extrapolation are all part of the methodology. See Governance: Model Risk, Accountability and Data.
One methodology everywhere: a curve built one way for pricing and another way for risk will produce risk that does not match the P&L.
Link to reserves and levels: quotes for long maturities and for illiquid basis curves may not be observable, which affects the level and the valuation reserves. See Fair-Value Hierarchy: Levels 1, 2 & 3.
Next, Interest Rate Curve Build, Part 4: Regression Fits covers curves that are fitted to the quotes, and not made to reprice them.