I am trying to use solve.QP to solve a portfolio optimization problem (quadratic problem)
Total 3 assets
There are 4 constraints:
- sum of weights equal to 1
- portfolio expected return equals to 5.2%
- each asset weight greater than 0
- each asset weight smaller than .5
Dmat is the 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 is each asset's expected return
dvec <- matrix(c(9.33, 3.33, 9.07), nrow=3, ncol=1)
Amat is the constraint matrix
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, first and second constraints are equality
Then I run the function solve.QP
library(quadprog)
qp <- solve.QP(Dmat, dvec, Amat, bvec, meq=2)
But it gives the error
Error in solve.QP(Dmat, dvec, Amat, bvec, meq = 2) : constraints are inconsistent, no solution!
I am not sure where I did wrong.