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));
}
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);
}
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());
}
Aggregations