# [R-SIG-Finance] Failure of solve.QP in portfolio modeling

Patrick Burns patrick at burns-stat.com
Tue Sep 22 22:03:14 CEST 2015

```One correction and another comment.

I should have said that a trade optimizer
not caring about positive definiteness is
usually a bad thing -- it has its uses
but giving the optimizer a shot at a
portfolio with negative variance is asking
for trouble (because it will do its best
to get there).

The estimates of the variance with only a
few observations are going to be extremely
noisy.  I think the length of history to
be used to estimate the variance should
depend on what length gives the best variance
estimate and should be independent of the
rebalancing schedule.  (Though perhaps I
have misinterpreted the original post.)

Pat

On 22/09/2015 19:59, Patrick Burns wrote:
> You can use a factor model or shrinkage
> to get a positive definite variance matrix.
> There is a function for each in the
> BurStFin package on CRAN.
>
> The optimizer in Portfolio Probe doesn't
> care about positive definiteness (though
> that is not always a good thing).  It is
>
> Pat
>
> On 22/09/2015 14:37, aschmid1 wrote:
>> Hi everyone,
>> I'm trying to estimate optimal Markowitz portfolio weights for a list of
>> stocks chosen upon some criterion using solve.QP from quadprog library.
>> When the number of stocks N reaches some limit, I get a message "matrix
>> D in quadratic function is not positive definite." For example, if I
>> rebalance every 6 weeks (which implies that variance is calculated for
>> 6-week interval prior to the period for which I calculate portfolio
>> weights), I can get solution for 25>=N<50. For 12-week interval,
>> solution exists for 50>=N<100, and for 24-week interval, I can get
>> solution for N=100. My attempt to remedy this problem with Higham's
>> method doesn't help. I'll greatly appreciate you input: first, why this
>> may happen (can there be lack of local minimum?), and second, whether
>> there are R solvers that may need only semi positive definite matrix.
>>
>> Thanks! Alec
>>
>> _______________________________________________
>> R-SIG-Finance at r-project.org mailing list
>> https://stat.ethz.ch/mailman/listinfo/r-sig-finance
>> -- Subscriber-posting only. If you want to post, subscribe first.
>> -- Also note that this is not the r-help list where general R questions
>> should go.
>

--
Patrick Burns
patrick at burns-stat.com
http://www.burns-stat.com
http://www.portfolioprobe.com/blog