Search in sources :

Example 46 with TimeSeries

use of org.ta4j.core.TimeSeries 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 47 with TimeSeries

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

the class IndicatorsToChart method main.

public static void main(String[] args) {
    /*
          Getting time series
         */
    TimeSeries series = CsvBarsLoader.loadAppleIncSeries();
    /*
          Creating indicators
         */
    // Close price
    ClosePriceIndicator closePrice = new ClosePriceIndicator(series);
    EMAIndicator avg14 = new EMAIndicator(closePrice, 14);
    StandardDeviationIndicator sd14 = new StandardDeviationIndicator(closePrice, 14);
    // Bollinger bands
    BollingerBandsMiddleIndicator middleBBand = new BollingerBandsMiddleIndicator(avg14);
    BollingerBandsLowerIndicator lowBBand = new BollingerBandsLowerIndicator(middleBBand, sd14);
    BollingerBandsUpperIndicator upBBand = new BollingerBandsUpperIndicator(middleBBand, sd14);
    /*
          Building chart dataset
         */
    TimeSeriesCollection dataset = new TimeSeriesCollection();
    dataset.addSeries(buildChartTimeSeries(series, closePrice, "Apple Inc. (AAPL) - NASDAQ GS"));
    dataset.addSeries(buildChartTimeSeries(series, lowBBand, "Low Bollinger Band"));
    dataset.addSeries(buildChartTimeSeries(series, upBBand, "High Bollinger Band"));
    /*
          Creating the chart
         */
    JFreeChart chart = ChartFactory.createTimeSeriesChart(// title
    "Apple Inc. 2013 Close Prices", // x-axis label
    "Date", // y-axis label
    "Price Per Unit", // data
    dataset, // create legend?
    true, // generate tooltips?
    true, // generate URLs?
    false);
    XYPlot plot = (XYPlot) chart.getPlot();
    DateAxis axis = (DateAxis) plot.getDomainAxis();
    axis.setDateFormatOverride(new SimpleDateFormat("yyyy-MM-dd"));
    /*
          Displaying the chart
         */
    displayChart(chart);
}
Also used : DateAxis(org.jfree.chart.axis.DateAxis) TimeSeries(org.ta4j.core.TimeSeries) EMAIndicator(org.ta4j.core.indicators.EMAIndicator) BollingerBandsLowerIndicator(org.ta4j.core.indicators.bollinger.BollingerBandsLowerIndicator) XYPlot(org.jfree.chart.plot.XYPlot) TimeSeriesCollection(org.jfree.data.time.TimeSeriesCollection) BollingerBandsMiddleIndicator(org.ta4j.core.indicators.bollinger.BollingerBandsMiddleIndicator) StandardDeviationIndicator(org.ta4j.core.indicators.statistics.StandardDeviationIndicator) BollingerBandsUpperIndicator(org.ta4j.core.indicators.bollinger.BollingerBandsUpperIndicator) ClosePriceIndicator(org.ta4j.core.indicators.helpers.ClosePriceIndicator) SimpleDateFormat(java.text.SimpleDateFormat) JFreeChart(org.jfree.chart.JFreeChart)

Example 48 with TimeSeries

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

the class CsvBarsLoader method main.

public static void main(String[] args) {
    TimeSeries series = CsvBarsLoader.loadAppleIncSeries();
    System.out.println("Series: " + series.getName() + " (" + series.getSeriesPeriodDescription() + ")");
    System.out.println("Number of bars: " + series.getBarCount());
    System.out.println("First bar: \n" + "\tVolume: " + series.getBar(0).getVolume() + "\n" + "\tOpen price: " + series.getBar(0).getOpenPrice() + "\n" + "\tClose price: " + series.getBar(0).getClosePrice());
}
Also used : TimeSeries(org.ta4j.core.TimeSeries) BaseTimeSeries(org.ta4j.core.BaseTimeSeries)

Aggregations

TimeSeries (org.ta4j.core.TimeSeries)48 MockTimeSeries (org.ta4j.core.mocks.MockTimeSeries)30 Test (org.junit.Test)24 ClosePriceIndicator (org.ta4j.core.indicators.helpers.ClosePriceIndicator)16 BaseTradingRecord (org.ta4j.core.BaseTradingRecord)12 TradingRecord (org.ta4j.core.TradingRecord)11 Bar (org.ta4j.core.Bar)9 Before (org.junit.Before)7 ArrayList (java.util.ArrayList)5 MockBar (org.ta4j.core.mocks.MockBar)5 BaseTimeSeries (org.ta4j.core.BaseTimeSeries)4 ZonedDateTime (java.time.ZonedDateTime)3 TimeSeriesCollection (org.jfree.data.time.TimeSeriesCollection)3 Strategy (org.ta4j.core.Strategy)3 BitfinexApiBroker (com.github.jnidzwetzki.bitfinex.v2.BitfinexApiBroker)2 BitfinexCandlestickSymbol (com.github.jnidzwetzki.bitfinex.v2.entity.symbol.BitfinexCandlestickSymbol)2 CountDownLatch (java.util.concurrent.CountDownLatch)2 JFreeChart (org.jfree.chart.JFreeChart)2 XYPlot (org.jfree.chart.plot.XYPlot)2 TimeSeriesManager (org.ta4j.core.TimeSeriesManager)2