0
votes

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.

1
I'm not familiar with this package, so this is tentative, but: I think you need to multiply matrix(1,nrow=n) by max.allocation and prepend a column of [1,rep(-1,n)] in Amat. And if you want to minimize for a portfolio return, I think you need to use the mean returns to express the portfolio return in terms of allocation, and then include that as a constraint. Also, since you're using linear equations, you'll probably have to minimize variance rather than std (which is equivalent, but the set-up will be slightly different). A link to the economistatlarge post might help.Acccumulation

1 Answers

1
votes

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.