Replicating Bloomberg Curves with QuantLib
The process of calculating a yield curve has many names in the finance industry. it can be called finding the redemption curve, constructing the term structure of interest rates, stripping and so on. In this blog post we will go through the process of constructing the yield curve for the Bloomberg SEK (vs. 6M STIBOR), also known as 348, with the help of the Python package QuantLib. When reading this tutorial consider that the main goal is to learn how to bootstrap interest rate curves with QuantLib and that Bloomberg's curve will be our answer key to make sure that everything is correct regarding dates, day count and calendar conventions. Moreover, it is assumed that the reader is familiar with instruments such as deposits and swaps - how else would you end up here?
SEK (vs. 6M STIBOR)
As shown in Figure 1, the SEK (vs. 6M STIBOR) is a swap curve based on the 6 month Stockholm Interbank Offered Rate, denoted by 6M STIBOR. The cash rate for the 6M STIBOR can be seen on the left-hand side of Figure 1, and the rates for the swaps can be seen on the right-hand side of Figure 1. The day count convention for each panel of instruments can also be observed at the bottom. The purpose of the SEK (vs. 6M STIBOR) is to forecast the interest rate for the 6M STIBOR. This means that whatever point we select on the curve is what the market will assume the 6M STIBOR will be in that amount of time.
Figure 1: Quotes for SEK (vs. 6M STIBOR) from Curve Construction in the Bloomberg Terminal.
Quantlib
We begin by setting the desired date and importing the necessary packages. The date at which the bootstrap procedure starts is determined with reference to the top right corner of Figure 2, In this case corresponding to the settlement date which often is T + 2 of the initial date in Sweden. It's important to note that this step is crucial (and may vary across trading desks) in the bootstrapping procedure, as it ensures that the maturity dates of the curve will be correct:
Furthermore, the main approach behind bootstrapping with QuantLib is to define all your instruments using helpers. Helpers are classes designed to define an instrument with its properties, which makes the bootstrapping procedure less cumbersome. There are helpers for each instrument such as:
- DepositRateHelper
- FraRateHelper
- FuturesRateHelper
and so on, you can find the list of all helpers here. Once you have defined the instruments with helpers, you will want to store them in a list so that you can call ql.PiecewiseLinearZero(), which will find the solutions for the curve given the instruments you have defined.
Since the first instrument in curve is the 6M STIBOR, it will be the first instrument to be modeled. The 6M STIBOR is interpreted as a deposit rate, so we use the QuantLib function DepositRateHelper:
In this next step we will create the underlying index of which the floating leg will follow:
Moreover, the swap rates in Figure 1 are given as ask and bid. The bootstrap procedure is based on the mid price, which is based on the average of the bid and ask:
Then continuing with SwapRateHelper:
Now that all instruments are defined we can execute the bootstrapping algorithm by using the following:
Note that you also have the option to change the calendar and the day count for the bootstrap. You can modify these parameters based on your desired outcome.
Result
The zero rates obtained from Bloomberg are displayed in Figure 2. MEanwhile, the resulting curve generated from QuantLib is shown in Figure 3. To facilitate the comparison of the curves, a table is created to calculate the difference between the results, as presented in Table 1. It is important to note that the basis point difference can be disregarded, as the result from Bloomberg is rounded. Therefore, any extra digits in the basis point difference are solely from the QuantLib approximation. If we were to round them up, they would result in zeros.
Figure 2: The Bloomberg curve SEK (vs. 6M STIBOR) from Curve Construction in the Bloomberg Terminal.
Figure 3: The resulting curve from QuantLib using quotes from Bloomberg.
Date | Quotes | QuantLib Zero Rates | Bloomberg Zero Rates | Basis Point Difference | |
---|---|---|---|---|---|
1 | 2023-07-13 | 3.218 | 3.23658 | 3.23658 | -0.015275 |
2 | 2024-01-11 | 3.52271 | 3.46208 | 3.46207 | -0.0746395 |
3 | 2025-01-13 | 3.47321 | 3.40873 | 3.40873 | -0.04655 |
4 | 2026-01-12 | 3.3141 | 3.25169 | 3.25169 | -0.0397416 |
5 | 2027-01-11 | 3.1997 | 3.13788 | 3.13788 | 0.038115 |
6 | 2028-01-11 | 3.1205 | 3.05876 | 3.05876 | -0.0230695 |
7 | 2029-01-11 | 3.0774 | 3.01476 | 3.01476 | 0.0163274 |
8 | 2030-01-11 | 3.049 | 2.98702 | 2.98702 | -0.00937578 |
9 | 2031-01-13 | 3.024 | 2.96223 | 2.96223 | -0.0348135 |
10 | 2032-01-12 | 3.0059 | 2.94438 | 2.94438 | -0.0386432 |
11 | 2033-01-11 | 2.9881 | 2.92562 | 2.92562 | 0.0279722 |
12 | 2035-01-11 | 2.9531 | 2.88943 | 2.88943 | -0.0104289 |
13 | 2038-01-11 | 2.8876 | 2.81743 | 2.81743 | -0.0475918 |
14 | 2043-01-12 | 2.7831 | 2.69882 | 2.69882 | -0.0153047 |
15 | 2053-01-13 | 2.5631 | 2.43391 | 2.43391 | -0.0218202 |
Table 1: QuantLib and Bloomberg zero rates with their corresponding underlying quotes.
Conclusion
In this blog post we have managed to recreate the SEK (vs. 6M STIBOR) from curve construction from the Bloomberg Terminal using QuantLib. If you are interested in the full Python code you can find here.
References
- Luigi Ballabio, Implementing QuantLib: Quantitative finance in C++: an inside look at the architecture of the QuantLib library, Autopubblicato
- Bloomberg L.P., SEK (vs. 6M STIBOR)