Search in sources :

Example 21 with ClosePriceIndicator

use of org.ta4j.core.indicators.helpers.ClosePriceIndicator in project ta4j by ta4j.

the class AbstractIndicatorTest method getTimeSeries.

@Test
public void getTimeSeries() {
    ClosePriceIndicator cp = new ClosePriceIndicator(series);
    assertEquals(series, cp.getTimeSeries());
    SMAIndicator sma = new SMAIndicator(cp, 3);
    assertEquals(series, sma.getTimeSeries());
}
Also used : ClosePriceIndicator(org.ta4j.core.indicators.helpers.ClosePriceIndicator) Test(org.junit.Test)

Example 22 with ClosePriceIndicator

use of org.ta4j.core.indicators.helpers.ClosePriceIndicator 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 23 with ClosePriceIndicator

use of org.ta4j.core.indicators.helpers.ClosePriceIndicator 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 24 with ClosePriceIndicator

use of org.ta4j.core.indicators.helpers.ClosePriceIndicator in project ta4j by ta4j.

the class CachedIndicatorTest method ifCacheWorks.

@Test
public void ifCacheWorks() {
    SMAIndicator sma = new SMAIndicator(new ClosePriceIndicator(series), 3);
    Decimal firstTime = sma.getValue(4);
    Decimal secondTime = sma.getValue(4);
    assertEquals(firstTime, secondTime);
}
Also used : Decimal(org.ta4j.core.Decimal) ClosePriceIndicator(org.ta4j.core.indicators.helpers.ClosePriceIndicator) Test(org.junit.Test)

Example 25 with ClosePriceIndicator

use of org.ta4j.core.indicators.helpers.ClosePriceIndicator 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

ClosePriceIndicator (org.ta4j.core.indicators.helpers.ClosePriceIndicator)81 Test (org.junit.Test)55 MockTimeSeries (org.ta4j.core.mocks.MockTimeSeries)26 TimeSeries (org.ta4j.core.TimeSeries)16 Before (org.junit.Before)14 SMAIndicator (org.ta4j.core.indicators.SMAIndicator)7 OverIndicatorRule (org.ta4j.core.trading.rules.OverIndicatorRule)6 ArrayList (java.util.ArrayList)5 TimeSeriesCollection (org.jfree.data.time.TimeSeriesCollection)5 MockBar (org.ta4j.core.mocks.MockBar)5 UnderIndicatorRule (org.ta4j.core.trading.rules.UnderIndicatorRule)5 SimpleDateFormat (java.text.SimpleDateFormat)4 JFreeChart (org.jfree.chart.JFreeChart)4 DateAxis (org.jfree.chart.axis.DateAxis)4 XYPlot (org.jfree.chart.plot.XYPlot)4 EMAIndicator (org.ta4j.core.indicators.EMAIndicator)4 CrossedDownIndicatorRule (org.ta4j.core.trading.rules.CrossedDownIndicatorRule)4 BaseStrategy (org.ta4j.core.BaseStrategy)3 Decimal (org.ta4j.core.Decimal)3 MaxPriceIndicator (org.ta4j.core.indicators.helpers.MaxPriceIndicator)3