statsmodels.tsa.deterministic.CalendarFourier

class statsmodels.tsa.deterministic.CalendarFourier(freq, order)[source]

Fourier series deterministic terms based on calendar time

Parameters:
freqstr

A string convertible to a pandas frequency.

orderint

The number of Fourier components to include. Must be <= 2*period.

Attributes:
freq

The frequency of the deterministic terms

is_dummy

Flag indicating whether the values produced are dummy variables

order

The order of the Fourier terms included

Notes

Both a sine and a cosine term are included for each i=1, …, order

\[\begin{split}f_{i,s,t} & = \sin\left(2 \pi i \tau_t \right) \\ f_{i,c,t} & = \cos\left(2 \pi i \tau_t \right)\end{split}\]

where m is the length of the period and \(\tau_t\) is the frequency normalized time. For example, when freq is “D” then an observation with a timestamp of 12:00:00 would have \(\tau_t=0.5\).

Examples

Here we simulate irregularly spaced hourly data and construct the calendar Fourier 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 CalendarFourier
>>> cal_fourier_gen = CalendarFourier("D", 2)
>>> cal_fourier_gen.in_sample(index)

Methods

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

freq

The frequency of the deterministic terms

is_dummy

Flag indicating whether the values produced are dummy variables

order

The order of the Fourier terms included


Last update: Nov 14, 2024