use of org.ta4j.core.mocks.MockTimeSeries in project ta4j by ta4j.
the class LinearTransactionCostCriterionTest method fixedCostWithOneTrade.
@Test
public void fixedCostWithOneTrade() {
MockTimeSeries series = new MockTimeSeries(100, 95, 100, 80, 85, 70);
Trade trade = new Trade();
double criterion;
criterion = getCriterion(1000d, 0d, 0.75d).calculate(series, trade);
assertEquals(0d, criterion, TATestsUtils.TA_OFFSET);
trade.operate(1);
criterion = getCriterion(1000d, 0d, 0.75d).calculate(series, trade);
assertEquals(0.75d, criterion, TATestsUtils.TA_OFFSET);
trade.operate(3);
criterion = getCriterion(1000d, 0d, 0.75d).calculate(series, trade);
assertEquals(1.5d, criterion, TATestsUtils.TA_OFFSET);
trade.operate(4);
criterion = getCriterion(1000d, 0d, 0.75d).calculate(series, trade);
assertEquals(1.5d, criterion, TATestsUtils.TA_OFFSET);
}
use of org.ta4j.core.mocks.MockTimeSeries in project ta4j by ta4j.
the class MaximumDrawdownCriterionTest method calculateWithOnlyGains.
@Test
public void calculateWithOnlyGains() {
MockTimeSeries series = new MockTimeSeries(1, 2, 3, 6, 8, 20, 3);
MaximumDrawdownCriterion mdd = new MaximumDrawdownCriterion();
TradingRecord tradingRecord = new BaseTradingRecord(Order.buyAt(0, series), Order.sellAt(1, series), Order.buyAt(2, series), Order.sellAt(5, series));
assertEquals(0d, mdd.calculate(series, tradingRecord), TATestsUtils.TA_OFFSET);
}
use of org.ta4j.core.mocks.MockTimeSeries in project ta4j by ta4j.
the class MaximumDrawdownCriterionTest method calculateWithNoTrades.
@Test
public void calculateWithNoTrades() {
MockTimeSeries series = new MockTimeSeries(1, 2, 3, 6, 5, 20, 3);
MaximumDrawdownCriterion mdd = new MaximumDrawdownCriterion();
assertEquals(0d, mdd.calculate(series, new BaseTradingRecord()), TATestsUtils.TA_OFFSET);
}
use of org.ta4j.core.mocks.MockTimeSeries in project ta4j by ta4j.
the class MaximumDrawdownCriterionTest method calculateWithNullSeriesSizeShouldReturn0.
@Test
public void calculateWithNullSeriesSizeShouldReturn0() {
MockTimeSeries series = new MockTimeSeries(new double[] {});
MaximumDrawdownCriterion mdd = new MaximumDrawdownCriterion();
assertEquals(0d, mdd.calculate(series, new BaseTradingRecord()), TATestsUtils.TA_OFFSET);
}
use of org.ta4j.core.mocks.MockTimeSeries in project ta4j by ta4j.
the class NumberOfBarsCriterionTest method calculateWithOneTrade.
@Test
public void calculateWithOneTrade() {
MockTimeSeries series = new MockTimeSeries(100, 95, 100, 80, 85, 70);
Trade t = new Trade(Order.buyAt(2, series), Order.sellAt(5, series));
AnalysisCriterion numberOfBars = new NumberOfBarsCriterion();
assertEquals(4, numberOfBars.calculate(series, t), TATestsUtils.TA_OFFSET);
}
Aggregations