Building the (zero-coupon) yield curve is the first step in most of the financial modeling problems. We will present in this post how the yield curve is computed into LexiFi Apropos, and how we make our algorithm generic so that it can easily be used to compute different kinds of yield curves or solve different problems.
Simple formulation of the problem
We assume a simplified market where we can observe the Deposit Rates and the Swap Rates. We also assume there is only one curve.
Let be today’s value of the -maturing bond. Building the yield curve means finding a function that allows
to match the market price of Deposit Rates and Swap Rates.
Let be the value of the -maturing deposit. We have:
Let be the value of the -maturing swap rate. We assume that the fix leg period of the swap is . We have:
We observe on the market for and for , where
Resolution of the simple problem
We define :
We note that only depends on for .
The problem can then be solved by using a “bootstrap” procedure:
- find on that allows to match
- find on that allows to match , knowing on
- …
- find on that allows to match , knowing on
The previous problem has an infinity of solutions. To avoid that, we can use a parametrisation such as for .
Let be the observed value of the -th instrument. We define the value of the -th instrument if the curve is .
The problem is now:
- find so that
- find so that
- …
- find so that
- set
At each step, there is only one real root to find.
Now, we need to find a good parametrisation for . In order to do that, we recall that there are some natural ways of rewriting the curve defining the yield:
or the instantaneous forward rate:
Thus, one needs to parametrise only or , using for instance a piecewise constant or a piecewise affine term-structure.
Remark on possible parametrisations
The use of a piecewise affine function for seems a good idea as it leads to a function . However, the resulting function can be “unstable”, because the mid value depends on the left value: a small perturbation on the left value will be compensated by a perturbation on the right value, in the opposite direction (and will propagate to the last date). On the other hand, the use of a piecewise constant function for leads to a only function , but with a more stable result as in this case the mid values depend only on the left value (then a small perturbation on the beginning of the curve doesn’t propagate itself).
At first, it seems that there is a trade-off between curve smoothness and curve stability. However, it can be easily solved by using a two step building procedure:
- Step 1: Bootstrap using a piecewise constant instantaneous forward.
- Step 2: Keep the bootstrapped values on the pillar dates (the dates on which is needed to match the market prices), and interpolate between these dates using a monotonic cubic spline for the yield.
This procedure leads to a stable and smooth curve, but requires one more step.
Proposed parametrisation of the curve
Even though the two step procedure is a good choice, we propose a different method, that is only one step, and achieves the same smoothness and stability. For that, we use a locally affine parametrisation of the instantaneous forward , ie given a level , is affine from to and constant after (until ):
- for
- for
Here is a visual example of this function:
This parametrisation leads to a function , and then functions and . The stability is achieved when we choose a small value for , as is almost piecewise constant in this case.
Generalisation
In finance, there are a lot of problems that require bootstrapping a function of the form . Then it can be a good idea to think about a generic implementation of this problem solving. In order to do that, we start by defining simple algebra for formula to bootstrap:
Expression Expression + Expression
Expression Expression * Expression
Expression (Expression)
Expression float
Expression P(date, date)
Such as
such a grammar can be defined using an Algebraic Data Type:
type expression =
| Add of expression * expression
| Mul of expression * expression
| Cst of float
| P of float * float
As an example, the expression to solve for the deposit is:
Add (Mul (Cst (1 / T), Add(P(T, 0), Cst (-1))),
Cst (-L(T)))
And for the bootstrap to be possible, we need to write an evaluation function that takes the function to bootstrap as an input:
let rec eval exn p =
match exn with
| Add (e1, e2) -> eval e1 p +. eval e2 p
| Mul (e1, e2) -> eval e1 p *. eval e2 p
| Cst x -> x
| P (t0, t1) -> p t1 /. p t0
To get an efficient implementation, we need two more functions. First, a simplification function that evaluates each occurrence of P(t0, t1) in the expression when t0 and t1 are lower than (with set to when finding P between and )). Then, a factorisation function that tries to write the simplified expression in the form A P(t0, t1) + B (so that the root has an analytic solution).
Having a generic algorithm allows us to factorise the code for the different bootstraps we encounter, eg single curve bootstrap, multi curve bootstrap, cross currency curve bootstrap, funding curve bootstrap, …
Conclusion
We proposed a parametrisation of the instantaneous forward that leads to a , stable zero-coupon curve, obtained in a one step procedure (instead of the “classical” way of doing it that needs two steps to achieve the same properties). We also gave some ideas to implement a generic bootstrapping algorithm, whatever the input data.