Re: [ojAlgo-user] Markowitz Model Problem - Optimization isssue
Mathematics, linear algebra and optimisation
Brought to you by:
apete
From: Anders P. <an...@op...> - 2009-07-26 21:18:25
|
Try setting the risk aversion factor to something other than 1.0. and/or do this: a) Do NOT set the target return or variance. b) Experiment with different risk aversion factors. Which risk aversion factors gives you portfolio returns 0.003081388 and 0.03360872? (the lowest and highest instrument returns) /Anders On 26 jul 2009, at 12.23, Nilesh Parekh wrote: > Hi..this is slighly modifed version of the already posted issue on > this forum earlier. > I am using ojalgo 2.6 & also tried same code with new beta 2.7 > version but the issue still persists > Below code works fails if i set the expected return to > markowitzModel.setTargetReturn(new BigDecimal("0.01051787")); > any value between 0.01051787 and 0.003081388 (which is the lowest > return in the return matrix) gives same output. > Note: Values (expected rerurn) between 0.01051787 and 0.03360872 > (max. return as per return matrix) works perfectly fine. > Do revert in case of any further clarifications. > --------START CODE--------------- > import java.math.BigDecimal; > import java.util.List; > > import org.ojalgo.finance.portfolio.MarketEquilibrium; > import org.ojalgo.finance.portfolio.MarkowitzModel; > import org.ojalgo.matrix.*; > import org.ojalgo.matrix.store.BigDenseStore; > import org.ojalgo.matrix.store.MatrixStore; > > > public class TestMarkowitz { > > public BasicMatrix getACovariances(double[][] returns){ > > int row = returns.length; > int col = returns[0].length; > MatrixStore<BigDecimal> a = BigDenseStore.FACTORY.makeZero(row, > col); > BasicMatrix covariances = new BigMatrix(a); > > for(int i=1;i<=row;i++){ > for(int j=i;j<=col;j++){ > covariances = covariances.set(i-1, j-1,returns[i-1][j-1]); > covariances = covariances.set(j-1, i-1,returns[j-1][i-1]); > } > > } > return covariances; > } > > > public static void main(String[] args) > { > int assetNum=16; > > > double[][] om={ > {0.003330616,0.003524811,0.00386567,0.003656347,0.004494241,0.004623772,0.00458625,0.004365933,0,0,0,0,0,0,0,0 > }, > {0.003524811,0.004274864,0.004372518,0.004135748,0.005144421,0.005292691,0.005249742,0.004997551,0,0,0,0,0,0,0,0 > }, > {0.00386567,0.004372518,0.005114057,0.004535687,0.005641369,0.005803962,0.005756863,0.005480312,0,0,0,0,0,0,0,0 > }, > {0.003656347,0.004135748,0.004535687,0.004728464,0.005511769,0.005670626,0.00562461,0.005354411,0,0,0,0,0,0,0,0 > }, > {0.004494241,0.005144421,0.005641369,0.005511769,0.007284319,0.006518612,0.006359324,0.00635862,0,0,0,0,0,0,0,0 > }, > {0.004623772,0.005292691,0.005803962,0.005670626,0.006518612,0.007542516,0.006562129,0.006561403,0,0,0,0,0,0,0,0 > }, > {0.00458625,0.005249742,0.005756863,0.00562461,0.006359324,0.006562129,0.007513433,0.00640107,0,0,0,0,0,0,0,0 > }, > {0.004365933,0.004997551,0.005480312,0.005354411,0.00635862,0.006561403,0.00640107,0.006805889,0,0,0,0,0,0,0,0 > }, > {0,0,0,0,0,0,0,0,0.000152891,0.000120753,7.98783E > -05,0.000116607,8.11225E-05,4.31112E-05,6.11874E-05,1.49376E-07}, > {0,0,0,0,0,0,0,0,0.000120753,0.000215819,0.000108447,0.000158311,7.62318E > -05,4.05121E-05,5.74986E-05,1.4037E-07}, > {0,0,0,0,0,0,0,0,7.98783E > -05,0.000108447,0.000251455,0.000104723,0.000105337,5.59796E > -05,7.94514E-05,1.93963E-07}, > {0,0,0,0,0,0,0,0,0.000116607,0.000158311,0.000104723,0.000285454,0.000109622,5.82568E > -05,8.26835E-05,2.01854E-07}, > {0,0,0,0,0,0,0,0,8.11225E > -05,7.62318E > -05,0.000105337,0.000109622,0.000110962,5.62808E > -05,7.47961E-05,1.97502E-06}, > {0,0,0,0,0,0,0,0,4.31112E > -05,4.05121E > -05,5.59796E > -05,5.82568E-05,5.62808E-05,4.12145E-05,4.25652E-05,1.12395E-06}, > {0,0,0,0,0,0,0,0,6.11874E > -05,5.74986E > -05,7.94514E > -05,8.26835E-05,7.47961E-05,4.25652E-05,7.62351E-05,1.4937E-06}, > {0,0,0,0,0,0,0,0,1.49376E > -07,1.4037E > -07,1.93963E > -07,2.01854E-07,1.97502E-06,1.12395E-06,1.4937E-06,6.52443E-06} > }; > > TestMarkowitz tm = new TestMarkowitz(); > > BasicMatrix covariances = tm.getACovariances(om); > > System.out.println(covariances); > > BigDecimal riskAversion = new BigDecimal(1.0); > > MarketEquilibrium marketEquilibrium = new > MarketEquilibrium(covariances,riskAversion); > > MatrixStore<BigDecimal> ret_matrix = BigDenseStore.FACTORY.makeZero > (assetNum, 1); > BasicMatrix expectedExcessReturns1 = new BigMatrix(ret_matrix); > > expectedExcessReturns1 = expectedExcessReturns1.set(0,0,0.03360872); > expectedExcessReturns1 = expectedExcessReturns1.set(1,0,0.027322319); > expectedExcessReturns1 = expectedExcessReturns1.set(2,0,0.027668137); > expectedExcessReturns1 = expectedExcessReturns1.set(3,0,0.03080239); > expectedExcessReturns1 = expectedExcessReturns1.set(4,0,0.025067124); > expectedExcessReturns1 = expectedExcessReturns1.set(5,0,0.016578507); > expectedExcessReturns1 = expectedExcessReturns1.set(6,0,0.022622714); > expectedExcessReturns1 = expectedExcessReturns1.set(7,0,0.028957183); > expectedExcessReturns1 = expectedExcessReturns1.set(8,0,0.009939058); > expectedExcessReturns1 = expectedExcessReturns1.set(9,0,0.010014445); > expectedExcessReturns1 = expectedExcessReturns1.set(10,0,0.011565874); > expectedExcessReturns1 = expectedExcessReturns1.set(11,0,0.011609169); > expectedExcessReturns1 = expectedExcessReturns1.set(12,0,0.006286505); > expectedExcessReturns1 = expectedExcessReturns1.set(13,0,0.004240681); > expectedExcessReturns1 = expectedExcessReturns1.set(14,0,0.006162067); > expectedExcessReturns1 = expectedExcessReturns1.set(15,0,0.003081388); > > System.out.println("Return Matrix" + expectedExcessReturns1); > > MarkowitzModel markowitzModel = new > MarkowitzModel(marketEquilibrium,expectedExcessReturns1); > > markowitzModel.setTargetReturn(new BigDecimal("0.01051787")); > > for(int i=0;i<assetNum;i++){ > markowitzModel.setLowerLimit(i, new BigDecimal(0.0)); > markowitzModel.setUpperLimit(i, new BigDecimal(1.0)); > } > > List<BigDecimal> re = markowitzModel.getWeights(); > > > System.out.println("=======result===================="); > for(int i=0;i<re..size();i++) > System.out.println(re.get(i)); > > System.out.println("=======result===================="); > System.out.println(markowitzModel.getMeanReturn()); > System.out.println(markowitzModel.getReturnVariance()); > return; > } > > } > > --------END CODE--------------- > -- > > Regards....Nilesh > ------------------------------------------------------------------------------ > _______________________________________________ > ojAlgo-user mailing list > ojA...@li... > https://lists.sourceforge.net/lists/listinfo/ojalgo-user |