[R-SIG-Finance] portfolio.optim and error in solve.QP: matrix D not positive definite

Lui ## lui.r.project at googlemail.com
Thu Jan 27 04:51:12 CET 2011


Dear Group,

I have  a large set of stocks and want to determine the efficient
frontier. The data set covers approx. 1.5 years and S&P 500 companies
(nothing weird). portfolio.optim from the PerformanceAnalytics package
works very well and fast. However, whenever I decrease the number of
stocks in the portfolio (to 10 or 400), I receive an error message:

"solve.QP(Dmat, dvec, Amat, bvec = b0, meq = 2) :
  matrix D in quadratic function is not positive definite!"

My command settings for portfolio.optim were:

seed <- portfolio.optim(t(x), pm = current_er, riskless = FALSE,
shorts = FALSE, rf = 0.0)

Even when I tried it with shorts = TRUE the error would still remain.
x is the set of stocks (stocks in columns, time in rows), current_er
is the target return (lies between the minimal mean and the maximum
mean of a long only portfolio).
I can not post the stock data here - so maybe you have some general
suggestions for me of what could have gone wrong... The covariance
matrix is positive definite. What could cause the problem? It works
fine with the large data set but does not work at all with the small
one...
Thanks a lot for your suggestions!

Lui



More information about the R-SIG-Finance mailing list