I am unfamiliar to portfolio optimization. For a given portfolio weight w, expected return and variance are respectively, w'μ=q and w' Σ w. We define the portfolio selection problem as: to minimize the variance w' Σ w subject to w' e=1 and w' μ=q, q is the expected rate of return. And short selling is prohibited. I want equally weighted portfolio. How can I do it? This code is correct for it? The other problem, e is the vector of ones do I have to write it or does quadprog already have it? Could you help me?
Dmat <- cov(x) #covariance matrix
dvec <- colMeans(x)
if(short=="no"){
Amat <- cbind(rep(1,20), diag(20)) # the weights sum up to 1
bvec <- c(1, rep(0, 20)) # No short-selling
}
portfolio.out <-solve.QP(Dmat, dvec, Amat, bvec, meq=1, factorized=FALSE)
portfolio.out$solution #portfolio weights
sum(portfolio.out$solution) #check whether sum up to 1
portfolio.out$value #portfolio variance
eff.frontier <- function (dvec, Dmat, alpha.min=0, alpha.max=1, nport=10, shorts=FALSE)
eff.frontier$weights
Well just to register: