Search in sources :

Example 36 with MockBar

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

the class KeltnerChannelUpperIndicatorTest 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));
    data = 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 37 with MockBar

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

the class AccumulationDistributionIndicatorTest method accumulationDistribution.

@Test
public void accumulationDistribution() {
    ZonedDateTime now = ZonedDateTime.now();
    List<Bar> bars = new ArrayList<>();
    // 2-2 * 200 / 4
    bars.add(new MockBar(now, 0d, 10d, 12d, 8d, 0d, 200d, 0));
    // 1-2 *100 / 3
    bars.add(new MockBar(now, 0d, 8d, 10d, 7d, 0d, 100d, 0));
    // 3-6 *300 /9
    bars.add(new MockBar(now, 0d, 9d, 15d, 6d, 0d, 300d, 0));
    // 15-20 *50 / 35
    bars.add(new MockBar(now, 0d, 20d, 40d, 5d, 0d, 50d, 0));
    // 27-0 *600 /27
    bars.add(new MockBar(now, 0d, 30d, 30d, 3d, 0d, 600d, 0));
    TimeSeries series = new MockTimeSeries(bars);
    AccumulationDistributionIndicator ac = new AccumulationDistributionIndicator(series);
    assertDecimalEquals(ac.getValue(0), 0);
    assertDecimalEquals(ac.getValue(1), -100d / 3);
    assertDecimalEquals(ac.getValue(2), -100d - (100d / 3));
    assertDecimalEquals(ac.getValue(3), (-250d / 35) + (-100d - (100d / 3)));
    assertDecimalEquals(ac.getValue(4), 600d + ((-250d / 35) + (-100d - (100d / 3))));
}
Also used : MockBar(org.ta4j.core.mocks.MockBar) Bar(org.ta4j.core.Bar) TimeSeries(org.ta4j.core.TimeSeries) MockTimeSeries(org.ta4j.core.mocks.MockTimeSeries) ZonedDateTime(java.time.ZonedDateTime) MockBar(org.ta4j.core.mocks.MockBar) ArrayList(java.util.ArrayList) MockTimeSeries(org.ta4j.core.mocks.MockTimeSeries) Test(org.junit.Test)

Example 38 with MockBar

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

the class IIIIndicatorTest method intradayIntensityIndex.

@Test
public void intradayIntensityIndex() {
    ZonedDateTime now = ZonedDateTime.now();
    List<Bar> bars = new ArrayList<>();
    // 2-2 * 200 / 4
    bars.add(new MockBar(now, 0d, 10d, 12d, 8d, 0d, 200d, 0));
    // 1-2 *100 / 3
    bars.add(new MockBar(now, 0d, 8d, 10d, 7d, 0d, 100d, 0));
    // 3-6 *300 /9
    bars.add(new MockBar(now, 0d, 9d, 15d, 6d, 0d, 300d, 0));
    // 15-20 *50 / 35
    bars.add(new MockBar(now, 0d, 20d, 40d, 5d, 0d, 50d, 0));
    // 27-0 *600 /27
    bars.add(new MockBar(now, 0d, 30d, 30d, 3d, 0d, 600d, 0));
    TimeSeries series = new MockTimeSeries(bars);
    IIIIndicator iiiIndicator = new IIIIndicator(series);
    assertDecimalEquals(iiiIndicator.getValue(0), 0);
    assertDecimalEquals(iiiIndicator.getValue(1), (2 * 8d - 10d - 7d) / ((10d - 7d) * 100d));
    assertDecimalEquals(iiiIndicator.getValue(2), (2 * 9d - 15d - 6d) / ((15d - 6d) * 300d));
    assertDecimalEquals(iiiIndicator.getValue(3), (2 * 20d - 40d - 5d) / ((40d - 5d) * 50d));
    assertDecimalEquals(iiiIndicator.getValue(4), (2 * 30d - 30d - 3d) / ((30d - 3d) * 600d));
}
Also used : MockBar(org.ta4j.core.mocks.MockBar) Bar(org.ta4j.core.Bar) TimeSeries(org.ta4j.core.TimeSeries) MockTimeSeries(org.ta4j.core.mocks.MockTimeSeries) ZonedDateTime(java.time.ZonedDateTime) MockBar(org.ta4j.core.mocks.MockBar) ArrayList(java.util.ArrayList) MockTimeSeries(org.ta4j.core.mocks.MockTimeSeries) Test(org.junit.Test)

Example 39 with MockBar

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

the class MVWAPIndicatorTest method setUp.

@Before
public void setUp() {
    List<Bar> bars = new ArrayList<Bar>();
    bars.add(new MockBar(44.98, 45.05, 45.17, 44.96, 1));
    bars.add(new MockBar(45.05, 45.10, 45.15, 44.99, 2));
    bars.add(new MockBar(45.11, 45.19, 45.32, 45.11, 1));
    bars.add(new MockBar(45.19, 45.14, 45.25, 45.04, 3));
    bars.add(new MockBar(45.12, 45.15, 45.20, 45.10, 1));
    bars.add(new MockBar(45.15, 45.14, 45.20, 45.10, 2));
    bars.add(new MockBar(45.13, 45.10, 45.16, 45.07, 1));
    bars.add(new MockBar(45.12, 45.15, 45.22, 45.10, 5));
    bars.add(new MockBar(45.15, 45.22, 45.27, 45.14, 1));
    bars.add(new MockBar(45.24, 45.43, 45.45, 45.20, 1));
    bars.add(new MockBar(45.43, 45.44, 45.50, 45.39, 1));
    bars.add(new MockBar(45.43, 45.55, 45.60, 45.35, 5));
    bars.add(new MockBar(45.58, 45.55, 45.61, 45.39, 7));
    bars.add(new MockBar(45.45, 45.01, 45.55, 44.80, 6));
    bars.add(new MockBar(45.03, 44.23, 45.04, 44.17, 1));
    bars.add(new MockBar(44.23, 43.95, 44.29, 43.81, 2));
    bars.add(new MockBar(43.91, 43.08, 43.99, 43.08, 1));
    bars.add(new MockBar(43.07, 43.55, 43.65, 43.06, 7));
    bars.add(new MockBar(43.56, 43.95, 43.99, 43.53, 6));
    bars.add(new MockBar(43.93, 44.47, 44.58, 43.93, 1));
    data = 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 40 with MockBar

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

the class OnBalanceVolumeIndicatorTest method stackOverflowError.

@Test
public void stackOverflowError() {
    List<Bar> bigListOfBars = new ArrayList<Bar>();
    for (int i = 0; i < 10000; i++) {
        bigListOfBars.add(new MockBar(i));
    }
    MockTimeSeries bigSeries = new MockTimeSeries(bigListOfBars);
    OnBalanceVolumeIndicator obv = new OnBalanceVolumeIndicator(bigSeries);
    // If a StackOverflowError is thrown here, then the RecursiveCachedIndicator
    // does not work as intended.
    assertDecimalEquals(obv.getValue(9999), 0);
}
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) Test(org.junit.Test)

Aggregations

MockBar (org.ta4j.core.mocks.MockBar)57 ArrayList (java.util.ArrayList)54 Bar (org.ta4j.core.Bar)48 MockTimeSeries (org.ta4j.core.mocks.MockTimeSeries)46 Before (org.junit.Before)35 Test (org.junit.Test)22 BaseTimeSeries (org.ta4j.core.BaseTimeSeries)6 TimeSeries (org.ta4j.core.TimeSeries)5 ClosePriceIndicator (org.ta4j.core.indicators.helpers.ClosePriceIndicator)5 ZonedDateTime (java.time.ZonedDateTime)3 VolumeIndicator (org.ta4j.core.indicators.helpers.VolumeIndicator)3 BaseTradingRecord (org.ta4j.core.BaseTradingRecord)1 TradingRecord (org.ta4j.core.TradingRecord)1 FixedRule (org.ta4j.core.trading.rules.FixedRule)1