예제 #1
0
    def setup_class(cls):
        cls.rng = RandomState(1234)
        cls.T = 1000
        cls.resids = cls.rng.standard_normal(cls.T)
        zm = ZeroMean()
        zm.volatility = GARCH()
        seed = 12345
        random_state = np.random.RandomState(seed)
        zm.distribution = Normal(random_state=random_state)
        sim_data = zm.simulate(np.array([0.1, 0.1, 0.8]), 1000)
        with pytest.raises(ValueError):
            zm.simulate(np.array([0.1, 0.1, 0.8]), 1000, initial_value=3.0)
        date_index = pd.date_range("2000-12-31", periods=1000, freq="W")
        cls.y = sim_data.data.values
        cls.y_df = pd.DataFrame(
            cls.y[:, None], columns=["LongVariableName"], index=date_index
        )

        cls.y_series = pd.Series(
            cls.y, name="VeryVeryLongLongVariableName", index=date_index
        )
        x = cls.resids + cls.rng.standard_normal(cls.T)
        cls.x = x[:, None]
        cls.x_df = pd.DataFrame(cls.x, columns=["LongExogenousName"])
        cls.resid_var = np.var(cls.resids)
        cls.sigma2 = np.zeros_like(cls.resids)
        cls.backcast = 1.0
예제 #2
0
    def test_zero_mean(self):
        zm = ZeroMean(self.y)
        parameters = np.array([1.0])
        data = zm.simulate(parameters, self.T)
        assert_equal(data.shape, (self.T, 3))
        assert_equal(data['data'].shape[0], self.T)
        assert_equal(zm.num_params, 0)
        bounds = zm.bounds()
        assert_equal(bounds, [])
        assert_equal(zm.constant, False)
        a, b = zm.constraints()
        assert_equal(a, np.empty((0, 0)))
        assert_equal(b, np.empty((0,)))
        assert isinstance(zm.volatility, ConstantVariance)
        assert isinstance(zm.distribution, Normal)
        assert_equal(zm.lags, None)
        res = zm.fit(disp='off')
        assert_almost_equal(res.params, np.array([np.mean(self.y ** 2)]))

        forecasts = res.forecast(horizon=99)
        direct = pd.DataFrame(index=np.arange(self.y.shape[0]),
                              columns=['h.{0:>02d}'.format(i + 1) for i in
                                       range(99)],
                              dtype=np.float64)
        direct.iloc[:, :] = 0.0
        assert isinstance(forecasts, ARCHModelForecast)
        # TODO
        # assert_frame_equal(direct, forecasts)
        garch = GARCH()
        zm.volatility = garch
        zm.fit(update_freq=0, disp=DISPLAY)
        assert isinstance(zm.__repr__(), str)
        assert isinstance(zm.__str__(), str)
        assert '<strong>' in zm._repr_html_()
예제 #3
0
파일: test_mean.py 프로젝트: esvhd/arch
    def test_zero_mean(self):
        zm = ZeroMean(self.y)
        parameters = np.array([1.0])
        data = zm.simulate(parameters, self.T)
        assert_equal(data.shape, (self.T, 3))
        assert_equal(data['data'].shape[0], self.T)
        assert_equal(zm.num_params, 0)
        bounds = zm.bounds()
        assert_equal(bounds, [])
        assert_equal(zm.constant, False)
        a, b = zm.constraints()
        assert_equal(a, np.empty((0, 0)))
        assert_equal(b, np.empty((0,)))
        assert isinstance(zm.volatility, ConstantVariance)
        assert isinstance(zm.distribution, Normal)
        assert_equal(zm.lags, None)
        res = zm.fit(disp='off')
        assert_almost_equal(res.params, np.array([np.mean(self.y ** 2)]))

        forecasts = res.forecast(horizon=99)
        direct = pd.DataFrame(index=np.arange(self.y.shape[0]),
                              columns=['h.{0:>02d}'.format(i + 1) for i in
                                       range(99)],
                              dtype=np.float64)
        direct.iloc[:, :] = 0.0
        assert isinstance(forecasts, ARCHModelForecast)
        # TODO
        # assert_frame_equal(direct, forecasts)
        garch = GARCH()
        zm.volatility = garch
        zm.fit(update_freq=0, disp=DISPLAY)
예제 #4
0
    def setup_class(cls):
        cls.rng = RandomState(1234)
        cls.T = 1000
        cls.resids = cls.rng.randn(cls.T)
        zm = ZeroMean()
        zm.volatility = GARCH()
        sim_data = zm.simulate(np.array([0.1, 0.1, 0.8]), 1000)
        with pytest.raises(ValueError):
            zm.simulate(np.array([0.1, 0.1, 0.8]), 1000, initial_value=3.0)
        date_index = pd.date_range('2000-12-31', periods=1000, freq='W')
        cls.y = sim_data.data.values
        cls.y_df = pd.DataFrame(cls.y[:, None],
                                columns=['LongVariableName'],
                                index=date_index)

        cls.y_series = pd.Series(cls.y,
                                 name='VeryVeryLongLongVariableName',
                                 index=date_index)
        x = cls.resids + cls.rng.randn(cls.T)
        cls.x = x[:, None]
        cls.x_df = pd.DataFrame(cls.x, columns=['LongExogenousName'])
        cls.resid_var = np.var(cls.resids)
        cls.sigma2 = np.zeros_like(cls.resids)
        cls.backcast = 1.0
예제 #5
0
파일: test_mean.py 프로젝트: esvhd/arch
    def setup_class(cls):
        np.random.seed(1234)
        cls.T = 1000
        cls.resids = randn(cls.T)
        np.random.seed(1234)
        zm = ZeroMean()
        zm.volatility = GARCH()
        sim_data = zm.simulate(np.array([0.1, 0.1, 0.8]), 1000)
        date_index = pd.date_range('2000-12-31', periods=1000, freq='W')
        cls.y = sim_data.data.values
        cls.y_df = pd.DataFrame(cls.y[:, None],
                                columns=['LongVariableName'],
                                index=date_index)

        cls.y_series = pd.Series(cls.y,
                                 name='VeryVeryLongLongVariableName',
                                 index=date_index)
        x = cls.resids + randn(cls.T)
        cls.x = x[:, None]
        cls.x_df = pd.DataFrame(cls.x, columns=['LongExogenousName'])
        cls.resid_var = np.var(cls.resids)
        cls.sigma2 = np.zeros_like(cls.resids)
        cls.backcast = 1.0
예제 #6
0
파일: test_mean.py 프로젝트: jkr2110/arch
    def setUpClass(cls):
        np.random.seed(1234)
        cls.T = 1000
        cls.resids = randn(cls.T)
        np.random.seed(1234)
        zm = ZeroMean()
        zm.volatility = GARCH()
        sim_data = zm.simulate(np.array([0.1, 0.1, 0.8]), 1000)
        date_index = pd.date_range('2000-12-31', periods=1000, freq='W')
        cls.y = sim_data.data.values
        cls.y_df = pd.DataFrame(cls.y[:, None],
                                columns=['LongVariableName'],
                                index=date_index)

        cls.y_series = pd.Series(cls.y,
                                 name='VeryVeryLongLongVariableName',
                                 index=date_index)
        x = cls.resids + randn(cls.T)
        cls.x = x[:, None]
        cls.x_df = pd.DataFrame(cls.x, columns=['LongExogenousName'])
        cls.resid_var = np.var(cls.resids)
        cls.sigma2 = np.zeros_like(cls.resids)
        cls.backcast = 1.0
예제 #7
0
def simulated_data(request):
    rs = np.random.RandomState(1)
    zm = ZeroMean(volatility=GARCH(), distribution=Normal(rs))
    sim_data = zm.simulate(np.array([0.1, 0.1, 0.88]), 1000)
    return np.asarray(sim_data.data) if request.param else sim_data.data
예제 #8
0
def simulated_data():
    rs = np.random.RandomState(1)
    zm = ZeroMean(volatility=GARCH(), distribution=Normal(rs))
    sim_data = zm.simulate(np.array([0.1, 0.1, 0.88]), 1000)
    return sim_data.data