#' Simulate a sample path of an geometric Brownian motion starting from a given point
#'
#' @param t length of time to simulate over
#' @param IC the initial values of the process
#' @param parameters a named list containing constants \code{mu} and \code{volat} describing the drift and volatility coefficients
#' @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 geometric Brownian motion 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{"gbm"}.}
#' @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_gbm <- function(t, IC, parameters, jumps = NULL, n = 10000)
{
if(is.null(IC))
{
stop("Need to pass list 'IC' containing initial values 'spot' for 'gbm'")
} else{
if(is.null(IC$spot))
{
stop("Need to pass initial value 'spot' in 'IC' list for 'gbm'")
}
IC$x0 <- 0
}
mu <- parameters$mu
volat <- parameters$volat
if(is.null(mu))
{
stop("'mu' must be passed in the 'parameters' list")
}
if(is.null(volat))
{
stop("'volat' must be passed in the 'parameters' list")
}
if(volat <= 0)
{
stop("'volat' must be positive")
}
if(is.null(parameters$lambda))
{
lambda <- function(x, t) 0
} else
{
lambda <- parameters$lambda
}
coeff <- list(f.mu = function(X, t) mu-0.5*volat^2,
f.vo = function(x, t) volat,
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)
}
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.