use of org.ta4j.core.AnalysisCriterion in project ta4j by ta4j.
the class NumberOfBarsCriterionTest method betterThan.
@Test
public void betterThan() {
AnalysisCriterion criterion = new NumberOfBarsCriterion();
assertTrue(criterion.betterThan(3, 6));
assertFalse(criterion.betterThan(6, 2));
}
use of org.ta4j.core.AnalysisCriterion in project ta4j by ta4j.
the class NumberOfBarsCriterionTest method calculateWithOneTrade.
@Test
public void calculateWithOneTrade() {
MockTimeSeries series = new MockTimeSeries(100, 95, 100, 80, 85, 70);
Trade t = new Trade(Order.buyAt(2, series), Order.sellAt(5, series));
AnalysisCriterion numberOfBars = new NumberOfBarsCriterion();
assertEquals(4, numberOfBars.calculate(series, t), TATestsUtils.TA_OFFSET);
}
use of org.ta4j.core.AnalysisCriterion in project ta4j by ta4j.
the class NumberOfBarsCriterionTest 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 numberOfBars = new NumberOfBarsCriterion();
assertEquals(6, numberOfBars.calculate(series, tradingRecord), TATestsUtils.TA_OFFSET);
}
use of org.ta4j.core.AnalysisCriterion in project ta4j by ta4j.
the class LinearTransactionCostCriterionTest method betterThan.
@Test
public void betterThan() {
AnalysisCriterion criterion = new LinearTransactionCostCriterion(1000, 0.5);
assertTrue(criterion.betterThan(3.1, 4.2));
assertFalse(criterion.betterThan(2.1, 1.9));
}
use of org.ta4j.core.AnalysisCriterion 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()));
}
Aggregations