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