Re: [ojAlgo-user] Markowitz optimisation
Mathematics, linear algebra and optimisation
Brought to you by:
apete
From: Anders P. <an...@op...> - 2008-01-17 17:22:10
|
I assume this is the solution you want: ############################################ 0.020 <= : 0.020 (0.007) <= 0.800 0.020 <= : 0.020 (0.004) <= 0.800 0.020 <= : 0.020 (0.004) <= 0.800 0.020 <= : 0.020 (0.006) <= 0.800 0.020 <= : 0.800 (-0.001) <= 0.800 0.020 <= : 0.060 (0.000) <= 0.800 0.020 <= : 0.020 (0.006) <= 0.800 0.020 <= : 0.020 (0.004) <= 0.800 0.020 <= : 0.020 (0.002) <= 0.800 Variance: 0.000 (4.270) 1.000 <= Balance: 1.000 <= 1.000 ############################################ There was a problem with the ActiveSetSolver that I've fixed now. You'll have to wait some days for a new release (or get the source from CVS). /Anders On 17 jan 2008, at 15.58, Arthur McGibbon wrote: > Hi Anders, > > Here's an example that gives an exception. Hopefully this code > will retain a semblance of formatting on emailing. > > public class TestStats extends TestCase > { > public void testEfficientFrontier() > { > // create expected returns matrix > PrimitiveMatrix expectedReturnsMatrix = new PrimitiveMatrix(new > double[][] { { -0.007155942261937039 }, > { -0.003665887902733331 }, { -0.004130184341000032 }, > { -0.005639860515211043 }, > { 0.0007211966666666817 }, { 0.0003258225000000077 }, > { -0.005754291666666666 }, > { -0.004264291666666667 }, { -0.0017500000000000003 } }); > // create covariance matrix > PrimitiveMatrix covarianceMatrix = new PrimitiveMatrix(new double > [][] { > { 0.001561410465201063, 0.00006366128201274021, > -0.0001323096896759724, 0.0000909074052724909, > 0.00003172000033558704, 0.00001955483223848944, > -0.00013771504482647386, -0.00004858457275314645, > -0.000012954723060403266 }, > { 0.00006366128201274021, 0.00016419786524761803, > -0.00001566288911558343, -0.00008688646089751923, > 0.0000027349925543017186, 0.0000012356159598500247, > -0.000024367796639005863, -0.000017576048221096555, > -0.0000070052245518771815 }, > { -0.0001323096896759724, -0.00001566288911558343, > 0.0001430155985985913, 0.00007675339168559199, > -0.00007600590426518823, 0.000032976538909267937, > 0.00009520305608240259, 0.00007373075639042642, > -0.000007477057858706954 }, > { 0.0000909074052724909, -0.00008688646089751923, > 0.00007675339168559199, 0.000967519991100896, > -0.0000533460293834595, 0.00008665760416026126, > 0.00014591175388747613, 0.0001232364989586903, > 0.00011097998789484925 }, > { 0.00003172000033558704, 0.0000027349925543017186, > -0.00007600590426518823, -0.0000533460293834595, > 0.000025267064307337795, -0.00003089584520279407, > -0.00005593123237578969, -0.000017013960349712132, > 0.0000013056146551724419 }, > { 0.00001955483223848944, 0.0000012356159598500247, > 0.000032976538909267937, 0.00008665760416026126, > -0.00003089584520279407, 0.0001625499447274783, > 0.00008242949058588471, 0.00010276895784859992, > 0.0000005898510775862205 }, > { -0.00013771504482647386, -0.000024367796639005863, > 0.00009520305608240259, 0.00014591175388747613, > -0.00005593123237578969, 0.00008242949058588471, > 0.000560956958802083, 0.0002838794236862429, > 0.00009143821659482758 }, > { -0.00004858457275314645, -0.000017576048221096555, > 0.00007373075639042642, 0.0001232364989586903, > -0.000017013960349712132, 0.00010276895784859992, > 0.0002838794236862429, 0.00021068964250359204, > 0.00004461044181034483 }, > { -0.000012954723060403266, -0.0000070052245518771815, > -0.000007477057858706954, 0.00011097998789484925, > 0.0000013056146551724419, 0.0000005898510775862205, > 0.00009143821659482758, 0.00004461044181034483, > 0.00006761920797413792 } }); > > 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.02")); > // require no more than 80% allocation to each asset > tmpVariables[i].setUpperLimit(new BigDecimal("0.80")); > } > > 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... > BigMatrix.FACTORY.buildColumnVector(quadModel.getDefaultSolver > ().getSolution()); > } > } > > > ******************************************************************** > 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 > > |