Time Series¶
statspai.timeseries — classical and Bayesian time-series models,
cointegration tests, local projections, GARCH, and structural-break
detection.
Univariate¶
# ARIMA(p,d,q) with automatic order selection
m = sp.arima(y, order=(1,1,1), seasonal_order=(1,1,1,12))
m.forecast(steps=24); m.plot()
# GARCH family
m = sp.garch(ret, p=1, q=1, model='garch') # 'garch'|'egarch'|'gjrgarch'
m.volatility; m.plot('conditional_volatility')
Multivariate¶
# Vector Autoregression
m = sp.var(df, columns=['gdp','infl','r'], lags=4)
m.impulse_response(shock='r', h=40, identification='cholesky')
m.variance_decomposition(h=40)
m.granger_causality(cause='r', effect='gdp')
# Bayesian VAR with Minnesota prior
m = sp.bvar(df, columns=['gdp','infl','r'], lags=4,
prior='minnesota',
lambda1=0.2, lambda2=0.5)
Cointegration¶
# Engle-Granger two-step
sp.cointegration(df[['y','x']], method='engle_granger')
# Johansen trace and max-eigenvalue
sp.cointegration(df[['y','x','z']], method='johansen', trend='c', k_ar_diff=2)
# Phillips-Ouliaris, Hansen
sp.cointegration(..., method='phillips_ouliaris')
Local projections (Jordà 2005)¶
sp.local_projections(
df, outcome='gdp', shock='mp_shock',
horizons=20,
controls=['infl_lag', 'r_lag'],
auto_lag=False, # controls are used verbatim
)
# Match lpirfs::lp_lin with a unit Cholesky shock.
sp.local_projections(
df, outcome='gdp', shock='mp_shock',
horizons=20,
identification='lpirfs_cholesky',
endog_order=['gdp', 'mp_shock'],
)
Structural break¶
sp.chow_test(y, x, break_point=t_star) # known break
sp.quandt_andrews(y, x) # unknown break, sup-F
sp.bai_perron(y, x, n_breaks=3) # multiple breaks