From 2d92077e609023c212e4910a6099089c74532843 Mon Sep 17 00:00:00 2001 From: Imanuel Costigan Date: Sat, 7 Sep 2019 13:20:36 +1000 Subject: [PATCH] interpolate() should use maturity --- R/vol-surface-class.R | 10 +++++----- tests/testthat/test-volsurface.R | 4 ++-- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/R/vol-surface-class.R b/R/vol-surface-class.R index 01a96fb..4a4a63e 100644 --- a/R/vol-surface-class.R +++ b/R/vol-surface-class.R @@ -30,7 +30,7 @@ new_VolSurface <- function(vol_quotes, interpolation) { f <- function(at) { if (is.LinearCubicTimeVarInterpolation(interpolation)) { - x0 <- fmdates::year_frac(rd, at$term, db) + x0 <- fmdates::year_frac(rd, at$maturity, db) y0 <- at$smile tt <- fmdates::year_frac(rd, vol_quotes$maturity, db) tbl <- tibble::tibble( @@ -197,13 +197,13 @@ is.VolQuotes <- function(x) { #' @param x object of class `VolSurface` to be interpolated. #' @param at indicates the coordinates at which the interpolation is performed. #' `at` should be given as a [tibble::tibble()] with two column names named -#' `term` and `smile`. e.g. list(term = c(1, 2), smile = c(72, 92)). +#' `maturity` and `smile`. e.g. list(maturity = c(1, 2), smile = c(72, 92)). #' @param ... unused in this model. #' @return `numeric` vector with length equal to the number of rows of `at`. #' @examples #' x <- build_vol_surface() #' at <- tibble::tibble( -#' term = c(as.Date("2020-03-31"), as.Date("2021-03-31")), +#' maturity = c(as.Date("2020-03-31"), as.Date("2021-03-31")), #' smile = c(40, 80) #' ) #' interpolate(x, at) @@ -213,8 +213,8 @@ is.VolQuotes <- function(x) { interpolate.VolSurface <- function(x, at, ...) { assertthat::assert_that( tibble::is_tibble(at), - setequal(names(at), c("term", "smile")), - assertthat::is.date(at$term), + setequal(names(at), c("maturity", "smile")), + assertthat::is.date(at$maturity), is.numeric(at$smile) ) x$interpolator(at) diff --git a/tests/testthat/test-volsurface.R b/tests/testthat/test-volsurface.R index c247c8e..064d3b0 100644 --- a/tests/testthat/test-volsurface.R +++ b/tests/testthat/test-volsurface.R @@ -11,13 +11,13 @@ testthat::test_that("Time variance interpolation creation works", { }) testthat::test_that("Time variance interpolation works", { - term <- c( + maturity <- c( as.Date("2023-08-15"), as.Date("2023-10-10"), as.Date("2020-02-29"), as.Date("2021-04-15"), as.Date("2022-06-10"), as.Date("2025-06-10") ) smile <- c(3, 96, 150, 80, 90, 300) vs <- build_vol_surface() - res <- interpolate(vs, tibble::tibble(term = term, smile = smile)) + res <- interpolate(vs, tibble::tibble(maturity = maturity, smile = smile)) exp <- c( 0.6076543447950257, 0.26853916752886564, 0.19909034016558932, 0.25769535624031686, 0.25855784359768552, 0.26647898600000003