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 P(T)P(T) be today’s value of the TT-maturing bond. Building the yield curve means finding a function PP that allows to match the market price of Deposit Rates and Swap Rates.

Let L(T)L(T) be the value of the TT-maturing deposit. We have:

L(T)=1T[1P(T)−1] L(T) = \frac{1}{T}\left[\frac{1}{P(T)} - 1\right]

Let S(T)S(T) be the value of the TT-maturing swap rate. We assume that the fix leg period of the swap is δ\delta. We have:

S(T)=1−P(T)δ∑i=1T/δP(δi) S(T) = \frac{1 - P(T)}{\delta \sum_{i = 1}^{T/\delta} P(\delta i)}

We observe on the market L(ti)L(t_i) for i∈[0;m−1]i \in [0; m - 1] and S(ti)S(t_i) for i∈[m;n−1]i \in [m; n - 1], where t0<t1<…<tn−1t_0 < t_1 < \ldots < t_{n-1}

Resolution of the simple problem

We define IiI_i:

Ii={L(ti)∀i∈[0;m−1]S(ti)∀i∈[m;n−1] I_i=\left\{ \begin{array}{ll} L(t_i) & \forall i \in [0; m - 1]\\ S(t_i) & \forall i \in [m; n - 1]\\ \end{array} \right.

We note that IiI_i only depends on P(t)P(t) for t≤tit \leq t_i.

The problem can then be solved by using a “bootstrap” procedure:

  • find PP on [0;t0][0; t_0] that allows to match I0I_0
  • find PP on [t0;t1][t_0; t_1] that allows to match I1I_1, knowing PP on [0;t0][0; t_0]
  • …
  • find PP on [tn−2;tn−1][t_{n - 2}; t_{n - 1}] that allows to match In−1I_{n - 1}, knowing PP on [0;tn−2][0; t_{n - 2}]

The previous problem has an infinity of solutions. To avoid that, we can use a parametrisation Pi\mathcal P_i such as P(t)=Pi(p0,p1,…pi,t)P(t) = \mathcal P_i(p_0, p_1, \ldots p_i, t) for t≤tit \leq t_i.

Let IimktI_i^{mkt} be the observed value of the ii-th instrument. We define Ii(P)\mathcal I_i(P) the value of the ii-th instrument if the curve is PP.

The problem is now:

  • find p0p_0 so that I0(P0(p0,⋅))=I0mkt\mathcal I_0 (\mathcal P_0(p_0, \cdot)) = I_0^{mkt}
  • find p1p_1 so that I1(P1(p0,p1,⋅))=I1mkt\mathcal I_1 (\mathcal P_1(p_0, p_1, \cdot)) = I_1^{mkt}
  • …
  • find pn−1p_{n - 1} so that In−1(Pn−1(p0,p1,…,pn−1,⋅))=In−1mkt\mathcal I_{n - 1} (\mathcal P_{n - 1}(p_0, p_1, \ldots , p_{n - 1}, \cdot)) = I_{n - 1}^{mkt}
  • set ∀t,P(t)=Pn−1(p0,p1,…,pn−1,t)\forall t, P(t) = \mathcal P_{n-1}(p_0, p_1, \ldots , p_{n - 1}, t)

At each step, there is only one real root to find.

Now, we need to find a good parametrisation for P\mathcal P. In order to do that, we recall that there are some natural ways of rewriting the curve defining the yield:

r(t)=−log(P(t))t⇒P(t)=e−r(t)t \begin{align*} r(t) &= -\frac{log(P(t))}{t}\\ \Rightarrow P(t) &= e^{-r(t)t} \end{align*}

or the instantaneous forward rate:

f(t)=−∂tlog(P(t))⇒P(t)=e−∫0tf(s)ds \begin{align*} f(t) &= -\partial_t log(P(t))\\ \Rightarrow P(t) &= e^{-\int_0^tf(s)ds} \end{align*}

Thus, one needs to parametrise only rr or ff, using for instance a piecewise constant or a piecewise affine term-structure.

Remark on possible parametrisations

The use of a piecewise affine function for ff seems a good idea as it leads to a C1\mathcal C^1 function PP. 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 ff leads to a only C0\mathcal C^0 function PP, 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 PP 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 ff, ie given a level ϵ\epsilon, ff is affine from ti−1t_{i-1} to ti−1+ϵ(ti−ti−1)t_{i - 1} + \epsilon (t_i - t_{i - 1}) and constant after (until tit_i):

  • fi−1:=f(ti−1)f_{i - 1} := f(t_{i-1})
  • fi:=f(ti)f_i := f(t_i)
  • f(t)=fi−1+(fi−fi−1)t−ti−1ϵ(ti−ti−1)f(t) = f_{i - 1} + (f_i - f_{i - 1})\frac{t - t_{i-1}}{\epsilon (t_i - t_{i-1})} for t∈[ti−1;ti−1+ϵ(ti−ti−1)]t \in [t_{i - 1}; t_{i - 1} + \epsilon (t_i - t_{i - 1})]
  • f(t)=fif(t) = f_i for t∈[ti−1+ϵ(ti−ti−1);ti]t \in [t_{i - 1} + \epsilon (t_i - t_{i - 1}); t_i]

Here is a visual example of this function:

This parametrisation leads to a C0\mathcal C^0 function ff, and then C1\mathcal C^1 functions rr and PP. The stability is achieved when we choose a small value for ϵ\epsilon, as ff is almost piecewise constant in this case.

Generalisation

In finance, there are a lot of problems that require bootstrapping a function of the form e−∫0tf(s)dse^{-\int_0^tf(s)ds}. 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 →\rightarrow Expression + Expression
Expression →\rightarrow Expression * Expression
Expression →\rightarrow (Expression)
Expression →\rightarrow float
Expression →\rightarrow P(date, date)

Such as

P(t0,t1)=e−∫t0t1f(s)ds P(t_0, t_1) = e^{-\int_{t_0}^{t_1}f(s)ds}

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 pp 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 TT (with TT set to ti−1t_{i-1} when finding P between ti−1t_{i-1} and tit_i)). 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 C1C^1, 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.