use of org.ta4j.core.mocks.MockTimeSeries in project ta4j by ta4j.
the class MaximumDrawdownCriterionTest method calculateShouldWork.
@Test
public void calculateShouldWork() {
MockTimeSeries series = new MockTimeSeries(1, 2, 3, 6, 5, 20, 3);
MaximumDrawdownCriterion mdd = new MaximumDrawdownCriterion();
TradingRecord tradingRecord = new BaseTradingRecord(Order.buyAt(0, series), Order.sellAt(1, series), Order.buyAt(3, series), Order.sellAt(4, series), Order.buyAt(5, series), Order.sellAt(6, series));
assertEquals(.875d, mdd.calculate(series, tradingRecord), TATestsUtils.TA_OFFSET);
}
use of org.ta4j.core.mocks.MockTimeSeries in project ta4j by ta4j.
the class MaximumDrawdownCriterionTest method withTradesThatSellBeforeBuying.
@Test
public void withTradesThatSellBeforeBuying() {
MockTimeSeries series = new MockTimeSeries(2, 1, 3, 5, 6, 3, 20);
MaximumDrawdownCriterion mdd = new MaximumDrawdownCriterion();
TradingRecord tradingRecord = new BaseTradingRecord(Order.buyAt(0, series), Order.sellAt(1, series), Order.buyAt(3, series), Order.sellAt(4, series), Order.sellAt(5, series), Order.buyAt(6, series));
assertEquals(.91, mdd.calculate(series, tradingRecord), TATestsUtils.TA_OFFSET);
}
use of org.ta4j.core.mocks.MockTimeSeries in project ta4j by ta4j.
the class NumberOfBarsCriterionTest method calculateWithNoTrades.
@Test
public void calculateWithNoTrades() {
MockTimeSeries series = new MockTimeSeries(100, 105, 110, 100, 95, 105);
AnalysisCriterion numberOfBars = new NumberOfBarsCriterion();
assertEquals(0, (int) numberOfBars.calculate(series, new BaseTradingRecord()));
}
use of org.ta4j.core.mocks.MockTimeSeries in project ta4j by ta4j.
the class NumberOfTradesCriterionTest method calculateWithNoTrades.
@Test
public void calculateWithNoTrades() {
MockTimeSeries series = new MockTimeSeries(100, 105, 110, 100, 95, 105);
AnalysisCriterion buyAndHold = new NumberOfTradesCriterion();
assertEquals(0d, buyAndHold.calculate(series, new BaseTradingRecord()), TATestsUtils.TA_OFFSET);
}
use of org.ta4j.core.mocks.MockTimeSeries in project ta4j by ta4j.
the class NumberOfTradesCriterionTest method calculateWithTwoTrades.
@Test
public void calculateWithTwoTrades() {
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 NumberOfTradesCriterion();
assertEquals(2d, buyAndHold.calculate(series, tradingRecord), TATestsUtils.TA_OFFSET);
}
Aggregations