Search in sources :

Example 6 with TradingRecord

use of org.ta4j.core.TradingRecord 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 7 with TradingRecord

use of org.ta4j.core.TradingRecord 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)

Example 8 with TradingRecord

use of org.ta4j.core.TradingRecord in project ta4j by ta4j.

the class LinearTransactionCostCriterionTest method externalData.

@Test
public void externalData() throws Exception {
    TimeSeries xlsSeries = xls.getSeries();
    TradingRecord xlsTradingRecord = xls.getTradingRecord();
    double value;
    value = getCriterion(1000d, 0.005, 0.2).calculate(xlsSeries, xlsTradingRecord);
    assertEquals(xls.getFinalCriterionValue(1000d, 0.005, 0.2).doubleValue(), value, TATestsUtils.TA_OFFSET);
    assertEquals(843.5492, value, TATestsUtils.TA_OFFSET);
    value = getCriterion(1000d, 0.1, 1.0).calculate(xlsSeries, xlsTradingRecord);
    assertEquals(xls.getFinalCriterionValue(1000d, 0.1, 1.0).doubleValue(), value, TATestsUtils.TA_OFFSET);
    assertEquals(1122.4410, value, TATestsUtils.TA_OFFSET);
}
Also used : TimeSeries(org.ta4j.core.TimeSeries) MockTimeSeries(org.ta4j.core.mocks.MockTimeSeries) BaseTradingRecord(org.ta4j.core.BaseTradingRecord) TradingRecord(org.ta4j.core.TradingRecord) ExternalCriterionTest(org.ta4j.core.ExternalCriterionTest) Test(org.junit.Test)

Example 9 with TradingRecord

use of org.ta4j.core.TradingRecord 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 10 with TradingRecord

use of org.ta4j.core.TradingRecord in project ta4j by ta4j.

the class CashFlowTest method reallyLongCashFlow.

@Test
public void reallyLongCashFlow() {
    int size = 1000000;
    TimeSeries sampleTimeSeries = new MockTimeSeries(Collections.nCopies(size, new MockBar(10)));
    TradingRecord tradingRecord = new BaseTradingRecord(Order.buyAt(0, sampleTimeSeries), Order.sellAt(size - 1, sampleTimeSeries));
    CashFlow cashFlow = new CashFlow(sampleTimeSeries, tradingRecord);
    assertDecimalEquals(cashFlow.getValue(size - 1), 1);
}
Also used : BaseTradingRecord(org.ta4j.core.BaseTradingRecord) TimeSeries(org.ta4j.core.TimeSeries) MockTimeSeries(org.ta4j.core.mocks.MockTimeSeries) BaseTradingRecord(org.ta4j.core.BaseTradingRecord) TradingRecord(org.ta4j.core.TradingRecord) MockBar(org.ta4j.core.mocks.MockBar) MockTimeSeries(org.ta4j.core.mocks.MockTimeSeries) Test(org.junit.Test)

Aggregations

TradingRecord (org.ta4j.core.TradingRecord)14 Test (org.junit.Test)13 BaseTradingRecord (org.ta4j.core.BaseTradingRecord)13 MockTimeSeries (org.ta4j.core.mocks.MockTimeSeries)13 TimeSeries (org.ta4j.core.TimeSeries)11 ExternalCriterionTest (org.ta4j.core.ExternalCriterionTest)3 AnalysisCriterion (org.ta4j.core.AnalysisCriterion)1 Strategy (org.ta4j.core.Strategy)1 TimeSeriesManager (org.ta4j.core.TimeSeriesManager)1 MockBar (org.ta4j.core.mocks.MockBar)1 MovingMomentumStrategy (ta4jexamples.strategies.MovingMomentumStrategy)1