Search in sources :

Example 16 with BaseTimeSeries

use of org.ta4j.core.BaseTimeSeries 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)16 BaseTimeSeries (org.ta4j.core.BaseTimeSeries)16 ArrayList (java.util.ArrayList)14 Before (org.junit.Before)12 BaseBar (org.ta4j.core.BaseBar)9 ZonedDateTime (java.time.ZonedDateTime)8 MockBar (org.ta4j.core.mocks.MockBar)6 CSVReader (com.opencsv.CSVReader)2 IOException (java.io.IOException)2 InputStream (java.io.InputStream)2 InputStreamReader (java.io.InputStreamReader)2 TimeSeries (org.ta4j.core.TimeSeries)2 BitfinexApiBroker (com.github.jnidzwetzki.bitfinex.v2.BitfinexApiBroker)1 APIException (com.github.jnidzwetzki.bitfinex.v2.entity.APIException)1 BitfinexCurrencyPair (com.github.jnidzwetzki.bitfinex.v2.entity.BitfinexCurrencyPair)1 BitfinexTick (com.github.jnidzwetzki.bitfinex.v2.entity.BitfinexTick)1 Timeframe (com.github.jnidzwetzki.bitfinex.v2.entity.Timeframe)1 BitfinexCandlestickSymbol (com.github.jnidzwetzki.bitfinex.v2.entity.symbol.BitfinexCandlestickSymbol)1 BarConverter (com.github.jnidzwetzki.cryptobot.util.BarConverter)1 Instant (java.time.Instant)1