Search in sources :

Example 41 with MockTimeSeries

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);
}
Also used : BaseTradingRecord(org.ta4j.core.BaseTradingRecord) BaseTradingRecord(org.ta4j.core.BaseTradingRecord) TradingRecord(org.ta4j.core.TradingRecord) MockTimeSeries(org.ta4j.core.mocks.MockTimeSeries) AnalysisCriterion(org.ta4j.core.AnalysisCriterion) Test(org.junit.Test)

Example 42 with MockTimeSeries

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);
}
Also used : MockBar(org.ta4j.core.mocks.MockBar) Bar(org.ta4j.core.Bar) MockBar(org.ta4j.core.mocks.MockBar) ArrayList(java.util.ArrayList) MockTimeSeries(org.ta4j.core.mocks.MockTimeSeries) Before(org.junit.Before)

Example 43 with MockTimeSeries

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());
    }
}
Also used : MockTimeSeries(org.ta4j.core.mocks.MockTimeSeries) ClosePriceIndicator(org.ta4j.core.indicators.helpers.ClosePriceIndicator) Test(org.junit.Test)

Example 44 with MockTimeSeries

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);
    }
}
Also used : TimeSeries(org.ta4j.core.TimeSeries) MockTimeSeries(org.ta4j.core.mocks.MockTimeSeries) MockTimeSeries(org.ta4j.core.mocks.MockTimeSeries) ClosePriceIndicator(org.ta4j.core.indicators.helpers.ClosePriceIndicator) Test(org.junit.Test)

Example 45 with MockTimeSeries

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);
}
Also used : TimeSeries(org.ta4j.core.TimeSeries) MockTimeSeries(org.ta4j.core.mocks.MockTimeSeries) MockTimeSeries(org.ta4j.core.mocks.MockTimeSeries) ClosePriceIndicator(org.ta4j.core.indicators.helpers.ClosePriceIndicator) Test(org.junit.Test)

Aggregations

MockTimeSeries (org.ta4j.core.mocks.MockTimeSeries)135 Test (org.junit.Test)90 MockBar (org.ta4j.core.mocks.MockBar)46 ArrayList (java.util.ArrayList)45 Before (org.junit.Before)45 Bar (org.ta4j.core.Bar)42 TimeSeries (org.ta4j.core.TimeSeries)29 ClosePriceIndicator (org.ta4j.core.indicators.helpers.ClosePriceIndicator)25 BaseTradingRecord (org.ta4j.core.BaseTradingRecord)17 TradingRecord (org.ta4j.core.TradingRecord)12 ZonedDateTime (java.time.ZonedDateTime)5 AnalysisCriterion (org.ta4j.core.AnalysisCriterion)3 BaseStrategy (org.ta4j.core.BaseStrategy)3 ExternalCriterionTest (org.ta4j.core.ExternalCriterionTest)3 Strategy (org.ta4j.core.Strategy)3 Decimal (org.ta4j.core.Decimal)2 TimeSeriesManager (org.ta4j.core.TimeSeriesManager)2 Trade (org.ta4j.core.Trade)2 SMAIndicator (org.ta4j.core.indicators.SMAIndicator)2 FixedRule (org.ta4j.core.trading.rules.FixedRule)2