Search in sources :

Example 46 with ClosePriceIndicator

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

the class RSIIndicatorTest method firstValueShouldBeZero.

@Test
public void firstValueShouldBeZero() throws Exception {
    Indicator<Decimal> indicator = getIndicator(new ClosePriceIndicator(data), 14);
    assertEquals(Decimal.ZERO, indicator.getValue(0));
}
Also used : ClosePriceIndicator(org.ta4j.core.indicators.helpers.ClosePriceIndicator) Test(org.junit.Test)

Example 47 with ClosePriceIndicator

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

the class SMAIndicatorTest method usingTimeFrame3UsingClosePrice.

@Test
public void usingTimeFrame3UsingClosePrice() throws Exception {
    Indicator<Decimal> indicator = getIndicator(new ClosePriceIndicator(data), 3);
    assertDecimalEquals(indicator.getValue(0), 1);
    assertDecimalEquals(indicator.getValue(1), 1.5);
    assertDecimalEquals(indicator.getValue(2), 2);
    assertDecimalEquals(indicator.getValue(3), 3);
    assertDecimalEquals(indicator.getValue(4), 10d / 3);
    assertDecimalEquals(indicator.getValue(5), 11d / 3);
    assertDecimalEquals(indicator.getValue(6), 4);
    assertDecimalEquals(indicator.getValue(7), 13d / 3);
    assertDecimalEquals(indicator.getValue(8), 4);
    assertDecimalEquals(indicator.getValue(9), 10d / 3);
    assertDecimalEquals(indicator.getValue(10), 10d / 3);
    assertDecimalEquals(indicator.getValue(11), 10d / 3);
    assertDecimalEquals(indicator.getValue(12), 3);
}
Also used : ClosePriceIndicator(org.ta4j.core.indicators.helpers.ClosePriceIndicator) Test(org.junit.Test)

Example 48 with ClosePriceIndicator

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

the class TripleEMAIndicatorTest method setUp.

@Before
public void setUp() {
    TimeSeries data = new MockTimeSeries(0.73, 0.72, 0.86, 0.72, 0.62, 0.76, 0.84, 0.69, 0.65, 0.71, 0.53, 0.73, 0.77, 0.67, 0.68);
    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 49 with ClosePriceIndicator

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

the class UlcerIndexIndicatorTest method ulcerIndexUsingTimeFrame14UsingIBMData.

@Test
public void ulcerIndexUsingTimeFrame14UsingIBMData() {
    UlcerIndexIndicator ulcer = new UlcerIndexIndicator(new ClosePriceIndicator(ibmData), 14);
    assertDecimalEquals(ulcer.getValue(0), 0);
    // From: http://stockcharts.com/school/doku.php?id=chart_school:technical_indicators:ulcer_index
    assertDecimalEquals(ulcer.getValue(26), 1.3047);
    assertDecimalEquals(ulcer.getValue(27), 1.3022);
    assertDecimalEquals(ulcer.getValue(28), 1.2156);
    assertDecimalEquals(ulcer.getValue(29), 0.9967);
    assertDecimalEquals(ulcer.getValue(30), 0.7257);
    assertDecimalEquals(ulcer.getValue(31), 0.453);
    assertDecimalEquals(ulcer.getValue(32), 0.4284);
    assertDecimalEquals(ulcer.getValue(33), 0.4284);
    assertDecimalEquals(ulcer.getValue(34), 0.4284);
    assertDecimalEquals(ulcer.getValue(35), 0.4287);
    assertDecimalEquals(ulcer.getValue(36), 0.5089);
    assertDecimalEquals(ulcer.getValue(37), 0.6673);
    assertDecimalEquals(ulcer.getValue(38), 0.9914);
    assertDecimalEquals(ulcer.getValue(39), 1.0921);
    assertDecimalEquals(ulcer.getValue(40), 1.3161);
    assertDecimalEquals(ulcer.getValue(41), 1.5632);
    assertDecimalEquals(ulcer.getValue(42), 1.7609);
}
Also used : ClosePriceIndicator(org.ta4j.core.indicators.helpers.ClosePriceIndicator) Test(org.junit.Test)

Example 50 with ClosePriceIndicator

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

the class WMAIndicatorTest method calculate.

@Test
public void calculate() {
    MockTimeSeries series = new MockTimeSeries(1d, 2d, 3d, 4d, 5d, 6d);
    Indicator<Decimal> close = new ClosePriceIndicator(series);
    Indicator<Decimal> wmaIndicator = new WMAIndicator(close, 3);
    assertDecimalEquals(wmaIndicator.getValue(0), 1);
    assertDecimalEquals(wmaIndicator.getValue(1), 1.6667);
    assertDecimalEquals(wmaIndicator.getValue(2), 2.3333);
    assertDecimalEquals(wmaIndicator.getValue(3), 3.3333);
    assertDecimalEquals(wmaIndicator.getValue(4), 4.3333);
    assertDecimalEquals(wmaIndicator.getValue(5), 5.3333);
}
Also used : Decimal(org.ta4j.core.Decimal) 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