optimatika / ojAlgo

oj! Algorithms
http://ojalgo.org
MIT License
459 stars 207 forks source link

MarkowitzModel is hanging on low target risk #24

Closed realintelligent closed 8 years ago

realintelligent commented 8 years ago

Hello,

I'm using ojAlgo for the MVO purposes. It works good with 33 expected returns. But when I'm passing 35 expected returns in the constructor(and 35 * 35 covariance table) - program is hanging on any get method of MarkowitzModel.

Please let me know if you need more information.

Thanks in advance!

apete commented 8 years ago

Yes, I need more information. MarkowitzModel can certainly handle more than 35 variables/instruments.

If you have a test case that demonstrates this problem I'd like to see it.

realintelligent commented 8 years ago

Hello,

I figured out a problem. Hanging is not caused by the high amount of the inputs, but by the low target risk.

Please find the test case in the attached file. MarkowitzTest.zip

apete commented 8 years ago

That sounds like a more reasonable explanation to the "hanging". Thanks for the test case. I'll have a loom at it.

apete commented 8 years ago

The "hanging" is caused by ending up in some sort of infinite loop in the underlying optimisation algorithm. Haven't studied this is detail yet, but on a higher level the problem is caused by you specifying a covariance matrix that is not positive semidefinite. You should fix that in your program.

apete commented 8 years ago

I've made some improvements but "hanging" with your exact original example still occurs. Short term this will not be fixed. Hanging is of course not good behavior, but the root cause is with the data. You have a problem with your data. Fix that and the hanging will go away.

If you get the latest source from master/HEAD you can now do:

model.optimisation().validate(true);

To fix/clean your covariance matrix one option is to do:

marketEquilibrium.clean();

realintelligent commented 8 years ago

Anders, thanks a lot, got it! I'll try to fix my data.

I have yet another question. Could we build the whole efficient frontier using ojAlgo? For now I'm building it dot by dot and it's not so efficient.

apete commented 8 years ago

These kind of questions are best suited for the ojalgo-user mailing list:

https://sourceforge.net/p/ojalgo/mailman/ojalgo-user/

You have to calculate it dot by dot but all you need to do is change the risk aversion (do not set a target return or variance) to get a new “dot”.

On 18 juli 2016, at 15:33, realintelligent notifications@github.com wrote:

Anders, thanks a lot, got it! I'll try to fix my data.

I have yet another question. Could we build the whole efficient frontier using ojAlgo? For now I'm building it dot by dot and it's not so efficient.

— You are receiving this because you commented. Reply to this email directly, view it on GitHub, or mute the thread.

realintelligent commented 8 years ago

Thanks Anders for you help, got it.

Issue can be closed from my side.