R/sample_path_bm.R

Defines functions sample_path_bm

Documented in sample_path_bm

#' Simulate a sample path of Brownian motion starting from a given point
#'
#' @param t length of time to simulate over
#' @param IC list of initial conditions
#' @param parameters list of parameters, in this case for the jump-dynamics
#' @param jumps a list of objects defining the jump-size distribution, can be NULL for purely continuous models
#' @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 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{"bm"}.}
#' @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 \code{X} (state).
sample_path_bm <- function(t, IC = NULL, parameters = NULL, jumps = NULL, n = 10000)
{
  if(is.null(IC))
  {
    IC <- list(x0 = 0)
  } else{
    if(is.null(IC$x0))
    {
      stop("Need to pass initial value 'x0' in 'IC' list for 'bm'")
    }
  }
  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))
  B <- euler_maruyama(t = t, coeff = coeff, IC = IC, jumps = jumps, exponential = FALSE, n = n)
  return(B)
}
shill1729/FeynmanKacSolver documentation built on May 19, 2020, 8:23 p.m.