Search in sources :

Example 86 with MockTimeSeries

use of org.ta4j.core.mocks.MockTimeSeries 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)

Example 87 with MockTimeSeries

use of org.ta4j.core.mocks.MockTimeSeries 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 88 with MockTimeSeries

use of org.ta4j.core.mocks.MockTimeSeries 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 89 with MockTimeSeries

use of org.ta4j.core.mocks.MockTimeSeries in project ta4j by ta4j.

the class FisherIndicatorTest method setUp.

@Before
public void setUp() {
    List<Bar> bars = new ArrayList<Bar>();
    bars.add(new MockBar(44.98, 45.05, 45.17, 44.96));
    bars.add(new MockBar(45.05, 45.10, 45.15, 44.99));
    bars.add(new MockBar(45.11, 45.19, 45.32, 45.11));
    bars.add(new MockBar(45.19, 45.14, 45.25, 45.04));
    bars.add(new MockBar(45.12, 45.15, 45.20, 45.10));
    bars.add(new MockBar(45.15, 45.14, 45.20, 45.10));
    bars.add(new MockBar(45.13, 45.10, 45.16, 45.07));
    bars.add(new MockBar(45.12, 45.15, 45.22, 45.10));
    bars.add(new MockBar(45.15, 45.22, 45.27, 45.14));
    bars.add(new MockBar(45.24, 45.43, 45.45, 45.20));
    bars.add(new MockBar(45.43, 45.44, 45.50, 45.39));
    bars.add(new MockBar(45.43, 45.55, 45.60, 45.35));
    bars.add(new MockBar(45.58, 45.55, 45.61, 45.39));
    bars.add(new MockBar(45.45, 45.01, 45.55, 44.80));
    bars.add(new MockBar(45.03, 44.23, 45.04, 44.17));
    bars.add(new MockBar(44.23, 43.95, 44.29, 43.81));
    bars.add(new MockBar(43.91, 43.08, 43.99, 43.08));
    bars.add(new MockBar(43.07, 43.55, 43.65, 43.06));
    bars.add(new MockBar(43.56, 43.95, 43.99, 43.53));
    bars.add(new MockBar(43.93, 44.47, 44.58, 43.93));
    series = new MockTimeSeries(bars);
}
Also used : MockBar(org.ta4j.core.mocks.MockBar) Bar(org.ta4j.core.Bar) MockBar(org.ta4j.core.mocks.MockBar) ArrayList(java.util.ArrayList) MockTimeSeries(org.ta4j.core.mocks.MockTimeSeries) Before(org.junit.Before)

Example 90 with MockTimeSeries

use of org.ta4j.core.mocks.MockTimeSeries in project ta4j by ta4j.

the class MMAIndicatorTest method stackOverflowError.

@Test
public void stackOverflowError() throws Exception {
    List<Bar> bigListOfBars = new ArrayList<>();
    for (int i = 0; i < 10000; i++) {
        bigListOfBars.add(new MockBar(i));
    }
    MockTimeSeries bigSeries = new MockTimeSeries(bigListOfBars);
    ClosePriceIndicator closePrice = new ClosePriceIndicator(bigSeries);
    Indicator<Decimal> actualIndicator = getIndicator(closePrice, 10);
    // if a StackOverflowError is thrown here, then the RecursiveCachedIndicator does not work as intended.
    assertEquals(9990.0, actualIndicator.getValue(9999).doubleValue(), TATestsUtils.TA_OFFSET);
}
Also used : MockBar(org.ta4j.core.mocks.MockBar) MockBar(org.ta4j.core.mocks.MockBar) ArrayList(java.util.ArrayList) MockTimeSeries(org.ta4j.core.mocks.MockTimeSeries) ClosePriceIndicator(org.ta4j.core.indicators.helpers.ClosePriceIndicator) Test(org.junit.Test)

Aggregations

MockTimeSeries (org.ta4j.core.mocks.MockTimeSeries)135 Test (org.junit.Test)90 MockBar (org.ta4j.core.mocks.MockBar)46 ArrayList (java.util.ArrayList)45 Before (org.junit.Before)45 Bar (org.ta4j.core.Bar)42 TimeSeries (org.ta4j.core.TimeSeries)29 ClosePriceIndicator (org.ta4j.core.indicators.helpers.ClosePriceIndicator)25 BaseTradingRecord (org.ta4j.core.BaseTradingRecord)17 TradingRecord (org.ta4j.core.TradingRecord)12 ZonedDateTime (java.time.ZonedDateTime)5 AnalysisCriterion (org.ta4j.core.AnalysisCriterion)3 BaseStrategy (org.ta4j.core.BaseStrategy)3 ExternalCriterionTest (org.ta4j.core.ExternalCriterionTest)3 Strategy (org.ta4j.core.Strategy)3 Decimal (org.ta4j.core.Decimal)2 TimeSeriesManager (org.ta4j.core.TimeSeriesManager)2 Trade (org.ta4j.core.Trade)2 SMAIndicator (org.ta4j.core.indicators.SMAIndicator)2 FixedRule (org.ta4j.core.trading.rules.FixedRule)2