Re: [ojAlgo-user] QuadraticSolver issue
Mathematics, linear algebra and optimisation
Brought to you by:
apete
From: Anders P. <an...@op...> - 2011-06-14 21:05:09
|
Here's what I get: [AE] = class org.ojalgo.matrix.PrimitiveMatrix {{1.0, 1.0, 1.0}} [BE] = class org.ojalgo.matrix.PrimitiveMatrix {{1.0}} [Q] = class org.ojalgo.matrix.PrimitiveMatrix {{4.0, 1.0, 2.0}, {1.0, 9.0, 1.0}, {2.0, 1.0, 16.0}} [C] = class org.ojalgo.matrix.PrimitiveMatrix {{10.0}, {15.0}, {18.0}} [AI] = class org.ojalgo.matrix.PrimitiveMatrix {{1.0, 0.0, 0.0}, {0.0, 1.0, 0.0}, {0.0, 0.0, 1.0}} [BI] = class org.ojalgo.matrix.PrimitiveMatrix {{1.0}, {1.0}, {1.0}} [X] = class org.ojalgo.matrix.PrimitiveMatrix {{-0.17441860465116266}, {0.6279069767441859}, {0.5465116279069767}} [LE] = class org.ojalgo.matrix.PrimitiveMatrix {{8.976744186046512}} [LI] = class org.ojalgo.matrix.PrimitiveMatrix {{0.0}, {0.0}, {0.0}} [SE] = class org.ojalgo.matrix.PrimitiveMatrix {{0.0}} [SI] = class org.ojalgo.matrix.PrimitiveMatrix {{1.1744186046511627}, {0.37209302325581406}, {0.4534883720930233}} I do not get any weights larger than 1.0, but I do get one weight smaller than 0.0. There's no constraint to restrict that! Add constraints for that and you should get the solutions you expect. Here's how I would find the efficient frontier: final BasicMatrix tmpCovars = ...; final BasicMatrix tmpReturs = ...; final MarketEquilibrium tmpME = new MarketEquilibrium(tmpCovars); final MarkowitzModel tmpMarkowitz = new MarkowitzModel(tmpME, tmpReturs); for (int i = 1; i < 10; i++) { // Some different risk aversion factors tmpMarkowitz.setRiskAversion(new BigDecimal(i)); final List<BigDecimal> tmpWeights = tmpMarkowitz.getWeights(); } On 14 jun 2011, at 17.59, Simon Greaves wrote: > Well I made this test case, but it requires a utilities library to load the files that contain the matrices. > You can see what I'm doing but it can't run. > I'm trying to to Efficient Frontier analysis. I tried using the ojAlgo.finance.porfolio.MarkowitzModel class, but I had a lot of trouble understanding the doc file. So I decided to to it myself using the QuadraticSolver, which I had less trouble with... > > I'm solving (as in the doc file): > min 1/2 [X]T[Q][X] - [C]T[X] > when [AE][X] == [BE] > and [AI][X] <= [BI] > > where (in the test case) > Q (Covariance Matrix): > 0.04 0.01 0.02 > 0.01 0.09 0.01 > 0.02 0.01 0.16 > > C (Expected Return Vector): > 0.10 > 0.15 > 0.18 > > The sum of X should be 1 since it's portfolio analysis, and I should use 100% of the investment on all activities. > And every Xi should be between 0 and 1. > So I made AE a vector of 1's and BE=1, so that takes care of sum(X)=1. And > AI is an identity matrix, and BI a 1 vector. So all Xi's should be <=1. > > But as a result I get, for example: [-2.4, 2.4, 1] > > So, I guess I'm not doing things right, and the inequality constraints aren't being respected... > From: Anders Peterson <an...@op...> > To: oja...@li... > Sent: Mon, June 13, 2011 4:55:38 PM > Subject: Re: [ojAlgo-user] QuadraticSolver issue > > What org.ojalgo.optimisation.State do you get? > > Why don't you construct a junit test case to show me exactly what you're doing. > > /Anders > <TempClass.java><COVAR_MATRIX.txt><RETURN.txt><VARS.txt>------------------------------------------------------------------------------ > EditLive Enterprise is the world's most technically advanced content > authoring tool. Experience the power of Track Changes, Inline Image > Editing and ensure content is compliant with Accessibility Checking. > http://p.sf.net/sfu/ephox-dev2dev_______________________________________________ > ojAlgo-user mailing list > ojA...@li... > https://lists.sourceforge.net/lists/listinfo/ojalgo-user |