statsmodels.tsa.deterministic.CalendarTimeTrend¶
- class statsmodels.tsa.deterministic.CalendarTimeTrend(freq, constant=True, order=0, *, base_period=None)[source]¶
Constant and time trend determinstic terms based on calendar time
- Parameters:
- freq
str
A string convertible to a pandas frequency.
- constantbool
Flag indicating whether a constant should be included.
- order
int
A non-negative int containing the powers to include (1, 2, …, order).
- base_period{
str
,pd.Timestamp
},default
None
The base period to use when computing the time stamps. This value is treated as 1 and so all other time indices are defined as the number of periods since or before this time stamp. If not provided, defaults to pandas base period for a PeriodIndex.
- freq
Notes
The time stamp, \(\tau_t\), is the number of periods that have elapsed since the base_period. \(\tau_t\) may be fractional.
Examples
Here we simulate irregularly spaced hourly data and construct the calendar time trend terms for the data.
>>> import numpy as np >>> import pandas as pd >>> base = pd.Timestamp("2020-1-1") >>> gen = np.random.default_rng() >>> gaps = np.cumsum(gen.integers(0, 1800, size=1000)) >>> times = [base + pd.Timedelta(gap, unit="s") for gap in gaps] >>> index = pd.DatetimeIndex(pd.to_datetime(times))
>>> from statsmodels.tsa.deterministic import CalendarTimeTrend >>> cal_trend_gen = CalendarTimeTrend("D", True, order=1) >>> cal_trend_gen.in_sample(index)
Next, we normalize using the first time stamp
>>> cal_trend_gen = CalendarTimeTrend("D", True, order=1, ... base_period=index[0]) >>> cal_trend_gen.in_sample(index)
- Attributes:
base_period
The base period
constant
Flag indicating that a constant is included
freq
The frequency of the deterministic terms
is_dummy
Flag indicating whether the values produced are dummy variables
order
Order of the time trend
Methods
from_string
(freq, trend[, base_period])Create a TimeTrend from a string description.
in_sample
(index)Produce deterministic trends for in-sample fitting.
out_of_sample
(steps, index[, forecast_index])Produce deterministic trends for out-of-sample forecasts
Properties
The base period
Flag indicating that a constant is included
The frequency of the deterministic terms
Flag indicating whether the values produced are dummy variables
Order of the time trend