knitr::opts_chunk$set(
  collapse = TRUE,
  comment = "#>",
  fig.path = "man/figures/README-",
  out.width = "100%"
)

SwapPricer

Project Status:Active CRAN_Status_Badge Travis build status

library(formattable)
sign_formatter <- formatter("span", 
  style = x ~ style(color = ifelse(x > 0, "green", 
    ifelse(x < 0, "red", "black"))))

The goal of SwapPricer is to allow you to price a book of interest rate swaps (IRS). IRS is the most traded over the counter financial derivative in the world and now you can easily price it in R. More details on the financial characteristics of this contract can be found here

Please note that as at version 1.0.2 the toolbox is able to price using just a one-curve framework but is able to price multiple currencies (ie. CHF, EUR, GBP, JPY and USD) and any convention in terms of coupon frequency, day count convention.

We are working to introduce OIS Discounting in the next releases

Installation

For now, you can just install the development version from GitHub with:

# install.packages("devtools")
devtools::install_github("DavideMagno/SwapPricer")

Example

The main function of the toolbox is SwapPortfolioPricing which uses just three inputs:

1) A table with the characteristics of the swap, like the following one

knitr::kable(SwapPricer::swap.basket, caption = "Input Portfolio", "html")

2) The date at which the swaps are being priced

3) As many interest rate lists as per the currencies in the swap portfolio. The list is made of a string with the code of the currency and a with a tibble with the discounting factor curve with two columns: Dates and Discount Factors (df). Here is an example of interest rate list:

SwapPricer::EUR.curves

Examples of items 1 and 3 have been provided with the package.

library(SwapPricer)
today <- lubridate::ymd(20190415)
SwapPricer::SwapPortfolioPricing(SwapPricer::swap.basket, today, 
                                 SwapPricer::EUR.curves, SwapPricer::GBP.curves,
                                 SwapPricer::USD.curves) 

This function returns a table that can be easily used for reporting like below

library(SwapPricer)
today <- lubridate::ymd(20190415)
SwapPricer::SwapPortfolioPricing(SwapPricer::swap.basket, today, SwapPricer::EUR.curves, SwapPricer::GBP.curves, SwapPricer::USD.curves)  %>% 
  dplyr::mutate_at(dplyr::vars("clean.mv","dirty.mv","accrual.pay","accrual.receive","pv01"),
                   formattable::comma) %>%
  dplyr::mutate_at(dplyr::vars("par"), formattable::percent) %>%
  knitr::kable(caption = "Pricing results", "html") %>%
  kableExtra::kable_styling(bootstrap_options = c("striped", "hover", "condensed","responsive"))

Learning More

The vignettes are a great place to learn more about SwapPricer.

If you are installing from github and want the vignettes, you'll need to run the following commands first:

devtools::install_github("DavideMagno/SwapPricer", build_vignettes = TRUE)
library(SwapPricer)

You can then access them from R with the vignette() command



DavideMagno/SwapPricer documentation built on Aug. 19, 2021, 6:36 p.m.