Skip to content

Commit

Permalink
updated all dependency versions and relevant api usage. bumped java t…
Browse files Browse the repository at this point in the history
…o 21
  • Loading branch information
TheCookieLab committed Sep 23, 2024
1 parent 30e1136 commit e87f8a4
Show file tree
Hide file tree
Showing 10 changed files with 268 additions and 264 deletions.
417 changes: 210 additions & 207 deletions pom.xml

Large diffs are not rendered by default.

10 changes: 5 additions & 5 deletions ta4j-core/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,14 @@
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
<version>1.7.25</version>
<version>2.0.13</version>
</dependency>

<!-- Test dependencies -->
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.13.1</version>
<version>4.13.2</version>
<scope>test</scope>
</dependency>
<dependency>
Expand All @@ -35,7 +35,7 @@
<dependency>
<groupId>org.apache.poi</groupId>
<artifactId>poi</artifactId>
<version>5.2.2</version>
<version>5.3.0</version>
<scope>test</scope>
</dependency>
<dependency>
Expand All @@ -49,7 +49,7 @@
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<version>3.1.0</version>
<version>3.4.1</version>
<configuration>
<archive>
<manifestFile>${project.build.outputDirectory}/META-INF/MANIFEST.MF</manifestFile>
Expand All @@ -59,7 +59,7 @@
<plugin>
<groupId>biz.aQute.bnd</groupId>
<artifactId>bnd-maven-plugin</artifactId>
<version>3.3.0</version>
<version>6.4.0</version>
<executions>
<execution>
<id>default-bnd-process</id>
Expand Down
8 changes: 4 additions & 4 deletions ta4j-examples/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.13.1</version>
<version>4.13.2</version>
<scope>test</scope>
</dependency>

Expand All @@ -29,13 +29,13 @@
<dependency>
<groupId>com.opencsv</groupId>
<artifactId>opencsv</artifactId>
<version>3.9</version>
<version>5.9</version>
</dependency>

<dependency>
<groupId>org.jfree</groupId>
<artifactId>jfreechart</artifactId>
<version>1.0.17</version>
<version>1.5.5</version>
</dependency>

<dependency>
Expand All @@ -46,7 +46,7 @@
<dependency>
<groupId>com.google.code.gson</groupId>
<artifactId>gson</artifactId>
<version>2.8.6</version>
<version>2.10.1</version>
</dependency>
</dependencies>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,10 +36,10 @@
import org.jfree.chart.plot.Marker;
import org.jfree.chart.plot.ValueMarker;
import org.jfree.chart.plot.XYPlot;
import org.jfree.chart.ui.ApplicationFrame;
import org.jfree.chart.ui.UIUtils;
import org.jfree.data.time.Minute;
import org.jfree.data.time.TimeSeriesCollection;
import org.jfree.ui.ApplicationFrame;
import org.jfree.ui.RefineryUtilities;
import org.ta4j.core.Bar;
import org.ta4j.core.BarSeries;
import org.ta4j.core.BarSeriesManager;
Expand Down Expand Up @@ -125,7 +125,7 @@ private static void displayChart(JFreeChart chart) {
ApplicationFrame frame = new ApplicationFrame("Ta4j example - Buy and sell signals to chart");
frame.setContentPane(panel);
frame.pack();
RefineryUtilities.centerFrameOnScreen(frame);
UIUtils.centerFrameOnScreen(frame);
frame.setVisible(true);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,10 +35,11 @@
import org.jfree.chart.axis.NumberAxis;
import org.jfree.chart.plot.XYPlot;
import org.jfree.chart.renderer.xy.StandardXYItemRenderer;
import org.jfree.chart.ui.ApplicationFrame;
import org.jfree.chart.ui.UIUtils;
import org.jfree.data.time.Minute;
import org.jfree.data.time.TimeSeriesCollection;
import org.jfree.ui.ApplicationFrame;
import org.jfree.ui.RefineryUtilities;

import org.ta4j.core.Bar;
import org.ta4j.core.BarSeries;
import org.ta4j.core.BarSeriesManager;
Expand All @@ -62,7 +63,7 @@ public class CashFlowToChart {
*
* @param barSeries the ta4j bar series
* @param indicator the indicator
* @param name the name of the chart time series
* @param name the name of the chart time series
* @return the JFreeChart time series
*/
private static org.jfree.data.time.TimeSeries buildChartBarSeries(BarSeries barSeries, Indicator<Num> indicator,
Expand All @@ -79,7 +80,7 @@ private static org.jfree.data.time.TimeSeries buildChartBarSeries(BarSeries barS
/**
* Adds the cash flow axis to the plot.
*
* @param plot the plot
* @param plot the plot
* @param dataset the cash flow dataset
*/
private static void addCashFlowAxis(XYPlot plot, TimeSeriesCollection dataset) {
Expand Down Expand Up @@ -108,7 +109,7 @@ private static void displayChart(JFreeChart chart) {
ApplicationFrame frame = new ApplicationFrame("Ta4j example - Cash flow to chart");
frame.setContentPane(panel);
frame.pack();
RefineryUtilities.centerFrameOnScreen(frame);
UIUtils.centerFrameOnScreen(frame);
frame.setVisible(true);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,12 +34,12 @@
import org.jfree.chart.plot.XYPlot;
import org.jfree.chart.renderer.xy.CandlestickRenderer;
import org.jfree.chart.renderer.xy.XYLineAndShapeRenderer;
import org.jfree.chart.ui.ApplicationFrame;
import org.jfree.chart.ui.UIUtils;
import org.jfree.data.time.Second;
import org.jfree.data.time.TimeSeriesCollection;
import org.jfree.data.xy.DefaultHighLowDataset;
import org.jfree.data.xy.OHLCDataset;
import org.jfree.ui.ApplicationFrame;
import org.jfree.ui.RefineryUtilities;
import org.ta4j.core.Bar;
import org.ta4j.core.BarSeries;
import org.ta4j.core.indicators.helpers.ClosePriceIndicator;
Expand Down Expand Up @@ -114,7 +114,7 @@ private static void displayChart(JFreeChart chart) {
ApplicationFrame frame = new ApplicationFrame("Ta4j example - Candlestick chart");
frame.setContentPane(panel);
frame.pack();
RefineryUtilities.centerFrameOnScreen(frame);
UIUtils.centerFrameOnScreen(frame);
frame.setVisible(true);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,13 +40,13 @@
import org.jfree.chart.plot.XYPlot;
import org.jfree.chart.renderer.xy.CandlestickRenderer;
import org.jfree.chart.renderer.xy.XYLineAndShapeRenderer;
import org.jfree.chart.ui.ApplicationFrame;
import org.jfree.chart.ui.UIUtils;
import org.jfree.data.time.Second;
import org.jfree.data.time.TimeSeriesCollection;
import org.jfree.data.xy.DefaultHighLowDataset;
import org.jfree.data.xy.OHLCDataset;
import org.jfree.data.xy.XYDataset;
import org.jfree.ui.ApplicationFrame;
import org.jfree.ui.RefineryUtilities;
import org.ta4j.core.Bar;
import org.ta4j.core.BarSeries;
import org.ta4j.core.indicators.ChopIndicator;
Expand Down Expand Up @@ -201,7 +201,7 @@ private static void displayChart(XYDataset ohlcDataset, XYDataset xyDataset, XYD
ApplicationFrame frame = new ApplicationFrame("Ta4j example - Candlestick chart");
frame.setContentPane(combinedChartPanel);
frame.pack();
RefineryUtilities.centerFrameOnScreen(frame);
UIUtils.centerFrameOnScreen(frame);
frame.setVisible(true);

// CHOP oscillator upper/lower threshold guidelines
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,10 @@
import org.jfree.chart.JFreeChart;
import org.jfree.chart.axis.DateAxis;
import org.jfree.chart.plot.XYPlot;
import org.jfree.chart.ui.ApplicationFrame;
import org.jfree.chart.ui.UIUtils;
import org.jfree.data.time.Day;
import org.jfree.data.time.TimeSeriesCollection;
import org.jfree.ui.ApplicationFrame;
import org.jfree.ui.RefineryUtilities;
import org.ta4j.core.Bar;
import org.ta4j.core.BarSeries;
import org.ta4j.core.Indicator;
Expand All @@ -58,7 +58,7 @@ public class IndicatorsToChart {
*
* @param barSeries the ta4j bar series
* @param indicator the indicator
* @param name the name of the chart time series
* @param name the name of the chart time series
* @return the JFreeChart time series
*/
private static org.jfree.data.time.TimeSeries buildChartBarSeries(BarSeries barSeries, Indicator<Num> indicator,
Expand Down Expand Up @@ -86,7 +86,7 @@ private static void displayChart(JFreeChart chart) {
ApplicationFrame frame = new ApplicationFrame("Ta4j example - Indicators to chart");
frame.setContentPane(panel);
frame.pack();
RefineryUtilities.centerFrameOnScreen(frame);
UIUtils.centerFrameOnScreen(frame);
frame.setVisible(true);
}

Expand Down
35 changes: 23 additions & 12 deletions ta4j-examples/src/main/java/ta4jexamples/loaders/CsvBarsLoader.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,10 @@
*/
package ta4jexamples.loaders;

import com.opencsv.CSVParserBuilder;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.nio.charset.Charset;
import java.time.LocalDate;
import java.time.ZoneId;
import java.time.ZonedDateTime;
Expand All @@ -38,6 +38,9 @@
import org.ta4j.core.BaseBarSeries;

import com.opencsv.CSVReader;
import com.opencsv.CSVReaderBuilder;
import com.opencsv.exceptions.CsvValidationException;
import java.nio.charset.StandardCharsets;

/**
* This class build a Ta4j bar series from a CSV file containing bars.
Expand All @@ -59,18 +62,26 @@ public static BarSeries loadCsvSeries(String filename) {

BarSeries series = new BaseBarSeries("apple_bars");

try (CSVReader csvReader = new CSVReader(new InputStreamReader(stream, Charset.forName("UTF-8")), ',', '"',
1)) {
String[] line;
while ((line = csvReader.readNext()) != null) {
ZonedDateTime date = LocalDate.parse(line[0], DATE_FORMAT).atStartOfDay(ZoneId.systemDefault());
double open = Double.parseDouble(line[1]);
double high = Double.parseDouble(line[2]);
double low = Double.parseDouble(line[3]);
double close = Double.parseDouble(line[4]);
double volume = Double.parseDouble(line[5]);
try {
assert stream != null;
try (CSVReader csvReader = new CSVReaderBuilder(new InputStreamReader(stream, StandardCharsets.UTF_8))
.withCSVParser(new CSVParserBuilder().withSeparator(',').build())
.withSkipLines(1)
.build()) {
String[] line;
while ((line = csvReader.readNext()) != null) {
ZonedDateTime date = LocalDate.parse(line[0], DATE_FORMAT).atStartOfDay(ZoneId.systemDefault());
double open = Double.parseDouble(line[1]);
double high = Double.parseDouble(line[2]);
double low = Double.parseDouble(line[3]);
double close = Double.parseDouble(line[4]);
double volume = Double.parseDouble(line[5]);

series.addBar(date, open, high, low, close, volume);
series.addBar(date, open, high, low, close, volume);
}
} catch (CsvValidationException e) {
Logger.getLogger(CsvBarsLoader.class.getName())
.log(Level.SEVERE, "Unable to load bars from CSV. File is not valid csv.", e);
}
} catch (IOException ioe) {
Logger.getLogger(CsvBarsLoader.class.getName()).log(Level.SEVERE, "Unable to load bars from CSV", ioe);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,8 @@
*/
package ta4jexamples.loaders;

import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.nio.charset.Charset;
import java.time.Duration;
import java.time.Instant;
import java.time.ZoneId;
Expand Down Expand Up @@ -56,22 +54,13 @@ public static BarSeries loadBitstampSeries() {
// Reading all lines of the CSV file
InputStream stream = CsvTradesLoader.class.getClassLoader()
.getResourceAsStream("bitstamp_trades_from_20131125_usd.csv");
CSVReader csvReader = null;
List<String[]> lines = null;
try {
csvReader = new CSVReader(new InputStreamReader(stream, Charset.forName("UTF-8")), ',');
assert stream != null;
try (CSVReader csvReader = new com.opencsv.CSVReader(new InputStreamReader(stream))) {
lines = csvReader.readAll();
lines.remove(0); // Removing header line
} catch (IOException ioe) {
} catch (Exception ioe) {
Logger.getLogger(CsvTradesLoader.class.getName()).log(Level.SEVERE, "Unable to load trades from CSV", ioe);
} finally {
if (csvReader != null) {
try {
csvReader.close();
} catch (IOException ioe) {
ioe.printStackTrace();
}
}
}

BarSeries series = new BaseBarSeries();
Expand Down Expand Up @@ -104,9 +93,9 @@ public static BarSeries loadBitstampSeries() {
* Builds a list of populated bars from csv data.
*
* @param beginTime the begin time of the whole period
* @param endTime the end time of the whole period
* @param duration the bar duration (in seconds)
* @param lines the csv data returned by CSVReader.readAll()
* @param endTime the end time of the whole period
* @param duration the bar duration (in seconds)
* @param lines the csv data returned by CSVReader.readAll()
*/
@SuppressWarnings("deprecation")
private static void buildSeries(BarSeries series, ZonedDateTime beginTime, ZonedDateTime endTime, int duration,
Expand Down Expand Up @@ -155,4 +144,4 @@ public static void main(String[] args) {
System.out.println("First bar: \n" + "\tVolume: " + series.getBar(0).getVolume() + "\n" + "\tNumber of trades: "
+ series.getBar(0).getTrades() + "\n" + "\tClose price: " + series.getBar(0).getClosePrice());
}
}
}

0 comments on commit e87f8a4

Please sign in to comment.