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);
}
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);
}
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);
}
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);
}
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());
}
Aggregations