@Test public void supportsDifferentCandleStickAmounts() { final ExponentialMovingAveragePrice cut = new ExponentialMovingAveragePrice(6); final List<Optional<Price>> prices = inputData.map(c -> cut.smooth(c)).collect(toList()); for (int i = 0; i < 5; i++) { assertThat(prices.get(i)).isEmpty(); } assertThat(price(prices, 5)).isEqualTo(1.42241, OFFSET); assertThat(price(prices, 6)).isEqualTo(1.42261, OFFSET); assertThat(price(prices, 7)).isEqualTo(1.42257, OFFSET); assertThat(price(prices, 8)).isEqualTo(1.42285, OFFSET); assertThat(price(prices, 9)).isEqualTo(1.42322, OFFSET); }
@Override public Optional<Price> smooth(final Price dataPoint) { if (aggregatedIs == 0) { ema = dataPoint.asPipette(); } else { ema += (dataPoint.asPipette() - ema) * factor; } if (aggregatedIs < aggregatedShould - 1) { aggregatedIs++; return Optional.empty(); } return Optional.of(new Price((long) ema)); }
ExponentialMovingAveragePrice implements Smoother<Price> { @Override public Optional<Price> smooth(final Price dataPoint) { if (aggregatedIs == 0) { ema = dataPoint.asPipette(); } else { ema += (dataPoint.asPipette() - ema) * factor; } if (aggregatedIs < aggregatedShould - 1) { aggregatedIs++; return Optional.empty(); } return Optional.of(new Price((long) ema)); } }
ExponentialMovingAveragePrice implements Smoother<Price> { @Override public Optional<Price> smooth(final Price dataPoint) { if (aggregatedIs == 0) { ema = dataPoint.asPipette(); } else { ema += (dataPoint.asPipette() - ema) * factor; } if (aggregatedIs < aggregatedShould - 1) { aggregatedIs++; return Optional.empty(); } return Optional.of(new Price((long) ema)); } ExponentialMovingAveragePrice(final int aggregationCount); }
ExponentialMovingAveragePrice implements Smoother<Price> { @Override public Optional<Price> smooth(final Price dataPoint) { if (aggregatedIs == 0) { ema = dataPoint.asPipette(); } else { ema += (dataPoint.asPipette() - ema) * factor; } if (aggregatedIs < aggregatedShould - 1) { aggregatedIs++; return Optional.empty(); } return Optional.of(new Price((long) ema)); } ExponentialMovingAveragePrice(final int aggregationCount); @Override Optional<Price> smooth(final Price dataPoint); }
ExponentialMovingAveragePrice implements Smoother<Price> { @Override public Optional<Price> smooth(final Price dataPoint) { if (aggregatedIs == 0) { ema = dataPoint.asPipette(); } else { ema += (dataPoint.asPipette() - ema) * factor; } if (aggregatedIs < aggregatedShould - 1) { aggregatedIs++; return Optional.empty(); } return Optional.of(new Price((long) ema)); } ExponentialMovingAveragePrice(final int aggregationCount); @Override Optional<Price> smooth(final Price dataPoint);  }