I have my input parameters mu (mean vector μ), Q (covariance matrix Q), and tau (risk tolerance τ) and I need to return the vector h (asset weights) that maximizes the following utility function U defined by:
U(h)= −1/2h^T*Q*h + τ*h^T*μ subject to constraints:
0 ≤ h ≤ 0.1 for all h and sum of all h is equal to 1: h^T*e = 1 TAU contains numbers from zero to 0.5 in steps of 0.001. How do I define the parameters: Dmat, dvec, Amat and bvec for this problem? I know the finance concepts but not how to program it correctly.
Thank you
This doesn't work as I still have negative weights indicative of short selling :(
frontieropti <- c(NULL) i <- 1 for (i in 1:nrow(TAU)){ solQP <- solve.QP(Dmat,TAU[i]*mu, Amat, bvec, meq = 1, factorized = F) sol <- c(i,solQP$value) frontieropti <- rbind(frontieropti,sol) i <- i +1 } solQP <- solve.QP(Dmat, TAU[1]*mu, Amat, bvec, meq = 1, factorized = F) solQP
quadprogfor mean-variance optimisation. The referenced code is at enricoschumann.net/files/mv.Ri?iis looking atTAUwhich is either an array of numbers from zero to 0.5 in increments of 0.001 or, as I have it written, different rows of a matrix with the same numbers. I am merely going row to row within theTAUmatrix but am I inadvertently skipping all the evens???forloop takes care of the increment itself. The statementi <- i+1is extra and not needed. However, I just tried it out and R completely ignores the extrai+1statement. So, it doesn' t do any harm and my suspicion was wrong. So, you are right that it works.