R/mixture_diffusion.R

Defines functions entropy_mixdiff kelly_mixdiff

Documented in entropy_mixdiff kelly_mixdiff

#' Kelly-criterion for mixture diffusions
#'
#' @param t current time
#' @param s current price
#' @param rate the discounting rate/money-market account return
#' @param parameters matrix with rows probs, mus, sigmas for the components
#' @param spot initial price
#'
#' @description {Straightforward generalization of the classic Kelly-fraction for
#' functions of time and space.}
#' @return numeric
#' @export kelly_mixdiff
kelly_mixdiff <- function(t, s, rate, parameters, spot)
{
  probs <- parameters[1, ]
  mus <- parameters[2, ]
  sigmas <- parameters[3, ]

  # Drift and volatility coefficients for mixture diffusion
  mu <- function(t, s) sde::drift_lvm(s, t, probs, mus, sigmas, spot)
  v <- function(t, s) sde::volat_lvm(s, t, probs, mus, sigmas, spot)
  z <- (mu(t, s)-rate)/(v(t, s)^2)
  return(z)
}

#' Compute the log-growth rate under optimally controlled mixture diffusions
#'
#' @param t time horizon
#' @param s current price
#' @param spot initial price
#' @param rate risk-free rate
#' @param parameters parameters of mixture
#'
#' @description {Compute the entropy rate as a function of the fraction. This
#' involves solving a Feynman-Kac PDE with running cost the sum of the risk-free rate
#' and half the square of the market price of risk.}
#' @return numeric
#' @export entropy_mixdiff
entropy_mixdiff <- function(t, s, spot, rate, parameters)
{
  probs <- parameters[1, ]
  mus <- parameters[2, ]
  sigmas <- parameters[3, ]
  mu <- function(t, x) sde::drift_lvm(x, t, probs, mus, sigmas, spot)
  volat <- function(t, x) sde::volat_lvm(x, t, probs, mus, sigmas, spot)
  sharpe <- function(t, x) (mu(t, x)- rate)/volat(t, x)

  dynamics <- list(function(t, x) mu(t, x)*x,
                   function(t, x) volat(t, x)*x
  )
  problem <- list(function(t, x) 0,
                  function(t, x) rate+0.5*sharpe(t, x)^2,
                  function(x) 0
  )
  region <- c(t, 0, 2*spot, 200, 200)
  v <- sde::fk_solver("price", FALSE, dynamics, problem, region)
  return(v)
}
shill1729/KellyCriterion documentation built on Oct. 12, 2020, 4:21 a.m.