#' Constant drift function
#'
#' @param x spatial input
#' @param t temporal input
#' @param mu constant mean drift rate
#'
#' @description {Consant mean drift rate function for coefficient of Ito diffusion}
#' @return numeric
#' @export drift_constant
drift_constant <- function(x, t, mu)
{
mu
}
#' GBM drift function
#'
#' @param x spatial-price input
#' @param t temporal input
#' @param mu constant mean drift rate
#'
#' @description {The drift coefficient function for geometric Brownian motion. It is equal to \eqn{mu(t, X_t)=mu X_t}}
#' @return numeric
#' @export drift_gbm
drift_gbm <- function(x, t, mu)
{
mu*x
}
#' Kelly-GBM drift 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 drift coefficient function for geometric Brownian motion under the Kelly strategy.}
#' @details {See .pdf on github for details of the mathematics.}
#' @return numeric
#' @export drift_kelly
drift_kelly <- function(x, t, mu, rate, volat)
{
kelly <- KellyCriterion::kelly.gbm(drift = mu, rate = rate, volat = volat)
return((mu-rate)*kelly+rate-0.5*(volat^2)*kelly^2)
}
#' Vasicek drift function
#'
#' @param x spatial input
#' @param t temporal input
#' @param theta the speed at which the diffusion reverts to its long-term mean level
#' @param mu the long term mean level.
#'
#' @description {The drift coefficient function for Vasicek process. It is equal to \eqn{\mu(t, X_t)=\theta (\mu-X_t)}}
#' @details {The coefficient for the short-rate Vasicek model shares the same coefficient as the CIR, and Hull-White.}
#' @return numeric
#' @export drift_vasicek
drift_vasicek <- function(x, t, theta, mu)
{
if(theta < 0)
{
stop("theta reversion speed must be positive")
}
theta*(mu-x)
}
#' local drift mixture coefficient function
#'
#' @param x the price
#' @param t the time, in trading years
#' @param probs the probability of each mixing component
#' @param mus the drift of each mixing component
#' @param sigmas the volatility of each mixing component
#' @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 drift_lvm
drift_lvm <- function(x, t, probs, mus, sigmas, spot)
{
maxState <- which.max(probs)
if(t >= 0 && t < 0.5/252)
{
return(sum(probs*mus))
}
ps <- stats::dnorm((log(x/spot)-(mus-0.5*sigmas^2)*t)/(sigmas*sqrt(t)))/(x*sigmas*sqrt(t))
p <- sum(probs*ps)
lambda <- (probs*ps)/p
v <- (sum(lambda*mus))
v <- ifelse(is.nan(v), sum(probs*mus), v)
return(v)
}
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.