README.md

SwapPricer

Project
Status:Active CRAN_Status_Badge Travis build
status

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

Input Portfolio ID currency notional start.date maturity.date strike type standard time.unit.pay time.unit.receive dcc.pay dcc.receive Swap 25y EUR 1.0e+07 19/01/2007 19/01/2032 0.0005982 receiver TRUE NA NA NA NA Swap 30y GBP 1.0e+06 24/04/2012 24/04/2042 0.0100000 payer TRUE NA NA NA NA Swap 10y USD 2.0e+06 21/02/2012 21/02/2022 0.0025000 receiver TRUE NA NA NA NA Swap 2y16y GBP 7.5e+06 14/04/2021 14/04/2037 0.0150000 receiver TRUE NA NA NA NA Swap non standard EUR 1.5e+07 26/05/2014 26/05/2039 0.0200000 payer FALSE 12 3 act/365 act/365 Swap 10y semi fixed EUR 1.0e+07 26/05/2014 26/05/2024 0.0010000 payer FALSE 6 6 act/365 act/365 Swap 30y quarter floating GBP 1.0e+06 24/04/2012 24/04/2042 0.0200000 receiver FALSE 3 12 act/360 act/365 Swap 10y irregular USD 2.0e+06 21/02/2012 21/02/2022 0.0025000 receiver FALSE 6 12 act/365 act/365 Swap 2y16y EUR 7.5e+06 14/04/2021 14/04/2037 0.0150000 payer FALSE 12 12 act/365 act/360

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
#> $currency
#> [1] "EUR"
#> 
#> $discount
#> # A tibble: 26 x 2
#>    Date          df
#>    <date>     <dbl>
#>  1 2019-04-15  1   
#>  2 2019-04-23  1.00
#>  3 2019-05-16  1.00
#>  4 2019-07-16  1.00
#>  5 2019-10-16  1.00
#>  6 2020-04-16  1.00
#>  7 2020-10-16  1.00
#>  8 2021-04-16  1.00
#>  9 2022-04-19  1.00
#> 10 2023-04-17  1.00
#> # … with 16 more rows

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

#> Called from: AccrualCalculation(.x, .y, swap, direction, floating.history)
#> debug at /Users/davidemagno/Documents/R/Pricingverse/SwapPricer/R/IRS.R#168: if (!is.null(swap.dates$fixing.date)) {
#>     floating.history <- floating.history[grepl(swap$currency, 
#>         floating.history$currency) & floating.history$time.unit == 
#>         swap$time.unit[[leg.type]], "rate.data"]
#>     floating.history <- purrr::flatten(floating.history$rate.data)[[1]]
#>     fixing.row <- floating.history[floating.history$date %in% 
#>         swap.dates$fixing.date, ]
#>     if (nrow(fixing.row) == 0) {
#>         closest.dates <- (floating.history$date - swap.dates$fixing.date)
#>         fixing.row <- floating.history[which(closest.dates == 
#>             max(closest.dates[closest.dates < 0])), ]
#>     }
#>     rate <- fixing.row[["value"]]/100
#> } else {
#>     rate <- swap$strike
#> }
#> debug at /Users/davidemagno/Documents/R/Pricingverse/SwapPricer/R/IRS.R#169: floating.history <- floating.history[grepl(swap$currency, floating.history$currency) & 
#>     floating.history$time.unit == swap$time.unit[[leg.type]], 
#>     "rate.data"]
#> debug at /Users/davidemagno/Documents/R/Pricingverse/SwapPricer/R/IRS.R#172: floating.history <- purrr::flatten(floating.history$rate.data)[[1]]
#> debug at /Users/davidemagno/Documents/R/Pricingverse/SwapPricer/R/IRS.R#174: fixing.row <- floating.history[floating.history$date %in% swap.dates$fixing.date, 
#>     ]
#> debug at /Users/davidemagno/Documents/R/Pricingverse/SwapPricer/R/IRS.R#177: if (nrow(fixing.row) == 0) {
#>     closest.dates <- (floating.history$date - swap.dates$fixing.date)
#>     fixing.row <- floating.history[which(closest.dates == max(closest.dates[closest.dates < 
#>         0])), ]
#> }
#> debug at /Users/davidemagno/Documents/R/Pricingverse/SwapPricer/R/IRS.R#183: rate <- fixing.row[["value"]]/100
#> debug at /Users/davidemagno/Documents/R/Pricingverse/SwapPricer/R/IRS.R#189: swap.dates %>% purrr::pluck("accrual.yf") %>% *(swap$notional * 
#>     rate * switch(leg.type, pay = -1, receive = 1))
#> Called from: AccrualCalculation(.x, .y, swap, direction, floating.history)
#> debug at /Users/davidemagno/Documents/R/Pricingverse/SwapPricer/R/IRS.R#168: if (!is.null(swap.dates$fixing.date)) {
#>     floating.history <- floating.history[grepl(swap$currency, 
#>         floating.history$currency) & floating.history$time.unit == 
#>         swap$time.unit[[leg.type]], "rate.data"]
#>     floating.history <- purrr::flatten(floating.history$rate.data)[[1]]
#>     fixing.row <- floating.history[floating.history$date %in% 
#>         swap.dates$fixing.date, ]
#>     if (nrow(fixing.row) == 0) {
#>         closest.dates <- (floating.history$date - swap.dates$fixing.date)
#>         fixing.row <- floating.history[which(closest.dates == 
#>             max(closest.dates[closest.dates < 0])), ]
#>     }
#>     rate <- fixing.row[["value"]]/100
#> } else {
#>     rate <- swap$strike
#> }
#> debug at /Users/davidemagno/Documents/R/Pricingverse/SwapPricer/R/IRS.R#186: rate <- swap$strike
#> debug at /Users/davidemagno/Documents/R/Pricingverse/SwapPricer/R/IRS.R#189: swap.dates %>% purrr::pluck("accrual.yf") %>% *(swap$notional * 
#>     rate * switch(leg.type, pay = -1, receive = 1))
#> Called from: AccrualCalculation(.x, .y, swap, direction, floating.history)
#> debug at /Users/davidemagno/Documents/R/Pricingverse/SwapPricer/R/IRS.R#168: if (!is.null(swap.dates$fixing.date)) {
#>     floating.history <- floating.history[grepl(swap$currency, 
#>         floating.history$currency) & floating.history$time.unit == 
#>         swap$time.unit[[leg.type]], "rate.data"]
#>     floating.history <- purrr::flatten(floating.history$rate.data)[[1]]
#>     fixing.row <- floating.history[floating.history$date %in% 
#>         swap.dates$fixing.date, ]
#>     if (nrow(fixing.row) == 0) {
#>         closest.dates <- (floating.history$date - swap.dates$fixing.date)
#>         fixing.row <- floating.history[which(closest.dates == 
#>             max(closest.dates[closest.dates < 0])), ]
#>     }
#>     rate <- fixing.row[["value"]]/100
#> } else {
#>     rate <- swap$strike
#> }
#> debug at /Users/davidemagno/Documents/R/Pricingverse/SwapPricer/R/IRS.R#186: rate <- swap$strike
#> debug at /Users/davidemagno/Documents/R/Pricingverse/SwapPricer/R/IRS.R#189: swap.dates %>% purrr::pluck("accrual.yf") %>% *(swap$notional * 
#>     rate * switch(leg.type, pay = -1, receive = 1))
#> Called from: AccrualCalculation(.x, .y, swap, direction, floating.history)
#> debug at /Users/davidemagno/Documents/R/Pricingverse/SwapPricer/R/IRS.R#168: if (!is.null(swap.dates$fixing.date)) {
#>     floating.history <- floating.history[grepl(swap$currency, 
#>         floating.history$currency) & floating.history$time.unit == 
#>         swap$time.unit[[leg.type]], "rate.data"]
#>     floating.history <- purrr::flatten(floating.history$rate.data)[[1]]
#>     fixing.row <- floating.history[floating.history$date %in% 
#>         swap.dates$fixing.date, ]
#>     if (nrow(fixing.row) == 0) {
#>         closest.dates <- (floating.history$date - swap.dates$fixing.date)
#>         fixing.row <- floating.history[which(closest.dates == 
#>             max(closest.dates[closest.dates < 0])), ]
#>     }
#>     rate <- fixing.row[["value"]]/100
#> } else {
#>     rate <- swap$strike
#> }
#> debug at /Users/davidemagno/Documents/R/Pricingverse/SwapPricer/R/IRS.R#169: floating.history <- floating.history[grepl(swap$currency, floating.history$currency) & 
#>     floating.history$time.unit == swap$time.unit[[leg.type]], 
#>     "rate.data"]
#> debug at /Users/davidemagno/Documents/R/Pricingverse/SwapPricer/R/IRS.R#172: floating.history <- purrr::flatten(floating.history$rate.data)[[1]]
#> debug at /Users/davidemagno/Documents/R/Pricingverse/SwapPricer/R/IRS.R#174: fixing.row <- floating.history[floating.history$date %in% swap.dates$fixing.date, 
#>     ]
#> debug at /Users/davidemagno/Documents/R/Pricingverse/SwapPricer/R/IRS.R#177: if (nrow(fixing.row) == 0) {
#>     closest.dates <- (floating.history$date - swap.dates$fixing.date)
#>     fixing.row <- floating.history[which(closest.dates == max(closest.dates[closest.dates < 
#>         0])), ]
#> }
#> debug at /Users/davidemagno/Documents/R/Pricingverse/SwapPricer/R/IRS.R#183: rate <- fixing.row[["value"]]/100
#> debug at /Users/davidemagno/Documents/R/Pricingverse/SwapPricer/R/IRS.R#189: swap.dates %>% purrr::pluck("accrual.yf") %>% *(swap$notional * 
#>     rate * switch(leg.type, pay = -1, receive = 1))
#> Called from: AccrualCalculation(.x, .y, swap, direction, floating.history)
#> debug at /Users/davidemagno/Documents/R/Pricingverse/SwapPricer/R/IRS.R#168: if (!is.null(swap.dates$fixing.date)) {
#>     floating.history <- floating.history[grepl(swap$currency, 
#>         floating.history$currency) & floating.history$time.unit == 
#>         swap$time.unit[[leg.type]], "rate.data"]
#>     floating.history <- purrr::flatten(floating.history$rate.data)[[1]]
#>     fixing.row <- floating.history[floating.history$date %in% 
#>         swap.dates$fixing.date, ]
#>     if (nrow(fixing.row) == 0) {
#>         closest.dates <- (floating.history$date - swap.dates$fixing.date)
#>         fixing.row <- floating.history[which(closest.dates == 
#>             max(closest.dates[closest.dates < 0])), ]
#>     }
#>     rate <- fixing.row[["value"]]/100
#> } else {
#>     rate <- swap$strike
#> }
#> debug at /Users/davidemagno/Documents/R/Pricingverse/SwapPricer/R/IRS.R#169: floating.history <- floating.history[grepl(swap$currency, floating.history$currency) & 
#>     floating.history$time.unit == swap$time.unit[[leg.type]], 
#>     "rate.data"]
#> debug at /Users/davidemagno/Documents/R/Pricingverse/SwapPricer/R/IRS.R#172: floating.history <- purrr::flatten(floating.history$rate.data)[[1]]
#> debug at /Users/davidemagno/Documents/R/Pricingverse/SwapPricer/R/IRS.R#174: fixing.row <- floating.history[floating.history$date %in% swap.dates$fixing.date, 
#>     ]
#> debug at /Users/davidemagno/Documents/R/Pricingverse/SwapPricer/R/IRS.R#177: if (nrow(fixing.row) == 0) {
#>     closest.dates <- (floating.history$date - swap.dates$fixing.date)
#>     fixing.row <- floating.history[which(closest.dates == max(closest.dates[closest.dates < 
#>         0])), ]
#> }
#> debug at /Users/davidemagno/Documents/R/Pricingverse/SwapPricer/R/IRS.R#183: rate <- fixing.row[["value"]]/100
#> debug at /Users/davidemagno/Documents/R/Pricingverse/SwapPricer/R/IRS.R#189: swap.dates %>% purrr::pluck("accrual.yf") %>% *(swap$notional * 
#>     rate * switch(leg.type, pay = -1, receive = 1))
#> Called from: AccrualCalculation(.x, .y, swap, direction, floating.history)
#> debug at /Users/davidemagno/Documents/R/Pricingverse/SwapPricer/R/IRS.R#168: if (!is.null(swap.dates$fixing.date)) {
#>     floating.history <- floating.history[grepl(swap$currency, 
#>         floating.history$currency) & floating.history$time.unit == 
#>         swap$time.unit[[leg.type]], "rate.data"]
#>     floating.history <- purrr::flatten(floating.history$rate.data)[[1]]
#>     fixing.row <- floating.history[floating.history$date %in% 
#>         swap.dates$fixing.date, ]
#>     if (nrow(fixing.row) == 0) {
#>         closest.dates <- (floating.history$date - swap.dates$fixing.date)
#>         fixing.row <- floating.history[which(closest.dates == 
#>             max(closest.dates[closest.dates < 0])), ]
#>     }
#>     rate <- fixing.row[["value"]]/100
#> } else {
#>     rate <- swap$strike
#> }
#> debug at /Users/davidemagno/Documents/R/Pricingverse/SwapPricer/R/IRS.R#186: rate <- swap$strike
#> debug at /Users/davidemagno/Documents/R/Pricingverse/SwapPricer/R/IRS.R#189: swap.dates %>% purrr::pluck("accrual.yf") %>% *(swap$notional * 
#>     rate * switch(leg.type, pay = -1, receive = 1))
#> Called from: AccrualCalculation(.x, .y, swap, direction, floating.history)
#> debug at /Users/davidemagno/Documents/R/Pricingverse/SwapPricer/R/IRS.R#168: if (!is.null(swap.dates$fixing.date)) {
#>     floating.history <- floating.history[grepl(swap$currency, 
#>         floating.history$currency) & floating.history$time.unit == 
#>         swap$time.unit[[leg.type]], "rate.data"]
#>     floating.history <- purrr::flatten(floating.history$rate.data)[[1]]
#>     fixing.row <- floating.history[floating.history$date %in% 
#>         swap.dates$fixing.date, ]
#>     if (nrow(fixing.row) == 0) {
#>         closest.dates <- (floating.history$date - swap.dates$fixing.date)
#>         fixing.row <- floating.history[which(closest.dates == 
#>             max(closest.dates[closest.dates < 0])), ]
#>     }
#>     rate <- fixing.row[["value"]]/100
#> } else {
#>     rate <- swap$strike
#> }
#> debug at /Users/davidemagno/Documents/R/Pricingverse/SwapPricer/R/IRS.R#186: rate <- swap$strike
#> debug at /Users/davidemagno/Documents/R/Pricingverse/SwapPricer/R/IRS.R#189: swap.dates %>% purrr::pluck("accrual.yf") %>% *(swap$notional * 
#>     rate * switch(leg.type, pay = -1, receive = 1))
#> Called from: AccrualCalculation(.x, .y, swap, direction, floating.history)
#> debug at /Users/davidemagno/Documents/R/Pricingverse/SwapPricer/R/IRS.R#168: if (!is.null(swap.dates$fixing.date)) {
#>     floating.history <- floating.history[grepl(swap$currency, 
#>         floating.history$currency) & floating.history$time.unit == 
#>         swap$time.unit[[leg.type]], "rate.data"]
#>     floating.history <- purrr::flatten(floating.history$rate.data)[[1]]
#>     fixing.row <- floating.history[floating.history$date %in% 
#>         swap.dates$fixing.date, ]
#>     if (nrow(fixing.row) == 0) {
#>         closest.dates <- (floating.history$date - swap.dates$fixing.date)
#>         fixing.row <- floating.history[which(closest.dates == 
#>             max(closest.dates[closest.dates < 0])), ]
#>     }
#>     rate <- fixing.row[["value"]]/100
#> } else {
#>     rate <- swap$strike
#> }
#> debug at /Users/davidemagno/Documents/R/Pricingverse/SwapPricer/R/IRS.R#186: rate <- swap$strike
#> debug at /Users/davidemagno/Documents/R/Pricingverse/SwapPricer/R/IRS.R#189: swap.dates %>% purrr::pluck("accrual.yf") %>% *(swap$notional * 
#>     rate * switch(leg.type, pay = -1, receive = 1))
#> Called from: AccrualCalculation(.x, .y, swap, direction, floating.history)
#> debug at /Users/davidemagno/Documents/R/Pricingverse/SwapPricer/R/IRS.R#168: if (!is.null(swap.dates$fixing.date)) {
#>     floating.history <- floating.history[grepl(swap$currency, 
#>         floating.history$currency) & floating.history$time.unit == 
#>         swap$time.unit[[leg.type]], "rate.data"]
#>     floating.history <- purrr::flatten(floating.history$rate.data)[[1]]
#>     fixing.row <- floating.history[floating.history$date %in% 
#>         swap.dates$fixing.date, ]
#>     if (nrow(fixing.row) == 0) {
#>         closest.dates <- (floating.history$date - swap.dates$fixing.date)
#>         fixing.row <- floating.history[which(closest.dates == 
#>             max(closest.dates[closest.dates < 0])), ]
#>     }
#>     rate <- fixing.row[["value"]]/100
#> } else {
#>     rate <- swap$strike
#> }
#> debug at /Users/davidemagno/Documents/R/Pricingverse/SwapPricer/R/IRS.R#186: rate <- swap$strike
#> debug at /Users/davidemagno/Documents/R/Pricingverse/SwapPricer/R/IRS.R#189: swap.dates %>% purrr::pluck("accrual.yf") %>% *(swap$notional * 
#>     rate * switch(leg.type, pay = -1, receive = 1))
#> Called from: AccrualCalculation(.x, .y, swap, direction, floating.history)
#> debug at /Users/davidemagno/Documents/R/Pricingverse/SwapPricer/R/IRS.R#168: if (!is.null(swap.dates$fixing.date)) {
#>     floating.history <- floating.history[grepl(swap$currency, 
#>         floating.history$currency) & floating.history$time.unit == 
#>         swap$time.unit[[leg.type]], "rate.data"]
#>     floating.history <- purrr::flatten(floating.history$rate.data)[[1]]
#>     fixing.row <- floating.history[floating.history$date %in% 
#>         swap.dates$fixing.date, ]
#>     if (nrow(fixing.row) == 0) {
#>         closest.dates <- (floating.history$date - swap.dates$fixing.date)
#>         fixing.row <- floating.history[which(closest.dates == 
#>             max(closest.dates[closest.dates < 0])), ]
#>     }
#>     rate <- fixing.row[["value"]]/100
#> } else {
#>     rate <- swap$strike
#> }
#> debug at /Users/davidemagno/Documents/R/Pricingverse/SwapPricer/R/IRS.R#169: floating.history <- floating.history[grepl(swap$currency, floating.history$currency) & 
#>     floating.history$time.unit == swap$time.unit[[leg.type]], 
#>     "rate.data"]
#> debug at /Users/davidemagno/Documents/R/Pricingverse/SwapPricer/R/IRS.R#172: floating.history <- purrr::flatten(floating.history$rate.data)[[1]]
#> debug at /Users/davidemagno/Documents/R/Pricingverse/SwapPricer/R/IRS.R#174: fixing.row <- floating.history[floating.history$date %in% swap.dates$fixing.date, 
#>     ]
#> debug at /Users/davidemagno/Documents/R/Pricingverse/SwapPricer/R/IRS.R#177: if (nrow(fixing.row) == 0) {
#>     closest.dates <- (floating.history$date - swap.dates$fixing.date)
#>     fixing.row <- floating.history[which(closest.dates == max(closest.dates[closest.dates < 
#>         0])), ]
#> }
#> debug at /Users/davidemagno/Documents/R/Pricingverse/SwapPricer/R/IRS.R#183: rate <- fixing.row[["value"]]/100
#> debug at /Users/davidemagno/Documents/R/Pricingverse/SwapPricer/R/IRS.R#189: swap.dates %>% purrr::pluck("accrual.yf") %>% *(swap$notional * 
#>     rate * switch(leg.type, pay = -1, receive = 1))
#> Called from: AccrualCalculation(.x, .y, swap, direction, floating.history)
#> debug at /Users/davidemagno/Documents/R/Pricingverse/SwapPricer/R/IRS.R#168: if (!is.null(swap.dates$fixing.date)) {
#>     floating.history <- floating.history[grepl(swap$currency, 
#>         floating.history$currency) & floating.history$time.unit == 
#>         swap$time.unit[[leg.type]], "rate.data"]
#>     floating.history <- purrr::flatten(floating.history$rate.data)[[1]]
#>     fixing.row <- floating.history[floating.history$date %in% 
#>         swap.dates$fixing.date, ]
#>     if (nrow(fixing.row) == 0) {
#>         closest.dates <- (floating.history$date - swap.dates$fixing.date)
#>         fixing.row <- floating.history[which(closest.dates == 
#>             max(closest.dates[closest.dates < 0])), ]
#>     }
#>     rate <- fixing.row[["value"]]/100
#> } else {
#>     rate <- swap$strike
#> }
#> debug at /Users/davidemagno/Documents/R/Pricingverse/SwapPricer/R/IRS.R#186: rate <- swap$strike
#> debug at /Users/davidemagno/Documents/R/Pricingverse/SwapPricer/R/IRS.R#189: swap.dates %>% purrr::pluck("accrual.yf") %>% *(swap$notional * 
#>     rate * switch(leg.type, pay = -1, receive = 1))
#> Called from: AccrualCalculation(.x, .y, swap, direction, floating.history)
#> debug at /Users/davidemagno/Documents/R/Pricingverse/SwapPricer/R/IRS.R#168: if (!is.null(swap.dates$fixing.date)) {
#>     floating.history <- floating.history[grepl(swap$currency, 
#>         floating.history$currency) & floating.history$time.unit == 
#>         swap$time.unit[[leg.type]], "rate.data"]
#>     floating.history <- purrr::flatten(floating.history$rate.data)[[1]]
#>     fixing.row <- floating.history[floating.history$date %in% 
#>         swap.dates$fixing.date, ]
#>     if (nrow(fixing.row) == 0) {
#>         closest.dates <- (floating.history$date - swap.dates$fixing.date)
#>         fixing.row <- floating.history[which(closest.dates == 
#>             max(closest.dates[closest.dates < 0])), ]
#>     }
#>     rate <- fixing.row[["value"]]/100
#> } else {
#>     rate <- swap$strike
#> }
#> debug at /Users/davidemagno/Documents/R/Pricingverse/SwapPricer/R/IRS.R#169: floating.history <- floating.history[grepl(swap$currency, floating.history$currency) & 
#>     floating.history$time.unit == swap$time.unit[[leg.type]], 
#>     "rate.data"]
#> debug at /Users/davidemagno/Documents/R/Pricingverse/SwapPricer/R/IRS.R#172: floating.history <- purrr::flatten(floating.history$rate.data)[[1]]
#> debug at /Users/davidemagno/Documents/R/Pricingverse/SwapPricer/R/IRS.R#174: fixing.row <- floating.history[floating.history$date %in% swap.dates$fixing.date, 
#>     ]
#> debug at /Users/davidemagno/Documents/R/Pricingverse/SwapPricer/R/IRS.R#177: if (nrow(fixing.row) == 0) {
#>     closest.dates <- (floating.history$date - swap.dates$fixing.date)
#>     fixing.row <- floating.history[which(closest.dates == max(closest.dates[closest.dates < 
#>         0])), ]
#> }
#> debug at /Users/davidemagno/Documents/R/Pricingverse/SwapPricer/R/IRS.R#183: rate <- fixing.row[["value"]]/100
#> debug at /Users/davidemagno/Documents/R/Pricingverse/SwapPricer/R/IRS.R#189: swap.dates %>% purrr::pluck("accrual.yf") %>% *(swap$notional * 
#>     rate * switch(leg.type, pay = -1, receive = 1))
#> Called from: AccrualCalculation(.x, .y, swap, direction, floating.history)
#> debug at /Users/davidemagno/Documents/R/Pricingverse/SwapPricer/R/IRS.R#168: if (!is.null(swap.dates$fixing.date)) {
#>     floating.history <- floating.history[grepl(swap$currency, 
#>         floating.history$currency) & floating.history$time.unit == 
#>         swap$time.unit[[leg.type]], "rate.data"]
#>     floating.history <- purrr::flatten(floating.history$rate.data)[[1]]
#>     fixing.row <- floating.history[floating.history$date %in% 
#>         swap.dates$fixing.date, ]
#>     if (nrow(fixing.row) == 0) {
#>         closest.dates <- (floating.history$date - swap.dates$fixing.date)
#>         fixing.row <- floating.history[which(closest.dates == 
#>             max(closest.dates[closest.dates < 0])), ]
#>     }
#>     rate <- fixing.row[["value"]]/100
#> } else {
#>     rate <- swap$strike
#> }
#> debug at /Users/davidemagno/Documents/R/Pricingverse/SwapPricer/R/IRS.R#169: floating.history <- floating.history[grepl(swap$currency, floating.history$currency) & 
#>     floating.history$time.unit == swap$time.unit[[leg.type]], 
#>     "rate.data"]
#> debug at /Users/davidemagno/Documents/R/Pricingverse/SwapPricer/R/IRS.R#172: floating.history <- purrr::flatten(floating.history$rate.data)[[1]]
#> debug at /Users/davidemagno/Documents/R/Pricingverse/SwapPricer/R/IRS.R#174: fixing.row <- floating.history[floating.history$date %in% swap.dates$fixing.date, 
#>     ]
#> debug at /Users/davidemagno/Documents/R/Pricingverse/SwapPricer/R/IRS.R#177: if (nrow(fixing.row) == 0) {
#>     closest.dates <- (floating.history$date - swap.dates$fixing.date)
#>     fixing.row <- floating.history[which(closest.dates == max(closest.dates[closest.dates < 
#>         0])), ]
#> }
#> debug at /Users/davidemagno/Documents/R/Pricingverse/SwapPricer/R/IRS.R#183: rate <- fixing.row[["value"]]/100
#> debug at /Users/davidemagno/Documents/R/Pricingverse/SwapPricer/R/IRS.R#189: swap.dates %>% purrr::pluck("accrual.yf") %>% *(swap$notional * 
#>     rate * switch(leg.type, pay = -1, receive = 1))
#> Called from: AccrualCalculation(.x, .y, swap, direction, floating.history)
#> debug at /Users/davidemagno/Documents/R/Pricingverse/SwapPricer/R/IRS.R#168: if (!is.null(swap.dates$fixing.date)) {
#>     floating.history <- floating.history[grepl(swap$currency, 
#>         floating.history$currency) & floating.history$time.unit == 
#>         swap$time.unit[[leg.type]], "rate.data"]
#>     floating.history <- purrr::flatten(floating.history$rate.data)[[1]]
#>     fixing.row <- floating.history[floating.history$date %in% 
#>         swap.dates$fixing.date, ]
#>     if (nrow(fixing.row) == 0) {
#>         closest.dates <- (floating.history$date - swap.dates$fixing.date)
#>         fixing.row <- floating.history[which(closest.dates == 
#>             max(closest.dates[closest.dates < 0])), ]
#>     }
#>     rate <- fixing.row[["value"]]/100
#> } else {
#>     rate <- swap$strike
#> }
#> debug at /Users/davidemagno/Documents/R/Pricingverse/SwapPricer/R/IRS.R#186: rate <- swap$strike
#> debug at /Users/davidemagno/Documents/R/Pricingverse/SwapPricer/R/IRS.R#189: swap.dates %>% purrr::pluck("accrual.yf") %>% *(swap$notional * 
#>     rate * switch(leg.type, pay = -1, receive = 1))
#> Called from: AccrualCalculation(.x, .y, swap, direction, floating.history)
#> debug at /Users/davidemagno/Documents/R/Pricingverse/SwapPricer/R/IRS.R#168: if (!is.null(swap.dates$fixing.date)) {
#>     floating.history <- floating.history[grepl(swap$currency, 
#>         floating.history$currency) & floating.history$time.unit == 
#>         swap$time.unit[[leg.type]], "rate.data"]
#>     floating.history <- purrr::flatten(floating.history$rate.data)[[1]]
#>     fixing.row <- floating.history[floating.history$date %in% 
#>         swap.dates$fixing.date, ]
#>     if (nrow(fixing.row) == 0) {
#>         closest.dates <- (floating.history$date - swap.dates$fixing.date)
#>         fixing.row <- floating.history[which(closest.dates == 
#>             max(closest.dates[closest.dates < 0])), ]
#>     }
#>     rate <- fixing.row[["value"]]/100
#> } else {
#>     rate <- swap$strike
#> }
#> debug at /Users/davidemagno/Documents/R/Pricingverse/SwapPricer/R/IRS.R#169: floating.history <- floating.history[grepl(swap$currency, floating.history$currency) & 
#>     floating.history$time.unit == swap$time.unit[[leg.type]], 
#>     "rate.data"]
#> debug at /Users/davidemagno/Documents/R/Pricingverse/SwapPricer/R/IRS.R#172: floating.history <- purrr::flatten(floating.history$rate.data)[[1]]
#> debug at /Users/davidemagno/Documents/R/Pricingverse/SwapPricer/R/IRS.R#174: fixing.row <- floating.history[floating.history$date %in% swap.dates$fixing.date, 
#>     ]
#> debug at /Users/davidemagno/Documents/R/Pricingverse/SwapPricer/R/IRS.R#177: if (nrow(fixing.row) == 0) {
#>     closest.dates <- (floating.history$date - swap.dates$fixing.date)
#>     fixing.row <- floating.history[which(closest.dates == max(closest.dates[closest.dates < 
#>         0])), ]
#> }
#> debug at /Users/davidemagno/Documents/R/Pricingverse/SwapPricer/R/IRS.R#183: rate <- fixing.row[["value"]]/100
#> debug at /Users/davidemagno/Documents/R/Pricingverse/SwapPricer/R/IRS.R#189: swap.dates %>% purrr::pluck("accrual.yf") %>% *(swap$notional * 
#>     rate * switch(leg.type, pay = -1, receive = 1))
#> Called from: AccrualCalculation(.x, .y, swap, direction, floating.history)
#> debug at /Users/davidemagno/Documents/R/Pricingverse/SwapPricer/R/IRS.R#168: if (!is.null(swap.dates$fixing.date)) {
#>     floating.history <- floating.history[grepl(swap$currency, 
#>         floating.history$currency) & floating.history$time.unit == 
#>         swap$time.unit[[leg.type]], "rate.data"]
#>     floating.history <- purrr::flatten(floating.history$rate.data)[[1]]
#>     fixing.row <- floating.history[floating.history$date %in% 
#>         swap.dates$fixing.date, ]
#>     if (nrow(fixing.row) == 0) {
#>         closest.dates <- (floating.history$date - swap.dates$fixing.date)
#>         fixing.row <- floating.history[which(closest.dates == 
#>             max(closest.dates[closest.dates < 0])), ]
#>     }
#>     rate <- fixing.row[["value"]]/100
#> } else {
#>     rate <- swap$strike
#> }
#> debug at /Users/davidemagno/Documents/R/Pricingverse/SwapPricer/R/IRS.R#186: rate <- swap$strike
#> debug at /Users/davidemagno/Documents/R/Pricingverse/SwapPricer/R/IRS.R#189: swap.dates %>% purrr::pluck("accrual.yf") %>% *(swap$notional * 
#>     rate * switch(leg.type, pay = -1, receive = 1))
#> Called from: AccrualCalculation(.x, .y, swap, direction, floating.history)
#> debug at /Users/davidemagno/Documents/R/Pricingverse/SwapPricer/R/IRS.R#168: if (!is.null(swap.dates$fixing.date)) {
#>     floating.history <- floating.history[grepl(swap$currency, 
#>         floating.history$currency) & floating.history$time.unit == 
#>         swap$time.unit[[leg.type]], "rate.data"]
#>     floating.history <- purrr::flatten(floating.history$rate.data)[[1]]
#>     fixing.row <- floating.history[floating.history$date %in% 
#>         swap.dates$fixing.date, ]
#>     if (nrow(fixing.row) == 0) {
#>         closest.dates <- (floating.history$date - swap.dates$fixing.date)
#>         fixing.row <- floating.history[which(closest.dates == 
#>             max(closest.dates[closest.dates < 0])), ]
#>     }
#>     rate <- fixing.row[["value"]]/100
#> } else {
#>     rate <- swap$strike
#> }
#> debug at /Users/davidemagno/Documents/R/Pricingverse/SwapPricer/R/IRS.R#186: rate <- swap$strike
#> debug at /Users/davidemagno/Documents/R/Pricingverse/SwapPricer/R/IRS.R#189: swap.dates %>% purrr::pluck("accrual.yf") %>% *(swap$notional * 
#>     rate * switch(leg.type, pay = -1, receive = 1))
#> Called from: AccrualCalculation(.x, .y, swap, direction, floating.history)
#> debug at /Users/davidemagno/Documents/R/Pricingverse/SwapPricer/R/IRS.R#168: if (!is.null(swap.dates$fixing.date)) {
#>     floating.history <- floating.history[grepl(swap$currency, 
#>         floating.history$currency) & floating.history$time.unit == 
#>         swap$time.unit[[leg.type]], "rate.data"]
#>     floating.history <- purrr::flatten(floating.history$rate.data)[[1]]
#>     fixing.row <- floating.history[floating.history$date %in% 
#>         swap.dates$fixing.date, ]
#>     if (nrow(fixing.row) == 0) {
#>         closest.dates <- (floating.history$date - swap.dates$fixing.date)
#>         fixing.row <- floating.history[which(closest.dates == 
#>             max(closest.dates[closest.dates < 0])), ]
#>     }
#>     rate <- fixing.row[["value"]]/100
#> } else {
#>     rate <- swap$strike
#> }
#> debug at /Users/davidemagno/Documents/R/Pricingverse/SwapPricer/R/IRS.R#186: rate <- swap$strike
#> debug at /Users/davidemagno/Documents/R/Pricingverse/SwapPricer/R/IRS.R#189: swap.dates %>% purrr::pluck("accrual.yf") %>% *(swap$notional * 
#>     rate * switch(leg.type, pay = -1, receive = 1))
Pricing results swap.id currency clean.mv dirty.mv accrual.pay accrual.receive par pv01 Swap 25y EUR \-881,831.25 \-874,928.79 5,506.67 1,395.80 0.77% \-12,390.87 Swap 30y GBP 105,100.25 104,665.66 \-4,739.73 4,305.14 1.54% 1,948.27 Swap 10y USD \-119,333.64 \-126,360.65 \-7,777.01 750.00 2.43% \-547.60 Swap 2y16y GBP \-94,850.43 \-94,850.43 \-0.00 0.00 1.59% \-10,393.05 Swap non standard EUR \-2,590,941.00 \-2,861,693.88 \-264,657.53 \-6,095.34 1.07% 27,912.93 Swap 10y semi fixed EUR \-16,313.13 \-29,967.92 \-3,835.62 \-9,819.18 0.07% 5,129.68 Swap 30y quarter floating GBP 88,228.04 105,652.23 \-2,082.67 19,506.85 1.55% \-1,940.77 Swap 10y irregular USD \-119,608.54 \-126,827.43 \-7,944.92 726.03 2.44% \-545.92 Swap 2y16y EUR \-361,098.10 \-361,098.10 \-0.00 0.00 1.18% 11,170.90

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.