Re: [ojAlgo-user] Problem with the constraints on the assets with Markowitz model
Mathematics, linear algebra and optimisation
Brought to you by:
apete
From: Samuel Le <Sam...@sr...> - 2011-10-27 12:59:08
|
Hi Anders, Thank you for your quick reply. I just upgraded my jars and re ran my code. This time I get a plausible result but for some reason different of yours: {{0.05}, {0.05}, {0.05}, {0.05}, {0.05}, {0.05}, {0.05}, {0.05}, {0.05}, {0.55}} I will keep investigating, I must have something else wrong. Cheers, Samuel -----Original Message----- From: Anders Peterson [mailto:an...@op...] Sent: 27 October 2011 13:24 To: oja...@li... Subject: Re: [ojAlgo-user] Problem with the constraints on the assets with Markowitz model Just ran your code. I got this solution: {{0.05}, {0.05}, {0.05}, {0.05}, {0.05}, {0.05}, {0.05}, {0.05}, {0.3}, {0.3}} I am of course using v31, but I don't know what would be the difference. Upgrade to v31 and see if the problem disappears for you as well. /Anders On 27 okt 2011, at 13:21, Samuel Le wrote: > Dear all, > > I am new to ojalgo and am trying to use it for portfolio optimisation. > I think I found a bug: when trying to find some optimal weights with constraints, I can obtain inconsistent weights. > I include below an example. I am using the ojalgo version 30.6. > I would be grateful if someone could tell me what I am doing wrong. > > Many thanks, > Samuel > > Here is my code: > > import java.math.BigDecimal; > > import org.ojalgo.finance.portfolio.MarketEquilibrium; > import org.ojalgo.finance.portfolio.MarkowitzModel; > import org.ojalgo.matrix.BasicMatrix; > import org.ojalgo.matrix.PrimitiveMatrix; > import org.ojalgo.matrix.store.PhysicalStore; > import org.ojalgo.matrix.store.PrimitiveDenseStore; > > public class OjalgoTest { > > public static void main(String[] args) { > int n = 10; > PhysicalStore<Double> resStore = PrimitiveDenseStore.FACTORY.makeZero(n, n); > Double[] vols = new Double[n]; > for(int i = 0; i < n; i++) { > vols[i] = new Double(i)/ new Double(n); > } > Double corr = 0.1; > for(int i = 0; i < n; i++) { > for(int j = 0; j < n; j ++) { > if(i == j) { > resStore.set(i, j, vols[i]*vols[i]); > } > else { > resStore.set(i,j,corr*vols[i]*vols[j]); > } > } > } > double[] expectedRets = new double[]{0.2,0.19,0.18,0.17,0.16,0.15,0.14,0.13,0.12,0.11}; > PhysicalStore<Double> physicalStorDbl = PrimitiveDenseStore.FACTORY.makeZero(n, 1); > for(int i = 0; i < n ; i++) { > physicalStorDbl.set(i, 0, expectedRets[i]); > } > PrimitiveMatrix expectedReturnsMatrix = new PrimitiveMatrix(physicalStorDbl); > PrimitiveMatrix covMat = new PrimitiveMatrix(resStore); > MarketEquilibrium me = new MarketEquilibrium(covMat); > MarkowitzModel markowitzModel = new MarkowitzModel(me, expectedReturnsMatrix); > for(int i = 0; i < n; i++) { > markowitzModel.setUpperLimit(i, new BigDecimal("0.05")); > markowitzModel.setLowerLimit(i, new BigDecimal("0.3")); > } > markowitzModel.setRiskAversion(new BigDecimal("0.0001")); > BasicMatrix tmpWgts = markowitzModel.getAssetWeights(); > System.out.println(tmpWgts); > > } > } > > And this is what I am getting: > > {{0.05}, > {0.05}, > {0.05}, > {0.05}, > {0.05}, > {0.05}, > {0.05}, > {0.05}, > {76.9098}, > {-76.3098}} > > > __________ Information from ESET NOD32 Antivirus, version of virus signature database 6275 (20110707) __________ > > The message was checked by ESET NOD32 Antivirus. > > http://www.eset.com > ------------------------------------------------------------------------------ > The demand for IT networking professionals continues to grow, and the > demand for specialized networking skills is growing even more rapidly. > Take a complimentary Learning@Cisco Self-Assessment and learn > about Cisco certifications, training, and career opportunities. > http://p.sf.net/sfu/cisco-dev2dev_______________________________________________ > ojAlgo-user mailing list > ojA...@li... > https://lists.sourceforge.net/lists/listinfo/ojalgo-user ------------------------------------------------------------------------------ The demand for IT networking professionals continues to grow, and the demand for specialized networking skills is growing even more rapidly. Take a complimentary Learning@Cisco Self-Assessment and learn about Cisco certifications, training, and career opportunities. http://p.sf.net/sfu/cisco-dev2dev _______________________________________________ ojAlgo-user mailing list ojA...@li... https://lists.sourceforge.net/lists/listinfo/ojalgo-user __________ Information from ESET NOD32 Antivirus, version of virus signature database 6275 (20110707) __________ The message was checked by ESET NOD32 Antivirus. http://www.eset.com __________ Information from ESET NOD32 Antivirus, version of virus signature database 6275 (20110707) __________ The message was checked by ESET NOD32 Antivirus. http://www.eset.com |