This example illustrates setting up a TimeSeries class for a segment of S&P 500 returns during a period in the late 80's.
import com.imsl.stat.*; import java.util.Date; import java.text.*; public class TimeSeriesEx1 { public static void main(String args[]) throws ParseException { double data1[] = { 0.940543272, 2.664279727, 0.252045652, 1.221098464, 0.270575973, 0.446882726, 0.073672969, -4.450030305, 0.007699415, -0.215808015, -0.498908466, -0.696433123, 0.113159704, 1.440322251, 0.887874183, 0.5585227, -0.049267619, -0.452119841, -0.488606538, 0.087972619, 0.549032948, -1.024238871, -0.589472147, -0.507487482, -0.365744931, 0.42010331, -1.687159586, 0.212950629, 1.147614577, 0.748805609, -1.311175287, -1.574960025, 0.484204788, 0.178009897, -0.869311816, 1.062785115, 0.098566846, 0.342257263, -0.47633197 }; String datestrings1[] = { "4/5/1988", "4/6/1988", "4/7/1988", "4/8/1988", "4/11/1988", "4/12/1988", "4/13/1988", "4/14/1988", "4/15/1988", "4/18/1988", "4/19/1988", "4/20/1988", "4/21/1988", "4/22/1988", "4/25/1988", "4/26/1988", "4/27/1988", "4/28/1988", "4/29/1988", "5/2/1988", "5/3/1988", "5/4/1988", "5/5/1988", "5/6/1988", "5/9/1988", "5/10/1988", "5/11/1988", "5/12/1988", "5/13/1988", "5/16/1988", "5/17/1988", "5/18/1988", "5/19/1988", "5/20/1988", "5/23/1988", "5/24/1988", "5/25/1988", "5/26/1988", "5/27/1988" }; SimpleDateFormat dateFormat = new SimpleDateFormat("M/d/y"); TimeSeries ts = new TimeSeries(); ts.setSeriesValues(data1); System.out.println("The number of observations = " + ts.getLength()); System.out.println("The number of missing observations = " + ts.getNumMissing()); Date dates1[] = new Date[ts.getLength()]; for (int i = 0; i < ts.getLength(); i++) { dates1[i] = dateFormat.parse(datestrings1[i]); } ts.setDates(dates1); System.out.println("The starting date is = " + ts.getStartDate()); } }
The number of observations = 39 The number of missing observations = 0 The starting date is = Tue Apr 05 00:00:00 CDT 1988Link to Java source.