Re: [ojAlgo-user] Markowitz optimisation
Mathematics, linear algebra and optimisation
Brought to you by:
apete
From: Arthur M. <art...@be...> - 2008-01-18 16:34:40
|
Hi Anders, Here's the test case for zero weightings at default risk aversion factor. Changing the RAF to "1" works although I'm wondering whether a better solut= ion would be with the 0.35% and 0.25% weights swapped round. All other ass= ets get a 0.05% weight. regards Arthur public void testEfficientFrontier2() { // create expected returns matrix PrimitiveMatrix expectedReturnsMatrix =3D new PrimitiveMatrix(new double[= ][] { {10.003264}, {9.989771}, {9.987513}, {9.988449}, {9.996579}, {9.99069= 0}, {9.994904}, {9.994514}, {9.984064}, {9.987534}}); // create covariance matrix PrimitiveMatrix covarianceMatrix =3D new PrimitiveMatrix(new double[][] {= {6.483565230120298E-4, -1.3344603795915894E-4, -4.610345510893708E-4, -7.33= 4405624030001E-4, 1.1551383115707195E-5, -0.00104145662863434, -1.072589668= 5568462E-4, -1.221384153392056E-4, -4.173413644389791E-4, -2.48610438949469= 35E-4}, {-1.3344603795915894E-4, 0.0026045957224784455, 0.0012394355327235707, = 9.243919166568456E-4, -8.653805945112411E-5, 8.100239312410631E-4, 4.215960= 274481846E-4, 5.243272007211247E-4, 0.0013062718630332956, 1.47664502933954= 05E-4}, {-4.610345510893708E-4, 0.0012394355327235707, 0.002361436913752224, 0.= 0020101714731002238, -1.4236763916609785E-5, 0.002120395905829043, 5.399158= 658928662E-4, 5.048790842067473E-4, 0.0014855261720730444, 4.84145810618139= 6E-4}, {-7.334405624030001E-4, 9.243919166568456E-4, 0.0020101714731002238, 0.= 0028542819089926895, -4.311102526746861E-6, 0.0028465650900869476, 6.242643= 883624462E-4, 4.086484048798765E-4, 0.001647437646316569, 7.58419663970477E= -4}, {1.1551383115707195E-5, -8.653805945112411E-5, -1.4236763916609785E-5, = -4.311102526746861E-6, 1.213366124417227E-4, -9.027529241741836E-5, 7.24138= 9994693716E-6, -3.166855950737129E-5, -1.2445276374560802E-5, -5.3976919759= 028745E-5}, {-0.00104145662863434, 8.100239312410631E-4, 0.002120395905829043, 0.00= 28465650900869476, -9.027529241741836E-5, 0.0064756879298965295, 2.80762775= 64885113E-4, 3.6082073553997553E-4, 0.001945238279500792, 0.001242113234298= 8626}, {-1.0725896685568462E-4, 4.215960274481846E-4, 5.399158658928662E-4, 6.= 242643883624462E-4, 7.241389994693716E-6, 2.8076277564885113E-4, 0.00101215= 00024739688, 8.206099676659543E-5, 1.6129237403855146E-4, 7.550465994733837= E-4}, {-1.221384153392056E-4, 5.243272007211247E-4, 5.048790842067473E-4, 4.0= 86484048798765E-4, -3.166855950737129E-5, 3.6082073553997553E-4, 8.20609967= 6659543E-5, 4.504461842318998E-4, 4.7980942831718363E-4, -4.763223568683059= E-5}, {-4.173413644389791E-4, 0.0013062718630332956, 0.0014855261720730444, 0= .001647437646316569, -1.2445276374560802E-5, 0.001945238279500792, 1.612923= 7403855146E-4, 4.7980942831718363E-4, 0.002228245076175045, 3.2083564921169= 634E-4}, {-2.4861043894946935E-4, 1.4766450293395405E-4, 4.841458106181396E-4, 7= .58419663970477E-4, -5.3976919759028745E-5, 0.0012421132342988626, 7.550465= 994733837E-4, -4.763223568683059E-5, 3.2083564921169634E-4, 0.0017093327832= 123186}}); MarketEquilibrium myMarket =3D new MarketEquilibrium(covarianceMatrix); // create asset variables - cost and weighting constraints Variable[] tmpVariables =3D new Variable[expectedReturnsMatrix.getRowDim(= )]; for (int i =3D 0; i < tmpVariables.length; i++) { tmpVariables[i] =3D new Variable(""); tmpVariables[i].setCost(expectedReturnsMatrix.toBigDecimal(i, 0).negate(= )); // set the constraints on the asset weights // require at least a 2% allocation to each asset tmpVariables[i].setLowerLimit(new BigDecimal("0.05")); // require no more than 80% allocation to each asset tmpVariables[i].setUpperLimit(new BigDecimal("0.35")); } QuadraticModel quadModel =3D new QuadraticModel(tmpVariables); Expression tmpExpr =3D quadModel.addCorrelationExpression("Variance", cov= arianceMatrix.toBigStore().toArray()); BigDecimal tmpRiskAversion =3D myMarket.getRiskAversion(); tmpExpr.setCost(tmpRiskAversion.multiply(BigMath.HALF)); // set balance expression tmpExpr =3D quadModel.addSimpleWeightExpression("Balance"); tmpExpr.setLowerLimit(BigMath.ONE); tmpExpr.setUpperLimit(BigMath.ONE); // exception here... BasicMatrix bm =3D BigMatrix.FACTORY.buildColumnVector(quadModel.getDefau= ltSolver().getSolution()); =09 System.out.print(bm.toString()); } ******************************************************************** This message and any attachment are confidential. If you are not the inten= ded recipient please contact the sender, delete this message and any attach= ment from your system and do not disclose, copy or distribute the contents = to any other person. Beach Horizon LLP (Beach Horizon) is not responsible = for any information contained in this email. Beach Horizon reserves the ri= ght to monitor all email messages passing through its network. ******************************************************************** |