Search in sources :

Example 31 with MockTimeSeries

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

the class AverageProfitCriterionTest method calculateWithOneTrade.

@Test
public void calculateWithOneTrade() {
    series = new MockTimeSeries(100, 105);
    Trade trade = new Trade(Order.buyAt(0, series), Order.sellAt(1, series));
    AnalysisCriterion average = new AverageProfitCriterion();
    assertEquals(Math.pow(105d / 100, 1d / 2), average.calculate(series, trade), TATestsUtils.TA_OFFSET);
}
Also used : MockTimeSeries(org.ta4j.core.mocks.MockTimeSeries) Test(org.junit.Test)

Example 32 with MockTimeSeries

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

the class AverageProfitableTradesCriterionTest method calculate.

@Test
public void calculate() {
    TimeSeries series = new MockTimeSeries(100d, 95d, 102d, 105d, 97d, 113d);
    TradingRecord tradingRecord = new BaseTradingRecord(Order.buyAt(0, series), Order.sellAt(1, series), Order.buyAt(2, series), Order.sellAt(3, series), Order.buyAt(4, series), Order.sellAt(5, series));
    AverageProfitableTradesCriterion average = new AverageProfitableTradesCriterion();
    assertEquals(2d / 3, average.calculate(series, tradingRecord), TATestsUtils.TA_OFFSET);
}
Also used : MockTimeSeries(org.ta4j.core.mocks.MockTimeSeries) MockTimeSeries(org.ta4j.core.mocks.MockTimeSeries) Test(org.junit.Test)

Example 33 with MockTimeSeries

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

the class BuyAndHoldCriterionTest method calculateWithOneTrade.

@Test
public void calculateWithOneTrade() {
    MockTimeSeries series = new MockTimeSeries(100, 105);
    Trade trade = new Trade(Order.buyAt(0, series), Order.sellAt(1, series));
    AnalysisCriterion buyAndHold = new BuyAndHoldCriterion();
    assertEquals(105d / 100, buyAndHold.calculate(series, trade), TATestsUtils.TA_OFFSET);
}
Also used : MockTimeSeries(org.ta4j.core.mocks.MockTimeSeries) Test(org.junit.Test)

Example 34 with MockTimeSeries

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

the class LinearTransactionCostCriterionTest method dummyData.

@Test
public void dummyData() {
    MockTimeSeries series = new MockTimeSeries(100, 150, 200, 100, 50, 100);
    TradingRecord tradingRecord = new BaseTradingRecord();
    double criterion;
    tradingRecord.operate(0);
    tradingRecord.operate(1);
    criterion = getCriterion(1000d, 0.005, 0.2).calculate(series, tradingRecord);
    assertEquals(12.861, criterion, TATestsUtils.TA_OFFSET);
    tradingRecord.operate(2);
    tradingRecord.operate(3);
    criterion = getCriterion(1000d, 0.005, 0.2).calculate(series, tradingRecord);
    assertEquals(24.3759, criterion, TATestsUtils.TA_OFFSET);
    tradingRecord.operate(5);
    criterion = getCriterion(1000d, 0.005, 0.2).calculate(series, tradingRecord);
    assertEquals(28.2488, criterion, 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) ExternalCriterionTest(org.ta4j.core.ExternalCriterionTest) Test(org.junit.Test)

Example 35 with MockTimeSeries

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

the class LinearTransactionCostCriterionTest method fixedCost.

@Test
public void fixedCost() {
    MockTimeSeries series = new MockTimeSeries(100, 105, 110, 100, 95, 105);
    TradingRecord tradingRecord = new BaseTradingRecord();
    double criterion;
    tradingRecord.operate(0);
    tradingRecord.operate(1);
    criterion = getCriterion(1000d, 0d, 1.3d).calculate(series, tradingRecord);
    assertEquals(2.6d, criterion, TATestsUtils.TA_OFFSET);
    tradingRecord.operate(2);
    tradingRecord.operate(3);
    criterion = getCriterion(1000d, 0d, 1.3d).calculate(series, tradingRecord);
    assertEquals(5.2d, criterion, TATestsUtils.TA_OFFSET);
    tradingRecord.operate(0);
    criterion = getCriterion(1000d, 0d, 1.3d).calculate(series, tradingRecord);
    assertEquals(6.5d, criterion, 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) ExternalCriterionTest(org.ta4j.core.ExternalCriterionTest) 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