@Override
    protected Num calculate(int index) {
        if (index == 0) {
            return indicator.getValue(0);
        }

        Num value = zero();
        int loopLength = (index - barCount < 0) ? index + 1 : barCount;
        int actualIndex = index;
        for (int i = loopLength; i > 0; i--) {
            value = value.plus(numOf(i).multipliedBy(indicator.getValue(actualIndex)));
            actualIndex--;
        }

        return value.dividedBy(numOf((loopLength * (loopLength + 1)) / 2));
    }
@Test
    public void calculate() {
        MockBarSeries series = new MockBarSeries(numFunction, 1d, 2d, 3d, 4d, 5d, 6d);
        Indicator<Num> close = new ClosePriceIndicator(series);
        Indicator<Num> wmaIndicator = new WMAIndicator(close, 3);

        assertNumEquals(1, wmaIndicator.getValue(0));
        assertNumEquals(1.6667, wmaIndicator.getValue(1));
        assertNumEquals(2.3333, wmaIndicator.getValue(2));
        assertNumEquals(3.3333, wmaIndicator.getValue(3));
        assertNumEquals(4.3333, wmaIndicator.getValue(4));
        assertNumEquals(5.3333, wmaIndicator.getValue(5));
    }