-
Notifications
You must be signed in to change notification settings - Fork 49
The timeseries package
At the heart of the Java Time Series library is the timeseries package. Time series are mappings from observation times to observation values. In the TimeSeries class, each observation time is represented as an OffsetDateTime from Java 8's time API, and each observation value is represented as a primitive double.
The bare minimum needed to create a new time series is an array of primitive doubles. For example, the simplest way of creating a new time series is the following:
TimeSeries series = TimeSeries.from(1, 2, 3)
The arrayFrom static methods in the DoubleFunctions utility class can help if the data is instead stored as either an array or Collection of some subtype of Number. Supplying such data as the argument to the arrayFrom method will return an array of primitive doubles which can in turn be used to construct a new TimeSeries object.
import static data.DoubleFunctions.arrayFrom;
Collection<Integer> c = Arrays.asList(1, 2, 3);
double[] data = arrayFrom(c);
TimeSeries series = TimeSeries.from(data);
The above approach is fine when the data is nonseasonal and/or the times at which observations are made is unimportant. Otherwise, information about observation times can be provided in quite a few different ways. If the observations are made annually, monthly, or quarterly, then the static factory constructors in the Ts class can be used for very easy creation of new series.
import timeseries.TestData;
double[] data = TestData.ausbeerArray; // From https://www.otexts.org/fpp/.
int startYear = 1956;
int startQuarter = 1;
TimeSeries series = Ts.newQuarterlySeries(startYear, startQuarter, data);