Site icon R-bloggers

SwapPricer is on Github

[This article was first published on R on The CuRious Financial Risk ManageR, and kindly contributed to R-bloggers]. (You can report issue about the content on this page here)
Want to share your content on R-bloggers? click here if you have a blog, or here if you don't.
  • 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)
    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 in a 5 swaps portfolio that can be referenced as 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 500 swaps portfolio and the results, in terms of performance are very encouraging. We analyse them using the amazing profvis tool.

  • To leave a comment for the author, please follow the link and comment on their blog: R on The CuRious Financial Risk ManageR.

    R-bloggers.com offers daily e-mail updates about R news and tutorials about learning R and many other topics. Click here if you're looking to post or find an R/data-science job.
    Want to share your content on R-bloggers? click here if you have a blog, or here if you don't.