@Test @SuppressWarnings("unchecked") public void calculatesDMICorrectly() { when(averagePlusDi.indicate(any())).thenReturn(optRatio(0.5), optRatio(0.568), optRatio(0.921), optRatio(0.201)); when(averageMinusDi.indicate(any())).thenReturn(optRatio(0.4), optRatio(0.958), optRatio(0.484), optRatio(0.69)); assertThat(cut.indicate(SOME_CANDLE).get()).isApproximatelyEqualTo(new Ratio(0.111111111), ALLOWED_OFFSET); assertThat(cut.indicate(SOME_CANDLE).get()).isApproximatelyEqualTo(new Ratio(0.255570118), ALLOWED_OFFSET); assertThat(cut.indicate(SOME_CANDLE).get()).isApproximatelyEqualTo(new Ratio(0.3110320285), ALLOWED_OFFSET); assertThat(cut.indicate(SOME_CANDLE).get()).isApproximatelyEqualTo(new Ratio(0.54882155), ALLOWED_OFFSET); }
@Override public Optional<Ratio> indicate(final C marketPrice) { final Optional<Ratio> optPlusDi = averagePlusDi.indicate(marketPrice); final Optional<Ratio> optMinusDi = averageMinusDi.indicate(marketPrice); return optPlusDi.flatMap(plusDi -> optMinusDi.map(minusDi -> new Ratio( abs((plusDi.asBasic() - minusDi.asBasic()) / (plusDi.asBasic() + minusDi.asBasic()))))); }
DirectionalMovementIndex implements Indicator<Ratio, C> { @Override public Optional<Ratio> indicate(final C marketPrice) { final Optional<Ratio> optPlusDi = averagePlusDi.indicate(marketPrice); final Optional<Ratio> optMinusDi = averageMinusDi.indicate(marketPrice); return optPlusDi.flatMap(plusDi -> optMinusDi.map(minusDi -> new Ratio( abs((plusDi.asBasic() - minusDi.asBasic()) / (plusDi.asBasic() + minusDi.asBasic()))))); } }
DirectionalMovementIndex implements Indicator<Ratio, C> { @Override public Optional<Ratio> indicate(final C marketPrice) { final Optional<Ratio> optPlusDi = averagePlusDi.indicate(marketPrice); final Optional<Ratio> optMinusDi = averageMinusDi.indicate(marketPrice); return optPlusDi.flatMap(plusDi -> optMinusDi.map(minusDi -> new Ratio( abs((plusDi.asBasic() - minusDi.asBasic()) / (plusDi.asBasic() + minusDi.asBasic()))))); } DirectionalMovementIndex(final Indicator<Ratio, C> averagePlusDi, final Indicator<Ratio, C> averageMinusDi); }
DirectionalMovementIndex implements Indicator<Ratio, C> { @Override public Optional<Ratio> indicate(final C marketPrice) { final Optional<Ratio> optPlusDi = averagePlusDi.indicate(marketPrice); final Optional<Ratio> optMinusDi = averageMinusDi.indicate(marketPrice); return optPlusDi.flatMap(plusDi -> optMinusDi.map(minusDi -> new Ratio( abs((plusDi.asBasic() - minusDi.asBasic()) / (plusDi.asBasic() + minusDi.asBasic()))))); } DirectionalMovementIndex(final Indicator<Ratio, C> averagePlusDi, final Indicator<Ratio, C> averageMinusDi); @Override Optional<Ratio> indicate(final C marketPrice); }
DirectionalMovementIndex implements Indicator<Ratio, C> { @Override public Optional<Ratio> indicate(final C marketPrice) { final Optional<Ratio> optPlusDi = averagePlusDi.indicate(marketPrice); final Optional<Ratio> optMinusDi = averageMinusDi.indicate(marketPrice); return optPlusDi.flatMap(plusDi -> optMinusDi.map(minusDi -> new Ratio( abs((plusDi.asBasic() - minusDi.asBasic()) / (plusDi.asBasic() + minusDi.asBasic()))))); } DirectionalMovementIndex(final Indicator<Ratio, C> averagePlusDi, final Indicator<Ratio, C> averageMinusDi); @Override Optional<Ratio> indicate(final C marketPrice);  }