Re: [ojAlgo-user] Markowitz Problem
Mathematics, linear algebra and optimisation
Brought to you by:
apete
From: Anders P. <an...@op...> - 2013-03-31 09:38:57
|
Yes, ojAlgo seems to have a problem solving that. I'll have to look into exactly what goes on. The covariance matrix is positive semidefinite, right? That should be enough, but positive definite would be better. You should always check the optimisation state. In this case it is APPROXIMATE. Suppose it should be FAILED or something, but anything less that OPTIMAL would indicate a problem with the underlying optimisation algorithm. Regarding how to create matrices; I think you should read this: http://code.google.com/p/ojalgo/wiki/GettingStartedLinearAlgebra /Anders On 29 mar 2013, at 13:19, Matteo Baccan <mat...@gm...> wrote: > Hi > > we have a problem with MarkowitzModel. > I have produced a little source that explain the problem. > > We have set 3 different TargetReturn on the same data.. > > With targets near to the best end worst target return, the MarkowitzModel works fine. > With targets within the interval of best and worst return, seem that the MarkowitzModel > is not able to find a correct list of weights. > > If you try this program and use target of 0.08 or 0.13 or 0.12 you can see a correct solution. > With a target of 0.10 MarkowitzModel is not able to find a valid solution. > > It's a OJAlgo bug or is a problem in my implementation? > > All the best > Matteo Baccan > > > > import java.math.BigDecimal; > import java.util.List; > > import org.ojalgo.access.AccessUtils; > import org.ojalgo.constant.BigMath; > import org.ojalgo.finance.portfolio.MarketEquilibrium; > import org.ojalgo.finance.portfolio.MarkowitzModel; > import org.ojalgo.matrix.BasicMatrix; > import org.ojalgo.matrix.BigMatrix; > import org.ojalgo.matrix.PrimitiveMatrix; > import org.ojalgo.matrix.store.BigDenseStore; > import org.ojalgo.matrix.store.MatrixStore; > import org.ojalgo.matrix.store.PrimitiveDenseStore; > import org.ojalgo.optimisation.Optimisation; > import org.ojalgo.optimisation.quadratic.QuadraticSolver; > > public class MarkowitzProblems > { > > public static void main(String[] args) > { > > //BigDecimal nTarget = new BigDecimal("0.08"); // OK > // 0.0 > // 1.0 > > BigDecimal nTarget = new BigDecimal("0.10"); // ERROR > // -0.9999 > // 1.9999 > > //BigDecimal nTarget = new BigDecimal("0.13"); // OK > // 0.8333 > // 0.1667 > > double[][] cm= > {{0.00360000, 0.001800000000}, > {0.001800000000, 0.00090000}} > ; > > int assetNum = cm.length; > > final int row = cm.length; > if (row > 0) { > final int col = cm[0].length; > final MatrixStore<BigDecimal> a = BigDenseStore.FACTORY.makeZero(row, col); > BasicMatrix covariances = BigMatrix.FACTORY.copy(a); > > for (int i = 0; i < row; i++) { > for (int j = 0; j < col; j++) { > covariances = covariances.replace(i, j, cm[i][j]); > } > } > > double nRisk = 1000.0; > final BigDecimal riskAversion = new BigDecimal(nRisk); > final MarketEquilibrium marketEquilibrium = new MarketEquilibrium(covariances, riskAversion); > > final MatrixStore<BigDecimal> ret_matrix = BigDenseStore.FACTORY.makeZero(assetNum, 1); > BasicMatrix expectedExcessReturns1 = BigMatrix.FACTORY.copy(ret_matrix); > > expectedExcessReturns1 = expectedExcessReturns1.replace(0, 0, 0.1400); > expectedExcessReturns1 = expectedExcessReturns1.replace(1, 0, 0.0800); > > final MarkowitzModel markowitzModel = new MarkowitzModel(marketEquilibrium, expectedExcessReturns1); > > markowitzModel.setLowerLimit(0, new BigDecimal(0.0000)); > markowitzModel.setUpperLimit(0, new BigDecimal(1.0000)); > markowitzModel.setLowerLimit(1, new BigDecimal(0.0000)); > markowitzModel.setUpperLimit(1, new BigDecimal(1.0000)); > > boolean bShort = false; > markowitzModel.setShortingAllowed(bShort); > markowitzModel.setTargetReturn(nTarget); > > final List<BigDecimal> re = markowitzModel.getWeights(); > for (int nn = 0; nn < re.size(); nn++) { > System.out.println( re.get(nn) ); > } > } > } > > } > > ------------------------------------------------------------------------------ > Own the Future-Intel(R) Level Up Game Demo Contest 2013 > Rise to greatness in Intel's independent game demo contest. Compete > for recognition, cash, and the chance to get your game on Steam. > $5K grand prize plus 10 genre and skill prizes. Submit your demo > by 6/6/13. http://altfarm.mediaplex.com/ad/ck/12124-176961-30367-2_______________________________________________ > ojAlgo-user mailing list > ojA...@li... > https://lists.sourceforge.net/lists/listinfo/ojalgo-user |