SwapPricer is on Github
In the previous posts we have seen how easy it is to price interest rate swaps using R. I am honoured to announce that I have decided to put all the functions I have described together into a package that is called…SwapPricer!
Ok, the name is not super original, but it should at least be easy to remember.
You can install it as follows:
# library(devtools) devtools::install_github("DavideMagno/SwapPricer")
The package is still unfortunately not on CRAN but it has an official hexagon. Here it is:
Let me know if you like it in the Disqus form below in the post.
In order to price a swap you just need to run the following code.
library(SwapPricer) portfolio <- SwapPricer::swap.basket %>% dplyr::filter(grepl("EUR", .$currency)) SwapPortfolioPricing(portfolio, lubridate::ymd(20190414), SwapPricer::EUR.curves)
## # A tibble: 4 x 8 ## swap.id currency clean.mv dirty.mv accrual.pay accrual.receive par ## <chr> <chr> <dbl> <dbl> <dbl> <dbl> <dbl> ## 1 Swap 2… EUR -8.82e5 -8.75e5 5441. 1379. 7.71e-3 ## 2 Swap n… EUR -2.59e6 -2.86e6 -263836. -5968. 1.07e-2 ## 3 Swap 1… EUR -1.63e4 -2.99e4 -3808. -9749. 6.82e-4 ## 4 Swap 2… EUR -3.61e5 -3.61e5 0 0 1.18e-2 ## # … with 1 more variable: pv01 <dbl>
You can see that I have used two objects that are delivered with the package:
swap.basket which consists in a 5 swaps portfolio that can be referenced as blueprint for your swap portfolio
EUR.curves this is the discount curve downloaded from Bloomberg as at the 14th of April 2019
We have tested the package using a 500 swaps portfolio and the results, in terms of performance are very encouraging. We analyse them using the amazing profvis tool.