{"id":3510,"date":"2019-05-15T11:28:23","date_gmt":"2019-05-15T15:28:23","guid":{"rendered":"https:\/\/ibkrcampus.com\/?p=3510"},"modified":"2025-02-07T15:08:14","modified_gmt":"2025-02-07T20:08:14","slug":"real-world-tidy-interest-rate-swap-pricing","status":"publish","type":"post","link":"https:\/\/www.interactivebrokers.com\/campus\/ibkr-quant-news\/real-world-tidy-interest-rate-swap-pricing\/","title":{"rendered":"Real world tidy interest rate swap pricing"},"content":{"rendered":"\n<p>In this post I will show how easy it is to price a portfolio of swaps leveraging the&nbsp;<strong>purrr<\/strong>&nbsp;package and given the swap pricing functions that we introduced in a&nbsp;<a href=\"https:\/\/www.curiousfrm.com\/2019\/03\/using-the-tidyverse-for-swap-pricing\/\" target=\"_blank\" rel=\"noreferrer noopener\">previous post<\/a>. I will do this in a \u201creal world\u201d environment using real market data from April 14.<\/p>\n\n\n\n<p>Import the discount factors from Bloomberg<\/p>\n\n\n\n<p>Let\u2019s start the pricing of the swap portfolio with\u00a0<strong>purrr<\/strong>\u00a0by loading from an external source the EUR discount factor curve. My source is\u00a0<em>Bloomberg,<\/em>\u00a0and in particular the\u00a0<em>SWPM<\/em>\u00a0page, which allows all Bloomberg users to price interest rate sensitive instruments. It also contains a tab with the curve information, which is the source of my curve. It is partly represented in the screenshot below, as well as in the following table:<\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><img decoding=\"async\" width=\"738\" height=\"531\" data-src=\"\/campus\/wp-content\/uploads\/sites\/2\/2023\/03\/real-world-tidy-interest-1.png\" alt=\"\" class=\"wp-image-187255 lazyload\" data-srcset=\"https:\/\/ibkrcampus.com\/campus\/wp-content\/uploads\/sites\/2\/2023\/03\/real-world-tidy-interest-1.png 738w, https:\/\/ibkrcampus.com\/campus\/wp-content\/uploads\/sites\/2\/2023\/03\/real-world-tidy-interest-1-700x504.png 700w, https:\/\/ibkrcampus.com\/campus\/wp-content\/uploads\/sites\/2\/2023\/03\/real-world-tidy-interest-1-300x216.png 300w\" data-sizes=\"(max-width: 738px) 100vw, 738px\" src=\"data:image\/svg+xml;base64,PHN2ZyB3aWR0aD0iMSIgaGVpZ2h0PSIxIiB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciPjwvc3ZnPg==\" style=\"--smush-placeholder-width: 738px; aspect-ratio: 738\/531;\" \/><\/figure>\n\n\n\n<pre class=\"wp-block-code\"><code>today &lt;- lubridate::ymd(20190414)\n ir_curve &lt;- readr::read_csv(here::here(\"data\/Basket of IRS\/Curve at 140419.csv\"))\n ir_curve %&gt;%\n knitr::kable(caption = \"Input from Bloomberg\", \"html\") %&gt;%\n kableExtra::kable_styling(bootstrap_options = c(\"striped\", \"hover\", \"condensed\", \"responsive\")) %&gt;%\n kableExtra::scroll_box(width = \"750px\", height = \"200px\") <\/code><\/pre>\n\n\n\n<figure class=\"wp-block-image size-full\"><img decoding=\"async\" width=\"304\" height=\"88\" data-src=\"\/campus\/wp-content\/uploads\/sites\/2\/2023\/03\/real-world-tidy-interest-2.png\" alt=\"\" class=\"wp-image-187256 lazyload\" data-srcset=\"https:\/\/ibkrcampus.com\/campus\/wp-content\/uploads\/sites\/2\/2023\/03\/real-world-tidy-interest-2.png 304w, https:\/\/ibkrcampus.com\/campus\/wp-content\/uploads\/sites\/2\/2023\/03\/real-world-tidy-interest-2-300x87.png 300w\" data-sizes=\"(max-width: 304px) 100vw, 304px\" src=\"data:image\/svg+xml;base64,PHN2ZyB3aWR0aD0iMSIgaGVpZ2h0PSIxIiB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciPjwvc3ZnPg==\" style=\"--smush-placeholder-width: 304px; aspect-ratio: 304\/88;\" \/><\/figure>\n\n\n\n<p><em>Note: R code and table can be downloaded from Davide\u2019s website:<br><a href=\"https:\/\/www.curiousfrm.com\/2019\/04\/real-world-tidy-interest-rate-swap-pricing\/\" target=\"_blank\" rel=\"noreferrer noopener\">https:\/\/www.curiousfrm.com\/2019\/04\/real-world-tidy-interest-rate-swap-pricing\/<\/a><\/em><\/p>\n\n\n\n<p>We now wrangle this data in order to get a two-column tibble containing the time to maturity and the discount factors for each pillar points on the curve. We us a&nbsp;<em>30\/360<\/em>-day count convention because it is the standard for the EUR <\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>df.table &lt;- ir_curve %&gt;%\n\n\tdplyr::mutate(`Maturity Date` = lubridate::mdy(`Maturity Date`)) %&gt;%\n\n\tdplyr::rowwise(.) %&gt;%\n\n\tdplyr::mutate(t2m = RQuantLib::yearFraction(today, `Maturity Date`, 6)) %&gt;%\n\n\tna.omit %&gt;%\n\n\tdplyr::select(t2m, Discount) %&gt;%\n\n\tdplyr::rename(df = Discount) %&gt;%\n\n\tdplyr::ungroup(.) %&gt;%\n\n\tdplyr::bind_rows(c(t2m = 0,df = 1)) %&gt;%\n\n\tdplyr::arrange(t2m)\n\n\t\n\n\tggplot2::ggplot(df.table, ggplot2::aes(x = t2m, y = df)) +\n\n\tggplot2::geom_point() + ggplot2::geom_line(colour = \"blue\") +\n\n\tggplot2::ggtitle(\"Discount Factor curve at 14th of April 2019\") +\n\n\tggplot2::xlab(\"Time to maturity\") +\n\n\tggplot2::ylab(\"Discount Factor\")\n<\/code><\/pre>\n\n\n\n<figure class=\"wp-block-image size-full\"><img decoding=\"async\" width=\"623\" height=\"444\" data-src=\"\/campus\/wp-content\/uploads\/sites\/2\/2023\/03\/real-world-tidy-interest-3.png\" alt=\"\" class=\"wp-image-187258 lazyload\" data-srcset=\"https:\/\/ibkrcampus.com\/campus\/wp-content\/uploads\/sites\/2\/2023\/03\/real-world-tidy-interest-3.png 623w, https:\/\/ibkrcampus.com\/campus\/wp-content\/uploads\/sites\/2\/2023\/03\/real-world-tidy-interest-3-300x214.png 300w\" data-sizes=\"(max-width: 623px) 100vw, 623px\" src=\"data:image\/svg+xml;base64,PHN2ZyB3aWR0aD0iMSIgaGVpZ2h0PSIxIiB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciPjwvc3ZnPg==\" style=\"--smush-placeholder-width: 623px; aspect-ratio: 623\/444;\" \/><\/figure>\n\n\n\n<p><strong>Interest Rate Swap pricing functions<\/strong><\/p>\n\n\n\n<p>I am now going to re-use the pricing functions that have been already described in a&nbsp;<a href=\"https:\/\/www.curiousfrm.com\/2019\/03\/using-the-tidyverse-for-swap-pricing\/\" target=\"_blank\" rel=\"noreferrer noopener\">previous post<\/a>. I have tidied them up a bit and given proper names, but the description still fully holds.<\/p>\n\n\n\n<p> Let\u2019s start from the one that calculates the swap cashflows. <\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>SwapCashflowYFCalculation &lt;- function(today, start.date, maturity.date,\n\n\ttime.unit, dcc, calendar) { \n0:((lubridate::year(maturity.date) - lubridate::year(start.date)) *\n\n\t(4 - time.unit)) %&gt;%\n\n\tpurrr::map_dbl(~RQuantLib::advance(calendar = calendar,\n\n\tdates = start.date,\n\n\tn = .x, timeUnit = time.unit,\n\n\tbdc = 1,\n\n\temr = TRUE)) %&gt;%\n\n\tlubridate::as_date() %&gt;% {\n\nif (start.date &lt; today) append(today, .) else .} %&gt;%\n\n\tpurrr::map_dbl(~RQuantLib::yearFraction(today, .x, dcc)) %&gt;%\n\n\ttibble::tibble(yf = .) }<\/code><\/pre>\n\n\n\n<p><\/p>\n\n\n\n<p>You may have noticed that I added one row&nbsp;<code>{if (start.date &lt; today) append(today, .) else .}<\/code>. This allows &nbsp;proper management of the pricing of swaps with a starting date before today.<\/p>\n\n\n\n<p>I now proceed with calculating the actual par swap rate, which is a key input to the pricing formula. Notice in the function below that I use a linear interpolation on the log of the discount factors. This is in line with one of the Bloomberg options. It is proven that it:<\/p>\n\n\n\n<ol class=\"wp-block-list\">\n<li>provides step constant forward rates<\/li>\n\n\n\n<li>locally stabilizes the bucketed sensitivities<\/li>\n<\/ol>\n\n\n\n<p>Also, the (old) swap rate pricing function is the same. We only filter for future cashflows, as we want to be able to price swaps with a starting date before today. <\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>OLDParSwapRate &lt;- function(swap.cf){\n swap.cf %&lt;&gt;%\n dplyr::filter(yf &gt;= 0)\n\n num &lt;- (swap.cf$df&#91;1] - swap.cf$df&#91;dim(swap.cf)&#91;1]])\n\n annuity &lt;- (sum(diff(swap.cf$yf)*swap.cf$df&#91;2:dim(swap.cf)&#91;1]])) \nreturn(list(swap.rate = num\/annuity,\n annuity = annuity))\n\n }\n\n ParSwapRateCalculation &lt;- function(\n swap.cf.yf, df.table) { swap.cf.yf %&gt;%\n dplyr::mutate(df = approx(df.table$t2m, log(df.table$df), .$yf) %&gt;%\n purrr::pluck(\"y\") %&gt;%\n exp) %&gt;%\n OLDParSwapRate\n }<\/code><\/pre>\n\n\n\n<p>I now want to introduce two new functions which are needed for calculating the actual market values:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>the first one extracts the year fraction for the accrual calculation<\/li>\n\n\n\n<li>the second one calculates the main characteristics of a swap:\n<ul class=\"wp-block-list\">\n<li>the par swap rate<\/li>\n\n\n\n<li>the pv01 (or analytic delta)<\/li>\n\n\n\n<li>the clean market value<\/li>\n\n\n\n<li>the accrual for the fixed rate leg<\/li>\n<\/ul>\n<\/li>\n<\/ul>\n\n\n\n<p>I have defined a variable&nbsp;<code>direction<\/code>&nbsp;which represents the type of swap:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>if it is equal to&nbsp;<code>1<\/code>&nbsp;then it is a&nbsp;<em>receiver<\/em>&nbsp;swap<\/li>\n\n\n\n<li>if it is equal to&nbsp;<code>-1<\/code>&nbsp;then it is a&nbsp;<em>payer<\/em>&nbsp;swap<\/li>\n<\/ul>\n\n\n\n<pre class=\"wp-block-code\"><code>CalculateAccrual &lt;- function(swap.cf){\n\n\tswap.cf %&gt;% dplyr::filter(yf &lt; 0) %&gt;%\n\n\tdplyr::select(yf) %&gt;%\n\n\tdplyr::arrange(dplyr::desc(yf)) %&gt;%\n\n\tdplyr::top_n(1) %&gt;% \nas.double %&gt;%\n\n\t{if (is.na(.)) 0 else .}\n\n\t}\n\n\t\n\n\tSwapCalculations &lt;- function(swap.cf.yf, notional, strike, direction, df.table) {\n\n\tswap.par.pricing &lt;- ParSwapRateCalculation(swap.cf.yf, df.table)\n\n\t\n\n\tmv &lt;- notional * swap.par.pricing$annuity * (strike - swap.par.pricing$swap.rate) * direction\n\n\t\n\n\taccrual.fixed &lt;- swap.cf.yf %&gt;%\n\n\tCalculateAccrual %&gt;%\n\n\t`*`(notional * strike * direction * -1)\n\n\t\n\n\tpv01 &lt;- notional\/10000 * swap.par.pricing$annuity * direction \n\nlist(clean.mv = mv, accrual.fixed = accrual.fixed, par = swap.par.pricing$swap.rate,\n\n\tpv01 = pv01)\n\n\t}<\/code><\/pre>\n\n\n\n<p>We then put everything together with the following pricing pipe:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>SwapPricing &lt;- function(today, swap, df.table) {\n SwapCashflowYFCalculation(today, swap$start.date,\n swap$maturity.date, swap$time.unit,\n swap$dcc, swap$calendar) %&gt;%\n SwapCalculations(swap$notional, swap$strike, swap$direction, df.table)\n }<\/code><\/pre>\n\n\n\n<p><em>Note: R code can be downloaded from Davide\u2019s website:<\/em><br><em><a rel=\"noreferrer noopener\" href=\"https:\/\/www.curiousfrm.com\/2019\/04\/real-world-tidy-interest-rate-swap-pricing\/\" target=\"_blank\">https:\/\/www.curiousfrm.com\/2019\/04\/real-world-tidy-interest-rate-swap-pricing\/<\/a><\/em><\/p>\n\n\n\n<p><em> Davide Magno is&nbsp;a professional financial engineer with more than 10 years of experience of managing complex financial quantitative tasks for banks, insurances and funds.&nbsp;He is passionate about both quantitative finance and data science: he is the author of the blog&nbsp;<\/em><a rel=\"noreferrer noopener\" href=\"https:\/\/www.curiousfrm.com\/\" target=\"_blank\"><em>curiousfrm.com<\/em><\/a><em>&nbsp;that aims at solving financial problems using modern data science coding languages and techniques. He is currently Head of Financial Risk Management in Axa Life Europe dac. Opinions expressed are solely his and do not express the views or opinions of his current employer. <\/em><\/p>\n","protected":false},"excerpt":{"rendered":"<p>In this post I will show how easy it is to price a portfolio of swaps leveraging the purrr package and given the swap pricing functions that we introduced in a previous post. <\/p>\n","protected":false},"author":123,"featured_media":3609,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[339,343,338,351,344,342],"tags":[806,487],"contributors-categories":[13656],"class_list":{"0":"post-3510","1":"post","2":"type-post","3":"status-publish","4":"format-standard","5":"has-post-thumbnail","7":"category-data-science","8":"category-programing-languages","9":"category-ibkr-quant-news","10":"category-quant-europe","11":"category-quant-regions","12":"category-r-development","13":"tag-data-science","14":"tag-r","15":"contributors-categories-curiousfrm-com"},"pp_statuses_selecting_workflow":false,"pp_workflow_action":"current","pp_status_selection":"publish","acf":[],"yoast_head":"<!-- This site is optimized with the Yoast SEO Premium plugin v26.9 (Yoast SEO v27.7) - https:\/\/yoast.com\/product\/yoast-seo-premium-wordpress\/ -->\n<title>Real world tidy interest rate swap pricing | IBKR Quant<\/title>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/www.interactivebrokers.com\/campus\/wp-json\/wp\/v2\/posts\/3510\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Real world tidy interest rate swap pricing | IBKR Campus US\" \/>\n<meta property=\"og:description\" content=\"In this post I will show how easy it is to price a portfolio of swaps leveraging the purrr package and given the swap pricing functions that we introduced in a previous post.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.interactivebrokers.com\/campus\/ibkr-quant-news\/real-world-tidy-interest-rate-swap-pricing\/\" \/>\n<meta property=\"og:site_name\" content=\"IBKR Campus US\" \/>\n<meta property=\"article:published_time\" content=\"2019-05-15T15:28:23+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2025-02-07T20:08:14+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/www.interactivebrokers.com\/campus\/wp-content\/uploads\/sites\/2\/2019\/05\/R-bond-analysis.png\" \/>\n\t<meta property=\"og:image:width\" content=\"622\" \/>\n\t<meta property=\"og:image:height\" content=\"445\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/png\" \/>\n<meta name=\"author\" content=\"Davide Magno\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Davide Magno\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"5 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\n\t    \"@context\": \"https:\\\/\\\/schema.org\",\n\t    \"@graph\": [\n\t        {\n\t            \"@type\": \"NewsArticle\",\n\t            \"@id\": \"https:\\\/\\\/www.interactivebrokers.com\\\/campus\\\/ibkr-quant-news\\\/real-world-tidy-interest-rate-swap-pricing\\\/#article\",\n\t            \"isPartOf\": {\n\t                \"@id\": \"https:\\\/\\\/www.interactivebrokers.com\\\/campus\\\/ibkr-quant-news\\\/real-world-tidy-interest-rate-swap-pricing\\\/\"\n\t            },\n\t            \"author\": {\n\t                \"name\": \"Davide Magno\",\n\t                \"@id\": \"https:\\\/\\\/ibkrcampus.com\\\/campus\\\/#\\\/schema\\\/person\\\/5dee9eb1d0d0933b55de5ad7ca31afd4\"\n\t            },\n\t            \"headline\": \"Real world tidy interest rate swap pricing\",\n\t            \"datePublished\": \"2019-05-15T15:28:23+00:00\",\n\t            \"dateModified\": \"2025-02-07T20:08:14+00:00\",\n\t            \"mainEntityOfPage\": {\n\t                \"@id\": \"https:\\\/\\\/www.interactivebrokers.com\\\/campus\\\/ibkr-quant-news\\\/real-world-tidy-interest-rate-swap-pricing\\\/\"\n\t            },\n\t            \"wordCount\": 586,\n\t            \"publisher\": {\n\t                \"@id\": \"https:\\\/\\\/ibkrcampus.com\\\/campus\\\/#organization\"\n\t            },\n\t            \"image\": {\n\t                \"@id\": \"https:\\\/\\\/www.interactivebrokers.com\\\/campus\\\/ibkr-quant-news\\\/real-world-tidy-interest-rate-swap-pricing\\\/#primaryimage\"\n\t            },\n\t            \"thumbnailUrl\": \"https:\\\/\\\/www.interactivebrokers.com\\\/campus\\\/wp-content\\\/uploads\\\/sites\\\/2\\\/2019\\\/05\\\/R-bond-analysis.png\",\n\t            \"keywords\": [\n\t                \"Data Science\",\n\t                \"R\"\n\t            ],\n\t            \"articleSection\": [\n\t                \"Data Science\",\n\t                \"Programming Languages\",\n\t                \"Quant\",\n\t                \"Quant Europe\",\n\t                \"Quant Regions\",\n\t                \"R Development\"\n\t            ],\n\t            \"inLanguage\": \"en-US\"\n\t        },\n\t        {\n\t            \"@type\": \"WebPage\",\n\t            \"@id\": \"https:\\\/\\\/www.interactivebrokers.com\\\/campus\\\/ibkr-quant-news\\\/real-world-tidy-interest-rate-swap-pricing\\\/\",\n\t            \"url\": \"https:\\\/\\\/www.interactivebrokers.com\\\/campus\\\/ibkr-quant-news\\\/real-world-tidy-interest-rate-swap-pricing\\\/\",\n\t            \"name\": \"Real world tidy interest rate swap pricing | IBKR Campus US\",\n\t            \"isPartOf\": {\n\t                \"@id\": \"https:\\\/\\\/ibkrcampus.com\\\/campus\\\/#website\"\n\t            },\n\t            \"primaryImageOfPage\": {\n\t                \"@id\": \"https:\\\/\\\/www.interactivebrokers.com\\\/campus\\\/ibkr-quant-news\\\/real-world-tidy-interest-rate-swap-pricing\\\/#primaryimage\"\n\t            },\n\t            \"image\": {\n\t                \"@id\": \"https:\\\/\\\/www.interactivebrokers.com\\\/campus\\\/ibkr-quant-news\\\/real-world-tidy-interest-rate-swap-pricing\\\/#primaryimage\"\n\t            },\n\t            \"thumbnailUrl\": \"https:\\\/\\\/www.interactivebrokers.com\\\/campus\\\/wp-content\\\/uploads\\\/sites\\\/2\\\/2019\\\/05\\\/R-bond-analysis.png\",\n\t            \"datePublished\": \"2019-05-15T15:28:23+00:00\",\n\t            \"dateModified\": \"2025-02-07T20:08:14+00:00\",\n\t            \"inLanguage\": \"en-US\",\n\t            \"potentialAction\": [\n\t                {\n\t                    \"@type\": \"ReadAction\",\n\t                    \"target\": [\n\t                        \"https:\\\/\\\/www.interactivebrokers.com\\\/campus\\\/ibkr-quant-news\\\/real-world-tidy-interest-rate-swap-pricing\\\/\"\n\t                    ]\n\t                }\n\t            ]\n\t        },\n\t        {\n\t            \"@type\": \"ImageObject\",\n\t            \"inLanguage\": \"en-US\",\n\t            \"@id\": \"https:\\\/\\\/www.interactivebrokers.com\\\/campus\\\/ibkr-quant-news\\\/real-world-tidy-interest-rate-swap-pricing\\\/#primaryimage\",\n\t            \"url\": \"https:\\\/\\\/www.interactivebrokers.com\\\/campus\\\/wp-content\\\/uploads\\\/sites\\\/2\\\/2019\\\/05\\\/R-bond-analysis.png\",\n\t            \"contentUrl\": \"https:\\\/\\\/www.interactivebrokers.com\\\/campus\\\/wp-content\\\/uploads\\\/sites\\\/2\\\/2019\\\/05\\\/R-bond-analysis.png\",\n\t            \"width\": 622,\n\t            \"height\": 445,\n\t            \"caption\": \"R-bond-analysis\"\n\t        },\n\t        {\n\t            \"@type\": \"WebSite\",\n\t            \"@id\": \"https:\\\/\\\/ibkrcampus.com\\\/campus\\\/#website\",\n\t            \"url\": \"https:\\\/\\\/ibkrcampus.com\\\/campus\\\/\",\n\t            \"name\": \"IBKR Campus US\",\n\t            \"description\": \"Financial Education from Interactive Brokers\",\n\t            \"publisher\": {\n\t                \"@id\": \"https:\\\/\\\/ibkrcampus.com\\\/campus\\\/#organization\"\n\t            },\n\t            \"potentialAction\": [\n\t                {\n\t                    \"@type\": \"SearchAction\",\n\t                    \"target\": {\n\t                        \"@type\": \"EntryPoint\",\n\t                        \"urlTemplate\": \"https:\\\/\\\/ibkrcampus.com\\\/campus\\\/?s={search_term_string}\"\n\t                    },\n\t                    \"query-input\": {\n\t                        \"@type\": \"PropertyValueSpecification\",\n\t                        \"valueRequired\": true,\n\t                        \"valueName\": \"search_term_string\"\n\t                    }\n\t                }\n\t            ],\n\t            \"inLanguage\": \"en-US\"\n\t        },\n\t        {\n\t            \"@type\": \"Organization\",\n\t            \"@id\": \"https:\\\/\\\/ibkrcampus.com\\\/campus\\\/#organization\",\n\t            \"name\": \"Interactive Brokers\",\n\t            \"alternateName\": \"IBKR\",\n\t            \"url\": \"https:\\\/\\\/ibkrcampus.com\\\/campus\\\/\",\n\t            \"logo\": {\n\t                \"@type\": \"ImageObject\",\n\t                \"inLanguage\": \"en-US\",\n\t                \"@id\": \"https:\\\/\\\/ibkrcampus.com\\\/campus\\\/#\\\/schema\\\/logo\\\/image\\\/\",\n\t                \"url\": \"https:\\\/\\\/www.interactivebrokers.com\\\/campus\\\/wp-content\\\/uploads\\\/sites\\\/2\\\/2024\\\/05\\\/ibkr-campus-logo.jpg\",\n\t                \"contentUrl\": \"https:\\\/\\\/www.interactivebrokers.com\\\/campus\\\/wp-content\\\/uploads\\\/sites\\\/2\\\/2024\\\/05\\\/ibkr-campus-logo.jpg\",\n\t                \"width\": 669,\n\t                \"height\": 669,\n\t                \"caption\": \"Interactive Brokers\"\n\t            },\n\t            \"image\": {\n\t                \"@id\": \"https:\\\/\\\/ibkrcampus.com\\\/campus\\\/#\\\/schema\\\/logo\\\/image\\\/\"\n\t            },\n\t            \"publishingPrinciples\": \"https:\\\/\\\/www.interactivebrokers.com\\\/campus\\\/about-ibkr-campus\\\/\",\n\t            \"ethicsPolicy\": \"https:\\\/\\\/www.interactivebrokers.com\\\/campus\\\/cyber-security-notice\\\/\"\n\t        },\n\t        {\n\t            \"@type\": \"Person\",\n\t            \"@id\": \"https:\\\/\\\/ibkrcampus.com\\\/campus\\\/#\\\/schema\\\/person\\\/5dee9eb1d0d0933b55de5ad7ca31afd4\",\n\t            \"name\": \"Davide Magno\",\n\t            \"url\": \"https:\\\/\\\/www.interactivebrokers.com\\\/campus\\\/author\\\/davide-magno\\\/\"\n\t        }\n\t    ]\n\t}<\/script>\n<!-- \/ Yoast SEO Premium plugin. -->","yoast_head_json":{"title":"Real world tidy interest rate swap pricing | IBKR Quant","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/www.interactivebrokers.com\/campus\/wp-json\/wp\/v2\/posts\/3510\/","og_locale":"en_US","og_type":"article","og_title":"Real world tidy interest rate swap pricing | IBKR Campus US","og_description":"In this post I will show how easy it is to price a portfolio of swaps leveraging the purrr package and given the swap pricing functions that we introduced in a previous post.","og_url":"https:\/\/www.interactivebrokers.com\/campus\/ibkr-quant-news\/real-world-tidy-interest-rate-swap-pricing\/","og_site_name":"IBKR Campus US","article_published_time":"2019-05-15T15:28:23+00:00","article_modified_time":"2025-02-07T20:08:14+00:00","og_image":[{"width":622,"height":445,"url":"https:\/\/www.interactivebrokers.com\/campus\/wp-content\/uploads\/sites\/2\/2019\/05\/R-bond-analysis.png","type":"image\/png"}],"author":"Davide Magno","twitter_card":"summary_large_image","twitter_misc":{"Written by":"Davide Magno","Est. reading time":"5 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"NewsArticle","@id":"https:\/\/www.interactivebrokers.com\/campus\/ibkr-quant-news\/real-world-tidy-interest-rate-swap-pricing\/#article","isPartOf":{"@id":"https:\/\/www.interactivebrokers.com\/campus\/ibkr-quant-news\/real-world-tidy-interest-rate-swap-pricing\/"},"author":{"name":"Davide Magno","@id":"https:\/\/ibkrcampus.com\/campus\/#\/schema\/person\/5dee9eb1d0d0933b55de5ad7ca31afd4"},"headline":"Real world tidy interest rate swap pricing","datePublished":"2019-05-15T15:28:23+00:00","dateModified":"2025-02-07T20:08:14+00:00","mainEntityOfPage":{"@id":"https:\/\/www.interactivebrokers.com\/campus\/ibkr-quant-news\/real-world-tidy-interest-rate-swap-pricing\/"},"wordCount":586,"publisher":{"@id":"https:\/\/ibkrcampus.com\/campus\/#organization"},"image":{"@id":"https:\/\/www.interactivebrokers.com\/campus\/ibkr-quant-news\/real-world-tidy-interest-rate-swap-pricing\/#primaryimage"},"thumbnailUrl":"https:\/\/www.interactivebrokers.com\/campus\/wp-content\/uploads\/sites\/2\/2019\/05\/R-bond-analysis.png","keywords":["Data Science","R"],"articleSection":["Data Science","Programming Languages","Quant","Quant Europe","Quant Regions","R Development"],"inLanguage":"en-US"},{"@type":"WebPage","@id":"https:\/\/www.interactivebrokers.com\/campus\/ibkr-quant-news\/real-world-tidy-interest-rate-swap-pricing\/","url":"https:\/\/www.interactivebrokers.com\/campus\/ibkr-quant-news\/real-world-tidy-interest-rate-swap-pricing\/","name":"Real world tidy interest rate swap pricing | IBKR Campus US","isPartOf":{"@id":"https:\/\/ibkrcampus.com\/campus\/#website"},"primaryImageOfPage":{"@id":"https:\/\/www.interactivebrokers.com\/campus\/ibkr-quant-news\/real-world-tidy-interest-rate-swap-pricing\/#primaryimage"},"image":{"@id":"https:\/\/www.interactivebrokers.com\/campus\/ibkr-quant-news\/real-world-tidy-interest-rate-swap-pricing\/#primaryimage"},"thumbnailUrl":"https:\/\/www.interactivebrokers.com\/campus\/wp-content\/uploads\/sites\/2\/2019\/05\/R-bond-analysis.png","datePublished":"2019-05-15T15:28:23+00:00","dateModified":"2025-02-07T20:08:14+00:00","inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.interactivebrokers.com\/campus\/ibkr-quant-news\/real-world-tidy-interest-rate-swap-pricing\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.interactivebrokers.com\/campus\/ibkr-quant-news\/real-world-tidy-interest-rate-swap-pricing\/#primaryimage","url":"https:\/\/www.interactivebrokers.com\/campus\/wp-content\/uploads\/sites\/2\/2019\/05\/R-bond-analysis.png","contentUrl":"https:\/\/www.interactivebrokers.com\/campus\/wp-content\/uploads\/sites\/2\/2019\/05\/R-bond-analysis.png","width":622,"height":445,"caption":"R-bond-analysis"},{"@type":"WebSite","@id":"https:\/\/ibkrcampus.com\/campus\/#website","url":"https:\/\/ibkrcampus.com\/campus\/","name":"IBKR Campus US","description":"Financial Education from Interactive Brokers","publisher":{"@id":"https:\/\/ibkrcampus.com\/campus\/#organization"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/ibkrcampus.com\/campus\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Organization","@id":"https:\/\/ibkrcampus.com\/campus\/#organization","name":"Interactive Brokers","alternateName":"IBKR","url":"https:\/\/ibkrcampus.com\/campus\/","logo":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/ibkrcampus.com\/campus\/#\/schema\/logo\/image\/","url":"https:\/\/www.interactivebrokers.com\/campus\/wp-content\/uploads\/sites\/2\/2024\/05\/ibkr-campus-logo.jpg","contentUrl":"https:\/\/www.interactivebrokers.com\/campus\/wp-content\/uploads\/sites\/2\/2024\/05\/ibkr-campus-logo.jpg","width":669,"height":669,"caption":"Interactive Brokers"},"image":{"@id":"https:\/\/ibkrcampus.com\/campus\/#\/schema\/logo\/image\/"},"publishingPrinciples":"https:\/\/www.interactivebrokers.com\/campus\/about-ibkr-campus\/","ethicsPolicy":"https:\/\/www.interactivebrokers.com\/campus\/cyber-security-notice\/"},{"@type":"Person","@id":"https:\/\/ibkrcampus.com\/campus\/#\/schema\/person\/5dee9eb1d0d0933b55de5ad7ca31afd4","name":"Davide Magno","url":"https:\/\/www.interactivebrokers.com\/campus\/author\/davide-magno\/"}]}},"jetpack_featured_media_url":"https:\/\/www.interactivebrokers.com\/campus\/wp-content\/uploads\/sites\/2\/2019\/05\/R-bond-analysis.png","_links":{"self":[{"href":"https:\/\/ibkrcampus.com\/campus\/wp-json\/wp\/v2\/posts\/3510","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/ibkrcampus.com\/campus\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/ibkrcampus.com\/campus\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/ibkrcampus.com\/campus\/wp-json\/wp\/v2\/users\/123"}],"replies":[{"embeddable":true,"href":"https:\/\/ibkrcampus.com\/campus\/wp-json\/wp\/v2\/comments?post=3510"}],"version-history":[{"count":0,"href":"https:\/\/ibkrcampus.com\/campus\/wp-json\/wp\/v2\/posts\/3510\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/ibkrcampus.com\/campus\/wp-json\/wp\/v2\/media\/3609"}],"wp:attachment":[{"href":"https:\/\/ibkrcampus.com\/campus\/wp-json\/wp\/v2\/media?parent=3510"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/ibkrcampus.com\/campus\/wp-json\/wp\/v2\/categories?post=3510"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/ibkrcampus.com\/campus\/wp-json\/wp\/v2\/tags?post=3510"},{"taxonomy":"contributors-categories","embeddable":true,"href":"https:\/\/ibkrcampus.com\/campus\/wp-json\/wp\/v2\/contributors-categories?post=3510"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}