@Test public void calculatesSmoothedMovingAverageCorrectly() { final List<Optional<Price>> prices = inputData.map(c -> cut.smooth(c)).collect(toList()); for (int i = 0; i < 2; i++) { assertThat(prices.get(i)).isEmpty(); } assertThat(price(prices, 2)).isEqualTo(1.45724, OFFSET); assertThat(price(prices, 3)).isEqualTo(1.45439, OFFSET); assertThat(price(prices, 4)).isEqualTo(1.45151, OFFSET); assertThat(price(prices, 5)).isEqualTo(1.44913, OFFSET); assertThat(price(prices, 6)).isEqualTo(1.44720, OFFSET); assertThat(price(prices, 7)).isEqualTo(1.44449, OFFSET); assertThat(price(prices, 8)).isEqualTo(1.44090, OFFSET); assertThat(price(prices, 9)).isEqualTo(1.43460, OFFSET); }
@Override public Optional<Price> smooth(final Price dataPoint) { if (count < aggregationCount) { smma += dataPoint.asPipette(); count++; return Optional.empty(); } if (count == aggregationCount) { smma = Math.round((smma + dataPoint.asPipette()) / (double) 3); count++; return Optional.of(new Price(smma)); } smma = Math.round((smma * aggregationCount + dataPoint.asPipette()) / (double) smoothingPeriod); return Optional.of(new Price(smma)); }
SmoothedMovingAveragePrice implements Smoother<Price> { @Override public Optional<Price> smooth(final Price dataPoint) { if (count < aggregationCount) { smma += dataPoint.asPipette(); count++; return Optional.empty(); } if (count == aggregationCount) { smma = Math.round((smma + dataPoint.asPipette()) / (double) 3); count++; return Optional.of(new Price(smma)); } smma = Math.round((smma * aggregationCount + dataPoint.asPipette()) / (double) smoothingPeriod); return Optional.of(new Price(smma)); } }
SmoothedMovingAveragePrice implements Smoother<Price> { @Override public Optional<Price> smooth(final Price dataPoint) { if (count < aggregationCount) { smma += dataPoint.asPipette(); count++; return Optional.empty(); } if (count == aggregationCount) { smma = Math.round((smma + dataPoint.asPipette()) / (double) 3); count++; return Optional.of(new Price(smma)); } smma = Math.round((smma * aggregationCount + dataPoint.asPipette()) / (double) smoothingPeriod); return Optional.of(new Price(smma)); } SmoothedMovingAveragePrice(final int smoothingPeriod); }
SmoothedMovingAveragePrice implements Smoother<Price> { @Override public Optional<Price> smooth(final Price dataPoint) { if (count < aggregationCount) { smma += dataPoint.asPipette(); count++; return Optional.empty(); } if (count == aggregationCount) { smma = Math.round((smma + dataPoint.asPipette()) / (double) 3); count++; return Optional.of(new Price(smma)); } smma = Math.round((smma * aggregationCount + dataPoint.asPipette()) / (double) smoothingPeriod); return Optional.of(new Price(smma)); } SmoothedMovingAveragePrice(final int smoothingPeriod); @Override Optional<Price> smooth(final Price dataPoint); }
SmoothedMovingAveragePrice implements Smoother<Price> { @Override public Optional<Price> smooth(final Price dataPoint) { if (count < aggregationCount) { smma += dataPoint.asPipette(); count++; return Optional.empty(); } if (count == aggregationCount) { smma = Math.round((smma + dataPoint.asPipette()) / (double) 3); count++; return Optional.of(new Price(smma)); } smma = Math.round((smma * aggregationCount + dataPoint.asPipette()) / (double) smoothingPeriod); return Optional.of(new Price(smma)); } SmoothedMovingAveragePrice(final int smoothingPeriod); @Override Optional<Price> smooth(final Price dataPoint);  }