Search in sources :

Example 56 with ClosePriceIndicator

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

the class CoppockCurveIndicatorTest method coppockCurveWithRoc14Roc11Wma10.

@Test
public void coppockCurveWithRoc14Roc11Wma10() {
    // Example from http://stockcharts.com/school/doku.php?id=chart_school:technical_indicators:coppock_curve
    TimeSeries data = new MockTimeSeries(872.81, 919.14, 919.32, 987.48, 1020.62, 1057.08, 1036.19, 1095.63, 1115.1, 1073.87, 1104.49, 1169.43, 1186.69, 1089.41, 1030.71, 1101.6, 1049.33, 1141.2, 1183.26, 1180.55, 1257.64, 1286.12, 1327.22, 1325.83, 1363.61, 1345.2, 1320.64, 1292.28, 1218.89, 1131.42, 1253.3, 1246.96, 1257.6, 1312.41, 1365.68, 1408.47, 1397.91, 1310.33, 1362.16, 1379.32);
    CoppockCurveIndicator cc = new CoppockCurveIndicator(new ClosePriceIndicator(data), 14, 11, 10);
    assertDecimalEquals(cc.getValue(31), 23.8929);
    assertDecimalEquals(cc.getValue(32), 19.3187);
    assertDecimalEquals(cc.getValue(33), 16.3505);
    assertDecimalEquals(cc.getValue(34), 14.12);
    assertDecimalEquals(cc.getValue(35), 12.782);
    assertDecimalEquals(cc.getValue(36), 11.3924);
    assertDecimalEquals(cc.getValue(37), 8.3662);
    assertDecimalEquals(cc.getValue(38), 7.4532);
    assertDecimalEquals(cc.getValue(39), 8.79);
}
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 57 with ClosePriceIndicator

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

the class DPOIndicatorTest method dpo.

@Test
public void dpo() {
    DPOIndicator dpo = new DPOIndicator(series, 9);
    ClosePriceIndicator cp = new ClosePriceIndicator(series);
    SMAIndicator sma = new SMAIndicator(cp, 9);
    int timeShift = 9 / 2 + 1;
    for (int i = series.getBeginIndex(); i <= series.getEndIndex(); i++) {
        assertEquals(dpo.getValue(i), cp.getValue(i).minus(sma.getValue(i - timeShift)));
    }
    assertDecimalEquals(dpo.getValue(9), 0.111999);
    assertDecimalEquals(dpo.getValue(10), -0.02);
    assertDecimalEquals(dpo.getValue(11), 0.21142857142);
    assertDecimalEquals(dpo.getValue(12), 0.169999999999999);
}
Also used : ClosePriceIndicator(org.ta4j.core.indicators.helpers.ClosePriceIndicator) Test(org.junit.Test)

Example 58 with ClosePriceIndicator

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

the class DoubleEMAIndicatorTest 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 59 with ClosePriceIndicator

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

the class EMAIndicatorTest method externalData.

@Test
public void externalData() throws Exception {
    TimeSeries xlsSeries = xls.getSeries();
    Indicator<Decimal> closePrice = new ClosePriceIndicator(xlsSeries);
    Indicator<Decimal> indicator;
    indicator = getIndicator(closePrice, 1);
    assertIndicatorEquals(xls.getIndicator(1), indicator);
    assertEquals(329.0, indicator.getValue(indicator.getTimeSeries().getEndIndex()).doubleValue(), TATestsUtils.TA_OFFSET);
    indicator = getIndicator(closePrice, 3);
    assertIndicatorEquals(xls.getIndicator(3), indicator);
    assertEquals(327.7748, indicator.getValue(indicator.getTimeSeries().getEndIndex()).doubleValue(), TATestsUtils.TA_OFFSET);
    indicator = getIndicator(closePrice, 13);
    assertIndicatorEquals(xls.getIndicator(13), indicator);
    assertEquals(327.4076, indicator.getValue(indicator.getTimeSeries().getEndIndex()).doubleValue(), TATestsUtils.TA_OFFSET);
}
Also used : MockTimeSeries(org.ta4j.core.mocks.MockTimeSeries) ClosePriceIndicator(org.ta4j.core.indicators.helpers.ClosePriceIndicator) Test(org.junit.Test)

Example 60 with ClosePriceIndicator

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

the class EMAIndicatorTest method usingTimeFrame10UsingClosePrice.

@Test
public void usingTimeFrame10UsingClosePrice() throws Exception {
    Indicator<Decimal> indicator = getIndicator(new ClosePriceIndicator(data), 10);
    assertDecimalEquals(indicator.getValue(9), 63.6948);
    assertDecimalEquals(indicator.getValue(10), 63.2648);
    assertDecimalEquals(indicator.getValue(11), 62.9457);
}
Also used : 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