def test_determintic_term_equiv(index): base = DeterministicProcess(pd.RangeIndex(0, 200), constant=True, order=2) dp = DeterministicProcess(index, constant=True, order=2) np.testing.assert_array_equal(base.in_sample(), dp.in_sample()) np.testing.assert_array_equal(base.out_of_sample(37), dp.out_of_sample(37)) np.testing.assert_array_equal(base.range(200, 237), dp.range(200, 237)) np.testing.assert_array_equal(base.range(50, 150), dp.range(50, 150)) np.testing.assert_array_equal(base.range(50, 250), dp.range(50, 250))
def test_drop(): index = pd.RangeIndex(0, 200) dummy = DummyTerm() str(dummy) assert dummy != TimeTrend() dp = DeterministicProcess(index, additional_terms=[dummy], drop=True) in_samp = dp.in_sample() assert in_samp.shape == (200, 4) oos = dp.out_of_sample(37) assert oos.shape == (37, 4) assert list(oos.columns) == list(in_samp.columns) valid = ("const", "trend", "dummy", "normal") for valid_col in valid: assert sum([1 for col in oos if valid_col in col]) == 1
def test_deterministic_process(time_index, constant, order, seasonal, fourier, period, drop): if seasonal and fourier: return dp = DeterministicProcess( time_index, constant=constant, order=order, seasonal=seasonal, fourier=fourier, period=period, drop=drop, ) terms = dp.in_sample() pd.testing.assert_index_equal(terms.index, time_index) terms = dp.out_of_sample(23) assert isinstance(terms, pd.DataFrame)
# the full set of values that match the index. from statsmodels.tsa.deterministic import DeterministicProcess index = pd.RangeIndex(0, 100) det_proc = DeterministicProcess(index, constant=True, order=1, seasonal=True, period=5) det_proc.in_sample() # The `out_of_sample` returns the next `steps` values after the end of the # in-sample. det_proc.out_of_sample(15) # `range(start, stop)` can also be used to produce the deterministic terms # over any range including in- and out-of-sample. # # ### Notes # # * When the index is a pandas `DatetimeIndex` or a `PeriodIndex`, then # `start` and `stop` can be date-like (strings, e.g., "2020-06-01", or # Timestamp) or integers. # * `stop` is always included in the range. While this is not very # Pythonic, it is needed since both statsmodels and Pandas include `stop` # when working with date-like slices. det_proc.range(190, 210)