I am trying to use solve.QP to solve portfolio optimization problem (quadratic problem)
Only 3 assets
There are 4 limitations:
- sum of weights equal to 1
- expected portfolio return is 5.2%
- the weight of each asset is greater than 0
- each asset weight is less than .5
Dmat - covariance matrix
Dmat <- matrix(c(356.25808, 12.31581, 261.8830, 212.31581, 27.24840, 18.50515, 261.88302, 18.50515,535.45960), nrow=3, ncol=3)
dvec - each asset, expected return
dvec <- matrix(c(9.33, 3.33, 9.07), nrow=3, ncol=1)
Amat - matrix of restrictions
A.Equality <- matrix(c(1,1,1), ncol=1) Amat <- cbind(A.Equality, dvec, diag(3), -diag(3))
constraint A ^ T b> = b_0, b vector
bvec <- c(1, 5.2, rep(0, 3), rep(-0.5, 3))
meq = 2, since there are two equality constraints, the first and second constraints are equality
Then I ran the solve.QP function
library(quadprog) qp <- solve.QP(Dmat, dvec, Amat, bvec, meq=2)
But he gives an error
Error in solve.QP(Dmat, dvec, Amat, bvec, meq = 2) : constraints are inconsistent, no solution!
I'm not sure where I made a mistake.