Search in sources :

Example 1 with AnalysisCriterion

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));
}
Also used : AnalysisCriterion(org.ta4j.core.AnalysisCriterion) Test(org.junit.Test)

Example 2 with AnalysisCriterion

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);
}
Also used : Trade(org.ta4j.core.Trade) MockTimeSeries(org.ta4j.core.mocks.MockTimeSeries) AnalysisCriterion(org.ta4j.core.AnalysisCriterion) Test(org.junit.Test)

Example 3 with AnalysisCriterion

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);
}
Also used : BaseTradingRecord(org.ta4j.core.BaseTradingRecord) BaseTradingRecord(org.ta4j.core.BaseTradingRecord) TradingRecord(org.ta4j.core.TradingRecord) MockTimeSeries(org.ta4j.core.mocks.MockTimeSeries) AnalysisCriterion(org.ta4j.core.AnalysisCriterion) Test(org.junit.Test)

Example 4 with AnalysisCriterion

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));
}
Also used : AnalysisCriterion(org.ta4j.core.AnalysisCriterion) ExternalCriterionTest(org.ta4j.core.ExternalCriterionTest) Test(org.junit.Test)

Example 5 with AnalysisCriterion

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()));
}
Also used : BaseTradingRecord(org.ta4j.core.BaseTradingRecord) MockTimeSeries(org.ta4j.core.mocks.MockTimeSeries) AnalysisCriterion(org.ta4j.core.AnalysisCriterion) Test(org.junit.Test)

Aggregations

Test (org.junit.Test)5 AnalysisCriterion (org.ta4j.core.AnalysisCriterion)5 MockTimeSeries (org.ta4j.core.mocks.MockTimeSeries)3 BaseTradingRecord (org.ta4j.core.BaseTradingRecord)2 ExternalCriterionTest (org.ta4j.core.ExternalCriterionTest)1 Trade (org.ta4j.core.Trade)1 TradingRecord (org.ta4j.core.TradingRecord)1