Re: [ojAlgo-user] Markowitz optimisation
Mathematics, linear algebra and optimisation
Brought to you by:
apete
From: Anders P. <an...@op...> - 2008-01-19 01:22:51
|
Works now. /Anders ############################################ 0.050 <= : 0.350 (-10.003) <= 0.350 0.050 <= : 0.050 (-9.990) <= 0.350 0.050 <= : 0.050 (-9.988) <= 0.350 0.050 <= : 0.050 (-9.988) <= 0.350 0.050 <= : 0.250 (-9.997) <= 0.350 0.050 <= : 0.050 (-9.991) <= 0.350 0.050 <= : 0.050 (-9.995) <= 0.350 0.050 <= : 0.050 (-9.995) <= 0.350 0.050 <= : 0.050 (-9.984) <= 0.350 0.050 <= : 0.050 (-9.988) <= 0.350 Variance: 0.001 (4.270) 1.000 <= Balance: 1.000 <= 1.000 ############################################ On 18 jan 2008, at 17.31, Arthur McGibbon wrote: > 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 solution would be with the 0.35% and 0.25% weights swapped > round. All other assets get a 0.05% weight. > > regards > Arthur > > public void testEfficientFrontier2() > { > // create expected returns matrix > PrimitiveMatrix expectedReturnsMatrix = new PrimitiveMatrix(new > double[][] { {10.003264}, {9.989771}, {9.987513}, {9.988449}, > {9.996579}, {9.990690}, {9.994904}, {9.994514}, {9.984064}, > {9.987534}}); > // create covariance matrix > PrimitiveMatrix covarianceMatrix = new PrimitiveMatrix(new double > [][] > {{6.483565230120298E-4, -1.3344603795915894E-4, -4.610345510893708E-4, > -7.334405624030001E-4, > 1.1551383115707195E-5, -0.00104145662863434, -1.0725896685568462E-4, - > 1.221384153392056E-4, -4.173413644389791E-4, -2.4861043894946935E-4}, > {-1.3344603795915894E-4, 0.0026045957224784455, > 0.0012394355327235707, 9.243919166568456E-4, -8.653805945112411E-5, > 8.100239312410631E-4, 4.215960274481846E-4, 5.243272007211247E-4, > 0.0013062718630332956, 1.4766450293395405E-4}, > {-4.610345510893708E-4, 0.0012394355327235707, > 0.002361436913752224, > 0.0020101714731002238, -1.4236763916609785E-5, > 0.002120395905829043, 5.399158658928662E-4, 5.048790842067473E-4, > 0.0014855261720730444, 4.841458106181396E-4}, > {-7.334405624030001E-4, 9.243919166568456E-4, > 0.0020101714731002238, > 0.0028542819089926895, -4.311102526746861E-6, > 0.0028465650900869476, 6.242643883624462E-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.241389994693716E-6, -3.166855950737129E-5, -1.2445276374560802E-5, - > 5.3976919759028745E-5}, > {-0.00104145662863434, 8.100239312410631E-4, > 0.002120395905829043, 0.0028465650900869476, -9.027529241741836E-5, > 0.0064756879298965295, 2.8076277564885113E-4, > 3.6082073553997553E-4, 0.001945238279500792, 0.0012421132342988626}, > {-1.0725896685568462E-4, 4.215960274481846E-4, > 5.399158658928662E-4, 6.242643883624462E-4, 7.241389994693716E-6, > 2.8076277564885113E-4, 0.0010121500024739688, 8.206099676659543E-5, > 1.6129237403855146E-4, 7.550465994733837E-4}, > {-1.221384153392056E-4, 5.243272007211247E-4, > 5.048790842067473E-4, 4.086484048798765E-4, -3.166855950737129E-5, > 3.6082073553997553E-4, 8.206099676659543E-5, 4.504461842318998E-4, > 4.7980942831718363E-4, -4.763223568683059E-5}, > {-4.173413644389791E-4, 0.0013062718630332956, > 0.0014855261720730444, > 0.001647437646316569, -1.2445276374560802E-5, 0.001945238279500792, > 1.6129237403855146E-4, 4.7980942831718363E-4, 0.002228245076175045, > 3.2083564921169634E-4}, > {-2.4861043894946935E-4, 1.4766450293395405E-4, > 4.841458106181396E-4, 7.58419663970477E-4, -5.3976919759028745E-5, > 0.0012421132342988626, 7.550465994733837E-4, -4.763223568683059E-5, > 3.2083564921169634E-4, 0.0017093327832123186}}); > > MarketEquilibrium myMarket = new MarketEquilibrium > (covarianceMatrix); > > // create asset variables - cost and weighting constraints > Variable[] tmpVariables = new Variable > [expectedReturnsMatrix.getRowDim()]; > for (int i = 0; i < tmpVariables.length; i++) > { > tmpVariables[i] = 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 = new QuadraticModel(tmpVariables); > > Expression tmpExpr = quadModel.addCorrelationExpression > ("Variance", covarianceMatrix.toBigStore().toArray()); > BigDecimal tmpRiskAversion = myMarket.getRiskAversion(); > tmpExpr.setCost(tmpRiskAversion.multiply(BigMath.HALF)); > > // set balance expression > tmpExpr = quadModel.addSimpleWeightExpression("Balance"); > tmpExpr.setLowerLimit(BigMath.ONE); > tmpExpr.setUpperLimit(BigMath.ONE); > > // exception here... > BasicMatrix bm = BigMatrix.FACTORY.buildColumnVector > (quadModel.getDefaultSolver().getSolution()); > > System.out.print(bm.toString()); > } > > > ******************************************************************** > This message and any attachment are confidential. If you are not > the intended recipient please contact the sender, delete this > message and any attachment 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 right to > monitor all email messages passing through its network. > ******************************************************************** > > > ---------------------------------------------------------------------- > --- > This SF.net email is sponsored by: Microsoft > Defy all challenges. Microsoft(R) Visual Studio 2008. > http://clk.atdmt.com/MRT/go/vse0120000070mrt/direct/01/ > _______________________________________________ > ojAlgo-user mailing list > ojA...@li... > https://lists.sourceforge.net/lists/listinfo/ojalgo-user > > |