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