Пример #1
0
    def test_ar_forecasting(self):
        params = np.array([0.9])
        forecasts = _ar_forecast(self.zero_mean, 5, 0, 0.0, params,
                                 np.empty(0), np.empty(0))
        expected = np.zeros((1000, 5))
        expected[:, 0] = 0.9 * self.zero_mean.values
        for i in range(1, 5):
            expected[:, i] = 0.9 * expected[:, i - 1]
        assert_allclose(forecasts, expected)

        params = np.array([0.5, -0.3, 0.2])
        forecasts = _ar_forecast(self.zero_mean, 5, 2, 0.0, params,
                                 np.empty(0), np.empty(0))
        expected = np.zeros((998, 8))
        expected[:, 0] = self.zero_mean.iloc[0:-2]
        expected[:, 1] = self.zero_mean.iloc[1:-1]
        expected[:, 2] = self.zero_mean.iloc[2:]
        for i in range(3, 8):
            expected[:,
                     i] = (0.5 * expected[:, i - 1] -
                           0.3 * expected[:, i - 2] + 0.2 * expected[:, i - 3])
        fill = np.empty((2, 5))
        fill.fill(np.nan)
        expected = np.concatenate((fill, expected[:, 3:]))
        assert_allclose(forecasts, expected[2:])
Пример #2
0
    def test_ar_forecasting(self):
        params = np.array([0.9])
        forecasts = _ar_forecast(self.zero_mean, 5, 0, 0.0, params)
        expected = np.zeros((1000, 5))
        expected[:, 0] = 0.9 * self.zero_mean.values
        for i in range(1, 5):
            expected[:, i] = 0.9 * expected[:, i - 1]
        assert_allclose(forecasts, expected)

        params = np.array([0.5, -0.3, 0.2])
        forecasts = _ar_forecast(self.zero_mean, 5, 2, 0.0, params)
        expected = np.zeros((998, 8))
        expected[:, 0] = self.zero_mean.iloc[0:-2]
        expected[:, 1] = self.zero_mean.iloc[1:-1]
        expected[:, 2] = self.zero_mean.iloc[2:]
        for i in range(3, 8):
            expected[:, i] = 0.5 * expected[:, i - 1] - \
                             0.3 * expected[:, i - 2] + \
                             0.2 * expected[:, i - 3]
        fill = np.empty((2, 5))
        fill.fill(np.nan)
        expected = np.concatenate((fill, expected[:, 3:]))
        assert_allclose(forecasts, expected)