J.Smith
J.Smith

Reputation: 11

Constrained portfolio optimisation with quadratic solving

I'm trying to grapple with portfolio optimisation in R and I'm struggling to find consensus about how to code constraints etc using solve.QP.

Essentially I have already calculated the covariance matrix of returns of n assets, which I understand to be Dmat, however, I'm unsure on the rest. I would like my constraints to purely be that all weights sum to 1 and they must all be below a certain size (max.allocation) in absolute value, i.e.

|x_i|<max.allocation<=1. 

Am I right in thinking, therefore, that my Amat should be:

Amat <- matrix(1,nrow=n)
Amat <- cbind(Amat, -diag(n))

Also, should my bvec be:

bvec <- 1
bvec <- c(bvec, rep(-max.allocation,n))

Am I right to believe that since only one constraint is an equality that meq=1? And finally, my research seems to point to:

dvec <- rep(0,n)

But if this is the case, where do the mean returns of the assets come into the problem?

All I am trying to do is solve for portfolio weights and minimise portfolio standard deviation for a given portfolio return, not plot the efficient frontier.

I've already seen the economistatlarge post and its got me to where I currently am. Apologies as I am new to this solving technique, but any help to simplify and clear up what my parameters need to be would be of great help.

Thanks.

Upvotes: 0

Views: 199

Answers (1)

Erwin Kalvelagen
Erwin Kalvelagen

Reputation: 16724

If you want to add

|x(i)| <= U

then in quadprog you need to split this into:

-x(i) >= -U
 x(i) >= -U

so you end up with 2 additional diagonal structures in Amat.

Upvotes: 1

Related Questions