use of org.ta4j.core.mocks.MockTimeSeries in project ta4j by ta4j.
the class VersusBuyAndHoldCriterionTest method calculateOnlyWithLossTrades.
@Test
public void calculateOnlyWithLossTrades() {
MockTimeSeries series = new MockTimeSeries(100, 95, 100, 80, 85, 70);
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 TotalProfitCriterion());
assertEquals(0.95 * 0.7 / 0.7, buyAndHold.calculate(series, tradingRecord), TATestsUtils.TA_OFFSET);
}
use of org.ta4j.core.mocks.MockTimeSeries in project ta4j by ta4j.
the class ATRIndicatorTest method testDummy.
@Test
public void testDummy() throws Exception {
List<Bar> bars = new ArrayList<Bar>();
bars.add(new MockBar(0, 12, 15, 8));
bars.add(new MockBar(0, 8, 11, 6));
bars.add(new MockBar(0, 15, 17, 14));
bars.add(new MockBar(0, 15, 17, 14));
bars.add(new MockBar(0, 0, 0, 2));
Indicator<Decimal> indicator = getIndicator(new MockTimeSeries(bars), 3);
assertEquals(7d, indicator.getValue(0).doubleValue(), TATestsUtils.TA_OFFSET);
assertEquals(6d / 3 + (1 - 1d / 3) * indicator.getValue(0).doubleValue(), indicator.getValue(1).doubleValue(), TATestsUtils.TA_OFFSET);
assertEquals(9d / 3 + (1 - 1d / 3) * indicator.getValue(1).doubleValue(), indicator.getValue(2).doubleValue(), TATestsUtils.TA_OFFSET);
assertEquals(3d / 3 + (1 - 1d / 3) * indicator.getValue(2).doubleValue(), indicator.getValue(3).doubleValue(), TATestsUtils.TA_OFFSET);
assertEquals(15d / 3 + (1 - 1d / 3) * indicator.getValue(3).doubleValue(), indicator.getValue(4).doubleValue(), TATestsUtils.TA_OFFSET);
}
use of org.ta4j.core.mocks.MockTimeSeries in project ta4j by ta4j.
the class AccelerationDecelerationIndicatorTest method setUp.
@Before
public void setUp() {
List<Bar> bars = new ArrayList<Bar>();
bars.add(new MockBar(0, 0, 16, 8));
bars.add(new MockBar(0, 0, 12, 6));
bars.add(new MockBar(0, 0, 18, 14));
bars.add(new MockBar(0, 0, 10, 6));
bars.add(new MockBar(0, 0, 8, 4));
series = new MockTimeSeries(bars);
}
use of org.ta4j.core.mocks.MockTimeSeries in project ta4j by ta4j.
the class CashFlowTest method cashFlowValueWithOnlyOneTradeAndAGapBefore.
@Test
public void cashFlowValueWithOnlyOneTradeAndAGapBefore() {
TimeSeries sampleTimeSeries = new MockTimeSeries(1d, 1d, 2d);
TradingRecord tradingRecord = new BaseTradingRecord(Order.buyAt(1, sampleTimeSeries), Order.sellAt(2, sampleTimeSeries));
CashFlow cashFlow = new CashFlow(sampleTimeSeries, tradingRecord);
assertDecimalEquals(cashFlow.getValue(0), 1);
assertDecimalEquals(cashFlow.getValue(1), 1);
assertDecimalEquals(cashFlow.getValue(2), 2);
}
use of org.ta4j.core.mocks.MockTimeSeries in project ta4j by ta4j.
the class CashFlowTest method cashFlowBuyWithOnlyOneTrade.
@Test
public void cashFlowBuyWithOnlyOneTrade() {
TimeSeries sampleTimeSeries = new MockTimeSeries(1d, 2d);
TradingRecord tradingRecord = new BaseTradingRecord(Order.buyAt(0, sampleTimeSeries), Order.sellAt(1, sampleTimeSeries));
CashFlow cashFlow = new CashFlow(sampleTimeSeries, tradingRecord);
assertDecimalEquals(cashFlow.getValue(0), 1);
assertDecimalEquals(cashFlow.getValue(1), 2);
}
Aggregations