use of org.ta4j.core.mocks.MockBar 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);
}
use of org.ta4j.core.mocks.MockBar in project ta4j by ta4j.
the class MassIndexIndicatorTest method setUp.
@Before
public void setUp() {
List<Bar> bars = new ArrayList<Bar>();
// open, close, high, low
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));
data = new BaseTimeSeries(bars);
}
use of org.ta4j.core.mocks.MockBar in project ta4j by ta4j.
the class ParabolicSarIndicatorTest method startUpAndDownTrendTest.
@Test
public void startUpAndDownTrendTest() {
List<Bar> bars = new ArrayList<Bar>();
bars.add(new MockBar(0, 75.1, 74.06, 75.11));
bars.add(new MockBar(0, 75.9, 76.030000, 74.640000));
bars.add(new MockBar(0, 75.24, 76.269900, 75.060000));
bars.add(new MockBar(0, 75.17, 75.280000, 74.500000));
bars.add(new MockBar(0, 74.6, 75.310000, 74.540000));
bars.add(new MockBar(0, 74.1, 75.467000, 74.010000));
bars.add(new MockBar(0, 73.740000, 74.700000, 73.546000));
bars.add(new MockBar(0, 73.390000, 73.830000, 72.720000));
bars.add(new MockBar(0, 73.25, 73.890000, 72.86));
bars.add(new MockBar(0, 74.36, 74.410000, 73, 26));
bars.add(new MockBar(0, 76.510000, 76.830000, 74.820000));
bars.add(new MockBar(0, 75.590000, 76.850000, 74.540000));
bars.add(new MockBar(0, 75.910000, 76.960000, 75.510000));
bars.add(new MockBar(0, 74.610000, 77.070000, 74.560000));
bars.add(new MockBar(0, 75.330000, 75.530000, 74.010000));
bars.add(new MockBar(0, 75.010000, 75.500000, 74.510000));
bars.add(new MockBar(0, 75.620000, 76.210000, 75.250000));
bars.add(new MockBar(0, 76.040000, 76.460000, 75.092800));
bars.add(new MockBar(0, 76.450000, 76.450000, 75.435000));
bars.add(new MockBar(0, 76.260000, 76.470000, 75.840000));
bars.add(new MockBar(0, 76.850000, 77.000000, 76.190000));
ParabolicSarIndicator sar = new ParabolicSarIndicator(new MockTimeSeries(bars));
assertEquals(sar.getValue(0).toString(), "NaN");
assertDecimalEquals(sar.getValue(1), 74.640000000000000568434188608080);
// start with up trend
assertDecimalEquals(sar.getValue(2), 74.640000000000000568434188608080);
// switch to downtrend
assertDecimalEquals(sar.getValue(3), 76.269900000000006912159733474255);
// hold trend...
assertDecimalEquals(sar.getValue(4), 76.234502000000006773916538804770);
assertDecimalEquals(sar.getValue(5), 76.200611960000006763493729522452);
assertDecimalEquals(sar.getValue(6), 76.112987481600006697590288240463);
assertDecimalEquals(sar.getValue(7), 75.958968232704006684543855953962);
assertDecimalEquals(sar.getValue(8), 75.699850774087686058830877300352);
// switch to up trend
assertDecimalEquals(sar.getValue(9), 75.461462712160671083174936939031);
// hold trend
assertDecimalEquals(sar.getValue(10), 72.719999999999998863131622783840);
assertDecimalEquals(sar.getValue(11), 72.802199999999998851762939011678);
assertDecimalEquals(sar.getValue(12), 72.964111999999998670318746007979);
assertDecimalEquals(sar.getValue(13), 73.203865279999998374933056766167);
assertDecimalEquals(sar.getValue(14), 73.513156057599997959241591161117);
assertDecimalEquals(sar.getValue(15), 73.797703572991997576805442804471);
assertDecimalEquals(sar.getValue(16), 74.059487287152637224964186316356);
assertDecimalEquals(sar.getValue(17), 74.300328304180425701270230347291);
assertDecimalEquals(sar.getValue(18), 74.521902039845991099471790855751);
assertDecimalEquals(sar.getValue(19), 74.725749876658311265817226523534);
assertDecimalEquals(sar.getValue(20), 74.913289886525645818855027337894);
}
use of org.ta4j.core.mocks.MockBar in project ta4j by ta4j.
the class TimeSeriesTest method setUp.
// it is purposed to test the deprecated sub series creation
@SuppressWarnings("deprecation")
@Before
public void setUp() {
bars = new LinkedList<>();
bars.add(new MockBar(ZonedDateTime.of(2014, 6, 13, 0, 0, 0, 0, ZoneId.systemDefault()), 1d));
bars.add(new MockBar(ZonedDateTime.of(2014, 6, 14, 0, 0, 0, 0, ZoneId.systemDefault()), 2d));
bars.add(new MockBar(ZonedDateTime.of(2014, 6, 15, 0, 0, 0, 0, ZoneId.systemDefault()), 3d));
bars.add(new MockBar(ZonedDateTime.of(2014, 6, 20, 0, 0, 0, 0, ZoneId.systemDefault()), 4d));
bars.add(new MockBar(ZonedDateTime.of(2014, 6, 25, 0, 0, 0, 0, ZoneId.systemDefault()), 5d));
bars.add(new MockBar(ZonedDateTime.of(2014, 6, 30, 0, 0, 0, 0, ZoneId.systemDefault()), 6d));
defaultName = "Series Name";
defaultSeries = new BaseTimeSeries(defaultName, bars);
constrainedSeries = new BaseTimeSeries(defaultSeries, 2, 4);
emptySeries = new BaseTimeSeries();
Strategy strategy = new BaseStrategy(new FixedRule(0, 2, 3, 6), new FixedRule(1, 4, 7, 8));
// Strategy would need a real test class
strategy.setUnstablePeriod(2);
}
use of org.ta4j.core.mocks.MockBar in project ta4j by ta4j.
the class KeltnerChannelMiddleIndicatorTest method setUp.
@Before
public void setUp() {
List<Bar> bars = new ArrayList<Bar>();
bars.add(new MockBar(11577.43, 11670.75, 11711.47, 11577.35));
bars.add(new MockBar(11670.90, 11691.18, 11698.22, 11635.74));
bars.add(new MockBar(11688.61, 11722.89, 11742.68, 11652.89));
bars.add(new MockBar(11716.93, 11697.31, 11736.74, 11667.46));
bars.add(new MockBar(11696.86, 11674.76, 11726.94, 11599.68));
bars.add(new MockBar(11672.34, 11637.45, 11677.33, 11573.87));
bars.add(new MockBar(11638.51, 11671.88, 11704.12, 11635.48));
bars.add(new MockBar(11673.62, 11755.44, 11782.23, 11673.62));
bars.add(new MockBar(11753.70, 11731.90, 11757.25, 11700.53));
bars.add(new MockBar(11732.13, 11787.38, 11794.15, 11698.83));
bars.add(new MockBar(11783.82, 11837.93, 11858.78, 11777.99));
bars.add(new MockBar(11834.21, 11825.29, 11861.24, 11798.46));
bars.add(new MockBar(11823.70, 11822.80, 11845.16, 11744.77));
bars.add(new MockBar(11822.95, 11871.84, 11905.48, 11822.80));
bars.add(new MockBar(11873.43, 11980.52, 11982.94, 11867.98));
bars.add(new MockBar(11980.52, 11977.19, 11985.97, 11898.74));
bars.add(new MockBar(11978.85, 11985.44, 12020.52, 11961.83));
bars.add(new MockBar(11985.36, 11989.83, 12019.53, 11971.93));
bars.add(new MockBar(11824.39, 11891.93, 11891.93, 11817.88));
bars.add(new MockBar(11892.50, 12040.16, 12050.75, 11892.50));
bars.add(new MockBar(12038.27, 12041.97, 12057.91, 12018.51));
bars.add(new MockBar(12040.68, 12062.26, 12080.54, 11981.05));
bars.add(new MockBar(12061.73, 12092.15, 12092.42, 12025.78));
bars.add(new MockBar(12092.38, 12161.63, 12188.76, 12092.30));
bars.add(new MockBar(12152.70, 12233.15, 12238.79, 12150.05));
bars.add(new MockBar(12229.29, 12239.89, 12254.23, 12188.19));
bars.add(new MockBar(12239.66, 12229.29, 12239.66, 12156.94));
bars.add(new MockBar(12227.78, 12273.26, 12285.94, 12180.48));
bars.add(new MockBar(12266.83, 12268.19, 12276.21, 12235.91));
bars.add(new MockBar(12266.75, 12226.64, 12267.66, 12193.27));
bars.add(new MockBar(12219.79, 12288.17, 12303.16, 12219.79));
bars.add(new MockBar(12287.72, 12318.14, 12331.31, 12253.24));
bars.add(new MockBar(12389.74, 12212.79, 12389.82, 12176.31));
bars.add(new MockBar(12211.81, 12105.78, 12221.12, 12063.43));
data = new MockTimeSeries(bars);
}
Aggregations