def test_one_step_predictions(self): ma_model = PureARMA(theta=[-0.9], sigma_sq=1) ma_data = [-2.58, 1.62, -0.96, 2.62, -1.36] ma = ARMA(ma_data, subtract_mean=False) self.assertEqual(ma.get_one_step_predictor(0, ma_model), 0) self.assertAlmostEqual(ma.get_one_step_predictor(1, ma_model, method="innovations_algo"), 1.28, 2) self.assertAlmostEqual(ma.get_one_step_predictor(2, ma_model, method="innovations_algo"), -0.22, 2) self.assertAlmostEqual(ma.get_one_step_predictor(3, ma_model, method="innovations_algo"), 0.55, 2) self.assertAlmostEqual(ma.get_one_step_predictor(4, ma_model, method="innovations_algo"), -1.63, 2) self.assertAlmostEqual(ma.get_one_step_predictor(5, ma_model, method="innovations_algo"), -0.22, 2) arma_data = [-1.1, 0.514, 0.116, -0.845, 0.872, -0.467, -0.977, -1.699, -1.228, -1.093] arma_model = PureARMA(phi=[0.2], theta=[0.4], sigma_sq=1) arma = ARMA(arma_data, subtract_mean=False) self.assertEqual(arma.get_one_step_predictor(0, arma_model, method="innovations_algo"), 0) self.assertAlmostEqual(arma.get_one_step_predictor(1, arma_model, method="innovations_algo"), -0.534, 1) self.assertAlmostEqual(arma.get_one_step_predictor(2, arma_model, method="innovations_algo"), 0.5068, 1) self.assertAlmostEqual(arma.get_one_step_predictor(3, arma_model, method="innovations_algo"), -0.1321, 1) self.assertAlmostEqual(arma.get_one_step_predictor(4, arma_model, method="innovations_algo"), -0.4539, 1) self.assertAlmostEqual(arma.get_one_step_predictor(5, arma_model, method="innovations_algo"), 0.7046, 1) data = [1, 2, 3, 4, 5] empty_model = PureARMA() empty = ARMA(data) empty.model = empty_model for k in range(6): self.assertEqual(empty.get_one_step_predictor(k, method="innovations_algo"), 0)
def test_one_step_kalman(self): ma_model = PureARMA(theta=[0.5], sigma_sq=2) ma_data = [1, 1.5, 0.5, -2] ma = ARMA(ma_data, subtract_mean=False) zeros = np.zeros(20) arma_model = PureARMA(phi=[0.2, -0.6, 0.3], theta=[0.3, -0.4], sigma_sq=0.25) arma = ARMA(zeros) ar_data = [1, 2, 4] ar_model = PureARMA(phi=[0.5, -0.5], sigma_sq=2) ar = ARMA(ar_data, subtract_mean=False) for k in range(21): self.assertEqual(arma.get_one_step_predictor(k, arma_model, method="kalman"), 0) self.assertAlmostEqual(ma.get_one_step_predictor(0, ma_model, method="kalman"), 0) self.assertAlmostEqual(ma.get_one_step_predictor(1, ma_model, method="kalman"), 0.5) self.assertAlmostEqual(ma.get_one_step_predictor(2, ma_model, method="kalman"), 0.5) self.assertAlmostEqual(ma.get_one_step_predictor(3, ma_model, method="kalman"), 0) self.assertAlmostEqual(ma.get_one_step_predictor(4, ma_model, method="kalman"), -1) self.assertAlmostEqual(ar.get_one_step_predictor(0, ar_model, method="kalman"), 0) self.assertAlmostEqual(ar.get_one_step_predictor(1, ar_model, method="kalman"), 0.5) self.assertAlmostEqual(ar.get_one_step_predictor(2, ar_model, method="kalman"), 0.5) self.assertAlmostEqual(ar.get_one_step_predictor(3, ar_model, method="kalman"), 1)