use of org.ta4j.core.mocks.MockTimeSeries in project ta4j by ta4j.
the class AverageProfitableTradesCriterionTest method calculateWithOneTrade.
@Test
public void calculateWithOneTrade() {
TimeSeries series = new MockTimeSeries(100d, 95d, 102d, 105d, 97d, 113d);
Trade trade = new Trade(Order.buyAt(0, series), Order.sellAt(1, series));
AverageProfitableTradesCriterion average = new AverageProfitableTradesCriterion();
assertEquals(0d, average.calculate(series, trade), TATestsUtils.TA_OFFSET);
trade = new Trade(Order.buyAt(1, series), Order.sellAt(2, series));
assertEquals(1d, average.calculate(series, trade), TATestsUtils.TA_OFFSET);
}
use of org.ta4j.core.mocks.MockTimeSeries in project ta4j by ta4j.
the class BuyAndHoldCriterionTest method calculateWithNoTrades.
@Test
public void calculateWithNoTrades() {
MockTimeSeries series = new MockTimeSeries(100, 95, 100, 80, 85, 70);
AnalysisCriterion buyAndHold = new BuyAndHoldCriterion();
assertEquals(0.7, buyAndHold.calculate(series, new BaseTradingRecord()), TATestsUtils.TA_OFFSET);
}
use of org.ta4j.core.mocks.MockTimeSeries in project ta4j by ta4j.
the class BuyAndHoldCriterionTest method calculateOnlyWithLossTrades.
@Test
public void calculateOnlyWithLossTrades() {
MockTimeSeries series = new MockTimeSeries(100, 95, 100, 80, 85, 70);
TradingRecord tradingRecord = new BaseTradingRecord(Order.buyAt(0, series), Order.sellAt(1, series), Order.buyAt(2, series), Order.sellAt(5, series));
AnalysisCriterion buyAndHold = new BuyAndHoldCriterion();
assertEquals(0.7, buyAndHold.calculate(series, tradingRecord), TATestsUtils.TA_OFFSET);
}
use of org.ta4j.core.mocks.MockTimeSeries in project ta4j by ta4j.
the class BuyAndHoldCriterionTest method calculateOnlyWithGainTrades.
@Test
public void calculateOnlyWithGainTrades() {
MockTimeSeries series = new MockTimeSeries(100, 105, 110, 100, 95, 105);
TradingRecord tradingRecord = new BaseTradingRecord(Order.buyAt(0, series), Order.sellAt(2, series), Order.buyAt(3, series), Order.sellAt(5, series));
AnalysisCriterion buyAndHold = new BuyAndHoldCriterion();
assertEquals(1.05, buyAndHold.calculate(series, tradingRecord), TATestsUtils.TA_OFFSET);
}
use of org.ta4j.core.mocks.MockTimeSeries in project ta4j by ta4j.
the class MaximumDrawdownCriterionTest method withSimpleTrades.
@Test
public void withSimpleTrades() {
MockTimeSeries series = new MockTimeSeries(1, 10, 5, 6, 1);
MaximumDrawdownCriterion mdd = new MaximumDrawdownCriterion();
TradingRecord tradingRecord = new BaseTradingRecord(Order.buyAt(0, series), Order.sellAt(1, series), Order.buyAt(1, series), Order.sellAt(2, series), Order.buyAt(2, series), Order.sellAt(3, series), Order.buyAt(3, series), Order.sellAt(4, series));
assertEquals(.9d, mdd.calculate(series, tradingRecord), TATestsUtils.TA_OFFSET);
}
Aggregations