@Test public void rateOfReturnIsCalculatedCorrectlyWhenTradeWasOpened() { assertThat(new BasicCompletedTrade(BUY, LIMIT, asList(SOME_PENDING_ORDER_OPENED, SOME_ORDER_CLOSED)) .getRateOfReturn().get()).isApproximatelyEqualTo(new Ratio(150, PERCENT), ALLOWED_OFFSET); assertThat(new BasicCompletedTrade(BUY, LIMIT, asList(SOME_PENDING_ORDER_OPENED, OTHER_ORDER_CLOSED)) .getRateOfReturn().get()).isApproximatelyEqualTo(new Ratio(50, PERCENT), ALLOWED_OFFSET); assertThat(new BasicCompletedTrade(SELL, LIMIT, asList(SOME_PENDING_ORDER_OPENED, SOME_ORDER_CLOSED)) .getRateOfReturn().get()).isApproximatelyEqualTo(new Ratio(50, PERCENT), ALLOWED_OFFSET); assertThat(new BasicCompletedTrade(SELL, LIMIT, asList(SOME_PENDING_ORDER_OPENED, OTHER_ORDER_CLOSED)) .getRateOfReturn().get()).isApproximatelyEqualTo(new Ratio(150, PERCENT), ALLOWED_OFFSET); }
public Optional<Ratio> getRateOfReturn() { return getExitPrice().flatMap(exit -> getEntryPrice().map(entry -> exit.asDouble() / entry.asDouble()) .map(ratio -> type == BUY ? new Ratio(ratio) : new Ratio(2.0 - ratio))); }
BasicCompletedTrade { public Optional<Ratio> getRateOfReturn() { return getExitPrice().flatMap(exit -> getEntryPrice().map(entry -> exit.asDouble() / entry.asDouble()) .map(ratio -> type == BUY ? new Ratio(ratio) : new Ratio(2.0 - ratio))); } }
BasicCompletedTrade { public Optional<Ratio> getRateOfReturn() { return getExitPrice().flatMap(exit -> getEntryPrice().map(entry -> exit.asDouble() / entry.asDouble()) .map(ratio -> type == BUY ? new Ratio(ratio) : new Ratio(2.0 - ratio))); } BasicCompletedTrade(final OrderType type, final ExecutionCondition executionCondition,
            final List<TradeEvent> events); }
BasicCompletedTrade { public Optional<Ratio> getRateOfReturn() { return getExitPrice().flatMap(exit -> getEntryPrice().map(entry -> exit.asDouble() / entry.asDouble()) .map(ratio -> type == BUY ? new Ratio(ratio) : new Ratio(2.0 - ratio))); } BasicCompletedTrade(final OrderType type, final ExecutionCondition executionCondition,
            final List<TradeEvent> events); OrderType getType(); ExecutionCondition getExecutionCondition(); List<TradeEvent> getEvents(); Optional<Price> getRelativeProfit(); Optional<Ratio> getRateOfReturn(); @Override boolean equals(final Object obj); @Override int hashCode(); @Override String toString(); }
BasicCompletedTrade { public Optional<Ratio> getRateOfReturn() { return getExitPrice().flatMap(exit -> getEntryPrice().map(entry -> exit.asDouble() / entry.asDouble()) .map(ratio -> type == BUY ? new Ratio(ratio) : new Ratio(2.0 - ratio))); } BasicCompletedTrade(final OrderType type, final ExecutionCondition executionCondition,
            final List<TradeEvent> events); OrderType getType(); ExecutionCondition getExecutionCondition(); List<TradeEvent> getEvents(); Optional<Price> getRelativeProfit(); Optional<Ratio> getRateOfReturn(); @Override boolean equals(final Object obj); @Override int hashCode(); @Override String toString();  }