Skip to content

Commit

Permalink
Move code
Browse files Browse the repository at this point in the history
  • Loading branch information
imanuelcostigan committed Sep 7, 2019
1 parent b51b23a commit 2bd66f7
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 36 deletions.
37 changes: 37 additions & 0 deletions R/interpolation-class.R
Original file line number Diff line number Diff line change
Expand Up @@ -207,3 +207,40 @@ linear_cubic_interp <- function(interp_data, x0, y0) {
}
res
}



# VolSurface methods --------------------------------


#' Interpolate a `VolSurface` object.
#'
#' This method is used to interpolate a `VolSurface` object at multiple points of
#' the plane. The interpolation depends on the type of the surface, if the vols are
#' given by strikes, delta, moneyness.
#'
#' @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
#' `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(
#' maturity = c(as.Date("2020-03-31"), as.Date("2021-03-31")),
#' smile = c(40, 80)
#' )
#' interpolate(x, at)
#' @family interpolate functions
#' @export

interpolate.VolSurface <- function(x, at, ...) {
assertthat::assert_that(
tibble::is_tibble(at),
setequal(names(at), c("maturity", "smile")),
assertthat::is.date(at$maturity),
is.numeric(at$smile)
)
x$interpolator(at)
}
36 changes: 0 additions & 36 deletions R/vol-surface-class.R
Original file line number Diff line number Diff line change
Expand Up @@ -186,39 +186,3 @@ validate_VolQuotes <- function(x) {
is.VolQuotes <- function(x) {
inherits(x, "VolQuotes")
}


# VolSurface methods --------------------------------


#' Interpolate a `VolSurface` object.
#'
#' This method is used to interpolate a `VolSurface` object at multiple points of
#' the plane. The interpolation depends on the type of the surface, if the vols are
#' given by strikes, delta, moneyness.
#'
#' @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
#' `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(
#' maturity = c(as.Date("2020-03-31"), as.Date("2021-03-31")),
#' smile = c(40, 80)
#' )
#' interpolate(x, at)
#' @family interpolate functions
#' @export

interpolate.VolSurface <- function(x, at, ...) {
assertthat::assert_that(
tibble::is_tibble(at),
setequal(names(at), c("maturity", "smile")),
assertthat::is.date(at$maturity),
is.numeric(at$smile)
)
x$interpolator(at)
}

0 comments on commit 2bd66f7

Please sign in to comment.