Search in sources :

Example 16 with MockTimeSeries

use of org.ta4j.core.mocks.MockTimeSeries in project ta4j by ta4j.

the class TotalProfitCriterionTest method calculateWithNoTradesShouldReturn1.

@Test
public void calculateWithNoTradesShouldReturn1() {
    MockTimeSeries series = new MockTimeSeries(100, 95, 100, 80, 85, 70);
    AnalysisCriterion profit = new TotalProfitCriterion();
    assertEquals(1d, profit.calculate(series, new BaseTradingRecord()), TATestsUtils.TA_OFFSET);
}
Also used : MockTimeSeries(org.ta4j.core.mocks.MockTimeSeries) Test(org.junit.Test)

Example 17 with MockTimeSeries

use of org.ta4j.core.mocks.MockTimeSeries in project ta4j by ta4j.

the class TotalProfitCriterionTest method calculateProfitWithTradesThatStartSelling.

@Test
public void calculateProfitWithTradesThatStartSelling() {
    MockTimeSeries series = new MockTimeSeries(100, 95, 100, 80, 85, 70);
    TradingRecord tradingRecord = new BaseTradingRecord(Order.sellAt(0, series), Order.buyAt(1, series), Order.sellAt(2, series), Order.buyAt(5, series));
    AnalysisCriterion profit = new TotalProfitCriterion();
    assertEquals((1 / 0.95) * (1 / 0.7), profit.calculate(series, tradingRecord), TATestsUtils.TA_OFFSET);
}
Also used : MockTimeSeries(org.ta4j.core.mocks.MockTimeSeries) Test(org.junit.Test)

Example 18 with MockTimeSeries

use of org.ta4j.core.mocks.MockTimeSeries in project ta4j by ta4j.

the class VersusBuyAndHoldCriterionTest method calculateWithNoTrades.

@Test
public void calculateWithNoTrades() {
    MockTimeSeries series = new MockTimeSeries(100, 95, 100, 80, 85, 70);
    AnalysisCriterion buyAndHold = new VersusBuyAndHoldCriterion(new TotalProfitCriterion());
    assertEquals(1 / 0.7, buyAndHold.calculate(series, new BaseTradingRecord()), TATestsUtils.TA_OFFSET);
}
Also used : MockTimeSeries(org.ta4j.core.mocks.MockTimeSeries) Test(org.junit.Test)

Example 19 with MockTimeSeries

use of org.ta4j.core.mocks.MockTimeSeries in project ta4j by ta4j.

the class VersusBuyAndHoldCriterionTest method calculateWithNumberOfBars.

@Test
public void calculateWithNumberOfBars() {
    MockTimeSeries series = new MockTimeSeries(100, 95, 100, 80, 85, 130);
    TradingRecord tradingRecord = new BaseTradingRecord(Order.buyAt(0, series), Order.sellAt(1, series), Order.buyAt(2, series), Order.sellAt(5, series));
    AnalysisCriterion buyAndHold = new VersusBuyAndHoldCriterion(new NumberOfBarsCriterion());
    assertEquals(6d / 6d, buyAndHold.calculate(series, tradingRecord), TATestsUtils.TA_OFFSET);
}
Also used : MockTimeSeries(org.ta4j.core.mocks.MockTimeSeries) Test(org.junit.Test)

Example 20 with MockTimeSeries

use of org.ta4j.core.mocks.MockTimeSeries in project ta4j by ta4j.

the class VersusBuyAndHoldCriterionTest 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 VersusBuyAndHoldCriterion(new TotalProfitCriterion());
    assertEquals(1.10 * 1.05 / 1.05, buyAndHold.calculate(series, tradingRecord), TATestsUtils.TA_OFFSET);
}
Also used : MockTimeSeries(org.ta4j.core.mocks.MockTimeSeries) Test(org.junit.Test)

Aggregations

MockTimeSeries (org.ta4j.core.mocks.MockTimeSeries)135 Test (org.junit.Test)90 MockBar (org.ta4j.core.mocks.MockBar)46 ArrayList (java.util.ArrayList)45 Before (org.junit.Before)45 Bar (org.ta4j.core.Bar)42 TimeSeries (org.ta4j.core.TimeSeries)29 ClosePriceIndicator (org.ta4j.core.indicators.helpers.ClosePriceIndicator)25 BaseTradingRecord (org.ta4j.core.BaseTradingRecord)17 TradingRecord (org.ta4j.core.TradingRecord)12 ZonedDateTime (java.time.ZonedDateTime)5 AnalysisCriterion (org.ta4j.core.AnalysisCriterion)3 BaseStrategy (org.ta4j.core.BaseStrategy)3 ExternalCriterionTest (org.ta4j.core.ExternalCriterionTest)3 Strategy (org.ta4j.core.Strategy)3 Decimal (org.ta4j.core.Decimal)2 TimeSeriesManager (org.ta4j.core.TimeSeriesManager)2 Trade (org.ta4j.core.Trade)2 SMAIndicator (org.ta4j.core.indicators.SMAIndicator)2 FixedRule (org.ta4j.core.trading.rules.FixedRule)2