-1

I have a question about this algorithm that I need answered, as I'm auditing my model and this inconsistency is concerning.

I am doing mean-variance optimization with constraints they must sum to 1, and the weights must be within my specified ranges. My inputs are as follows:

Dmat = Sigma
dvec = rep(0, ncol(Sigma))
Amat = rbind(rep(1, ncol(Sigma)), diag(ncol(Sigma)), -diag(ncol(Sigma)),    
    ncol=ncol(Sigma))
bvec = c(1, MinWeights, -MaxWeights) 

Then I run:

Out = solve.QP(Dmat, dvec, t(Amat), bvec, meq=1)
Weights = Out$solution
Var = t(Weights) %*% Sigma %*% Weights
Var == Out$value

The problem is I get FALSE for that last command. It's not a rounding issue, they are off by a magnitude of almost 20%.

Anyone know what the problem is?

milkmotel
  • 402
  • 4
  • 13
  • 1) solve.QP 2) I will edit in the matrices when I get home – milkmotel Oct 01 '16 at 00:47
  • Please consider turning your question into a [Minimal, Reproducible Example](https://stackoverflow.com/help/minimal-reproducible-example). The code you posted doesn't provide definitions for variables `Sigma`, `MinWeights`, and `-MaxWeights`. Also, assuming that `MinWeights` and `MaxWeights` are of length `ncol(Sigma)`, the `Amac` and `bvec` are of incompatible dimensions. What's the role of `ncol=ncol(Sigma)`? – Mihai Apr 28 '21 at 07:34

1 Answers1

1

I figured out the issue.

Sigma should be 2*Sigma, which is the value in the Lagrangian for portfolio optimization using matrix algebra.

milkmotel
  • 402
  • 4
  • 13
  • It could help improve the clarity of your answer by indicating that `Dmat` should be defined as `2 * Sigma`, i.e., `Dmat = 2 * Sigma`. Then, the equality `Var == Out$value` holds. – Mihai Apr 28 '21 at 07:38