statsmodels.tsa.filters.hp_filter.hpfilter¶
-
statsmodels.tsa.filters.hp_filter.hpfilter(x, lamb=
1600)[source]¶ Hodrick-Prescott 滤波器。
- Parameters:¶
- xarray_like
要过滤的时间序列,1维。
- lamb
float Hodrick-Prescott 平滑参数。对于季度数据,建议使用 1600 的值。Ravn 和 Uhlig 建议对于年度数据使用 6.25(1600/4**4)的值,对于月度数据使用 129600(1600*3**4)的值。
- Returns:¶
另请参阅
statsmodels.tsa.filters.bk_filter.bkfilterBaxter-King 滤波器。
statsmodels.tsa.filters.cf_filter.cffilterChristiano Fitzgerald 非对称随机游走滤波器。
statsmodels.tsa.seasonal.seasonal_decompose使用移动平均法分解时间序列。
statsmodels.tsa.seasonal.STL使用LOESS进行季节趋势分解。
注释
HP滤波器通过求解去除数据x中的平滑趋势T。
- min sum((x[t] - T[t])**2 + lamb*((T[t+1] - T[t]) - (T[t] - T[t-1]))**2)
T 温度
在这里,我们使用 scipy.sparse 将 HP 滤波器实现为岭回归规则。从这个意义上说,解可以写成
T = inv(I + lamb*K’K)x
其中 I 是一个 nobs x nobs 的单位矩阵,K 是一个 (nobs-2) x nobs 的矩阵,使得
K[i,j] = 1 如果 i == j 或 i == j + 2 K[i,j] = -2 如果 i == j + 1 K[i,j] = 0 否则
请参阅笔记本 时间序列过滤器 以获取概述。
参考文献
- Hodrick, R.J, and E. C. Prescott. 1980. “Postwar U.S. Business Cycles: An
实证调查。” 卡内基梅隆大学讨论论文第451号。
- Ravn, M.O and H. Uhlig. 2002. “Notes On Adjusted the Hodrick-Prescott
过滤观测频率。” 经济学与统计学评论,84(2),371-80。
示例
>>> import statsmodels.api as sm >>> import pandas as pd >>> dta = sm.datasets.macrodata.load_pandas().data >>> index = pd.period_range('1959Q1', '2009Q3', freq='Q') >>> dta.set_index(index, inplace=True)>>> cycle, trend = sm.tsa.filters.hpfilter(dta.realgdp, 1600) >>> gdp_decomp = dta[['realgdp']] >>> gdp_decomp["cycle"] = cycle >>> gdp_decomp["trend"] = trend>>> import matplotlib.pyplot as plt >>> fig, ax = plt.subplots() >>> gdp_decomp[["realgdp", "trend"]]["2000-03-31":].plot(ax=ax, ... fontsize=16) >>> plt.show()
Last update:
Oct 16, 2024