short-sale constraint with nonpositive-definite matrix in portfolio optimization

301 Views Asked by At

This question is about portfolio optimization in R. I have a nonpositive-definite matrix. I have handled with the singularity.

Unfortunately, quadprog etc. optimization packages fail to solve the optimization problem under the constraints because these packages take the covariance matrix as an input.

But I have inverted matrix and I want to use it as an input under the non-negativity constraint (short sale prohibited). It is hard to solve with lagrange because of non-negativity constraint. Which method should I use?

Thank you.

I am trying to construct a portfolio weight vector to minimize the variance of the returns.

w ̂=argmin w'Σ w 

    s. t.  w'I = 1           #weights sum up to 1                                                 
           w'μ=ρ             #target expected return
           w≥0               #non-negativity(short-sale) constraint

where w is the vector of weights, Σ covariance matrix.

 optimization<-function(returns) {
  p <- ncol(x)                    #number of assets
  n <- nrow(x)                    #number of observations
  x <- matrix(data$return,n,assets)
  mean <- colMeans(na.rm=FALSE,x)
  M <- as.integer(10)             #nuber of ports on the eff.front.
  S <- cov(x)                     #covariance matrix
  Rmax<- 0.01                     #max monthly return value
  Dmat   <- solve(S)              #inverse of covariance matrix
  u <- rep(1,p)                   #vector of ones

  These codes are for the Lagrange solutions

  a<- matrix(rep(0,4), nrow=2)    
  a[1,1] <- t(u)%*% Dmat %*%u 
  a[1,2] <- t(mean)%*%Dmat%*%u
  a[2,1] <- a[1,2] 
  a[2,2] <- t(mean)%*%Dmat%*%mean 
  d <- a[1,1]*a[2,2]-a[1,2]*a[1,2] 
  f <- (Dmat%*%(a[2,2]*u-a[1,2]*mean))/d 
  g <- (Dmat%*%(-a[1,2]*u+a[1,1]*mean))/d
  r <- seq(0, Rmax, length=M)
  w <- matrix((rep(0, p*M)), nrow=p)

I tried to find non-negative weights using the codes below:

for(i in 1:M) { w[,i] = f+r[i]*g                    #portfolio weights 
      if (w[,i] <0) {w[,i]=0} else {w[,i]=w[,i]}
    } 
Also, I tried to make a loop using 'while' function in R.

 while (w> 0) 
  { for(i in 1:M) { w[,i] = f+r[i]*g }
  print(w)                     
  } 

Unfortunately, I could not get the positive weights. Is there another solution to get positive weights?

Thank you