* Tests simple portfolio construction.
*/
public void testSimplePortfolioConstruction() {
List<Pair<Integer, Double>> portfolio =
ps.constructPortfolio(new PortfolioProblemDescription(
new PortfolioPerformanceData(PERF_DATA), 1, false, 1, 2));
assertTrue(portfolio.size() == 1 || portfolio.size() == 2);
double weightSum = 0;
for (Pair<Integer, Double> pElem : portfolio) {
assertTrue(pElem.getSecondValue() >= 0 && pElem.getSecondValue() <= 1.0);
assertTrue(pElem.getFirstValue() >= 0
&& pElem.getFirstValue() < PERF_DATA[0].length);
weightSum += pElem.getSecondValue();
}
assertTrue(Math.abs(1 - weightSum) <= AbstractPortfolioSelector.EPSILON);
// This is a stochastic result (although *very* likely) - re-run if check
// fails
PERF_DATA[0] = new Double[] { .5, .5, .5, .5 };
portfolio =
ps.constructPortfolio(new PortfolioProblemDescription(
new PortfolioPerformanceData(PERF_DATA), 1, true, 1, 2));
assertEquals(1, portfolio.size());
assertEquals(2, portfolio.get(0).getFirstValue().intValue());
portfolio =
ps.constructPortfolio(new PortfolioProblemDescription(
new PortfolioPerformanceData(PERF_DATA), 1, false, 1, 2));
assertEquals(1, portfolio.size());
assertEquals(0, portfolio.get(0).getFirstValue().intValue());
}