use of org.ta4j.core.mocks.MockTimeSeries in project ta4j by ta4j.
the class TotalProfitCriterionTest method calculateWithNoTradesShouldReturn1.
@Test
public void calculateWithNoTradesShouldReturn1() {
MockTimeSeries series = new MockTimeSeries(100, 95, 100, 80, 85, 70);
AnalysisCriterion profit = new TotalProfitCriterion();
assertEquals(1d, profit.calculate(series, new BaseTradingRecord()), TATestsUtils.TA_OFFSET);
}
use of org.ta4j.core.mocks.MockTimeSeries in project ta4j by ta4j.
the class TotalProfitCriterionTest method calculateProfitWithTradesThatStartSelling.
@Test
public void calculateProfitWithTradesThatStartSelling() {
MockTimeSeries series = new MockTimeSeries(100, 95, 100, 80, 85, 70);
TradingRecord tradingRecord = new BaseTradingRecord(Order.sellAt(0, series), Order.buyAt(1, series), Order.sellAt(2, series), Order.buyAt(5, series));
AnalysisCriterion profit = new TotalProfitCriterion();
assertEquals((1 / 0.95) * (1 / 0.7), profit.calculate(series, tradingRecord), TATestsUtils.TA_OFFSET);
}
use of org.ta4j.core.mocks.MockTimeSeries in project ta4j by ta4j.
the class VersusBuyAndHoldCriterionTest method calculateWithNoTrades.
@Test
public void calculateWithNoTrades() {
MockTimeSeries series = new MockTimeSeries(100, 95, 100, 80, 85, 70);
AnalysisCriterion buyAndHold = new VersusBuyAndHoldCriterion(new TotalProfitCriterion());
assertEquals(1 / 0.7, buyAndHold.calculate(series, new BaseTradingRecord()), TATestsUtils.TA_OFFSET);
}
use of org.ta4j.core.mocks.MockTimeSeries in project ta4j by ta4j.
the class VersusBuyAndHoldCriterionTest method calculateWithNumberOfBars.
@Test
public void calculateWithNumberOfBars() {
MockTimeSeries series = new MockTimeSeries(100, 95, 100, 80, 85, 130);
TradingRecord tradingRecord = new BaseTradingRecord(Order.buyAt(0, series), Order.sellAt(1, series), Order.buyAt(2, series), Order.sellAt(5, series));
AnalysisCriterion buyAndHold = new VersusBuyAndHoldCriterion(new NumberOfBarsCriterion());
assertEquals(6d / 6d, buyAndHold.calculate(series, tradingRecord), TATestsUtils.TA_OFFSET);
}
use of org.ta4j.core.mocks.MockTimeSeries in project ta4j by ta4j.
the class VersusBuyAndHoldCriterionTest method calculateOnlyWithGainTrades.
@Test
public void calculateOnlyWithGainTrades() {
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 buyAndHold = new VersusBuyAndHoldCriterion(new TotalProfitCriterion());
assertEquals(1.10 * 1.05 / 1.05, buyAndHold.calculate(series, tradingRecord), TATestsUtils.TA_OFFSET);
}
Aggregations