Search in sources :

Example 36 with ClosePriceIndicator

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

the class BollingerBandWidthIndicatorTest method setUp.

@Before
public void setUp() {
    TimeSeries data = new MockTimeSeries(10, 12, 15, 14, 17, 20, 21, 20, 20, 19, 20, 17, 12, 12, 9, 8, 9, 10, 9, 10);
    closePrice = new ClosePriceIndicator(data);
}
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) Before(org.junit.Before)

Example 37 with ClosePriceIndicator

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

the class BollingerBandsMiddleIndicatorTest method bollingerBandsMiddleUsingSMA.

@Test
public void bollingerBandsMiddleUsingSMA() {
    SMAIndicator sma = new SMAIndicator(new ClosePriceIndicator(data), 3);
    BollingerBandsMiddleIndicator bbmSMA = new BollingerBandsMiddleIndicator(sma);
    for (int i = 0; i < data.getBarCount(); i++) {
        assertEquals(sma.getValue(i), bbmSMA.getValue(i));
    }
}
Also used : SMAIndicator(org.ta4j.core.indicators.SMAIndicator) ClosePriceIndicator(org.ta4j.core.indicators.helpers.ClosePriceIndicator) Test(org.junit.Test)

Example 38 with ClosePriceIndicator

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

the class BollingerBandsUpperIndicatorTest method setUp.

@Before
public void setUp() {
    TimeSeries data = new MockTimeSeries(1, 2, 3, 4, 3, 4, 5, 4, 3, 3, 4, 3, 2);
    timeFrame = 3;
    closePrice = new ClosePriceIndicator(data);
    sma = new SMAIndicator(closePrice, timeFrame);
}
Also used : SMAIndicator(org.ta4j.core.indicators.SMAIndicator) TimeSeries(org.ta4j.core.TimeSeries) MockTimeSeries(org.ta4j.core.mocks.MockTimeSeries) MockTimeSeries(org.ta4j.core.mocks.MockTimeSeries) ClosePriceIndicator(org.ta4j.core.indicators.helpers.ClosePriceIndicator) Before(org.junit.Before)

Example 39 with ClosePriceIndicator

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

the class KAMAIndicatorTest method kama.

@Test
public void kama() {
    ClosePriceIndicator closePrice = new ClosePriceIndicator(data);
    KAMAIndicator kama = new KAMAIndicator(closePrice, 10, 2, 30);
    assertDecimalEquals(kama.getValue(9), 109.2400);
    assertDecimalEquals(kama.getValue(10), 109.2449);
    assertDecimalEquals(kama.getValue(11), 109.2165);
    assertDecimalEquals(kama.getValue(12), 109.1173);
    assertDecimalEquals(kama.getValue(13), 109.0981);
    assertDecimalEquals(kama.getValue(14), 109.0894);
    assertDecimalEquals(kama.getValue(15), 109.1240);
    assertDecimalEquals(kama.getValue(16), 109.1376);
    assertDecimalEquals(kama.getValue(17), 109.2769);
    assertDecimalEquals(kama.getValue(18), 109.4365);
    assertDecimalEquals(kama.getValue(19), 109.4569);
    assertDecimalEquals(kama.getValue(20), 109.4651);
    assertDecimalEquals(kama.getValue(21), 109.4612);
    assertDecimalEquals(kama.getValue(22), 109.3904);
    assertDecimalEquals(kama.getValue(23), 109.3165);
    assertDecimalEquals(kama.getValue(24), 109.2924);
    assertDecimalEquals(kama.getValue(25), 109.1836);
    assertDecimalEquals(kama.getValue(26), 109.0778);
    assertDecimalEquals(kama.getValue(27), 108.9498);
    assertDecimalEquals(kama.getValue(28), 108.4230);
    assertDecimalEquals(kama.getValue(29), 108.0157);
    assertDecimalEquals(kama.getValue(30), 107.9967);
    assertDecimalEquals(kama.getValue(31), 108.0069);
    assertDecimalEquals(kama.getValue(32), 108.2596);
    assertDecimalEquals(kama.getValue(33), 108.4818);
    assertDecimalEquals(kama.getValue(34), 108.9119);
    assertDecimalEquals(kama.getValue(35), 109.6734);
    assertDecimalEquals(kama.getValue(36), 110.4947);
    assertDecimalEquals(kama.getValue(37), 111.1077);
    assertDecimalEquals(kama.getValue(38), 111.4622);
    assertDecimalEquals(kama.getValue(39), 111.6092);
    assertDecimalEquals(kama.getValue(40), 111.5663);
    assertDecimalEquals(kama.getValue(41), 111.5491);
    assertDecimalEquals(kama.getValue(42), 111.5425);
    assertDecimalEquals(kama.getValue(43), 111.5426);
    assertDecimalEquals(kama.getValue(44), 111.5457);
    assertDecimalEquals(kama.getValue(45), 111.5658);
    assertDecimalEquals(kama.getValue(46), 111.5688);
    assertDecimalEquals(kama.getValue(47), 111.5522);
    assertDecimalEquals(kama.getValue(48), 111.5595);
}
Also used : ClosePriceIndicator(org.ta4j.core.indicators.helpers.ClosePriceIndicator) Test(org.junit.Test)

Example 40 with ClosePriceIndicator

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

the class KAMAIndicatorTest method getValueOnDeepIndicesShouldNotCauseStackOverflow.

@Test
public void getValueOnDeepIndicesShouldNotCauseStackOverflow() {
    TimeSeries series = new MockTimeSeries();
    series.setMaximumBarCount(5000);
    assertEquals(5000, series.getBarCount());
    KAMAIndicator kama = new KAMAIndicator(new ClosePriceIndicator(series), 10, 2, 30);
    try {
        assertDecimalEquals(kama.getValue(3000), "2999.75");
    } catch (Throwable t) {
        fail(t.getMessage());
    }
}
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