how come I got negative weights despite the no-short sales constraint in the portfolio optimization problem?

75 Views Asked by At

I used the CVXR library to find the weights of a minimum variance portfolio consisting of 183 assets.

(1) min(w) (1/2)*((w)^T)*sigma*(w)

(2) s.t. sum(w) ==1

(3) w >= 0

  • “Sigma” is the matrix of variances and covariances and has dimension 183*183. The matrix of variances and covariances is semidefinite positive and was estimated one using historical data of security returns (313 return per security).

  • “w” are the weights of the assets in the minimum variance portfolio.

I tried to fix this in code below, but nothing was useful.

library(readxl)
library(matrixcalc)
Library(CVXR)

Return <- read_excel ("datasets.xlsx")
Return <- as.data.frame(Return)

sigma <- cov(Return)
is.positive.definite(sigma)
[1] TRUE


#quadratic programming

w <- Variable(183)

objective <- Minimize((1/2) %*% (quad_form(w, sigma)))

constraints <- list( w >= 0,   sum(w) == 1 )

problem <- Problem(objective, constraints)

soln <- solve(problem)

b <- soln$getValue(w)


#verify

sum(b)
[1] 1

min(b)
[1] -5.781906e-22

Constraint (2) is verified, while constraint (3) is not verified. Despite the no-short-selling constraint (3), I obtained weights of securities with negative value. What am I doing wrong?

0

There are 0 best solutions below