R/volatility_coefficients.R

Defines functions volat_lvm volat_cir volat_kelly volat_gbm volat_constant

Documented in volat_cir volat_constant volat_gbm volat_kelly volat_lvm

#' Constant volatility coefficient function for Brownian motion with drift
#'
#' @param x spatial input
#' @param t temporal input
#' @param vcf constant volatility
#'
#' @description {The constant volatility for generic Brownian motion with drift and volatility.}
#' @return numeric
#' @export volat_constant
volat_constant <- function(x, t, vcf)
{
  vcf
}

#' GBM volatility coefficient function
#'
#' @param x spatial input
#' @param t temporal input
#' @param vcf constant volatility
#'
#' @description {The volatility for geometric Brownian motion with drift and volatility.}
#' @return numeric
#' @export volat_gbm
volat_gbm <- function(x, t, vcf)
{
  vcf*x
}

#' Kelly-GBM volatility function
#'
#' @param x spatial log-input
#' @param t temporal input
#' @param mu constant mean drift rate
#' @param rate the money-market account interest rate
#' @param volat the annualized volatility
#'
#' @description {The volatility coefficient function for geometric Brownian motion under the Kelly strategy.}
#' @details {See .pdf on github for details of the mathematics.}
#' @return numeric
#' @export volat_kelly
volat_kelly <- function(x, t, mu, rate, volat)
{
  kelly <- KellyCriterion::kelly.gbm(drift = mu, rate = rate, volat = volat)
  return(volat*kelly)
}


#' CIR volatility coefficient function
#'
#' @param x spatial input
#' @param t temporal input
#' @param vcf constant volatility
#'
#' @description {The volatility for CIR process. It is the square root of the process itself multiplied by the volatility constant.}
#' @return numeric
#' @export volat_cir
volat_cir <- function(x, t, vcf)
{
  if(x <0)
  {
    stop("Square root not defined on negatives")
  }
  vcf*sqrt(x)
}


#' local volatility mixture coefficient function
#'
#' @param x the price
#' @param t the time, in trading years
#' @param probs the probability of each mixing component
#' @param sigmas the volatility of each mixing component
#' @param rate the drift or risk-free rate (depending on measure) can also be a mixture
#' @param spot the spot value
#' @description {A local volatility mixture of constant volatilities, with linear behavior near time zero.}
#' @details {See .pdf for derivation}
#' @return numeric
#' @export volat_lvm
volat_lvm <- function(x, t, probs, sigmas, rate, spot)
{
  maxState <- which.max(probs)
  meanVol <- sqrt(sum(probs*sigmas^2)+sum(probs*rate^2)-(sum(probs*rate))^2)

  if(t >= 0 && t < 0.5/252)
  {
    return(meanVol)
  }

  ps <- stats::dnorm((log(x/spot)-(rate-0.5*sigmas^2)*t)/(sigmas*sqrt(t)))/(x*sigmas*sqrt(t))
  p <- sum(probs*ps)
  lambda <- (probs*ps)/p
  v <- sqrt(sum(lambda*sigmas^2))
  v <- ifelse(is.nan(v), meanVol, v)
  return(v)
}
shill1729/FeynmanKacSolver documentation built on May 19, 2020, 8:23 p.m.