Search in sources :

Example 51 with ClosePriceIndicator

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

the class WMAIndicatorTest method wmaUsingTimeFrame9UsingClosePrice.

@Test
public void wmaUsingTimeFrame9UsingClosePrice() {
    // Example from http://traders.com/Documentation/FEEDbk_docs/2010/12/TradingIndexesWithHullMA.xls
    TimeSeries data = new MockTimeSeries(84.53, 87.39, 84.55, 82.83, 82.58, 83.74, 83.33, 84.57, 86.98, 87.10, 83.11, 83.60, 83.66, 82.76, 79.22, 79.03, 78.18, 77.42, 74.65, 77.48, 76.87);
    WMAIndicator wma = new WMAIndicator(new ClosePriceIndicator(data), 9);
    assertDecimalEquals(wma.getValue(8), 84.4958);
    assertDecimalEquals(wma.getValue(9), 85.0158);
    assertDecimalEquals(wma.getValue(10), 84.6807);
    assertDecimalEquals(wma.getValue(11), 84.5387);
    assertDecimalEquals(wma.getValue(12), 84.4298);
    assertDecimalEquals(wma.getValue(13), 84.1224);
    assertDecimalEquals(wma.getValue(14), 83.1031);
    assertDecimalEquals(wma.getValue(15), 82.1462);
    assertDecimalEquals(wma.getValue(16), 81.1149);
    assertDecimalEquals(wma.getValue(17), 80.0736);
    assertDecimalEquals(wma.getValue(18), 78.6907);
    assertDecimalEquals(wma.getValue(19), 78.1504);
    assertDecimalEquals(wma.getValue(20), 77.6133);
}
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 52 with ClosePriceIndicator

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

the class WilliamsRIndicatorTest method williamsRUsingTimeFrame10UsingClosePrice.

@Test
public void williamsRUsingTimeFrame10UsingClosePrice() {
    WilliamsRIndicator wr = new WilliamsRIndicator(new ClosePriceIndicator(data), 10, new MaxPriceIndicator(data), new MinPriceIndicator(data));
    assertDecimalEquals(wr.getValue(9), -4.0816);
    assertDecimalEquals(wr.getValue(10), -11.7647);
    assertDecimalEquals(wr.getValue(11), -8.9286);
    assertDecimalEquals(wr.getValue(12), -10.5263);
}
Also used : MaxPriceIndicator(org.ta4j.core.indicators.helpers.MaxPriceIndicator) MinPriceIndicator(org.ta4j.core.indicators.helpers.MinPriceIndicator) ClosePriceIndicator(org.ta4j.core.indicators.helpers.ClosePriceIndicator) Test(org.junit.Test)

Example 53 with ClosePriceIndicator

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

the class WilliamsRIndicatorTest method valueLessThenTimeFrame.

@Test
public void valueLessThenTimeFrame() {
    WilliamsRIndicator wr = new WilliamsRIndicator(new ClosePriceIndicator(data), 100, new MaxPriceIndicator(data), new MinPriceIndicator(data));
    assertDecimalEquals(wr.getValue(0), -100d * (0.12 / 0.21));
    assertDecimalEquals(wr.getValue(1), -100d * (0.07 / 0.21));
    assertDecimalEquals(wr.getValue(2), -100d * (0.13 / 0.36));
    assertDecimalEquals(wr.getValue(3), -100d * (0.18 / 0.36));
}
Also used : MaxPriceIndicator(org.ta4j.core.indicators.helpers.MaxPriceIndicator) MinPriceIndicator(org.ta4j.core.indicators.helpers.MinPriceIndicator) ClosePriceIndicator(org.ta4j.core.indicators.helpers.ClosePriceIndicator) Test(org.junit.Test)

Example 54 with ClosePriceIndicator

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

the class CMOIndicatorTest method dpo.

@Test
public void dpo() {
    CMOIndicator cmo = new CMOIndicator(new ClosePriceIndicator(series), 9);
    assertDecimalEquals(cmo.getValue(5), 85.1351);
    assertDecimalEquals(cmo.getValue(6), 53.9326);
    assertDecimalEquals(cmo.getValue(7), 6.2016);
    assertDecimalEquals(cmo.getValue(8), -1.083);
    assertDecimalEquals(cmo.getValue(9), 0.7092);
    assertDecimalEquals(cmo.getValue(10), -1.4493);
    assertDecimalEquals(cmo.getValue(11), 10.7266);
    assertDecimalEquals(cmo.getValue(12), -3.5857);
    assertDecimalEquals(cmo.getValue(13), 4.7619);
    assertDecimalEquals(cmo.getValue(14), 24.1983);
    assertDecimalEquals(cmo.getValue(15), 47.644);
}
Also used : ClosePriceIndicator(org.ta4j.core.indicators.helpers.ClosePriceIndicator) Test(org.junit.Test)

Example 55 with ClosePriceIndicator

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

the class CachedIndicatorTest method getValueWithCacheLengthIncrease.

@Test
public void getValueWithCacheLengthIncrease() {
    double[] data = new double[200];
    Arrays.fill(data, 10);
    SMAIndicator sma = new SMAIndicator(new ClosePriceIndicator(new MockTimeSeries(data)), 100);
    assertDecimalEquals(sma.getValue(105), 10);
}
Also used : 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