Quantra as a QuantLib multiprocess platform

### About QuantLib

Quantlib is a quantitative finance library that started being developed on early 2000s beeing an active project since then. To have an idea of the library capabilities visit the project docs section. <p>It is written in C++ and exist multipe projects porting the library to different languages or platforms like MS Excel. Visit the QuantLib extension section from the project site to see what is going on.

### Examples

#### Turn of year effect

It is known that rates suffer jumps due to some reasons like high liquidity demand on certain dates and this affecting to the yield curve shape. It typically happens the end of the year although it could also happen at some other dates like end of quarter. Some publications and information about it:

- Section 4.8 of Ametrano and Bianchetti Everything You Always Wanted to Know About Multiple Interest Rate Curve Bootstrapping But Were Afraid To Ask<
- Ametrano and Mazzochi EONIA Jumps and Proper Euribor Forwarding presentation
- More recent Ametrano, Bertocchi and Mazzocchi Advanced EONIA Curve Calibration
- And everything inspired by Burghardt and Kirshner One Good Turn

Most of the examples from Ametrano publications are calculated with Quantlib and reproduced in QuantLib Python Cookbooks from Luigi Ballabio (which I strongly recommend), so what we will do here is translate the Python examples to quantra API and see we obtain same results.

To solve the problem we need to apply the jump to just the last day of the year leaving the rest the curve as it should be without it and to do so we need to know the size of it. And we need to calculate the the size with the existing qutoed instruments.

Let’s see first how a jump affects to a Libor 3M curve (we have taken the curve from Everything You Always Wanted to Know About Multiple Interest Rate Curve Bootstrapping But Were Afraid To Ask). All the steps are in End of year effect spreadhseet.

Let’s plot the overnight flat forward curve:

We have plotted the same curve with and without the jump on last day of the year and what can be seen is that the curve with the jump (red line) has decreased with the excepion of December 31st which contains the jump.

This happens because the discrete forward rate is the average of the instantaneous forward rates, and to keep the value for this section with the jump the rest needs to decrease.

Lets plot now the 3M forward rate to see ho it is affected:

Here we see that since 3 months before the end of the year till the end of the year there is a jump and the rest of the curve remains smooth. That is because any forward section going through the end of the year will be affected by the jump, and the first one will be 3 months before end of year.

If we would plot a 6 months forward curve we would see a smaller jump starting 6 months before the end of the year, the reason it would be smaller is because the jump has less weight in the average for 6 months. Figure 24 of Everything You Always Wanted to Know About Multiple Interest Rate Curve Bootstrapping But Were Afraid To Ask plots ON, 1M and 3M curves to show this.

We will try now to calculate the jump for end of 2013 for the Eonia curve from section 5.1 of Everything You Always Wanted to Know About Multiple Interest Rate Curve Bootstrapping But Were Afraid To Ask paper from F. M. Ametrano and M. Bianchetti. We will also follow the steps of the QuantLib Python Cookbook from Luigi Ballabio in End of year jump calculation spreadsheet.

As is stated in the paper the results are obtained with Quantlib so they should be close to the ones we will get here. Any justification of the decisions taken can be found in the paper so it will not be explained here.

First step is creating a forward curve with the rates from the figure 25 of the paper. These are three deposits that go from overnight to spot night, four OIS swaps, five OIS forwards and eighteen other OIS swaps till 30 years. The deposit rates are the yellow cells that go from B5 to H7. OIS swaps are put together even they are separated in time as they have to be passed together to the function. They are the B12:F33 ones, in blue up to one month and the rest of them in purple. OIS forwards are at B38:E42. As you will see all of them are passed to functions like a spreadsheet matrix.

We will first create a cubic spline monotonic interpolated curve bootstrapped over log discount rates (why is done like this in the paper and further information can be found at Methods for Constructing a Yield Curve Hagan and West).

We will call GENERATEFWDCURVE google sheets function with aforementioned rates and settings from J4:N8 cells. The function will be called from Data tab of the spreadsheet and plotted at J10:N27 of first tab. The resulting curve is shown below.

As can be seen a jump shows up at the end of 2012 and we will need to remove it. Let’s follow the steps from Luigi Ballabio book. We first change the settings of the curve to a backward flat interpolation over forward rates to see it more clearly and determine the size of the jump.

Lets call the GENERATEFWDCURVE once more with P4:Q8 settings and plot the curve (shown at P10:T27).

Lets get now the node values from the interpolated curve with the CURVENODES function. Values can be found at V4:V34:

... | ... | ... |

0,000689431 | 2012-12-27 | 5 |

0,000973298 | 2013-01-03 | 6 |

0,000672816 | 2013-01-14 | 7 |

... | ... | ... |

We can clearly see that the seventh node (sixth position of the array and highlighted in red) is above the ones surrounding it. To supress it we will calculate the average of these two and reassign the value to the seventh node (cells Z4:Z34):

... | ... | ... |

0,000689431 | 2012-12-27 | 5 |

0,0006811235 | 2013-01-03 | 6 |

0,000672816 | 2013-01-14 | 7 |

... | ... | ... |

Lets create the curve again with INTERPOLATEDFWDCURVE function with resulting nodes at cells Z4:Z34 and settings from AD5:AE8 and plot the curve again along with the previous one. In red the original one and in blue the one with the modified rate.

Once we have the curve we need to calculate the size of the jump and assign it to the last day of the year (like is epxplaned in the paper and further information about it in this presentation).

From QuantLib Python Cookbook we see that the forward rate over the two weeks around the end of the year will give us a value close to the one from the paper.

All calculations are done at AJ5:AO7, and the value of the rate for the last day is at AK10. This is 0,001008631315, which is close to the 0.101% of the paper. Lets get and add to the curve the corresponding discount value to the last day of the year.

We just need to call the GENERATEFWDCURVE function again adding the date and value of the jump at 8th parameter with same settings we had. We can plot now the log discounting curves with and without the jump to see the difference. The red line shows the original curve and blue is the one with the jump. We can clearly see that the curve is smoother with a jump located at the last day of the year.

#### Interest rate sensitivity

In this section I will reproduce the results of the **Interest-rate sensitivities via zero spread** from QuantLib Python Cookbook Luigi Ballabio’s book. It will be done with the quantra Google Sheets add-on, and although results will be really close, they will not be exactly the same than the book as the API has some limitations.

This is the spreadsheet with the calculations.

What we will do here is generate an interest rate curve, aply different spreads to it and price an Interest Rate Swap with the curves to see how its price is affected.

First step is creating the curve as it is in the book with one difference, in the example the curve is created with 2 settlement days but this option is not available in the API, so we will do the same with 0 settlement days. The curve we will use is created with below instruments:

- 1 deposit
- 18 FRAs
- 17 Swaps

And the curve goes up to 60 years. The details for the instruments and curve configuration can be found on the spreadsheet.

Lets create the curve (cell J14) and plot it:

We will now apply a 5bp spread to the zero curve and generate a new curve. The applied spread will generate a curve with the same spread applied to the whole curve (cell N14).

We will now apply a spread that goes from a negative to a positive value during 20 years, being 0 at seven years from now. For this purpose we need to provide an array of values and dates, and the values inbetween will be linearly interpolated (values at cells R8:S28 and calculation at cell U14).

Below the three curves together that we will use to price the Swap.

Next tab has the Interest Rate Swap defined and the three valuations for it:

- NPV: -189,831 for the original curve
- NPV: -135,134 for the
*parallel*spreaded curve - NPV: -138,575 for the interpolated curve

### Quantra features

Just a small part of QuantLib is currently available in quantra, although the goal is making the API grow and keep adding new features.

Check following sections to see what is already implemented and visit the API documentation for further detail:

#### Curves and term structures

Curves can be created from:

- Deposits
- FRAs
- Futures
- Swaps
- Bonds
- OIS
- OIS Futures

And available interpolations for curves are:

- Linear
- BackwardFlat
- ForwardFlat
- LogCubic
- LogLinear

Also jumps for the end of year effect can be added to the curves.

Below some Google Sheets examples using some of the curve functionalities available (visit How to use google sheets section to start using the add-in):

#### Interest rate swaps pricing

This is it, you can price interest rate swaps with quantra. So basically set the IRS values, create the schedules for the fixed and floating legs, create the discount and forward curves and price it.

As a result you will receive the pricing values and the detail for each flow. To see an example of an interest rate swap priced:

#### Bond pricing

Fixed, floating and zero coupon bonds can be priced with quantra. Set the bonds and curves and price them. A Google sheets example to price a bond:

#### Dates and calendars

Quantra has implemented multiple functionalities related to calendars and day counters such as:

- Is Leap
- End of month
- Is end of month
- Next week day
- Nth week day
- Is business day
- Is holiday
- Holiday list
- Adjust date
- Advance date
- Business days between
- Is IMM Date
- Next IMM Date
- Year fraction

Quantra has implemented multiple functionalities related to calendars and day counters such as:

## Quantra as a QuantLib multiprocess platform

Although is possible, QuantLib is not thought to be used as a multithreaded library (see this question and Luigi’s response at stackoverflow).

With a load balancer like nginx and multiple instances of quantra would be pretty easy to create a multiprocess and distributed pricing engine based in QuantLib.

## Sample applications

A couple of example applications using the API: some Google Sheets scripts and a web based application.

### Google Sheets

Some functionalities of the API can be used with Google Sheets scripts.

To start using them: open a spreadsheet, select **Tools -> Script editor** and copy paste the code from the github repository. Functions are in separate files to make it easier to find them.

The list below contains some Google spreadhseets using them:

### Web app

A sample web application has been developed with the API that allows Interest Rate Swaps pricing and generate curves. Everything is stored in a Postgres database.

Take a look to the help section to see how it works.