MovingAverageTimeSeriesOrderIdentifier { public int getOrder(final DoubleTimeSeries<?> ts) { Validate.notNull(ts); if (ts.isEmpty()) { throw new IllegalArgumentException("Time series was empty"); } if (ts.size() < _maxOrder) { throw new IllegalArgumentException("Number of data points lower than the maximum order to calculate"); } final double[] acf = _calculator.evaluate(ts); final int n = ts.size(); final double bound = _criticalValue / Math.sqrt(n); for (int i = _maxOrder; i > 0; i--) { if (Math.abs(acf[i]) > bound) { return i; } } throw new IllegalArgumentException("Could not find order of series; no significant autocorrelations"); } MovingAverageTimeSeriesOrderIdentifier(final int maxOrder, final double level); int getOrder(final DoubleTimeSeries<?> ts);  }
@Test(expectedExceptions = IllegalArgumentException.class) public void testNullTS() { MA_IDENTIFIER.getOrder(null); }
@Test(expectedExceptions = IllegalArgumentException.class) public void testEmptyTS() { MA_IDENTIFIER.getOrder(ImmutableInstantDoubleTimeSeries.EMPTY_SERIES); }
@Test(expectedExceptions = IllegalArgumentException.class) public void testInsufficientData() { MA_IDENTIFIER.getOrder(ImmutableLocalDateDoubleTimeSeries.of(new LocalDate[] {LocalDate.ofEpochDay(1), LocalDate.ofEpochDay(2)}, new double[] {0.1, 0.2})); }
@Test(expectedExceptions = IllegalArgumentException.class) public void testRandomTS() { MA_IDENTIFIER.getOrder(RANDOM); }
@Test public void test() { assertEquals(MA_IDENTIFIER.getOrder(MA3), 3); }