use of org.ta4j.core.mocks.MockTimeSeries in project ta4j by ta4j.
the class RewardRiskRatioCriterionTest method withOneTrade.
@Test
public void withOneTrade() {
MockTimeSeries series = new MockTimeSeries(100, 95, 95, 100, 90, 95, 80, 120);
Trade trade = new Trade(Order.buyAt(0, series), Order.sellAt(1, series));
RewardRiskRatioCriterion ratioCriterion = new RewardRiskRatioCriterion();
assertEquals((95d / 100) / ((1d - 0.95d)), TATestsUtils.TA_OFFSET, ratioCriterion.calculate(series, trade));
}
use of org.ta4j.core.mocks.MockTimeSeries in project ta4j by ta4j.
the class TotalProfitCriterionTest method calculateWithOpenedTradeShouldReturn1.
@Test
public void calculateWithOpenedTradeShouldReturn1() {
MockTimeSeries series = new MockTimeSeries(100, 95, 100, 80, 85, 70);
AnalysisCriterion profit = new TotalProfitCriterion();
Trade trade = new Trade();
assertEquals(1d, profit.calculate(series, trade), TATestsUtils.TA_OFFSET);
trade.operate(0);
assertEquals(1d, profit.calculate(series, trade), TATestsUtils.TA_OFFSET);
}
use of org.ta4j.core.mocks.MockTimeSeries in project ta4j by ta4j.
the class TotalProfitCriterionTest 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 profit = new TotalProfitCriterion();
assertEquals(1.10 * 1.05, profit.calculate(series, tradingRecord), TATestsUtils.TA_OFFSET);
}
use of org.ta4j.core.mocks.MockTimeSeries in project ta4j by ta4j.
the class VersusBuyAndHoldCriterionTest method calculateWithAverageProfit.
@Test
public void calculateWithAverageProfit() {
MockTimeSeries series = new MockTimeSeries(100, 95, 100, 80, 85, 130);
TradingRecord tradingRecord = new BaseTradingRecord(Order.buyAt(0, Decimal.NaN, Decimal.NaN), Order.sellAt(1, Decimal.NaN, Decimal.NaN), Order.buyAt(2, Decimal.NaN, Decimal.NaN), Order.sellAt(5, Decimal.NaN, Decimal.NaN));
AnalysisCriterion buyAndHold = new VersusBuyAndHoldCriterion(new AverageProfitCriterion());
assertEquals(Math.pow(95d / 100 * 130d / 100, 1d / 6) / Math.pow(130d / 100, 1d / 6), buyAndHold.calculate(series, tradingRecord), TATestsUtils.TA_OFFSET);
}
use of org.ta4j.core.mocks.MockTimeSeries in project ta4j by ta4j.
the class VersusBuyAndHoldCriterionTest method calculateWithOnlyOneTrade.
@Test
public void calculateWithOnlyOneTrade() {
MockTimeSeries series = new MockTimeSeries(100, 95, 100, 80, 85, 70);
Trade trade = new Trade(Order.buyAt(0, series), Order.sellAt(1, series));
AnalysisCriterion buyAndHold = new VersusBuyAndHoldCriterion(new TotalProfitCriterion());
assertEquals((100d / 70) / (100d / 95), buyAndHold.calculate(series, trade), TATestsUtils.TA_OFFSET);
}
Aggregations