Skip to content

Commit

Permalink
interpolate() should use maturity
Browse files Browse the repository at this point in the history
  • Loading branch information
imanuelcostigan committed Sep 7, 2019
1 parent ab55794 commit 2d92077
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 7 deletions.
10 changes: 5 additions & 5 deletions R/vol-surface-class.R
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down Expand Up @@ -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)
Expand All @@ -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)
Expand Down
4 changes: 2 additions & 2 deletions tests/testthat/test-volsurface.R
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 2d92077

Please sign in to comment.