在 ARCH ( p )模型中,如果 p 很大,则要估计很多参数,会损失样本容量。Bollerslev(1986)提出 GARCH,使得待估计参数减少,而对未来条件方差的预测更加准确。其基本思想是,在 ARCH 模型的基础上,再加上 σ2t 的自同归部分, 即 σ2t 还是 {σ2t−1,⋯,σ2t−p} 的函数。 GARCH (p, q ) 的模型设定为:
σ2t=α0+α1ε2t−1+⋯+αqε2t−q+γ1σ2t−1+⋯+γpσ2t−p其中,p 为 σ2t 的自回归阶数,而 q 为 ε2t 的滞后阶数。称 ε2t−i 为“ARCH 项”,而称 σ2t−i 为“GARCH 项”。
首先,用 OLS 估计原方程“ yt=x′tβ+εt,得到残差序列 {et}∘ 其次,用 0LS 估计辅助同归 ,e2t=α0+α1e2t−1+⋯+αpe2t−p+errort, 并检验原假设“ H0:α1=α2=⋯=αp=0"( 不存在条件异方差 )。Engle(1982)提出进行 LM 检验,其检验统计量为 TR2d⟶χ2(p),其中 T 为样本 容量, R2 为上述辅助同归的可决系数。如果拒绝 H0, 则认为应使用 ARCH 或 GARCH 模型。
可以对残差平方序列 |e2t| 进行 Q 检验, , 检验其序列相关性。如果 {e2t} 存在自相关,则认为 εt 存在条件异方差。
最为直接的方法是,在估计 ARCH 或 GARCH 模型之后,看条件方差方程中的系数 (即所有 α 与 γ ) 是否显著。
ARCH-M:金融理论认为,金融资产的风险越高,其期望收益率也应该越高,这样才会有人愿意持有它。超出正常期望收益率的部分,称为"风险溢价"(riskpremium)。但在标准的 ARCH 模型中,变量的均值与条件方差却没有关系。Engle,Lilien and Robins (1987)提出了如下"ARCH - in - Mean 模型"(简记 ARCH - M)。
TARCH:"坏消息"对资产价格波动性的影响可能大于好消息的影响。Glosten,Jagannathanand Runkle ( 1993)提出了非对称( asymmetric)的"门限 GARCH"模型( Threshold GARCH,简记 TARCH)。
EGARCH:在标准的 GARCH 模型中,对参数的取值有所限制,给 MLE 估计带来不便。为此,使用对数形式的条件方差方程
带 ARMA 的 GARCH
在条件方差方程中引入解释变量
使用非正态扰动项
任何分布都能化为 [0, 1] 均匀分布
假设 FX(a)=p(x≤a) 为累积分布函数,f(x) 为概率密度函数, FX(a)=∫a−∞f(x)dx, 则存在如下等式:
P(FX(X)≤a)=P(X≤F−1X(a))=FX(F−1X(a))=a则累积分布函数 Y=FX(X) 服从 [0, 1] 间的均匀分布。
import datetime as dt
import arch.data.sp500
st = dt.datetime(1988, 1, 1)
en = dt.datetime(2018, 1, 1)
data = arch.data.sp500.load()
market = data['Adj Close']
returns = 100 * market.pct_change().dropna()
ax = returns.plot()
xlim = ax.set_xlim(returns.index.min(), returns.index.max())
from arch import arch_model
model_arch = arch_model(y=returns, mean='Constant', lags=0, vol='GARCH',p=1,
o=0, q=1, dist='normal') # 构建 GARCH(1,1)模型
res = model_arch.fit()
res.summary()
Iteration: 1, Func. Count: 6, Neg. LLF: 6955.831420300672 Iteration: 2, Func. Count: 16, Neg. LLF: 6951.317990771391 Iteration: 3, Func. Count: 24, Neg. LLF: 6947.0646164023 Iteration: 4, Func. Count: 32, Neg. LLF: 6946.364741603253 Iteration: 5, Func. Count: 39, Neg. LLF: 6942.159596737265 Iteration: 6, Func. Count: 46, Neg. LLF: 6939.773381475562 Iteration: 7, Func. Count: 53, Neg. LLF: 6938.412846197003 Iteration: 8, Func. Count: 60, Neg. LLF: 6936.760037838338 Iteration: 9, Func. Count: 66, Neg. LLF: 6936.742006327482 Iteration: 10, Func. Count: 72, Neg. LLF: 6936.718529994181 Iteration: 11, Func. Count: 78, Neg. LLF: 6936.7184774904035 Optimization terminated successfully. (Exit mode 0) Current function value: 6936.718476989043 Iterations: 11 Function evaluations: 79 Gradient evaluations: 11
Dep. Variable: | Adj Close | R-squared: | -0.001 |
---|---|---|---|
Mean Model: | Constant Mean | Adj. R-squared: | -0.001 |
Vol Model: | GARCH | Log-Likelihood: | -6936.72 |
Distribution: | Normal | AIC: | 13881.4 |
Method: | Maximum Likelihood | BIC: | 13907.5 |
No. Observations: | 5030 | ||
Date: | Thu, Jun 04 2020 | Df Residuals: | 5026 |
Time: | 09:09:56 | Df Model: | 4 |
coef | std err | t | P>|t| | 95.0% Conf. Int. | |
---|---|---|---|---|---|
mu | 0.0564 | 1.149e-02 | 4.906 | 9.302e-07 | [3.384e-02,7.887e-02] |
coef | std err | t | P>|t| | 95.0% Conf. Int. | |
---|---|---|---|---|---|
omega | 0.0175 | 4.683e-03 | 3.738 | 1.854e-04 | [8.328e-03,2.669e-02] |
alpha[1] | 0.1022 | 1.301e-02 | 7.852 | 4.105e-15 | [7.665e-02, 0.128] |
beta[1] | 0.8852 | 1.380e-02 | 64.125 | 0.000 | [ 0.858, 0.912] |
pic = res.plot()
牛津大学教授代码:https://pan.baidu.com/s/1N_J_cYhRq-b_jfPaO_qL2g#list/path=%2F
GARCH 估计与残差分布检验
% 1.导入数据
data = xlsread('C:\Users\Administrator\Desktop\各市场收益率');
rst = data(:,2); %WTI市场现货原始收益率
mldate = x2mdate(data(:,1)); % 导入日期
% 2.处理汇率收益率序列
epsilon=rst-mean(rst); %现货原始收益率残差
T=length(epsilon);
% 3.构建GARCH(1,1)模型
options=optimset('fminunc');
options=optimset(options,'TolFun',1e-005);
options=optimset(options,'TolX',1e-005);
options=optimset(options,'Display','off');
options=optimset(options,'Diagnostics','off');
options=optimset(options,'LargeScale','off');
options=optimset(options,'MaxFunEvals',2000);
[garch11p,garch11LL,garch11ht,garch11vcvrobust]=tarch(epsilon,1,0,1,'SKEWT',[],[],options);
[garch11text,garch11AIC,garch11BIC]=tarch_display(garch11p,garch11LL,garch11vcvrobust,epsilon,1,2,1);
% 4.检验残差分布选择是否合理(可以利用AIC值、QQ图、KS检验、标准残差做ARCH检验)
% 4.1 KS检验
ehat = epsilon./sqrt(garch11ht); %标准残差
u = skewtcdf(ehat,garch11p(4,1),garch11p(5,1)); %概率积分变换
v = unifrnd(0,1,T,1);
[H, pValue, KSstatistic] = kstest2(u,v);
% 4.2 QQ图
fig=figure;
set(fig,'Position',[100 100 550 500],'Color',[1 1 1])
y = unifinv((1:T)'/(T+1),0,1);
LB = 0;
UB=1;
h=plot([LB UB],[LB UB],sort(u),y);
set(h(1),'LineStyle','--','Color',[1 0 0],'LineWidth',1)
set(h(2),'LineStyle','none','Marker','o','MarkerSize',1,'Color',[0 0 1])
axis tight
set(gca,'FontSize',16)
a = 'WTI';
title(['' a '原油现货收益率Q-Q图'],'FontSize',16)
xlabel('U(0,1)')
ylabel('残差概率值');
% 4.3 标准残差做ARCH检验,p值高说明无法拒绝原假设(不存在条件异方差)
[h,p,stat,cValue] = archtest(ehat,'lags',10);
if p<=0.01
arch{1,1} = ['' num2str(stat,'%3.3f') '***'];
elseif p<=0.05
arch{1,1} = ['' num2str(stat,'%3.3f') '**'];
elseif p<=0.1
arch{1,1} = ['' num2str(stat,'%3.3f') '*'];
else arch{1,1} = ['' num2str(stat,'%3.3f') ''];
end