[ojAlgo-user] Markowitz Problem
Mathematics, linear algebra and optimisation
Brought to you by:
apete
From: Matteo B. <mat...@gm...> - 2013-03-29 12:19:49
|
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) ); } } } } |