R/sample_path_lvm.R

Defines functions sample_path_lvm

Documented in sample_path_lvm

#' Simulate a sample path of an local volatility mixture GBM starting from a given point
#'
#' @param t length of time to simulate over
#' @param IC list of initial value of the local volatility mixture GBM, no default
#' @param parameters a named list containing vectors \code{probs}, \code{mus} and \code{sigmas} describing the mixing components of the GMM.
#' @param jumps a list of objects defining the jump-size distribution, can be NULL for purely continuous models, see details.
#' @param n number of time sub-intervals in the discretization
#'
#' @description {Non-exported Wrapper to \code{sample_path_em} to directly simulate a sample path of local volatility mixture GBM without having to specify the constant
#' coefficient functions. This function should not be called directly but rather through \code{sample_path} with \code{continuous.model} set to \code{"lvm"}.}
#' @details {The drift of a GBM is in the form of \eqn{\mu-0.5\sigma^2} where \eqn{\sigma} is the volatility.
#' \itemize{
#' \item \code{distr} the name of the distribution of the jump-sizes e.g. "norm", "unif", "kou"
#' \item \code{param} named list of parameters for the distribution matching the input in \code{rdistr} for a given "distr".
#' }}
#' @return data.frame containing \code{t} (time) and \code{X} (state).
sample_path_lvm <- function(t, IC, parameters, jumps = NULL, n = 10000)
{
  if(is.null(IC))
  {
    stop("Need to pass list 'IC' containing initial values 'spot' for 'lvm'")
  } else{
    if(is.null(IC$spot))
    {
      stop("Need to pass initial value 'spot' in 'IC' list for 'lvm'")
    }
    IC$x0 <- 0
  }
  probs <- parameters$probs
  mus <- parameters$mus
  sigmas <- parameters$sigmas
  spot <- IC$spot
  if(is.null(spot))
  {
    stop("'spot' must be passed in the 'IC' list")
  }
  if(is.null(probs))
  {
    stop("'probs' must be passed in the 'parameters' list")
  }
  if(!all(probs >0) || !all(probs <= 1))
  {
    stop("'probs' entries must be in unit-interval")
  }
  if(is.null(mus))
  {
    stop("'mus' must be passed in the 'parameters' list")
  }
  if(is.null(sigmas))
  {
    stop("'sigmas' must be passed in the 'parameters' list")
  }
  if(!all(sigmas > 0))
  {
    stop("'sigmas' must be positive")
  }
  if(is.null(parameters$lambda))
  {
    lambda <- function(x, t) 0
  } else
  {
    lambda <- parameters$lambda
  }
  coeff <- list(f.mu = function(x, t) drift_lvm(spot*exp(x), t, probs, mus, sigmas, spot)-0.5*volat_lvm(spot*exp(x), t, probs, sigmas, rate = mus, spot)^2,
                f.vo = function(x, t) volat_lvm(spot*exp(x), t, probs, sigmas, rate = mus, spot),
                f.lambda = function(x, t) lambda(x, t))
  B <- euler_maruyama(t = t, coeff = coeff, IC = IC, jumps = jumps, exponential = TRUE, n = n)
  return(B)
}
shill1729/FeynmanKacSolver documentation built on May 19, 2020, 8:23 p.m.