AutoregressiveMovingAverageTimeSeriesModel { public LocalDateDoubleTimeSeries getSeries(final double[] phi, final int p, final double[] theta, final int q, final LocalDate[] dates) { if (phi == null && p != 0) { throw new IllegalArgumentException("AR coefficient array was null"); } if (p < 0) { throw new IllegalArgumentException("p must be positive"); } if (phi != null && phi.length < p + 1) { throw new IllegalArgumentException("AR coefficient array must contain at least " + (p + 1) + " elements"); } if (theta == null && q != 0) { throw new IllegalArgumentException("MA coefficient array was null"); } if (q < 0) { throw new IllegalArgumentException("q must be positive"); } if (theta != null && theta.length < q) { throw new IllegalArgumentException("MA coefficient array must contain at least " + q + " elements"); } Validate.notNull(dates, "dates"); ArgumentChecker.notEmpty(dates, "dates"); if (theta != null) { final double[] theta1 = new double[theta.length + 1]; theta1[0] = 0.; for (int i = 0; i < theta.length; i++) { theta1[i + 1] = theta[i]; } if (p == 0) { return _maModel.getSeries(theta1, q, dates); } if (q == 0) { return _arModel.getSeries(phi, p, dates); } return _arModel.getSeries(phi, p, dates).add(_maModel.getSeries(theta1, q, dates)); } return _arModel.getSeries(phi, p, dates); } AutoregressiveMovingAverageTimeSeriesModel(final ProbabilityDistribution<Double> random); LocalDateDoubleTimeSeries getSeries(final double[] phi, final int p, final double[] theta, final int q, final LocalDate[] dates);  }
@Test(expectedExceptions = IllegalArgumentException.class) public void testNullPhi() { MODEL.getSeries(null, P, THETA, Q, DATES); }
@Test(expectedExceptions = IllegalArgumentException.class) public void testNegativeP() { MODEL.getSeries(PHI, -P, THETA, Q, DATES); }
@Test(expectedExceptions = IllegalArgumentException.class) public void testWrongP() { MODEL.getSeries(PHI, 2 * P, THETA, Q, DATES); }
@Test(expectedExceptions = IllegalArgumentException.class) public void testNullTheta() { MODEL.getSeries(PHI, P, null, Q, DATES); }
@Test(expectedExceptions = IllegalArgumentException.class) public void testNegativeQ() { MODEL.getSeries(PHI, P, THETA, -Q, DATES); }
@Test(expectedExceptions = IllegalArgumentException.class) public void testWrongQ() { MODEL.getSeries(PHI, P, THETA, 2 * Q, DATES); }
@Test(expectedExceptions = IllegalArgumentException.class) public void testNullDates() { MODEL.getSeries(PHI, P, THETA, Q, null); }
@Test(expectedExceptions = IllegalArgumentException.class) public void testEmptyDates() { MODEL.getSeries(PHI, P, THETA, Q, new LocalDate[0]); }
@Test public void test() { final AutocovarianceFunctionCalculator autocovariance = new AutocovarianceFunctionCalculator(); final AutocorrelationFunctionCalculator autocorrelation = new AutocorrelationFunctionCalculator(); final double[] rhoAR = autocorrelation.evaluate(AR); final double[] rhoMA = autocorrelation.evaluate(MA); final double[] rhoARMAP0 = autocorrelation.evaluate(MODEL.getSeries(PHI, P, null, 0, DATES)); final double[] rhoARMA0Q = autocorrelation.evaluate(MODEL.getSeries(null, 0, THETA, Q, DATES)); final double eps = Math.sqrt(STD) + 0.01; for (int i = 0; i < 200; i++) { assertEquals(Math.abs(rhoARMAP0[i] - rhoAR[i]), 0., eps); assertEquals(Math.abs(rhoARMA0Q[i] - rhoMA[i]), 0., eps); } final double[] rhoARMA11 = autocorrelation.evaluate(ARMA11); final double[] gammaARMA11 = autocovariance.evaluate(ARMA11); assertEquals(PHI[1] - THETA[1] * STD * STD / gammaARMA11[0], rhoARMA11[1], eps); }