R/fDR.R

Defines functions fDR

fDR <- function(w, M2) {

  ### input
  # w         : weight vector
  # M2        : covariance matrix
  #
  ### output
  # objective : minus the diversification ratio
  # gradient  : the gradient of the objective with respect to w

  # objective value
  s <- sqrt(diag(M2))
  wSigw <- sum(w * M2 %*% w)
  divratio <- sum(w * s) / sqrt(wSigw)
  obj <- -divratio

  # gradient
  gr <- -(s / sqrt(wSigw) - sum(w * s) / (wSigw)^1.5 * M2 %*% w)

  list(objective = obj, gradient = gr)
}
cdries/mvskPortfolios documentation built on Feb. 10, 2021, 7:31 p.m.