R Programming: Package DEoptim Returning Inconsistent Results

44 Views Asked by At

I am running a portfolio optimization using the DEoptim to minimize the inverse of the Sharpe ratio, which is the same as maximizing the Sharpe ratio. However, I am receiving inconsistent results as to what is the vector of the weights that can be used to maximize my Sharpe.

  # Computing the covariance matrix and returns to be used in the optimization
  covMat <- cov(dft[idx_window_begin:idx_window_end,returns])
  Returns <- colMeans(dft[idx_window_begin:idx_window_end,returns])
  
  # Sharpe ratio function to be used in the DEoptim function
  port_sharpe <- function(W) {
    W <- W/sum(W)
    return(as.numeric((W%*%covMat%*%W)^0.5/(W%*%Returns)))
  }
  
  # Calling DEoptim
  sol <- DEoptim(port_sharpe, lower=rep(-100,nrow(covMat)), upper=rep(100,nrow(covMat)))

I was expecting the same vector of weights to be returned each time i.e. sol$optim$bestmem should return the same vector of weights for all runs.

0

There are 0 best solutions below