Re: [ojAlgo-user] Report A Bug Of ojalgo finace library
Mathematics, linear algebra and optimisation
Brought to you by:
apete
From: Anders P. <an...@op...> - 2017-05-09 21:32:56
|
Haven’t fully understood yet why that small/simple model is so problematic. The covariance matrix is not positive definite, Strictly speaking it needs to be, but most of the time semidefinite is ok. Setting a target return or variance is not the best way to use ojAlgo’s MarkowitzModel class. Work directly with the risk aversion factor instead. If what you want to do is to calculate the efficient frontier then it’s better to use the EfficientFrontier class rather than the MarkowitzModel class. /Anders > On 8 May 2017, at 14:20, lvz...@gt... wrote: > > > Hi, > I have a problem when calculate best invest group by using markowitzModel in ojalgo with code below(for test); > > > > > for(int j = 0; j < 100; j ++) > { Builder<PrimitiveMatrix> tmpBuilder = PrimitiveMatrix.FACTORY.getBuilder(2, 2); > tmpBuilder.add(0, 0, 0.040000); > tmpBuilder.add(0, 1, 0.1000); > tmpBuilder.add(1, 0, 0.1000); > tmpBuilder.add(1, 1, 0.250000); > BasicMatrix covariances = tmpBuilder.build(); > tmpBuilder = PrimitiveMatrix.FACTORY.getBuilder(2); > tmpBuilder.add(0, 0.20000); > tmpBuilder.add(1, 0.40000); > BasicMatrix expectedExcessReturns = tmpBuilder.build(); > > MarketEquilibrium equilibrium = new MarketEquilibrium(covariances); > MarkowitzModel markowitzModel = new MarkowitzModel(equilibrium, expectedExcessReturns); > markowitzModel.setShortingAllowed(false); > // markowitzModel.optimiser().validate(true); > markowitzModel.setTargetReturn(new BigDecimal(0.2 + (0.002 * j))); > for (int i = 0; i < 2; i++) { > markowitzModel.setLowerLimit(i, new BigDecimal(0.00000)); > markowitzModel.setUpperLimit(i, new BigDecimal(1.00000)); > } > System.out.println(0.2 + (0.002 * j) + "," + markowitzModel.getReturnVariance() + " , " + markowitzModel.getMeanReturn() + "," + markowitzModel.getWeights()); > > > } > > > when TargetReturn equal to 0.206,Variance equal to 0.04 , weights equal to [1.0, 0.0] > when TargetReturn equal to 0.208, Variance equal to 0.25,weights equal to [0.0, 1.0] > Below Relationship of TargetReturn And Target Variance(Y-Axis TargetReturn,X-AXis standard deviation) > > > > 吕子锋 > > <1.jpg>------------------------------------------------------------------------------ > Check out the vibrant tech community on one of the world's most > engaging tech sites, Slashdot.org! http://sdm.link/slashdot_______________________________________________ > ojAlgo-user mailing list > ojA...@li... > https://lists.sourceforge.net/lists/listinfo/ojalgo-user |