### Question:
WMAIndicator extends CachedIndicator<Decimal> { @Override protected Decimal calculate(int index) { if (index == 0) { return indicator.getValue(0); } Decimal value = Decimal.ZERO; if(index - timeFrame < 0) { for(int i = index + 1; i > 0; i--) { value = value.plus(Decimal.valueOf(i).multipliedBy(indicator.getValue(i-1))); } return value.dividedBy(Decimal.valueOf(((index + 1) * (index + 2)) / 2)); } int actualIndex = index; for(int i = timeFrame; i > 0; i--) { value = value.plus(Decimal.valueOf(i).multipliedBy(indicator.getValue(actualIndex))); actualIndex--; } return value.dividedBy(Decimal.valueOf((timeFrame * (timeFrame + 1)) / 2)); } WMAIndicator(Indicator<Decimal> indicator, int timeFrame); @Override String toString();  }### Answer:
@Test public void calculate() { MockTimeSeries series = new MockTimeSeries(1d, 2d, 3d, 4d, 5d, 6d); Indicator<Decimal> close = new ClosePriceIndicator(series); Indicator<Decimal> wmaIndicator = new WMAIndicator(close, 3); assertDecimalEquals(wmaIndicator.getValue(0), 1); assertDecimalEquals(wmaIndicator.getValue(1), 1.6667); assertDecimalEquals(wmaIndicator.getValue(2), 2.3333); assertDecimalEquals(wmaIndicator.getValue(3), 3.3333); assertDecimalEquals(wmaIndicator.getValue(4), 4.3333); assertDecimalEquals(wmaIndicator.getValue(5), 5.3333); }