我想计算高阶 AR(4) 模型的半衰期。基本上,我想知道荷兰 GDP 增长均值回归的速度。
我有一个 AR(1) 模型的半衰期 python 代码
供您参考:grw 是一个数据框,其中 index=dates 和荷兰经济的 GDP 增长
# Halflife calculation
gdp_lags = np.roll(grw['Growth_yoy'],1)
gdp_lags[0] = 0
gdp_rets = grw['Growth_yoy'] - gdp_lags
gdp_rets[0] = 0
#adds intercept terms to X variable for regression
gdp_lags2 = sm.add_constant(gdp_lags)
model = sm.OLS(gdp_rets,gdp_lags2)
results = model.fit()
halflife = -np.log(2) / results.params[1]
print(halflife)
我想为 AR(4) 模型提供 python 代码。