# Which library shall I use for time series analysis in Java?

I'm looking for a library to do some time series analysis in Java but I can't find anything suitable.

I've found plenty of libraries such as Math3 of JSAT but there's much I can you for my problem.

As an example, I'd like to compute standard deviation over time, moving average etc for a specific time series.

• There is something weird in your second sentence... could you please correct it? – SRKX Dec 9 '14 at 8:34
• Don't forget that classes like this can always be "Wrapped" in a class full of functions to do those things you listed (which you will have to implement yourself). Finding a simple time-series class that supports the TYPE of operation you need should be enough: consider if you need fixed time points or variable? Do you need to insert/replace an arbitrary period of time with a new value? Can you afford to store a generic type for each time period (like a Double) or does it have to be an intrinsic like double for performance? How does it persist?... Implement the stuff you listed yourself. – Bill K Jul 5 '19 at 18:31

I work with time series intensively, and I am experienced in Java and scripting languages such as MATLAB and R. I strongly suggest that you should cook up your own implementations in Java, and stop hunting for and relying on any off-the-shelf implementations. They are not reliable. One should be able to write std, corr, cov, ma, etc., easily by hand. Coding them independently can really enhance your comprehension of the underlying problem.

In short, Java is not a good tool for analysis. You may want to perform prototyping and research in MATLAB, R and Python, and implement the required features in Java after the preliminary research.

• I think commons math is pretty reliable. Agree most other simple things are easier to code than to figure out something like TA-Lib for instance. apache commons math link – brian Sep 1 '14 at 4:14
• Hi Brian, agree. I personally also use commons math as a utility library. However, I often write up a wrapper around these third-party implementations, so I can have a full control over the interface. – Simon Sep 1 '14 at 13:17
• I agree that there is no obvious leader in the market but I don't think there shouldn't be one (i.e. it wouldn't be a bad thing if we could rely on something decent, like pandas for python). I'm actually amazed that nobody has seized this market already, although there are some candidates. For easy things such as standard deviation then re-implementing is fine, but for more complicated things it might be actually very helpful to use more efficient/optimized functions. – SRKX Dec 9 '14 at 8:31
• I like your answer except for the recommendation that these things should be built from scratch by each user. While you're right that this is a highly valuable learning experience, it also is unproductive and very error-prone. Everything else you said, especially the advice on adding another tool, is spot-on. – user5352 Feb 25 '15 at 22:00
• yes but what data structure would you use in java to hold financial time series? – Trajan Jun 22 '18 at 12:32

You can try TimEL, a Java library I've been writing to evaluate expressions for time-series data.

Here is library for time series modelling. There are exponential smoothing models (simple, double, triple) with maximum likelihood estimation and another time series utility classes:

Tablesaw is similar to Python's Pandas: https://github.com/jtablesaw/tablesaw

You might find TA-Lib useful:

TA-Lib is widely used by trading software developers requiring to perform technical analysis of financial market data.

Includes 200 indicators such as ADX, MACD, RSI, Stochastic, Bollinger Bands etc... (more info)
Candlestick pattern recognition
Open-source API for C/C++, Java, Perl, Python and 100% Managed .NET


It is pretty useful and versatile: you can grow with it beyond just standard deviation and moving averages, and also to other programming languages, as mentioned above.

Good luck!

JFreeeChart provides a TimeSeries data structures with some basic functionality but not a lot of analytics. I have started writing my own and I may open source it if there is sufficient interest. Moving averages, deviations, correlations, returns and most of the easy stuff are already implemented, but I think it needs a few more interesting features before I can consider it truly useful.