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