Search in sources :

Example 11 with BaseBar

use of org.ta4j.core.BaseBar in project ta4j by ta4j.

the class ChaikinMoneyFlowIndicatorTest method getValue.

@Test
public void getValue() {
    ZonedDateTime now = ZonedDateTime.now();
    List<Bar> bars = new ArrayList<>();
    bars.add(new BaseBar(now, "0", "62.34", "61.37", "62.15", "7849.025"));
    bars.add(new BaseBar(now, "0", "62.05", "60.69", "60.81", "11692.075"));
    bars.add(new BaseBar(now, "0", "62.27", "60.10", "60.45", "10575.307"));
    bars.add(new BaseBar(now, "0", "60.79", "58.61", "59.18", "13059.128"));
    bars.add(new BaseBar(now, "0", "59.93", "58.71", "59.24", "20733.508"));
    bars.add(new BaseBar(now, "0", "61.75", "59.86", "60.20", "29630.096"));
    bars.add(new BaseBar(now, "0", "60.00", "57.97", "58.48", "17705.294"));
    bars.add(new BaseBar(now, "0", "59.00", "58.02", "58.24", "7259.203"));
    bars.add(new BaseBar(now, "0", "59.07", "57.48", "58.69", "10474.629"));
    bars.add(new BaseBar(now, "0", "59.22", "58.30", "58.65", "5203.714"));
    bars.add(new BaseBar(now, "0", "58.75", "57.83", "58.47", "3422.865"));
    bars.add(new BaseBar(now, "0", "58.65", "57.86", "58.02", "3962.150"));
    bars.add(new BaseBar(now, "0", "58.47", "57.91", "58.17", "4095.905"));
    bars.add(new BaseBar(now, "0", "58.25", "57.83", "58.07", "3766.006"));
    bars.add(new BaseBar(now, "0", "58.35", "57.53", "58.13", "4239.335"));
    bars.add(new BaseBar(now, "0", "59.86", "58.58", "58.94", "8039.979"));
    bars.add(new BaseBar(now, "0", "59.53", "58.30", "59.10", "6956.717"));
    bars.add(new BaseBar(now, "0", "62.10", "58.53", "61.92", "18171.552"));
    bars.add(new BaseBar(now, "0", "62.16", "59.80", "61.37", "22225.894"));
    bars.add(new BaseBar(now, "0", "62.67", "60.93", "61.68", "14613.509"));
    bars.add(new BaseBar(now, "0", "62.38", "60.15", "62.09", "12319.763"));
    bars.add(new BaseBar(now, "0", "63.73", "62.26", "62.89", "15007.690"));
    bars.add(new BaseBar(now, "0", "63.85", "63.00", "63.53", "8879.667"));
    bars.add(new BaseBar(now, "0", "66.15", "63.58", "64.01", "22693.812"));
    bars.add(new BaseBar(now, "0", "65.34", "64.07", "64.77", "10191.814"));
    bars.add(new BaseBar(now, "0", "66.48", "65.20", "65.22", "10074.152"));
    bars.add(new BaseBar(now, "0", "65.23", "63.21", "63.28", "9411.620"));
    bars.add(new BaseBar(now, "0", "63.40", "61.88", "62.40", "10391.690"));
    bars.add(new BaseBar(now, "0", "63.18", "61.11", "61.55", "8926.512"));
    bars.add(new BaseBar(now, "0", "62.70", "61.25", "62.69", "7459.575"));
    TimeSeries series = new BaseTimeSeries(bars);
    ChaikinMoneyFlowIndicator cmf = new ChaikinMoneyFlowIndicator(series, 20);
    assertDecimalEquals(cmf.getValue(0), 0.6082);
    assertDecimalEquals(cmf.getValue(1), -0.2484);
    assertDecimalEquals(cmf.getValue(19), -0.1211);
    assertDecimalEquals(cmf.getValue(20), -0.0997);
    assertDecimalEquals(cmf.getValue(21), -0.0659);
    assertDecimalEquals(cmf.getValue(22), -0.0257);
    assertDecimalEquals(cmf.getValue(23), -0.0617);
    assertDecimalEquals(cmf.getValue(24), -0.0481);
    assertDecimalEquals(cmf.getValue(25), -0.0086);
    assertDecimalEquals(cmf.getValue(26), -0.0087);
    assertDecimalEquals(cmf.getValue(27), -0.005);
    assertDecimalEquals(cmf.getValue(28), -0.0574);
    assertDecimalEquals(cmf.getValue(29), -0.0148);
}
Also used : BaseBar(org.ta4j.core.BaseBar) Bar(org.ta4j.core.Bar) BaseTimeSeries(org.ta4j.core.BaseTimeSeries) TimeSeries(org.ta4j.core.TimeSeries) ZonedDateTime(java.time.ZonedDateTime) BaseBar(org.ta4j.core.BaseBar) BaseTimeSeries(org.ta4j.core.BaseTimeSeries) ArrayList(java.util.ArrayList) Test(org.junit.Test)

Aggregations

Bar (org.ta4j.core.Bar)11 BaseBar (org.ta4j.core.BaseBar)11 ZonedDateTime (java.time.ZonedDateTime)10 ArrayList (java.util.ArrayList)9 BaseTimeSeries (org.ta4j.core.BaseTimeSeries)8 Before (org.junit.Before)6 Instant (java.time.Instant)2 CSVReader (com.opencsv.CSVReader)1 IOException (java.io.IOException)1 InputStream (java.io.InputStream)1 InputStreamReader (java.io.InputStreamReader)1 Duration (java.time.Duration)1 Random (java.util.Random)1 Test (org.junit.Test)1 TimeSeries (org.ta4j.core.TimeSeries)1 EMAIndicator (org.ta4j.core.indicators.EMAIndicator)1