Search in sources :

Example 11 with MockBar

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

the class MedianPriceIndicatorTest method setUp.

@Before
public void setUp() {
    List<Bar> bars = new ArrayList<Bar>();
    bars.add(new MockBar(0, 0, 16, 8));
    bars.add(new MockBar(0, 0, 12, 6));
    bars.add(new MockBar(0, 0, 18, 14));
    bars.add(new MockBar(0, 0, 10, 6));
    bars.add(new MockBar(0, 0, 32, 6));
    bars.add(new MockBar(0, 0, 2, 2));
    bars.add(new MockBar(0, 0, 0, 0));
    bars.add(new MockBar(0, 0, 8, 1));
    bars.add(new MockBar(0, 0, 83, 32));
    bars.add(new MockBar(0, 0, 9, 3));
    this.timeSeries = new MockTimeSeries(bars);
    average = new MedianPriceIndicator(timeSeries);
}
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 12 with MockBar

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

the class ATRIndicatorTest method testDummy.

@Test
public void testDummy() throws Exception {
    List<Bar> bars = new ArrayList<Bar>();
    bars.add(new MockBar(0, 12, 15, 8));
    bars.add(new MockBar(0, 8, 11, 6));
    bars.add(new MockBar(0, 15, 17, 14));
    bars.add(new MockBar(0, 15, 17, 14));
    bars.add(new MockBar(0, 0, 0, 2));
    Indicator<Decimal> indicator = getIndicator(new MockTimeSeries(bars), 3);
    assertEquals(7d, indicator.getValue(0).doubleValue(), TATestsUtils.TA_OFFSET);
    assertEquals(6d / 3 + (1 - 1d / 3) * indicator.getValue(0).doubleValue(), indicator.getValue(1).doubleValue(), TATestsUtils.TA_OFFSET);
    assertEquals(9d / 3 + (1 - 1d / 3) * indicator.getValue(1).doubleValue(), indicator.getValue(2).doubleValue(), TATestsUtils.TA_OFFSET);
    assertEquals(3d / 3 + (1 - 1d / 3) * indicator.getValue(2).doubleValue(), indicator.getValue(3).doubleValue(), TATestsUtils.TA_OFFSET);
    assertEquals(15d / 3 + (1 - 1d / 3) * indicator.getValue(3).doubleValue(), indicator.getValue(4).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) Test(org.junit.Test)

Example 13 with MockBar

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

the class AccelerationDecelerationIndicatorTest method setUp.

@Before
public void setUp() {
    List<Bar> bars = new ArrayList<Bar>();
    bars.add(new MockBar(0, 0, 16, 8));
    bars.add(new MockBar(0, 0, 12, 6));
    bars.add(new MockBar(0, 0, 18, 14));
    bars.add(new MockBar(0, 0, 10, 6));
    bars.add(new MockBar(0, 0, 8, 4));
    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 14 with MockBar

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

the class CCIIndicatorTest method setUp.

@Before
public void setUp() {
    ArrayList<Bar> bars = new ArrayList<Bar>();
    for (Double price : typicalPrices) {
        bars.add(new MockBar(price, price, price, price));
    }
    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 15 with MockBar

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

the class EMAIndicatorTest method stackOverflowError.

@Test
public void stackOverflowError() throws Exception {
    List<Bar> bigListOfBars = new ArrayList<Bar>();
    for (int i = 0; i < 10000; i++) {
        bigListOfBars.add(new MockBar(i));
    }
    MockTimeSeries bigSeries = new MockTimeSeries(bigListOfBars);
    Indicator<Decimal> indicator = getIndicator(new ClosePriceIndicator(bigSeries), 10);
    // if a StackOverflowError is thrown here, then the RecursiveCachedIndicator does not work as intended.
    assertDecimalEquals(indicator.getValue(9999), 9994.5);
}
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

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