Close Navigation
Learn more about IBKR accounts
SwapPricer is on Github

SwapPricer is on Github

Posted August 9, 2019
Davide Magno
curiousfrm.com

In previous posts we coded in R to estimate prices of interest rate swaps. I am honoured to announce that I have decided to put all the functions I have described together into an R package that is called…SwapPricer!

You can install it as follows:

# library(devtools)
devtools::install_github(“DavideMagno/SwapPricer”)

The package is not on CRAN yet, but it already has an official hexagon sticker. Here it is:

SwapPricer is on Github

In order to price a swap you just need to run the following code.

library(SwapPricer)
SwapPortfolioPricing(SwapPricer::swap.basket, lubridate::ymd(20190414), SwapPricer::df.table)

## # A tibble:    5 x 7
##   swap.id            clean.mv     dirty.mv  accrual.pay  accrual.receive      par          pv01
##      <chr>                  <dbl>        <dbl>          <dbl>        <dbl>                    <dbl>        <dbl>
## 1 Swap    25y         -8.82e5     -8.75e5      5441.        1379.                   0.00771    -12394.
## 2 Swap    30y          2.34e5      1.24e5      -97222.    -12470                  0.0111       20867.
## 3 Swap     10y         2.22e5      2.36e5       6702.       7361.                  -0.00138     -5724.
## 4 Swap     2y16y     3.60e5      3.60e5        0                0                        0.0118      -11163.
## 5 Swap     non …    -2.59e6      -2.87e6      -263836.   -14681.             0.0107        27914.

You can see that I have used two objects that are delivered with the package:

  • swap.basket which consists of a portfolio of 5 swaps that can be referenced as a blueprint for your swap portfolio
  • df.table this is the discount curve downloaded from Bloomberg as at the 14th of April 2019

We have tested the package using a portfolio of 500 swaps. We analyse the results using the amazing profvis tool.

Visit Davide’s Blog to learn more about the analysis with the profvis tool, and to download the code for the microbenchmark test.

Note: this is v0.1.0 of the package. Let Davide know your comments via his Blog.

Disclosure: Interactive Brokers

Information posted on IBKR Campus that is provided by third-parties does NOT constitute a recommendation that you should contract for the services of that third party. Third-party participants who contribute to IBKR Campus are independent of Interactive Brokers and Interactive Brokers does not make any representations or warranties concerning the services offered, their past or future performance, or the accuracy of the information provided by the third party. Past performance is no guarantee of future results.

This material is from curiousfrm.com and is being posted with its permission. The views expressed in this material are solely those of the author and/or curiousfrm.com and Interactive Brokers is not endorsing or recommending any investment or trading discussed in the material. This material is not and should not be construed as an offer to buy or sell any security. It should not be construed as research or investment advice or a recommendation to buy, sell or hold any security or commodity. This material does not and is not intended to take into account the particular financial conditions, investment objectives or requirements of individual customers. Before acting on this material, you should consider whether it is suitable for your particular circumstances and, as necessary, seek professional advice.

IBKR Campus Newsletters

This website uses cookies to collect usage information in order to offer a better browsing experience. By browsing this site or by clicking on the "ACCEPT COOKIES" button you accept our Cookie Policy.