use of org.ta4j.core.mocks.MockTimeSeries in project ta4j by ta4j.
the class NumberOfBarsCriterionTest method calculateWithTwoTrades.
@Test
public void calculateWithTwoTrades() {
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 numberOfBars = new NumberOfBarsCriterion();
assertEquals(6, numberOfBars.calculate(series, tradingRecord), TATestsUtils.TA_OFFSET);
}
use of org.ta4j.core.mocks.MockTimeSeries in project ta4j by ta4j.
the class CCIIndicatorTest method setUp.
@Before
public void setUp() {
ArrayList<Bar> bars = new ArrayList<Bar>();
for (Double price : typicalPrices) {
bars.add(new MockBar(price, price, price, price));
}
series = new MockTimeSeries(bars);
}
use of org.ta4j.core.mocks.MockTimeSeries in project ta4j by ta4j.
the class CachedIndicatorTest method recursiveCachedIndicatorOnMovingTimeSeriesShouldNotCauseStackOverflow.
@Test
public void recursiveCachedIndicatorOnMovingTimeSeriesShouldNotCauseStackOverflow() {
// Added to check issue #120: https://github.com/mdeverdelhan/ta4j/issues/120
// See also: CachedIndicator#getValue(int index)
series = new MockTimeSeries();
series.setMaximumBarCount(5);
assertEquals(5, series.getBarCount());
ZLEMAIndicator zlema = new ZLEMAIndicator(new ClosePriceIndicator(series), 1);
try {
assertDecimalEquals(zlema.getValue(8), "4996");
} catch (Throwable t) {
fail(t.getMessage());
}
}
use of org.ta4j.core.mocks.MockTimeSeries in project ta4j by ta4j.
the class CachedIndicatorTest method getValueOnResultsCalculatedFromRemovedBarsShouldReturnFirstRemainingResult.
@Test
public void getValueOnResultsCalculatedFromRemovedBarsShouldReturnFirstRemainingResult() {
TimeSeries timeSeries = new MockTimeSeries(1, 1, 1, 1, 1);
timeSeries.setMaximumBarCount(3);
assertEquals(2, timeSeries.getRemovedBarsCount());
SMAIndicator sma = new SMAIndicator(new ClosePriceIndicator(timeSeries), 2);
for (int i = 0; i < 5; i++) {
assertDecimalEquals(sma.getValue(i), 1);
}
}
use of org.ta4j.core.mocks.MockTimeSeries in project ta4j by ta4j.
the class CachedIndicatorTest method getValueWithOldResultsRemoval.
@Test
public void getValueWithOldResultsRemoval() {
double[] data = new double[20];
Arrays.fill(data, 1);
TimeSeries timeSeries = new MockTimeSeries(data);
SMAIndicator sma = new SMAIndicator(new ClosePriceIndicator(timeSeries), 10);
assertDecimalEquals(sma.getValue(5), 1);
assertDecimalEquals(sma.getValue(10), 1);
timeSeries.setMaximumBarCount(12);
assertDecimalEquals(sma.getValue(19), 1);
}
Aggregations