use of org.ta4j.core.mocks.MockTimeSeries in project ta4j by ta4j.
the class CashFlowTest method cashFlowWithSellAndBuyOrders.
@Test
public void cashFlowWithSellAndBuyOrders() {
TimeSeries sampleTimeSeries = new MockTimeSeries(2, 1, 3, 5, 6, 3, 20);
TradingRecord tradingRecord = new BaseTradingRecord(Order.buyAt(0, sampleTimeSeries), Order.sellAt(1, sampleTimeSeries), Order.buyAt(3, sampleTimeSeries), Order.sellAt(4, sampleTimeSeries), Order.sellAt(5, sampleTimeSeries), Order.buyAt(6, sampleTimeSeries));
CashFlow cashFlow = new CashFlow(sampleTimeSeries, tradingRecord);
assertDecimalEquals(cashFlow.getValue(0), 1);
assertDecimalEquals(cashFlow.getValue(1), "0.5");
assertDecimalEquals(cashFlow.getValue(2), "0.5");
assertDecimalEquals(cashFlow.getValue(3), "0.5");
assertDecimalEquals(cashFlow.getValue(4), "0.6");
assertDecimalEquals(cashFlow.getValue(5), "0.6");
assertDecimalEquals(cashFlow.getValue(6), "0.09");
}
use of org.ta4j.core.mocks.MockTimeSeries in project ta4j by ta4j.
the class AbstractAnalysisCriterionTest method bestShouldBeBuyAndHoldOnLoss.
@Test
public void bestShouldBeBuyAndHoldOnLoss() {
MockTimeSeries series = new MockTimeSeries(6.0, 3.0, 6.0, 6.0);
TimeSeriesManager manager = new TimeSeriesManager(series);
Strategy bestStrategy = new TotalProfitCriterion().chooseBest(manager, strategies);
assertEquals(buyAndHoldStrategy, bestStrategy);
}
use of org.ta4j.core.mocks.MockTimeSeries in project ta4j by ta4j.
the class AbstractAnalysisCriterionTest method bestShouldBeAlwaysOperateOnProfit.
@Test
public void bestShouldBeAlwaysOperateOnProfit() {
MockTimeSeries series = new MockTimeSeries(6.0, 9.0, 6.0, 6.0);
TimeSeriesManager manager = new TimeSeriesManager(series);
Strategy bestStrategy = new TotalProfitCriterion().chooseBest(manager, strategies);
assertEquals(alwaysStrategy, bestStrategy);
}
use of org.ta4j.core.mocks.MockTimeSeries in project ta4j by ta4j.
the class AverageProfitCriterionTest method calculateOnlyWithGainTrades.
@Test
public void calculateOnlyWithGainTrades() {
series = new MockTimeSeries(100d, 105d, 110d, 100d, 95d, 105d);
TradingRecord tradingRecord = new BaseTradingRecord(Order.buyAt(0, series), Order.sellAt(2, series), Order.buyAt(3, series), Order.sellAt(5, series));
AnalysisCriterion averageProfit = new AverageProfitCriterion();
assertEquals(1.0243, TATestsUtils.TA_OFFSET, averageProfit.calculate(series, tradingRecord));
}
use of org.ta4j.core.mocks.MockTimeSeries in project ta4j by ta4j.
the class AverageProfitCriterionTest method calculateWithASimpleTrade.
@Test
public void calculateWithASimpleTrade() {
series = new MockTimeSeries(100d, 105d, 110d, 100d, 95d, 105d);
TradingRecord tradingRecord = new BaseTradingRecord(Order.buyAt(0, series), Order.sellAt(2, series));
AnalysisCriterion averageProfit = new AverageProfitCriterion();
assertEquals(Math.pow(110d / 100, 1d / 3), averageProfit.calculate(series, tradingRecord), TATestsUtils.TA_OFFSET);
}
Aggregations