Search in sources :

Example 6 with BaseTradingRecord

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

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

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

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

Example 10 with BaseTradingRecord

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

the class CashFlowTest method cashFlowSize.

@Test
public void cashFlowSize() {
    TimeSeries sampleTimeSeries = new MockTimeSeries(1d, 2d, 3d, 4d, 5d);
    CashFlow cashFlow = new CashFlow(sampleTimeSeries, new BaseTradingRecord());
    assertEquals(5, cashFlow.getSize());
}
Also used : BaseTradingRecord(org.ta4j.core.BaseTradingRecord) TimeSeries(org.ta4j.core.TimeSeries) MockTimeSeries(org.ta4j.core.mocks.MockTimeSeries) MockTimeSeries(org.ta4j.core.mocks.MockTimeSeries) Test(org.junit.Test)

Aggregations

BaseTradingRecord (org.ta4j.core.BaseTradingRecord)17 MockTimeSeries (org.ta4j.core.mocks.MockTimeSeries)17 Test (org.junit.Test)15 TradingRecord (org.ta4j.core.TradingRecord)12 TimeSeries (org.ta4j.core.TimeSeries)11 Before (org.junit.Before)2 AnalysisCriterion (org.ta4j.core.AnalysisCriterion)2 ExternalCriterionTest (org.ta4j.core.ExternalCriterionTest)2 ClosePriceIndicator (org.ta4j.core.indicators.helpers.ClosePriceIndicator)2 MockBar (org.ta4j.core.mocks.MockBar)1