

I must admit to being flummoxed here, mainly because my linear algebra was 25 years ago and I can't remember what a Hessian is.
I have a matrix of 60 securities' weekly returns, along with 60 projected returns. The returns are in a vector called Ret.vect and the covariance matrix of weekly returns in cov.mat . I have the minConstraints and maxConstraints that the parameters are permitted to take. I cycle through targeted risks and get the same error for each risk targeted...below I have removed the loop to focus on the risk=0.002.
wgt.vect=c(rep(1/60, 60))
constr.fun < function(wgt.vect) {;
c1 = sqrt(crossprod(t(wgt.vect %*% cov.mat),wgt.vect));
c2 = sum(wgt.vect);
return(c(c1,c2));
}
ineqconstr.fun < function(wgt.vect) {
wgt.vect[1:60];
}
opt.fun < function(wgt.vect) {crossprod(wgt.vect,t(Ret.vect))}
OptimSolution < solnp(wgt.vect,opt.fun,constr.fun,eqB=c(0.002,1),ineqconstr.fun,ineqLB=minConstraints,ineqUB=maxConstraints)
I get the following error:
solnp> Solution not reliable....Problem Inverting Hessian.
Well, that doesn't tell me very much! The parameters (weights) that are output for each run, as I cycle through the weights, are very scrambled...lots of little allocations, rather than clumping as you would expect to happen especially at the risky and riskless ends of the spectrum.
Can anyone with more math than me give me a helping hand on the Hessian?
Thanks,
Mike
Michael Ashton, CFA
Managing Principal
Enduring Investments LLC
W: 973.457.4602
C: 551.655.8006
________________________________
This email and any attachments are confidential and inte...{{dropped:9}}
_______________________________________________
[hidden email] mailing list
https://stat.ethz.ch/mailman/listinfo/rsigfinance Subscriberposting only. If you want to post, subscribe first.
 Also note that this is not the rhelp list where general R questions should go.


The Hessian is the matrix of second derivatives
( https://en.wikipedia.org/wiki/Hessian_matrix)  in scalar terms,
you're finding a point where the second derivative is zero and then
trying to divide by the second derivative to calculate the step size.
I haven't gone through your code in any detail, but I'd start by
checking the covariance matrix since that's proportional to the
Hessian of your objective function. Is it (comfortably) nonsingular?
Since you're just solving the standard Markowitz problem, you might
try a simpler (quadratic/convex) solver instead of a general
nonlinear solver. Should behave a bit better.
Michael
On Mon, Dec 14, 2015 at 6:13 PM, Michael Ashton
< [hidden email]> wrote:
> I must admit to being flummoxed here, mainly because my linear algebra was 25 years ago and I can't remember what a Hessian is.
>
> I have a matrix of 60 securities' weekly returns, along with 60 projected returns. The returns are in a vector called Ret.vect and the covariance matrix of weekly returns in cov.mat . I have the minConstraints and maxConstraints that the parameters are permitted to take. I cycle through targeted risks and get the same error for each risk targeted...below I have removed the loop to focus on the risk=0.002.
>
> wgt.vect=c(rep(1/60, 60))
> constr.fun < function(wgt.vect) {;
> c1 = sqrt(crossprod(t(wgt.vect %*% cov.mat),wgt.vect));
> c2 = sum(wgt.vect);
> return(c(c1,c2));
> }
> ineqconstr.fun < function(wgt.vect) {
> wgt.vect[1:60];
> }
> opt.fun < function(wgt.vect) {crossprod(wgt.vect,t(Ret.vect))}
>
> OptimSolution < solnp(wgt.vect,opt.fun,constr.fun,eqB=c(0.002,1),ineqconstr.fun,ineqLB=minConstraints,ineqUB=maxConstraints)
>
> I get the following error:
> solnp> Solution not reliable....Problem Inverting Hessian.
>
> Well, that doesn't tell me very much! The parameters (weights) that are output for each run, as I cycle through the weights, are very scrambled...lots of little allocations, rather than clumping as you would expect to happen especially at the risky and riskless ends of the spectrum.
>
> Can anyone with more math than me give me a helping hand on the Hessian?
>
> Thanks,
>
>
> Mike
>
> Michael Ashton, CFA
> Managing Principal
>
> Enduring Investments LLC
> W: 973.457.4602
> C: 551.655.8006
>
>
> ________________________________
> This email and any attachments are confidential and inte...{{dropped:9}}
>
> _______________________________________________
> [hidden email] mailing list
> https://stat.ethz.ch/mailman/listinfo/rsigfinance>  Subscriberposting only. If you want to post, subscribe first.
>  Also note that this is not the rhelp list where general R questions should go.
_______________________________________________
[hidden email] mailing list
https://stat.ethz.ch/mailman/listinfo/rsigfinance Subscriberposting only. If you want to post, subscribe first.
 Also note that this is not the rhelp list where general R questions should go.


Do you have a suggestion for such? I have in the past tried fPortfolio, but it would not allow me to specify my own projected return vectors rather than the historical returns of the series (which is exactly backwards).
As for whether the matrix is comfortably nonsingular...I suppose it depends in a Clintonian way on the meaning of "comfortably," but I can create a Cholesky decomposition without it blowing up, which is usually how I can tell if I have done something stupid. Well, stupider than normal.
Original Message
From: Michael Weylandt [mailto: [hidden email]]
Sent: Monday, December 14, 2015 8:32 PM
To: Michael Ashton
Cc: [hidden email]
Subject: Re: [RSIGFinance] solnp Problem Inverting Hessian
The Hessian is the matrix of second derivatives
( https://en.wikipedia.org/wiki/Hessian_matrix)  in scalar terms, you're finding a point where the second derivative is zero and then trying to divide by the second derivative to calculate the step size.
I haven't gone through your code in any detail, but I'd start by checking the covariance matrix since that's proportional to the Hessian of your objective function. Is it (comfortably) nonsingular?
Since you're just solving the standard Markowitz problem, you might try a simpler (quadratic/convex) solver instead of a general nonlinear solver. Should behave a bit better.
Michael
On Mon, Dec 14, 2015 at 6:13 PM, Michael Ashton < [hidden email]> wrote:
> I must admit to being flummoxed here, mainly because my linear algebra was 25 years ago and I can't remember what a Hessian is.
>
> I have a matrix of 60 securities' weekly returns, along with 60 projected returns. The returns are in a vector called Ret.vect and the covariance matrix of weekly returns in cov.mat . I have the minConstraints and maxConstraints that the parameters are permitted to take. I cycle through targeted risks and get the same error for each risk targeted...below I have removed the loop to focus on the risk=0.002.
>
> wgt.vect=c(rep(1/60, 60))
> constr.fun < function(wgt.vect) {;
> c1 = sqrt(crossprod(t(wgt.vect %*% cov.mat),wgt.vect));
> c2 = sum(wgt.vect);
> return(c(c1,c2));
> }
> ineqconstr.fun < function(wgt.vect) {
> wgt.vect[1:60];
> }
> opt.fun < function(wgt.vect) {crossprod(wgt.vect,t(Ret.vect))}
>
> OptimSolution <
> solnp(wgt.vect,opt.fun,constr.fun,eqB=c(0.002,1),ineqconstr.fun,ineqLB
> =minConstraints,ineqUB=maxConstraints)
>
> I get the following error:
> solnp> Solution not reliable....Problem Inverting Hessian.
>
> Well, that doesn't tell me very much! The parameters (weights) that are output for each run, as I cycle through the weights, are very scrambled...lots of little allocations, rather than clumping as you would expect to happen especially at the risky and riskless ends of the spectrum.
>
> Can anyone with more math than me give me a helping hand on the Hessian?
>
> Thanks,
>
>
> Mike
>
> Michael Ashton, CFA
> Managing Principal
>
> Enduring Investments LLC
> W: 973.457.4602
> C: 551.655.8006
>
>
> ________________________________
> This email and any attachments are confidential and
> inte...{{dropped:9}}
>
> _______________________________________________
> [hidden email] mailing list
> https://stat.ethz.ch/mailman/listinfo/rsigfinance>  Subscriberposting only. If you want to post, subscribe first.
>  Also note that this is not the rhelp list where general R questions should go.
This email and any attachments are confidential and intended only for the recipient noted above. You are hereby notified that any use, printing, copying or disclosure is strictly prohibited without the permission of Enduring Investments LLC. For further information please contact: [hidden email]; (973) 4574602.
_______________________________________________
[hidden email] mailing list
https://stat.ethz.ch/mailman/listinfo/rsigfinance Subscriberposting only. If you want to post, subscribe first.
 Also note that this is not the rhelp list where general R questions should go.


Michael,
Perhaps your covariance matrix is singular (non positive definite) so you can "fix" this matrix by finding the nearest correlation matrix that is non singular.
The simplest recipe is to set the negative eigenvalues to a small positive number and rescale the matrix.
Also look at nearPD in the Matrix package.
Best
Krishna

> On Dec 14, 2015, at 9:06 PM, Michael Ashton < [hidden email]> wrote:
>
> Do you have a suggestion for such? I have in the past tried fPortfolio, but it would not allow me to specify my own projected return vectors rather than the historical returns of the series (which is exactly backwards).
>
> As for whether the matrix is comfortably nonsingular...I suppose it depends in a Clintonian way on the meaning of "comfortably," but I can create a Cholesky decomposition without it blowing up, which is usually how I can tell if I have done something stupid. Well, stupider than normal.
>
> Original Message
> From: Michael Weylandt [mailto: [hidden email]]
> Sent: Monday, December 14, 2015 8:32 PM
> To: Michael Ashton
> Cc: [hidden email]
> Subject: Re: [RSIGFinance] solnp Problem Inverting Hessian
>
> The Hessian is the matrix of second derivatives
> ( https://en.wikipedia.org/wiki/Hessian_matrix)  in scalar terms, you're finding a point where the second derivative is zero and then trying to divide by the second derivative to calculate the step size.
>
> I haven't gone through your code in any detail, but I'd start by checking the covariance matrix since that's proportional to the Hessian of your objective function. Is it (comfortably) nonsingular?
>
> Since you're just solving the standard Markowitz problem, you might try a simpler (quadratic/convex) solver instead of a general nonlinear solver. Should behave a bit better.
>
> Michael
>
>
>> On Mon, Dec 14, 2015 at 6:13 PM, Michael Ashton < [hidden email]> wrote:
>> I must admit to being flummoxed here, mainly because my linear algebra was 25 years ago and I can't remember what a Hessian is.
>>
>> I have a matrix of 60 securities' weekly returns, along with 60 projected returns. The returns are in a vector called Ret.vect and the covariance matrix of weekly returns in cov.mat . I have the minConstraints and maxConstraints that the parameters are permitted to take. I cycle through targeted risks and get the same error for each risk targeted...below I have removed the loop to focus on the risk=0.002.
>>
>> wgt.vect=c(rep(1/60, 60))
>> constr.fun < function(wgt.vect) {;
>> c1 = sqrt(crossprod(t(wgt.vect %*% cov.mat),wgt.vect));
>> c2 = sum(wgt.vect);
>> return(c(c1,c2));
>> }
>> ineqconstr.fun < function(wgt.vect) {
>> wgt.vect[1:60];
>> }
>> opt.fun < function(wgt.vect) {crossprod(wgt.vect,t(Ret.vect))}
>>
>> OptimSolution <
>> solnp(wgt.vect,opt.fun,constr.fun,eqB=c(0.002,1),ineqconstr.fun,ineqLB
>> =minConstraints,ineqUB=maxConstraints)
>>
>> I get the following error:
>> solnp> Solution not reliable....Problem Inverting Hessian.
>>
>> Well, that doesn't tell me very much! The parameters (weights) that are output for each run, as I cycle through the weights, are very scrambled...lots of little allocations, rather than clumping as you would expect to happen especially at the risky and riskless ends of the spectrum.
>>
>> Can anyone with more math than me give me a helping hand on the Hessian?
>>
>> Thanks,
>>
>>
>> Mike
>>
>> Michael Ashton, CFA
>> Managing Principal
>>
>> Enduring Investments LLC
>> W: 973.457.4602
>> C: 551.655.8006
>>
>>
>> ________________________________
>> This email and any attachments are confidential and
>> inte...{{dropped:9}}
>>
>> _______________________________________________
>> [hidden email] mailing list
>> https://stat.ethz.ch/mailman/listinfo/rsigfinance>>  Subscriberposting only. If you want to post, subscribe first.
>>  Also note that this is not the rhelp list where general R questions should go.
>
> This email and any attachments are confidential and in...{{dropped:10}}
_______________________________________________
[hidden email] mailing list
https://stat.ethz.ch/mailman/listinfo/rsigfinance Subscriberposting only. If you want to post, subscribe first.
 Also note that this is not the rhelp list where general R questions should go.


What's the condition number of your correlation/covariance matrix? (?kappa)
I think I've used quadprog for portfolio optimization with success,
but it's been a while.
MW
On Mon, Dec 14, 2015 at 8:06 PM, Michael Ashton
< [hidden email]> wrote:
> Do you have a suggestion for such? I have in the past tried fPortfolio, but it would not allow me to specify my own projected return vectors rather than the historical returns of the series (which is exactly backwards).
>
> As for whether the matrix is comfortably nonsingular...I suppose it depends in a Clintonian way on the meaning of "comfortably," but I can create a Cholesky decomposition without it blowing up, which is usually how I can tell if I have done something stupid. Well, stupider than normal.
>
> Original Message
> From: Michael Weylandt [mailto: [hidden email]]
> Sent: Monday, December 14, 2015 8:32 PM
> To: Michael Ashton
> Cc: [hidden email]
> Subject: Re: [RSIGFinance] solnp Problem Inverting Hessian
>
> The Hessian is the matrix of second derivatives
> ( https://en.wikipedia.org/wiki/Hessian_matrix)  in scalar terms, you're finding a point where the second derivative is zero and then trying to divide by the second derivative to calculate the step size.
>
> I haven't gone through your code in any detail, but I'd start by checking the covariance matrix since that's proportional to the Hessian of your objective function. Is it (comfortably) nonsingular?
>
> Since you're just solving the standard Markowitz problem, you might try a simpler (quadratic/convex) solver instead of a general nonlinear solver. Should behave a bit better.
>
> Michael
>
>
> On Mon, Dec 14, 2015 at 6:13 PM, Michael Ashton < [hidden email]> wrote:
>> I must admit to being flummoxed here, mainly because my linear algebra was 25 years ago and I can't remember what a Hessian is.
>>
>> I have a matrix of 60 securities' weekly returns, along with 60 projected returns. The returns are in a vector called Ret.vect and the covariance matrix of weekly returns in cov.mat . I have the minConstraints and maxConstraints that the parameters are permitted to take. I cycle through targeted risks and get the same error for each risk targeted...below I have removed the loop to focus on the risk=0.002.
>>
>> wgt.vect=c(rep(1/60, 60))
>> constr.fun < function(wgt.vect) {;
>> c1 = sqrt(crossprod(t(wgt.vect %*% cov.mat),wgt.vect));
>> c2 = sum(wgt.vect);
>> return(c(c1,c2));
>> }
>> ineqconstr.fun < function(wgt.vect) {
>> wgt.vect[1:60];
>> }
>> opt.fun < function(wgt.vect) {crossprod(wgt.vect,t(Ret.vect))}
>>
>> OptimSolution <
>> solnp(wgt.vect,opt.fun,constr.fun,eqB=c(0.002,1),ineqconstr.fun,ineqLB
>> =minConstraints,ineqUB=maxConstraints)
>>
>> I get the following error:
>> solnp> Solution not reliable....Problem Inverting Hessian.
>>
>> Well, that doesn't tell me very much! The parameters (weights) that are output for each run, as I cycle through the weights, are very scrambled...lots of little allocations, rather than clumping as you would expect to happen especially at the risky and riskless ends of the spectrum.
>>
>> Can anyone with more math than me give me a helping hand on the Hessian?
>>
>> Thanks,
>>
>>
>> Mike
>>
>> Michael Ashton, CFA
>> Managing Principal
>>
>> Enduring Investments LLC
>> W: 973.457.4602
>> C: 551.655.8006
>>
>>
>> ________________________________
>> This email and any attachments are confidential and
>> inte...{{dropped:9}}
>>
>> _______________________________________________
>> [hidden email] mailing list
>> https://stat.ethz.ch/mailman/listinfo/rsigfinance>>  Subscriberposting only. If you want to post, subscribe first.
>>  Also note that this is not the rhelp list where general R questions should go.
>
> This email and any attachments are confidential and in...{{dropped:6}}
_______________________________________________
[hidden email] mailing list
https://stat.ethz.ch/mailman/listinfo/rsigfinance Subscriberposting only. If you want to post, subscribe first.
 Also note that this is not the rhelp list where general R questions should go.


All eigenvalues are positive.
From: Krishna Kumar [mailto: [hidden email]]
Sent: Monday, December 14, 2015 9:27 PM
To: Michael Ashton
Cc: Michael Weylandt; [hidden email]
Subject: Re: [RSIGFinance] solnp Problem Inverting Hessian
Michael,
Perhaps your covariance matrix is singular (non positive definite) so you can "fix" this matrix by finding the nearest correlation matrix that is non singular.
The simplest recipe is to set the negative eigenvalues to a small positive number and rescale the matrix.
Also look at nearPD in the Matrix package.
Best
Krishna

On Dec 14, 2015, at 9:06 PM, Michael Ashton < [hidden email]<mailto: [hidden email]>> wrote:
Do you have a suggestion for such? I have in the past tried fPortfolio, but it would not allow me to specify my own projected return vectors rather than the historical returns of the series (which is exactly backwards).
As for whether the matrix is comfortably nonsingular...I suppose it depends in a Clintonian way on the meaning of "comfortably," but I can create a Cholesky decomposition without it blowing up, which is usually how I can tell if I have done something stupid. Well, stupider than normal.
Original Message
From: Michael Weylandt [mailto: [hidden email]]
Sent: Monday, December 14, 2015 8:32 PM
To: Michael Ashton
Cc: [hidden email]<mailto: [hidden email]>
Subject: Re: [RSIGFinance] solnp Problem Inverting Hessian
The Hessian is the matrix of second derivatives
( https://en.wikipedia.org/wiki/Hessian_matrix)  in scalar terms, you're finding a point where the second derivative is zero and then trying to divide by the second derivative to calculate the step size.
I haven't gone through your code in any detail, but I'd start by checking the covariance matrix since that's proportional to the Hessian of your objective function. Is it (comfortably) nonsingular?
Since you're just solving the standard Markowitz problem, you might try a simpler (quadratic/convex) solver instead of a general nonlinear solver. Should behave a bit better.
Michael
On Mon, Dec 14, 2015 at 6:13 PM, Michael Ashton < [hidden email]<mailto: [hidden email]>> wrote:
I must admit to being flummoxed here, mainly because my linear algebra was 25 years ago and I can't remember what a Hessian is.
I have a matrix of 60 securities' weekly returns, along with 60 projected returns. The returns are in a vector called Ret.vect and the covariance matrix of weekly returns in cov.mat . I have the minConstraints and maxConstraints that the parameters are permitted to take. I cycle through targeted risks and get the same error for each risk targeted...below I have removed the loop to focus on the risk=0.002.
wgt.vect=c(rep(1/60, 60))
constr.fun < function(wgt.vect) {;
c1 = sqrt(crossprod(t(wgt.vect %*% cov.mat),wgt.vect));
c2 = sum(wgt.vect);
return(c(c1,c2));
}
ineqconstr.fun < function(wgt.vect) {
wgt.vect[1:60];
}
opt.fun < function(wgt.vect) {crossprod(wgt.vect,t(Ret.vect))}
OptimSolution <
solnp(wgt.vect,opt.fun,constr.fun,eqB=c(0.002,1),ineqconstr.fun,ineqLB
=minConstraints,ineqUB=maxConstraints)
I get the following error:
solnp> Solution not reliable....Problem Inverting Hessian.
Well, that doesn't tell me very much! The parameters (weights) that are output for each run, as I cycle through the weights, are very scrambled...lots of little allocations, rather than clumping as you would expect to happen especially at the risky and riskless ends of the spectrum.
Can anyone with more math than me give me a helping hand on the Hessian?
Thanks,
Mike
Michael Ashton, CFA
Managing Principal
Enduring Investments LLC
W: 973.457.4602
C: 551.655.8006
________________________________
This email and any attachments are confidential and
inte...{{dropped:9}}
_______________________________________________
[hidden email]<mailto: [hidden email]> mailing list
https://stat.ethz.ch/mailman/listinfo/rsigfinance Subscriberposting only. If you want to post, subscribe first.
 Also note that this is not the rhelp list where general R questions should go.
This email and any attachments are confidential and intended only for the recipient noted above. You are hereby notified that any use, printing, copying or disclosure is strictly prohibited without the permission of Enduring Investments LLC. For further information please contact: [hidden email]<mailto: [hidden email]>; (973) 4574602.
_______________________________________________
[hidden email]<mailto: [hidden email]> mailing list
https://stat.ethz.ch/mailman/listinfo/rsigfinance Subscriberposting only. If you want to post, subscribe first.
 Also note that this is not the rhelp list where general R questions should go.
________________________________
This email and any attachments are confidential and intended only for the recipient noted above. You are hereby notified that any use, printing, copying or disclosure is strictly prohibited without the permission of Enduring Investments LLC. For further information please contact: [hidden email]; (973) 4574602.
[[alternative HTML version deleted]]
_______________________________________________
[hidden email] mailing list
https://stat.ethz.ch/mailman/listinfo/rsigfinance Subscriberposting only. If you want to post, subscribe first.
 Also note that this is not the rhelp list where general R questions should go.


(+list  I'm not a numerical linear algebra expert or portfolio
optimization expert, but there are a number on this list who might
chime in)
That is quite high, and almost certainly problematic.
I'm not sure what an acceptable bound is (will depend on your solver),
but that's almost certainly above it for any algorithm which will
require inverting cov.mat.
Two things you could try:
 use a different (nonHessianusing) optimization algorithm;
 use some form of shrinkage/regularization (LedoitWolf is a common
choice) to tame your covariance matrix.
Michael
On Mon, Dec 14, 2015 at 10:10 PM, Michael Ashton
< [hidden email]> wrote:
> Well, not sure whether this makes any sense but kappa(cov.mat) gives me 11148245007.
>
> That seems large. But I am not sure what it is supposed to be.
>
> Original Message
> From: Michael Weylandt [mailto: [hidden email]]
> Sent: Monday, December 14, 2015 9:29 PM
> To: Michael Ashton
> Cc: [hidden email]
> Subject: Re: [RSIGFinance] solnp Problem Inverting Hessian
>
> What's the condition number of your correlation/covariance matrix? (?kappa)
>
> I think I've used quadprog for portfolio optimization with success, but it's been a while.
>
> MW
>
> On Mon, Dec 14, 2015 at 8:06 PM, Michael Ashton < [hidden email]> wrote:
>> Do you have a suggestion for such? I have in the past tried fPortfolio, but it would not allow me to specify my own projected return vectors rather than the historical returns of the series (which is exactly backwards).
>>
>> As for whether the matrix is comfortably nonsingular...I suppose it depends in a Clintonian way on the meaning of "comfortably," but I can create a Cholesky decomposition without it blowing up, which is usually how I can tell if I have done something stupid. Well, stupider than normal.
>>
>> Original Message
>> From: Michael Weylandt [mailto: [hidden email]]
>> Sent: Monday, December 14, 2015 8:32 PM
>> To: Michael Ashton
>> Cc: [hidden email]
>> Subject: Re: [RSIGFinance] solnp Problem Inverting Hessian
>>
>> The Hessian is the matrix of second derivatives
>> ( https://en.wikipedia.org/wiki/Hessian_matrix)  in scalar terms, you're finding a point where the second derivative is zero and then trying to divide by the second derivative to calculate the step size.
>>
>> I haven't gone through your code in any detail, but I'd start by checking the covariance matrix since that's proportional to the Hessian of your objective function. Is it (comfortably) nonsingular?
>>
>> Since you're just solving the standard Markowitz problem, you might try a simpler (quadratic/convex) solver instead of a general nonlinear solver. Should behave a bit better.
>>
>> Michael
>>
>>
>> On Mon, Dec 14, 2015 at 6:13 PM, Michael Ashton < [hidden email]> wrote:
>>> I must admit to being flummoxed here, mainly because my linear algebra was 25 years ago and I can't remember what a Hessian is.
>>>
>>> I have a matrix of 60 securities' weekly returns, along with 60 projected returns. The returns are in a vector called Ret.vect and the covariance matrix of weekly returns in cov.mat . I have the minConstraints and maxConstraints that the parameters are permitted to take. I cycle through targeted risks and get the same error for each risk targeted...below I have removed the loop to focus on the risk=0.002.
>>>
>>> wgt.vect=c(rep(1/60, 60))
>>> constr.fun < function(wgt.vect) {;
>>> c1 = sqrt(crossprod(t(wgt.vect %*% cov.mat),wgt.vect));
>>> c2 = sum(wgt.vect);
>>> return(c(c1,c2));
>>> }
>>> ineqconstr.fun < function(wgt.vect) {
>>> wgt.vect[1:60];
>>> }
>>> opt.fun < function(wgt.vect) {crossprod(wgt.vect,t(Ret.vect))}
>>>
>>> OptimSolution <
>>> solnp(wgt.vect,opt.fun,constr.fun,eqB=c(0.002,1),ineqconstr.fun,ineqL
>>> B
>>> =minConstraints,ineqUB=maxConstraints)
>>>
>>> I get the following error:
>>> solnp> Solution not reliable....Problem Inverting Hessian.
>>>
>>> Well, that doesn't tell me very much! The parameters (weights) that are output for each run, as I cycle through the weights, are very scrambled...lots of little allocations, rather than clumping as you would expect to happen especially at the risky and riskless ends of the spectrum.
>>>
>>> Can anyone with more math than me give me a helping hand on the Hessian?
>>>
>>> Thanks,
>>>
>>>
>>> Mike
>>>
>>> Michael Ashton, CFA
>>> Managing Principal
>>>
>>> Enduring Investments LLC
>>> W: 973.457.4602
>>> C: 551.655.8006
>>>
>>>
>>> ________________________________
>>> This email and any attachments are confidential and
>>> inte...{{dropped:9}}
>>>
>>> _______________________________________________
>>> [hidden email] mailing list
>>> https://stat.ethz.ch/mailman/listinfo/rsigfinance>>>  Subscriberposting only. If you want to post, subscribe first.
>>>  Also note that this is not the rhelp list where general R questions should go.
>>
>> This email and any attachments are confidential and intended only for the recipient noted above. You are hereby notified that any use, printing, copying or disclosure is strictly prohibited without the permission of Enduring Investments LLC. For further information please contact: [hidden email]; (973) 4574602.
>
> This email and any attachments are confidential and in...{{dropped:6}}
_______________________________________________
[hidden email] mailing list
https://stat.ethz.ch/mailman/listinfo/rsigfinance Subscriberposting only. If you want to post, subscribe first.
 Also note that this is not the rhelp list where general R questions should go.


I have not been paying close attention and I've missed something in this
thread, but ...
I think the hessian in the optimization will be the second derivative of
this function
>>>>opt.fun < function(wgt.vect) {crossprod(wgt.vect,t(Ret.vect))}
WRT wgt.vect. If there are zero elements in Ret.vect then that hessian
will be singular. And if there are orders of magnitude difference
between the largest and smallest elements in Ret.vect then the hessian
will be illconditioned.
The illconditioned case is a numerical problem and you might solve it
with a different algorithm, or by better scaling. The zero case is a
theoretical problem, there is not a unique optimal point but rather
whole continuum of optimal points (your parameters corresponding to the
zero elements will not make any difference in the function value).
HTH,
Paul
On 12/14/2015 11:39 PM, Michael Weylandt wrote:
> (+list  I'm not a numerical linear algebra expert or portfolio
> optimization expert, but there are a number on this list who might
> chime in)
>
> That is quite high, and almost certainly problematic.
>
> I'm not sure what an acceptable bound is (will depend on your solver),
> but that's almost certainly above it for any algorithm which will
> require inverting cov.mat.
>
> Two things you could try:
>  use a different (nonHessianusing) optimization algorithm;
>  use some form of shrinkage/regularization (LedoitWolf is a common
> choice) to tame your covariance matrix.
>
> Michael
>
> On Mon, Dec 14, 2015 at 10:10 PM, Michael Ashton
> < [hidden email]> wrote:
>> Well, not sure whether this makes any sense but kappa(cov.mat) gives me 11148245007.
>>
>> That seems large. But I am not sure what it is supposed to be.
>>
>> Original Message
>> From: Michael Weylandt [mailto: [hidden email]]
>> Sent: Monday, December 14, 2015 9:29 PM
>> To: Michael Ashton
>> Cc: [hidden email]
>> Subject: Re: [RSIGFinance] solnp Problem Inverting Hessian
>>
>> What's the condition number of your correlation/covariance matrix? (?kappa)
>>
>> I think I've used quadprog for portfolio optimization with success, but it's been a while.
>>
>> MW
>>
>> On Mon, Dec 14, 2015 at 8:06 PM, Michael Ashton < [hidden email]> wrote:
>>> Do you have a suggestion for such? I have in the past tried fPortfolio, but it would not allow me to specify my own projected return vectors rather than the historical returns of the series (which is exactly backwards).
>>>
>>> As for whether the matrix is comfortably nonsingular...I suppose it depends in a Clintonian way on the meaning of "comfortably," but I can create a Cholesky decomposition without it blowing up, which is usually how I can tell if I have done something stupid. Well, stupider than normal.
>>>
>>> Original Message
>>> From: Michael Weylandt [mailto: [hidden email]]
>>> Sent: Monday, December 14, 2015 8:32 PM
>>> To: Michael Ashton
>>> Cc: [hidden email]
>>> Subject: Re: [RSIGFinance] solnp Problem Inverting Hessian
>>>
>>> The Hessian is the matrix of second derivatives
>>> ( https://en.wikipedia.org/wiki/Hessian_matrix)  in scalar terms, you're finding a point where the second derivative is zero and then trying to divide by the second derivative to calculate the step size.
>>>
>>> I haven't gone through your code in any detail, but I'd start by checking the covariance matrix since that's proportional to the Hessian of your objective function. Is it (comfortably) nonsingular?
>>>
>>> Since you're just solving the standard Markowitz problem, you might try a simpler (quadratic/convex) solver instead of a general nonlinear solver. Should behave a bit better.
>>>
>>> Michael
>>>
>>>
>>> On Mon, Dec 14, 2015 at 6:13 PM, Michael Ashton < [hidden email]> wrote:
>>>> I must admit to being flummoxed here, mainly because my linear algebra was 25 years ago and I can't remember what a Hessian is.
>>>>
>>>> I have a matrix of 60 securities' weekly returns, along with 60 projected returns. The returns are in a vector called Ret.vect and the covariance matrix of weekly returns in cov.mat . I have the minConstraints and maxConstraints that the parameters are permitted to take. I cycle through targeted risks and get the same error for each risk targeted...below I have removed the loop to focus on the risk=0.002.
>>>>
>>>> wgt.vect=c(rep(1/60, 60))
>>>> constr.fun < function(wgt.vect) {;
>>>> c1 = sqrt(crossprod(t(wgt.vect %*% cov.mat),wgt.vect));
>>>> c2 = sum(wgt.vect);
>>>> return(c(c1,c2));
>>>> }
>>>> ineqconstr.fun < function(wgt.vect) {
>>>> wgt.vect[1:60];
>>>> }
>>>> opt.fun < function(wgt.vect) {crossprod(wgt.vect,t(Ret.vect))}
>>>>
>>>> OptimSolution <
>>>> solnp(wgt.vect,opt.fun,constr.fun,eqB=c(0.002,1),ineqconstr.fun,ineqL
>>>> B
>>>> =minConstraints,ineqUB=maxConstraints)
>>>>
>>>> I get the following error:
>>>> solnp> Solution not reliable....Problem Inverting Hessian.
>>>>
>>>> Well, that doesn't tell me very much! The parameters (weights) that are output for each run, as I cycle through the weights, are very scrambled...lots of little allocations, rather than clumping as you would expect to happen especially at the risky and riskless ends of the spectrum.
>>>>
>>>> Can anyone with more math than me give me a helping hand on the Hessian?
>>>>
>>>> Thanks,
>>>>
>>>>
>>>> Mike
>>>>
>>>> Michael Ashton, CFA
>>>> Managing Principal
>>>>
>>>> Enduring Investments LLC
>>>> W: 973.457.4602
>>>> C: 551.655.8006
>>>>
>>>>
>>>> ________________________________
>>>> This email and any attachments are confidential and
>>>> inte...{{dropped:9}}
>>>>
>>>> _______________________________________________
>>>> [hidden email] mailing list
>>>> https://stat.ethz.ch/mailman/listinfo/rsigfinance>>>>  Subscriberposting only. If you want to post, subscribe first.
>>>>  Also note that this is not the rhelp list where general R questions should go.
>>>
>>> This email and any attachments are confidential and intended only for the recipient noted above. You are hereby notified that any use, printing, copying or disclosure is strictly prohibited without the permission of Enduring Investments LLC. For further information please contact: [hidden email]; (973) 4574602.
>>
>> This email and any attachments are confidential and in...{{dropped:6}}
>
> _______________________________________________
> [hidden email] mailing list
> https://stat.ethz.ch/mailman/listinfo/rsigfinance>  Subscriberposting only. If you want to post, subscribe first.
>  Also note that this is not the rhelp list where general R questions should go.
>
_______________________________________________
[hidden email] mailing list
https://stat.ethz.ch/mailman/listinfo/rsigfinance Subscriberposting only. If you want to post, subscribe first.
 Also note that this is not the rhelp list where general R questions should go.


That is very interesting. Actually some of the projected returns are negative, some are very close to zero. None is exactly zero, which I guess is why it's not singular, but that's why it's illconditioned. Very interesting. And hard to solve...if I add 5% to all returns will I still get the same portfolio? Seems to me intuitively I shouldn't since the proportional risk/return tradeoff then is greater for the assets on the low end of the spectrum, but I might be wrong.
Original Message
From: Paul Gilbert [mailto: [hidden email]]
Sent: Tuesday, December 15, 2015 9:58 AM
To: Michael Ashton
Cc: Michael Weylandt; [hidden email]
Subject: Re: [RSIGFinance] solnp Problem Inverting Hessian
I have not been paying close attention and I've missed something in this thread, but ...
I think the hessian in the optimization will be the second derivative of this function
>>>>opt.fun < function(wgt.vect) {crossprod(wgt.vect,t(Ret.vect))}
WRT wgt.vect. If there are zero elements in Ret.vect then that hessian will be singular. And if there are orders of magnitude difference between the largest and smallest elements in Ret.vect then the hessian will be illconditioned.
The illconditioned case is a numerical problem and you might solve it with a different algorithm, or by better scaling. The zero case is a theoretical problem, there is not a unique optimal point but rather whole continuum of optimal points (your parameters corresponding to the zero elements will not make any difference in the function value).
HTH,
Paul
On 12/14/2015 11:39 PM, Michael Weylandt wrote:
> (+list  I'm not a numerical linear algebra expert or portfolio
> optimization expert, but there are a number on this list who might
> chime in)
>
> That is quite high, and almost certainly problematic.
>
> I'm not sure what an acceptable bound is (will depend on your solver),
> but that's almost certainly above it for any algorithm which will
> require inverting cov.mat.
>
> Two things you could try:
>  use a different (nonHessianusing) optimization algorithm;
>  use some form of shrinkage/regularization (LedoitWolf is a common
> choice) to tame your covariance matrix.
>
> Michael
>
> On Mon, Dec 14, 2015 at 10:10 PM, Michael Ashton
> < [hidden email]> wrote:
>> Well, not sure whether this makes any sense but kappa(cov.mat) gives me 11148245007.
>>
>> That seems large. But I am not sure what it is supposed to be.
>>
>> Original Message
>> From: Michael Weylandt [mailto: [hidden email]]
>> Sent: Monday, December 14, 2015 9:29 PM
>> To: Michael Ashton
>> Cc: [hidden email]
>> Subject: Re: [RSIGFinance] solnp Problem Inverting Hessian
>>
>> What's the condition number of your correlation/covariance matrix?
>> (?kappa)
>>
>> I think I've used quadprog for portfolio optimization with success, but it's been a while.
>>
>> MW
>>
>> On Mon, Dec 14, 2015 at 8:06 PM, Michael Ashton < [hidden email]> wrote:
>>> Do you have a suggestion for such? I have in the past tried fPortfolio, but it would not allow me to specify my own projected return vectors rather than the historical returns of the series (which is exactly backwards).
>>>
>>> As for whether the matrix is comfortably nonsingular...I suppose it depends in a Clintonian way on the meaning of "comfortably," but I can create a Cholesky decomposition without it blowing up, which is usually how I can tell if I have done something stupid. Well, stupider than normal.
>>>
>>> Original Message
>>> From: Michael Weylandt [mailto: [hidden email]]
>>> Sent: Monday, December 14, 2015 8:32 PM
>>> To: Michael Ashton
>>> Cc: [hidden email]
>>> Subject: Re: [RSIGFinance] solnp Problem Inverting Hessian
>>>
>>> The Hessian is the matrix of second derivatives
>>> ( https://en.wikipedia.org/wiki/Hessian_matrix)  in scalar terms, you're finding a point where the second derivative is zero and then trying to divide by the second derivative to calculate the step size.
>>>
>>> I haven't gone through your code in any detail, but I'd start by checking the covariance matrix since that's proportional to the Hessian of your objective function. Is it (comfortably) nonsingular?
>>>
>>> Since you're just solving the standard Markowitz problem, you might try a simpler (quadratic/convex) solver instead of a general nonlinear solver. Should behave a bit better.
>>>
>>> Michael
>>>
>>>
>>> On Mon, Dec 14, 2015 at 6:13 PM, Michael Ashton < [hidden email]> wrote:
>>>> I must admit to being flummoxed here, mainly because my linear algebra was 25 years ago and I can't remember what a Hessian is.
>>>>
>>>> I have a matrix of 60 securities' weekly returns, along with 60 projected returns. The returns are in a vector called Ret.vect and the covariance matrix of weekly returns in cov.mat . I have the minConstraints and maxConstraints that the parameters are permitted to take. I cycle through targeted risks and get the same error for each risk targeted...below I have removed the loop to focus on the risk=0.002.
>>>>
>>>> wgt.vect=c(rep(1/60, 60))
>>>> constr.fun < function(wgt.vect) {;
>>>> c1 = sqrt(crossprod(t(wgt.vect %*% cov.mat),wgt.vect));
>>>> c2 = sum(wgt.vect);
>>>> return(c(c1,c2));
>>>> }
>>>> ineqconstr.fun < function(wgt.vect) {
>>>> wgt.vect[1:60];
>>>> }
>>>> opt.fun < function(wgt.vect) {crossprod(wgt.vect,t(Ret.vect))}
>>>>
>>>> OptimSolution <
>>>> solnp(wgt.vect,opt.fun,constr.fun,eqB=c(0.002,1),ineqconstr.fun,ine
>>>> qL
>>>> B
>>>> =minConstraints,ineqUB=maxConstraints)
>>>>
>>>> I get the following error:
>>>> solnp> Solution not reliable....Problem Inverting Hessian.
>>>>
>>>> Well, that doesn't tell me very much! The parameters (weights) that are output for each run, as I cycle through the weights, are very scrambled...lots of little allocations, rather than clumping as you would expect to happen especially at the risky and riskless ends of the spectrum.
>>>>
>>>> Can anyone with more math than me give me a helping hand on the Hessian?
>>>>
>>>> Thanks,
>>>>
>>>>
>>>> Mike
>>>>
>>>> Michael Ashton, CFA
>>>> Managing Principal
>>>>
>>>> Enduring Investments LLC
>>>> W: 973.457.4602
>>>> C: 551.655.8006
>>>>
>>>>
>>>> ________________________________
>>>> This email and any attachments are confidential and
>>>> inte...{{dropped:9}}
>>>>
>>>> _______________________________________________
>>>> [hidden email] mailing list
>>>> https://stat.ethz.ch/mailman/listinfo/rsigfinance>>>>  Subscriberposting only. If you want to post, subscribe first.
>>>>  Also note that this is not the rhelp list where general R questions should go.
>>>
>>> This email and any attachments are confidential and intended only for the recipient noted above. You are hereby notified that any use, printing, copying or disclosure is strictly prohibited without the permission of Enduring Investments LLC. For further information please contact: [hidden email]; (973) 4574602.
>>
>> This email and any attachments are confidential and
>> in...{{dropped:6}}
>
> _______________________________________________
> [hidden email] mailing list
> https://stat.ethz.ch/mailman/listinfo/rsigfinance>  Subscriberposting only. If you want to post, subscribe first.
>  Also note that this is not the rhelp list where general R questions should go.
>
This email and any attachments are confidential and inte...{{dropped:6}}
_______________________________________________
[hidden email] mailing list
https://stat.ethz.ch/mailman/listinfo/rsigfinance Subscriberposting only. If you want to post, subscribe first.
 Also note that this is not the rhelp list where general R questions should go.


Just to be clear, when I said "difference between the largest and
smallest elements" I am think of the absolute value. It is the scale not
the sign that causes problems in optimization. And I cannot commenting
on whether you have the correct objective function, just pointing out
what would happen numerically with the one you specified.
Paul
On 12/15/2015 10:17 AM, Michael Ashton wrote:
> That is very interesting. Actually some of the projected returns are
> negative, some are very close to zero. None is exactly zero, which I
> guess is why it's not singular, but that's why it's illconditioned.
> Very interesting. And hard to solve...if I add 5% to all returns will
> I still get the same portfolio? Seems to me intuitively I shouldn't
> since the proportional risk/return tradeoff then is greater for the
> assets on the low end of the spectrum, but I might be wrong.
>
> Original Message From: Paul Gilbert
> [mailto: [hidden email]] Sent: Tuesday, December 15, 2015 9:58
> AM To: Michael Ashton Cc: Michael Weylandt;
> [hidden email] Subject: Re: [RSIGFinance] solnp
> Problem Inverting Hessian
>
> I have not been paying close attention and I've missed something in
> this thread, but ...
>
> I think the hessian in the optimization will be the second derivative
> of this function
>
>>>>> opt.fun < function(wgt.vect)
>>>>> {crossprod(wgt.vect,t(Ret.vect))}
>
> WRT wgt.vect. If there are zero elements in Ret.vect then that
> hessian will be singular. And if there are orders of magnitude
> difference between the largest and smallest elements in Ret.vect then
> the hessian will be illconditioned.
>
> The illconditioned case is a numerical problem and you might solve
> it with a different algorithm, or by better scaling. The zero case is
> a theoretical problem, there is not a unique optimal point but rather
> whole continuum of optimal points (your parameters corresponding to
> the zero elements will not make any difference in the function
> value).
>
> HTH, Paul
>
> On 12/14/2015 11:39 PM, Michael Weylandt wrote:
>> (+list  I'm not a numerical linear algebra expert or portfolio
>> optimization expert, but there are a number on this list who might
>> chime in)
>>
>> That is quite high, and almost certainly problematic.
>>
>> I'm not sure what an acceptable bound is (will depend on your
>> solver), but that's almost certainly above it for any algorithm
>> which will require inverting cov.mat.
>>
>> Two things you could try:  use a different (nonHessianusing)
>> optimization algorithm;  use some form of shrinkage/regularization
>> (LedoitWolf is a common choice) to tame your covariance matrix.
>>
>> Michael
>>
>> On Mon, Dec 14, 2015 at 10:10 PM, Michael Ashton
>> < [hidden email]> wrote:
>>> Well, not sure whether this makes any sense but kappa(cov.mat)
>>> gives me 11148245007.
>>>
>>> That seems large. But I am not sure what it is supposed to be.
>>>
>>> Original Message From: Michael Weylandt
>>> [mailto: [hidden email]] Sent: Monday, December 14,
>>> 2015 9:29 PM To: Michael Ashton Cc: [hidden email]
>>> Subject: Re: [RSIGFinance] solnp Problem Inverting Hessian
>>>
>>> What's the condition number of your correlation/covariance
>>> matrix? (?kappa)
>>>
>>> I think I've used quadprog for portfolio optimization with
>>> success, but it's been a while.
>>>
>>> MW
>>>
>>> On Mon, Dec 14, 2015 at 8:06 PM, Michael Ashton
>>> < [hidden email]> wrote:
>>>> Do you have a suggestion for such? I have in the past tried
>>>> fPortfolio, but it would not allow me to specify my own
>>>> projected return vectors rather than the historical returns of
>>>> the series (which is exactly backwards).
>>>>
>>>> As for whether the matrix is comfortably nonsingular...I
>>>> suppose it depends in a Clintonian way on the meaning of
>>>> "comfortably," but I can create a Cholesky decomposition
>>>> without it blowing up, which is usually how I can tell if I
>>>> have done something stupid. Well, stupider than normal.
>>>>
>>>> Original Message From: Michael Weylandt
>>>> [mailto: [hidden email]] Sent: Monday, December 14,
>>>> 2015 8:32 PM To: Michael Ashton Cc:
>>>> [hidden email] Subject: Re: [RSIGFinance] solnp
>>>> Problem Inverting Hessian
>>>>
>>>> The Hessian is the matrix of second derivatives
>>>> ( https://en.wikipedia.org/wiki/Hessian_matrix)  in scalar
>>>> terms, you're finding a point where the second derivative is
>>>> zero and then trying to divide by the second derivative to
>>>> calculate the step size.
>>>>
>>>> I haven't gone through your code in any detail, but I'd start
>>>> by checking the covariance matrix since that's proportional to
>>>> the Hessian of your objective function. Is it (comfortably)
>>>> nonsingular?
>>>>
>>>> Since you're just solving the standard Markowitz problem, you
>>>> might try a simpler (quadratic/convex) solver instead of a
>>>> general nonlinear solver. Should behave a bit better.
>>>>
>>>> Michael
>>>>
>>>>
>>>> On Mon, Dec 14, 2015 at 6:13 PM, Michael Ashton
>>>> < [hidden email]> wrote:
>>>>> I must admit to being flummoxed here, mainly because my
>>>>> linear algebra was 25 years ago and I can't remember what a
>>>>> Hessian is.
>>>>>
>>>>> I have a matrix of 60 securities' weekly returns, along with
>>>>> 60 projected returns. The returns are in a vector called
>>>>> Ret.vect and the covariance matrix of weekly returns in
>>>>> cov.mat . I have the minConstraints and maxConstraints that
>>>>> the parameters are permitted to take. I cycle through
>>>>> targeted risks and get the same error for each risk
>>>>> targeted...below I have removed the loop to focus on the
>>>>> risk=0.002.
>>>>>
>>>>> wgt.vect=c(rep(1/60, 60)) constr.fun < function(wgt.vect)
>>>>> {; c1 = sqrt(crossprod(t(wgt.vect %*% cov.mat),wgt.vect)); c2
>>>>> = sum(wgt.vect); return(c(c1,c2)); } ineqconstr.fun <
>>>>> function(wgt.vect) { wgt.vect[1:60]; } opt.fun <
>>>>> function(wgt.vect) {crossprod(wgt.vect,t(Ret.vect))}
>>>>>
>>>>> OptimSolution <
>>>>> solnp(wgt.vect,opt.fun,constr.fun,eqB=c(0.002,1),ineqconstr.fun,ine
>>>>>
>>>>>
qL
>>>>> B =minConstraints,ineqUB=maxConstraints)
>>>>>
>>>>> I get the following error: solnp> Solution not
>>>>> reliable....Problem Inverting Hessian.
>>>>>
>>>>> Well, that doesn't tell me very much! The parameters
>>>>> (weights) that are output for each run, as I cycle through
>>>>> the weights, are very scrambled...lots of little allocations,
>>>>> rather than clumping as you would expect to happen especially
>>>>> at the risky and riskless ends of the spectrum.
>>>>>
>>>>> Can anyone with more math than me give me a helping hand on
>>>>> the Hessian?
>>>>>
>>>>> Thanks,
>>>>>
>>>>>
>>>>> Mike
>>>>>
>>>>> Michael Ashton, CFA Managing Principal
>>>>>
>>>>> Enduring Investments LLC W: 973.457.4602 C: 551.655.8006
>>>>>
>>>>>
>>>>> ________________________________ This email and any
>>>>> attachments are confidential and inte...{{dropped:9}}
>>>>>
>>>>> _______________________________________________
>>>>> [hidden email] mailing list
>>>>> https://stat.ethz.ch/mailman/listinfo/rsigfinance 
>>>>> Subscriberposting only. If you want to post, subscribe
>>>>> first.  Also note that this is not the rhelp list where
>>>>> general R questions should go.
>>>>
>>>> This email and any attachments are confidential and intended
>>>> only for the recipient noted above. You are hereby notified
>>>> that any use, printing, copying or disclosure is strictly
>>>> prohibited without the permission of Enduring Investments LLC.
>>>> For further information please contact:
>>>> [hidden email]; (973) 4574602.
>>>
>>> This email and any attachments are confidential and
>>> in...{{dropped:6}}
>>
>> _______________________________________________
>> [hidden email] mailing list
>> https://stat.ethz.ch/mailman/listinfo/rsigfinance 
>> Subscriberposting only. If you want to post, subscribe first. 
>> Also note that this is not the rhelp list where general R
>> questions should go.
>>
>
> This email and any attachments are confidential and in...{{dropped:7}}
_______________________________________________
[hidden email] mailing list
https://stat.ethz.ch/mailman/listinfo/rsigfinance Subscriberposting only. If you want to post, subscribe first.
 Also note that this is not the rhelp list where general R questions should go.


Understood. I was just noting that Ret.vect spans zero, and thus some projected returns will always be pretty close to zero.
> On Dec 15, 2015, at 10:43 AM, Paul Gilbert < [hidden email]> wrote:
>
> Just to be clear, when I said "difference between the largest and
> smallest elements" I am think of the absolute value. It is the scale not
> the sign that causes problems in optimization. And I cannot commenting
> on whether you have the correct objective function, just pointing out
> what would happen numerically with the one you specified.
>
> Paul
>
>> On 12/15/2015 10:17 AM, Michael Ashton wrote:
>> That is very interesting. Actually some of the projected returns are
>> negative, some are very close to zero. None is exactly zero, which I
>> guess is why it's not singular, but that's why it's illconditioned.
>> Very interesting. And hard to solve...if I add 5% to all returns will
>> I still get the same portfolio? Seems to me intuitively I shouldn't
>> since the proportional risk/return tradeoff then is greater for the
>> assets on the low end of the spectrum, but I might be wrong.
>>
>> Original Message From: Paul Gilbert
>> [mailto: [hidden email]] Sent: Tuesday, December 15, 2015 9:58
>> AM To: Michael Ashton Cc: Michael Weylandt;
>> [hidden email] Subject: Re: [RSIGFinance] solnp
>> Problem Inverting Hessian
>>
>> I have not been paying close attention and I've missed something in
>> this thread, but ...
>>
>> I think the hessian in the optimization will be the second derivative
>> of this function
>>
>>>>>> opt.fun < function(wgt.vect)
>>>>>> {crossprod(wgt.vect,t(Ret.vect))}
>>
>> WRT wgt.vect. If there are zero elements in Ret.vect then that
>> hessian will be singular. And if there are orders of magnitude
>> difference between the largest and smallest elements in Ret.vect then
>> the hessian will be illconditioned.
>>
>> The illconditioned case is a numerical problem and you might solve
>> it with a different algorithm, or by better scaling. The zero case is
>> a theoretical problem, there is not a unique optimal point but rather
>> whole continuum of optimal points (your parameters corresponding to
>> the zero elements will not make any difference in the function
>> value).
>>
>> HTH, Paul
>>
>>> On 12/14/2015 11:39 PM, Michael Weylandt wrote:
>>> (+list  I'm not a numerical linear algebra expert or portfolio
>>> optimization expert, but there are a number on this list who might
>>> chime in)
>>>
>>> That is quite high, and almost certainly problematic.
>>>
>>> I'm not sure what an acceptable bound is (will depend on your
>>> solver), but that's almost certainly above it for any algorithm
>>> which will require inverting cov.mat.
>>>
>>> Two things you could try:  use a different (nonHessianusing)
>>> optimization algorithm;  use some form of shrinkage/regularization
>>> (LedoitWolf is a common choice) to tame your covariance matrix.
>>>
>>> Michael
>>>
>>> On Mon, Dec 14, 2015 at 10:10 PM, Michael Ashton
>>> < [hidden email]> wrote:
>>>> Well, not sure whether this makes any sense but kappa(cov.mat)
>>>> gives me 11148245007.
>>>>
>>>> That seems large. But I am not sure what it is supposed to be.
>>>>
>>>> Original Message From: Michael Weylandt
>>>> [mailto: [hidden email]] Sent: Monday, December 14,
>>>> 2015 9:29 PM To: Michael Ashton Cc: [hidden email]
>>>> Subject: Re: [RSIGFinance] solnp Problem Inverting Hessian
>>>>
>>>> What's the condition number of your correlation/covariance
>>>> matrix? (?kappa)
>>>>
>>>> I think I've used quadprog for portfolio optimization with
>>>> success, but it's been a while.
>>>>
>>>> MW
>>>>
>>>> On Mon, Dec 14, 2015 at 8:06 PM, Michael Ashton
>>>> < [hidden email]> wrote:
>>>>> Do you have a suggestion for such? I have in the past tried
>>>>> fPortfolio, but it would not allow me to specify my own
>>>>> projected return vectors rather than the historical returns of
>>>>> the series (which is exactly backwards).
>>>>>
>>>>> As for whether the matrix is comfortably nonsingular...I
>>>>> suppose it depends in a Clintonian way on the meaning of
>>>>> "comfortably," but I can create a Cholesky decomposition
>>>>> without it blowing up, which is usually how I can tell if I
>>>>> have done something stupid. Well, stupider than normal.
>>>>>
>>>>> Original Message From: Michael Weylandt
>>>>> [mailto: [hidden email]] Sent: Monday, December 14,
>>>>> 2015 8:32 PM To: Michael Ashton Cc:
>>>>> [hidden email] Subject: Re: [RSIGFinance] solnp
>>>>> Problem Inverting Hessian
>>>>>
>>>>> The Hessian is the matrix of second derivatives
>>>>> ( https://en.wikipedia.org/wiki/Hessian_matrix)  in scalar
>>>>> terms, you're finding a point where the second derivative is
>>>>> zero and then trying to divide by the second derivative to
>>>>> calculate the step size.
>>>>>
>>>>> I haven't gone through your code in any detail, but I'd start
>>>>> by checking the covariance matrix since that's proportional to
>>>>> the Hessian of your objective function. Is it (comfortably)
>>>>> nonsingular?
>>>>>
>>>>> Since you're just solving the standard Markowitz problem, you
>>>>> might try a simpler (quadratic/convex) solver instead of a
>>>>> general nonlinear solver. Should behave a bit better.
>>>>>
>>>>> Michael
>>>>>
>>>>>
>>>>> On Mon, Dec 14, 2015 at 6:13 PM, Michael Ashton
>>>>> < [hidden email]> wrote:
>>>>>> I must admit to being flummoxed here, mainly because my
>>>>>> linear algebra was 25 years ago and I can't remember what a
>>>>>> Hessian is.
>>>>>>
>>>>>> I have a matrix of 60 securities' weekly returns, along with
>>>>>> 60 projected returns. The returns are in a vector called
>>>>>> Ret.vect and the covariance matrix of weekly returns in
>>>>>> cov.mat . I have the minConstraints and maxConstraints that
>>>>>> the parameters are permitted to take. I cycle through
>>>>>> targeted risks and get the same error for each risk
>>>>>> targeted...below I have removed the loop to focus on the
>>>>>> risk=0.002.
>>>>>>
>>>>>> wgt.vect=c(rep(1/60, 60)) constr.fun < function(wgt.vect)
>>>>>> {; c1 = sqrt(crossprod(t(wgt.vect %*% cov.mat),wgt.vect)); c2
>>>>>> = sum(wgt.vect); return(c(c1,c2)); } ineqconstr.fun <
>>>>>> function(wgt.vect) { wgt.vect[1:60]; } opt.fun <
>>>>>> function(wgt.vect) {crossprod(wgt.vect,t(Ret.vect))}
>>>>>>
>>>>>> OptimSolution <
>>>>>> solnp(wgt.vect,opt.fun,constr.fun,eqB=c(0.002,1),ineqconstr.fun,ine
> qL
>>>>>> B =minConstraints,ineqUB=maxConstraints)
>>>>>>
>>>>>> I get the following error: solnp> Solution not
>>>>>> reliable....Problem Inverting Hessian.
>>>>>>
>>>>>> Well, that doesn't tell me very much! The parameters
>>>>>> (weights) that are output for each run, as I cycle through
>>>>>> the weights, are very scrambled...lots of little allocations,
>>>>>> rather than clumping as you would expect to happen especially
>>>>>> at the risky and riskless ends of the spectrum.
>>>>>>
>>>>>> Can anyone with more math than me give me a helping hand on
>>>>>> the Hessian?
>>>>>>
>>>>>> Thanks,
>>>>>>
>>>>>>
>>>>>> Mike
>>>>>>
>>>>>> Michael Ashton, CFA Managing Principal
>>>>>>
>>>>>> Enduring Investments LLC W: 973.457.4602 C: 551.655.8006
>>>>>>
>>>>>>
>>>>>> ________________________________ This email and any
>>>>>> attachments are confidential and inte...{{dropped:9}}
>>>>>>
>>>>>> _______________________________________________
>>>>>> [hidden email] mailing list
>>>>>> https://stat.ethz.ch/mailman/listinfo/rsigfinance 
>>>>>> Subscriberposting only. If you want to post, subscribe
>>>>>> first.  Also note that this is not the rhelp list where
>>>>>> general R questions should go.
>>>>>
>>>>> This email and any attachments are confidential and intended
>>>>> only for the recipient noted above. You are hereby notified
>>>>> that any use, printing, copying or disclosure is strictly
>>>>> prohibited without the permission of Enduring Investments LLC.
>>>>> For further information please contact:
>>>>> [hidden email]; (973) 4574602.
>>>>
>>>> This email and any attachments are confidential and
>>>> in...{{dropped:6}}
>>>
>>> _______________________________________________
>>> [hidden email] mailing list
>>> https://stat.ethz.ch/mailman/listinfo/rsigfinance 
>>> Subscriberposting only. If you want to post, subscribe first. 
>>> Also note that this is not the rhelp list where general R
>>> questions should go.
>>
>> This email and any attachments are confidential and intended only for
>> the recipient noted above. You are hereby notified that any use,
>> printing, copying or disclosure is strictly prohibited without the
>> permission of Enduring Investments LLC. For further information
>> please contact: [hidden email]; (973) 4574602.
>>
This email and any attachments are confidential and inte...{{dropped:6}}
_______________________________________________
[hidden email] mailing list
https://stat.ethz.ch/mailman/listinfo/rsigfinance Subscriberposting only. If you want to post, subscribe first.
 Also note that this is not the rhelp list where general R questions should go.


WRT scaling I should also add that, while it is almost always the right
thing to do numerically, it does not always make sense in a particular
application. One often does optimization in a situation where the
parameters have different units, or have no units, so the scales are
arbitrary to begin with and rescaling is numerically convenient. In
application like yours, you may be summing things that are all in the
same unit, dollars. Rescaling could mean some are in dollars and some in
millions or billions of dollars. Theoretically, at the maximum of an
unconstrained problem, scaling will not make any difference because the
gradient will be zero in all directions. Practically, there is a
difficulty that the numerical solution stops according to some rule when
it gets "close enough". By rescaling you will be emphasizing the
importance of parameters that really have no effect on the portfolio. It
might be better to simply eliminate the parameters that have no
contribution to the objective. (Take this all with a grain of salt, I
don't know anything about portfolio optimization.)
Paul
On 12/15/2015 10:45 AM, Michael Ashton wrote:
> Understood. I was just noting that Ret.vect spans zero, and thus some
> projected returns will always be pretty close to zero.
>
>> On Dec 15, 2015, at 10:43 AM, Paul Gilbert < [hidden email]>
>> wrote:
>>
>> Just to be clear, when I said "difference between the largest and
>> smallest elements" I am think of the absolute value. It is the
>> scale not the sign that causes problems in optimization. And I
>> cannot commenting on whether you have the correct objective
>> function, just pointing out what would happen numerically with the
>> one you specified.
>>
>> Paul
>>
>>> On 12/15/2015 10:17 AM, Michael Ashton wrote: That is very
>>> interesting. Actually some of the projected returns are negative,
>>> some are very close to zero. None is exactly zero, which I guess
>>> is why it's not singular, but that's why it's illconditioned.
>>> Very interesting. And hard to solve...if I add 5% to all returns
>>> will I still get the same portfolio? Seems to me intuitively I
>>> shouldn't since the proportional risk/return tradeoff then is
>>> greater for the assets on the low end of the spectrum, but I
>>> might be wrong.
>>>
>>> Original Message From: Paul Gilbert
>>> [mailto: [hidden email]] Sent: Tuesday, December 15, 2015
>>> 9:58 AM To: Michael Ashton Cc: Michael Weylandt;
>>> [hidden email] Subject: Re: [RSIGFinance] solnp
>>> Problem Inverting Hessian
>>>
>>> I have not been paying close attention and I've missed something
>>> in this thread, but ...
>>>
>>> I think the hessian in the optimization will be the second
>>> derivative of this function
>>>
>>>>>>> opt.fun < function(wgt.vect)
>>>>>>> {crossprod(wgt.vect,t(Ret.vect))}
>>>
>>> WRT wgt.vect. If there are zero elements in Ret.vect then that
>>> hessian will be singular. And if there are orders of magnitude
>>> difference between the largest and smallest elements in Ret.vect
>>> then the hessian will be illconditioned.
>>>
>>> The illconditioned case is a numerical problem and you might
>>> solve it with a different algorithm, or by better scaling. The
>>> zero case is a theoretical problem, there is not a unique optimal
>>> point but rather whole continuum of optimal points (your
>>> parameters corresponding to the zero elements will not make any
>>> difference in the function value).
>>>
>>> HTH, Paul
>>>
>>>> On 12/14/2015 11:39 PM, Michael Weylandt wrote: (+list  I'm
>>>> not a numerical linear algebra expert or portfolio optimization
>>>> expert, but there are a number on this list who might chime
>>>> in)
>>>>
>>>> That is quite high, and almost certainly problematic.
>>>>
>>>> I'm not sure what an acceptable bound is (will depend on your
>>>> solver), but that's almost certainly above it for any
>>>> algorithm which will require inverting cov.mat.
>>>>
>>>> Two things you could try:  use a different
>>>> (nonHessianusing) optimization algorithm;  use some form of
>>>> shrinkage/regularization (LedoitWolf is a common choice) to
>>>> tame your covariance matrix.
>>>>
>>>> Michael
>>>>
>>>> On Mon, Dec 14, 2015 at 10:10 PM, Michael Ashton
>>>> < [hidden email]> wrote:
>>>>> Well, not sure whether this makes any sense but
>>>>> kappa(cov.mat) gives me 11148245007.
>>>>>
>>>>> That seems large. But I am not sure what it is supposed to
>>>>> be.
>>>>>
>>>>> Original Message From: Michael Weylandt
>>>>> [mailto: [hidden email]] Sent: Monday, December
>>>>> 14, 2015 9:29 PM To: Michael Ashton Cc:
>>>>> [hidden email] Subject: Re: [RSIGFinance]
>>>>> solnp Problem Inverting Hessian
>>>>>
>>>>> What's the condition number of your correlation/covariance
>>>>> matrix? (?kappa)
>>>>>
>>>>> I think I've used quadprog for portfolio optimization with
>>>>> success, but it's been a while.
>>>>>
>>>>> MW
>>>>>
>>>>> On Mon, Dec 14, 2015 at 8:06 PM, Michael Ashton
>>>>> < [hidden email]> wrote:
>>>>>> Do you have a suggestion for such? I have in the past
>>>>>> tried fPortfolio, but it would not allow me to specify my
>>>>>> own projected return vectors rather than the historical
>>>>>> returns of the series (which is exactly backwards).
>>>>>>
>>>>>> As for whether the matrix is comfortably nonsingular...I
>>>>>> suppose it depends in a Clintonian way on the meaning of
>>>>>> "comfortably," but I can create a Cholesky decomposition
>>>>>> without it blowing up, which is usually how I can tell if
>>>>>> I have done something stupid. Well, stupider than normal.
>>>>>>
>>>>>> Original Message From: Michael Weylandt
>>>>>> [mailto: [hidden email]] Sent: Monday, December
>>>>>> 14, 2015 8:32 PM To: Michael Ashton Cc:
>>>>>> [hidden email] Subject: Re: [RSIGFinance]
>>>>>> solnp Problem Inverting Hessian
>>>>>>
>>>>>> The Hessian is the matrix of second derivatives
>>>>>> ( https://en.wikipedia.org/wiki/Hessian_matrix)  in
>>>>>> scalar terms, you're finding a point where the second
>>>>>> derivative is zero and then trying to divide by the second
>>>>>> derivative to calculate the step size.
>>>>>>
>>>>>> I haven't gone through your code in any detail, but I'd
>>>>>> start by checking the covariance matrix since that's
>>>>>> proportional to the Hessian of your objective function. Is
>>>>>> it (comfortably) nonsingular?
>>>>>>
>>>>>> Since you're just solving the standard Markowitz problem,
>>>>>> you might try a simpler (quadratic/convex) solver instead
>>>>>> of a general nonlinear solver. Should behave a bit
>>>>>> better.
>>>>>>
>>>>>> Michael
>>>>>>
>>>>>>
>>>>>> On Mon, Dec 14, 2015 at 6:13 PM, Michael Ashton
>>>>>> < [hidden email]> wrote:
>>>>>>> I must admit to being flummoxed here, mainly because my
>>>>>>> linear algebra was 25 years ago and I can't remember what
>>>>>>> a Hessian is.
>>>>>>>
>>>>>>> I have a matrix of 60 securities' weekly returns, along
>>>>>>> with 60 projected returns. The returns are in a vector
>>>>>>> called Ret.vect and the covariance matrix of weekly
>>>>>>> returns in cov.mat . I have the minConstraints and
>>>>>>> maxConstraints that the parameters are permitted to take.
>>>>>>> I cycle through targeted risks and get the same error for
>>>>>>> each risk targeted...below I have removed the loop to
>>>>>>> focus on the risk=0.002.
>>>>>>>
>>>>>>> wgt.vect=c(rep(1/60, 60)) constr.fun <
>>>>>>> function(wgt.vect) {; c1 = sqrt(crossprod(t(wgt.vect %*%
>>>>>>> cov.mat),wgt.vect)); c2 = sum(wgt.vect);
>>>>>>> return(c(c1,c2)); } ineqconstr.fun < function(wgt.vect)
>>>>>>> { wgt.vect[1:60]; } opt.fun < function(wgt.vect)
>>>>>>> {crossprod(wgt.vect,t(Ret.vect))}
>>>>>>>
>>>>>>> OptimSolution <
>>>>>>> solnp(wgt.vect,opt.fun,constr.fun,eqB=c(0.002,1),ineqconstr.fun,ine
>>
>>>>>>>
qL
>>>>>>> B =minConstraints,ineqUB=maxConstraints)
>>>>>>>
>>>>>>> I get the following error: solnp> Solution not
>>>>>>> reliable....Problem Inverting Hessian.
>>>>>>>
>>>>>>> Well, that doesn't tell me very much! The parameters
>>>>>>> (weights) that are output for each run, as I cycle
>>>>>>> through the weights, are very scrambled...lots of little
>>>>>>> allocations, rather than clumping as you would expect to
>>>>>>> happen especially at the risky and riskless ends of the
>>>>>>> spectrum.
>>>>>>>
>>>>>>> Can anyone with more math than me give me a helping hand
>>>>>>> on the Hessian?
>>>>>>>
>>>>>>> Thanks,
>>>>>>>
>>>>>>>
>>>>>>> Mike
>>>>>>>
>>>>>>> Michael Ashton, CFA Managing Principal
>>>>>>>
>>>>>>> Enduring Investments LLC W: 973.457.4602 C: 551.655.8006
>>>>>>>
>>>>>>>
>>>>>>> ________________________________ This email and any
>>>>>>> attachments are confidential and inte...{{dropped:9}}
>>>>>>>
>>>>>>> _______________________________________________
>>>>>>> [hidden email] mailing list
>>>>>>> https://stat.ethz.ch/mailman/listinfo/rsigfinance 
>>>>>>> Subscriberposting only. If you want to post, subscribe
>>>>>>> first.  Also note that this is not the rhelp list
>>>>>>> where general R questions should go.
>>>>>>
>>>>>> This email and any attachments are confidential and
>>>>>> intended only for the recipient noted above. You are hereby
>>>>>> notified that any use, printing, copying or disclosure is
>>>>>> strictly prohibited without the permission of Enduring
>>>>>> Investments LLC. For further information please contact:
>>>>>> [hidden email]; (973) 4574602.
>>>>>
>>>>> This email and any attachments are confidential and
>>>>> in...{{dropped:6}}
>>>>
>>>> _______________________________________________
>>>> [hidden email] mailing list
>>>> https://stat.ethz.ch/mailman/listinfo/rsigfinance 
>>>> Subscriberposting only. If you want to post, subscribe first.
>>>>  Also note that this is not the rhelp list where general R
>>>> questions should go.
>>>
>>> This email and any attachments are confidential and intended only
>>> for the recipient noted above. You are hereby notified that any
>>> use, printing, copying or disclosure is strictly prohibited
>>> without the permission of Enduring Investments LLC. For further
>>> information please contact: [hidden email];
>>> (973) 4574602.
>>>
>
> This email and any attachments are confidential and in...{{dropped:7}}
_______________________________________________
[hidden email] mailing list
https://stat.ethz.ch/mailman/listinfo/rsigfinance Subscriberposting only. If you want to post, subscribe first.
 Also note that this is not the rhelp list where general R questions should go.


In addition to Paul's comments I have noticed with a large number of assets when the correlation matrix is hand cooked (not estimated) it often could end up with small eigenvalues which are arbitrarily close to zero and hessian blows up this could well be the cause of the issue here. A minimum reproducible example would help diagnose your problem better.

> On Dec 15, 2015, at 10:17 AM, Michael Ashton < [hidden email]> wrote:
>
> That is very interesting. Actually some of the projected returns are negative, some are very close to zero. None is exactly zero, which I guess is why it's not singular, but that's why it's illconditioned. Very interesting. And hard to solve...if I add 5% to all returns will I still get the same portfolio? Seems to me intuitively I shouldn't since the proportional risk/return tradeoff then is greater for the assets on the low end of the spectrum, but I might be wrong.
>
> Original Message
> From: Paul Gilbert [mailto: [hidden email]]
> Sent: Tuesday, December 15, 2015 9:58 AM
> To: Michael Ashton
> Cc: Michael Weylandt; [hidden email]
> Subject: Re: [RSIGFinance] solnp Problem Inverting Hessian
>
> I have not been paying close attention and I've missed something in this thread, but ...
>
> I think the hessian in the optimization will be the second derivative of this function
>
>>>>> opt.fun < function(wgt.vect) {crossprod(wgt.vect,t(Ret.vect))}
>
> WRT wgt.vect. If there are zero elements in Ret.vect then that hessian will be singular. And if there are orders of magnitude difference between the largest and smallest elements in Ret.vect then the hessian will be illconditioned.
>
> The illconditioned case is a numerical problem and you might solve it with a different algorithm, or by better scaling. The zero case is a theoretical problem, there is not a unique optimal point but rather whole continuum of optimal points (your parameters corresponding to the zero elements will not make any difference in the function value).
>
> HTH,
> Paul
>
>> On 12/14/2015 11:39 PM, Michael Weylandt wrote:
>> (+list  I'm not a numerical linear algebra expert or portfolio
>> optimization expert, but there are a number on this list who might
>> chime in)
>>
>> That is quite high, and almost certainly problematic.
>>
>> I'm not sure what an acceptable bound is (will depend on your solver),
>> but that's almost certainly above it for any algorithm which will
>> require inverting cov.mat.
>>
>> Two things you could try:
>>  use a different (nonHessianusing) optimization algorithm;
>>  use some form of shrinkage/regularization (LedoitWolf is a common
>> choice) to tame your covariance matrix.
>>
>> Michael
>>
>> On Mon, Dec 14, 2015 at 10:10 PM, Michael Ashton
>> < [hidden email]> wrote:
>>> Well, not sure whether this makes any sense but kappa(cov.mat) gives me 11148245007.
>>>
>>> That seems large. But I am not sure what it is supposed to be.
>>>
>>> Original Message
>>> From: Michael Weylandt [mailto: [hidden email]]
>>> Sent: Monday, December 14, 2015 9:29 PM
>>> To: Michael Ashton
>>> Cc: [hidden email]
>>> Subject: Re: [RSIGFinance] solnp Problem Inverting Hessian
>>>
>>> What's the condition number of your correlation/covariance matrix?
>>> (?kappa)
>>>
>>> I think I've used quadprog for portfolio optimization with success, but it's been a while.
>>>
>>> MW
>>>
>>>> On Mon, Dec 14, 2015 at 8:06 PM, Michael Ashton < [hidden email]> wrote:
>>>> Do you have a suggestion for such? I have in the past tried fPortfolio, but it would not allow me to specify my own projected return vectors rather than the historical returns of the series (which is exactly backwards).
>>>>
>>>> As for whether the matrix is comfortably nonsingular...I suppose it depends in a Clintonian way on the meaning of "comfortably," but I can create a Cholesky decomposition without it blowing up, which is usually how I can tell if I have done something stupid. Well, stupider than normal.
>>>>
>>>> Original Message
>>>> From: Michael Weylandt [mailto: [hidden email]]
>>>> Sent: Monday, December 14, 2015 8:32 PM
>>>> To: Michael Ashton
>>>> Cc: [hidden email]
>>>> Subject: Re: [RSIGFinance] solnp Problem Inverting Hessian
>>>>
>>>> The Hessian is the matrix of second derivatives
>>>> ( https://en.wikipedia.org/wiki/Hessian_matrix)  in scalar terms, you're finding a point where the second derivative is zero and then trying to divide by the second derivative to calculate the step size.
>>>>
>>>> I haven't gone through your code in any detail, but I'd start by checking the covariance matrix since that's proportional to the Hessian of your objective function. Is it (comfortably) nonsingular?
>>>>
>>>> Since you're just solving the standard Markowitz problem, you might try a simpler (quadratic/convex) solver instead of a general nonlinear solver. Should behave a bit better.
>>>>
>>>> Michael
>>>>
>>>>
>>>>> On Mon, Dec 14, 2015 at 6:13 PM, Michael Ashton < [hidden email]> wrote:
>>>>> I must admit to being flummoxed here, mainly because my linear algebra was 25 years ago and I can't remember what a Hessian is.
>>>>>
>>>>> I have a matrix of 60 securities' weekly returns, along with 60 projected returns. The returns are in a vector called Ret.vect and the covariance matrix of weekly returns in cov.mat . I have the minConstraints and maxConstraints that the parameters are permitted to take. I cycle through targeted risks and get the same error for each risk targeted...below I have removed the loop to focus on the risk=0.002.
>>>>>
>>>>> wgt.vect=c(rep(1/60, 60))
>>>>> constr.fun < function(wgt.vect) {;
>>>>> c1 = sqrt(crossprod(t(wgt.vect %*% cov.mat),wgt.vect));
>>>>> c2 = sum(wgt.vect);
>>>>> return(c(c1,c2));
>>>>> }
>>>>> ineqconstr.fun < function(wgt.vect) {
>>>>> wgt.vect[1:60];
>>>>> }
>>>>> opt.fun < function(wgt.vect) {crossprod(wgt.vect,t(Ret.vect))}
>>>>>
>>>>> OptimSolution <
>>>>> solnp(wgt.vect,opt.fun,constr.fun,eqB=c(0.002,1),ineqconstr.fun,ine
>>>>> qL
>>>>> B
>>>>> =minConstraints,ineqUB=maxConstraints)
>>>>>
>>>>> I get the following error:
>>>>> solnp> Solution not reliable....Problem Inverting Hessian.
>>>>>
>>>>> Well, that doesn't tell me very much! The parameters (weights) that are output for each run, as I cycle through the weights, are very scrambled...lots of little allocations, rather than clumping as you would expect to happen especially at the risky and riskless ends of the spectrum.
>>>>>
>>>>> Can anyone with more math than me give me a helping hand on the Hessian?
>>>>>
>>>>> Thanks,
>>>>>
>>>>>
>>>>> Mike
>>>>>
>>>>> Michael Ashton, CFA
>>>>> Managing Principal
>>>>>
>>>>> Enduring Investments LLC
>>>>> W: 973.457.4602
>>>>> C: 551.655.8006
>>>>>
>>>>>
>>>>> ________________________________
>>>>> This email and any attachments are confidential and
>>>>> inte...{{dropped:9}}
>>>>>
>>>>> _______________________________________________
>>>>> [hidden email] mailing list
>>>>> https://stat.ethz.ch/mailman/listinfo/rsigfinance>>>>>  Subscriberposting only. If you want to post, subscribe first.
>>>>>  Also note that this is not the rhelp list where general R questions should go.
>>>>
>>>> This email and any attachments are confidential and intended only for the recipient noted above. You are hereby notified that any use, printing, copying or disclosure is strictly prohibited without the permission of Enduring Investments LLC. For further information please contact: [hidden email]; (973) 4574602.
>>>
>>> This email and any attachments are confidential and
>>> in...{{dropped:6}}
>>
>> _______________________________________________
>> [hidden email] mailing list
>> https://stat.ethz.ch/mailman/listinfo/rsigfinance>>  Subscriberposting only. If you want to post, subscribe first.
>>  Also note that this is not the rhelp list where general R questions should go.
>
> This email and any attachments are confidential and in...{{dropped:8}}
_______________________________________________
[hidden email] mailing list
https://stat.ethz.ch/mailman/listinfo/rsigfinance Subscriberposting only. If you want to post, subscribe first.
 Also note that this is not the rhelp list where general R questions should go.

