R/kou.R

Defines functions pkou dkou rkou

Documented in dkou pkou rkou

#' Simulate double-exponential jumps
#'
#' @param n number of variates to simulate
#' @param p mixing probability
#' @param alpha mean size of positive jumps
#' @param beta mean size of negative jumps
#'
#' @description {Simulates mixture of two exponentials one negative.}
#' @return vector
#' @export rkou
#' @references The double-exponential mixture distribution or the Kou distribution was introduced (in mathematical finance) in the paper \href{http://www.columbia.edu/~sk75/MagSci02.pdf}{http://www.columbia.edu/~sk75/MagSci02.pdf} by S.G. Kou.
rkou <- function(n, p, alpha, beta)
{
  if(p <= 0 || p > 1)
  {
    stop("argument 'p' must be in the unit-interval")
  }
  if(alpha <= 0 || beta <= 0)
  {
    stop("means must be positive")
  }

  X <- stats::rexp(n, rate = 1/alpha)
  Y <- stats::rexp(n, rate = 1/beta)
  B <- stats::rbinom(n, size = 1, prob = p)
  Z <- B*X-(1-B)*Y
  return(Z)
}

#' PDF of double-exponential jumps
#'
#' @param x real-input of the PDF
#' @param p mixing probability
#' @param alpha mean size of positive jumps
#' @param beta mean size of negative jumps
#'
#' @description {PDF of mixture of two exponentials one negative.}
#' @return vector
#' @export dkou
#' @references The double-exponential mixture distribution or the Kou distribution was introduced (in mathematical finance) in the paper \href{http://www.columbia.edu/~sk75/MagSci02.pdf}{http://www.columbia.edu/~sk75/MagSci02.pdf} by S.G. Kou.
dkou <- function(x, p, alpha, beta)
{
  if(p <= 0 || p > 1)
  {
    stop("argument 'p' must be in the unit-interval")
  }
  if(alpha <= 0 || beta <= 0)
  {
    stop("means must be positive")
  }
  p*stats::dexp(x, rate = 1/alpha)*ifelse(x >= 0, 1, 0)+(1-p)*stats::dexp(-x, rate = 1/beta)*ifelse(x < 0, 1, 0)
}

#' CDF of double-exponential jumps
#'
#' @param x real-input of the PDF
#' @param p mixing probability
#' @param alpha mean size of positive jumps
#' @param beta mean size of negative jumps
#'
#' @description {CDF of mixture of two exponentials one negative.}
#' @return vector
#' @export pkou
#' @references The double-exponential mixture distribution or the Kou distribution was introduced (in mathematical finance) in the paper \href{http://www.columbia.edu/~sk75/MagSci02.pdf}{http://www.columbia.edu/~sk75/MagSci02.pdf} by S.G. Kou.
pkou <- function(x, p, alpha, beta)
{
  if(p <= 0 || p > 1)
  {
    stop("argument 'p' must be in the unit-interval")
  }
  if(alpha <= 0 || beta <= 0)
  {
    stop("means must be positive")
  }
  p*stats::pexp(x, rate = 1/alpha)*ifelse(x >= 0, 1, 0)+(1-p)*stats::pexp(-x, rate = 1/beta)*ifelse(x < 0, 1, 0)
}
shill1729/FeynmanKacSolver documentation built on May 19, 2020, 8:23 p.m.