Reputation: 1
I am trying to do the test of Ehling and Ramos (2006), paper is here. Simply, the paper compares diversification benefit between a portfolio of companies and a benchmark. I am considering my benchmark to be an index of 500 Equally Weighted (EW) companies, and my portfolio of companies includes 35 companies.
The optimisation works as follows:
min w'Σw - v s.t w'1 = 1 w'μ = β
where w is the vector of portfolio weights in the primitive assets and 1 is a vector of ones. The benchmark has a return of r and E(r_t) = β, Var(r_t) = v. The matrix R includes the returns of the assets I have, they have return of E(R_t) = μ, and Cov(R_t) = Σ and Cov(R_t,r_t) = γ.
The measure of efficiency for the assets in respect to the benchmark is given by λ = Var(r^β_t - v). As short selling is not allowed, the w_i ≥ 0.
The measure of efficiency for both problems is the value of the Lagrangian:
λ = L = w'Σw - v + δ1 (w'1 -1) + δ2 (w'μ - β) + δ3 w
I wrote the following code on R:
Sigma <- matrix(cov(returns), ncol = ncol(returns))
mu <- colMeans(returns)
v <- var(monthly_index$Return)
beta <- mean(monthly_index$Return)
gamma <- cov(returns, monthly_index$Return)
Dmat <- 2 * Sigma
dvec <- rep(0, length(mu))
Amat <- rbind(t(mu), rep(1, length(mu)))
bvec <- c(beta, 1)
meq <- 2 # The first 2 constraints are equality constraints
solution <- solve.QP(Dmat, dvec, Amat, bvec, meq)
weights <- solution$solution
However, when I run the solve.QP function, I encounter the following error:
Error in solve.QP(Dmat, dvec, Amat, bvec, meq) :
Amat and dvec are incompatible!
> length(Amat)
[1] 70
> length(Amat)
[1] 70
> length(dvec)
[1] 35
> dim(Amat)
[1] 2 35
As a first step, I need to obtain the w to be able to calculate λ. How can I resolve this issue?
Upvotes: 0
Views: 73