R/sample_path_pbm.R

Defines functions sample_path_pbm

Documented in sample_path_pbm

#' Simulate a sample path of planar Brownian motion starting from a given point
#'
#' @param t length of time to simulate over
#' @param IC list of initial values
#' @param parameters list of parameters for jump-dynamics
#' @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 planar Brownian motion without having to specify the trivial
#' coefficient functions. This function should not be called directly but rather through \code{sample_path} with \code{continuous.model} set to \code{"pbm"}.}
#' @details { The list \code{jumps} should contain
#' \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 the two planar coordinates \code{x} and \code{y}.
sample_path_pbm <- function(t, IC = NULL, parameters = NULL, jumps = NULL, n = 10000)
{
  if(is.null(IC))
  {
    IC <- list(x0 = 0, y0 = 0)
  } else{
    if(is.null(IC$x0))
    {
      stop("Need to pass initial value 'x0' in 'IC' list for 'pbm'")
    } else if(is.null(IC$y0))
    {
      stop("Need to pass initial value 'y0' in 'IC' list for 'pbm'")
    }
  }
  if(is.null(parameters) || is.null(parameters$lambda))
  {
    lambda <- function(x, t) 0
  } else
  {
    lambda <- parameters$lambda
  }


  coeff <- list(f.mu = function(X, t) 0,
                f.vo = function(x, t) 1,
                f.lambda = function(x, t) lambda(x, t))
  # Simulate two independent BMs
  X <- euler_maruyama(t = t, coeff = coeff, IC = list(x0 = IC$x0), jumps = jumps, exponential = FALSE, n = n)
  Y <- euler_maruyama(t = t, coeff = coeff, IC = list(x0 = IC$y0), jumps = jumps, exponential = FALSE, n = n)
  B <- data.frame(t = X$t, x = X$X, y = Y$X)
  return(B)
}
shill1729/FeynmanKacSolver documentation built on May 19, 2020, 8:23 p.m.