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:

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 portfoliodf.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 Traders’ Insight that is provided by third-parties and not by Interactive Brokers does NOT constitute a recommendation by Interactive Brokers that you should contract for the services of that third party. Third-party participants who contribute to IBKR Traders’ Insight 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 permission from curiousfrm.com. The views expressed in this material are solely those of the author and/or curiousfrm.com and IBKR 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 sell or the solicitation of an offer to buy any security. To the extent that this material discusses general market activity, industry or sector trends or other broad based economic or political conditions, it should not be construed as research or investment advice. To the extent that it includes references to specific securities, commodities, currencies, or other instruments, those references do not constitute a recommendation to buy, sell or hold such security. 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.
In accordance with EU regulation: The statements in this document shall not be considered as an objective or independent explanation of the matters. Please note that this document (a) has not been prepared in accordance with legal requirements designed to promote the independence of investment research, and (b) is not subject to any prohibition on dealing ahead of the dissemination or publication of investment research.
Any trading symbols displayed are for illustrative purposes only and are not intended to portray recommendations.