[ojAlgo-user] Negative weights in MarkowitzMarkowitz model when setShortingAllowed(false) and weigh
Mathematics, linear algebra and optimisation
Brought to you by:
apete
From: Anthony E. <ant...@al...> - 2013-10-21 16:11:27
|
Hi I was under the impression that if I create a MarkowitzModel, then set setShortingAllowed to false and setTargetReturn then the weights should always be positive or zero? MarkowitzModel markowitzModel = new MarkowitzModel(cvm, erm); markowitzModel.setShortingAllowed(false); markowitzModel.setTargetReturn(new BigDecimal(targetReturn)); for (int i=0; i<er.length; i++) { markowitzModel.setLowerLimit(i, new BigDecimal(minWgt[i])); markowitzModel.setUpperLimit(i, new BigDecimal(maxWgt[i])); System.out.println("Limits["+i+"] --> "+minWgt[i]+" to "+maxWgt[i]); } final List<BigDecimal> re = markowitzModel.getWeights(); for (int nn = 0; nn < re.size(); nn++) { //System.out.println( re.get(nn) ); weights[nn] = re.get(nn).doubleValue(); } This gives me some negative weights with my covariance (cvm) and expected returns (erm). Any idea what am I doing wrong? Ive tried all sorts of combinations but it doesnt seem to help. Interestingly, if I do setRiskAversion() instead of setTargetReturn() then the weight limits seem to be respected. Basically, I am trying to plot out the efficient frontier but calling the above for a rage of target returns ... Any help gratefully appraciated. Thanks Tony |