
%-------------------------------------------
% Written by Zhu, Junjun,
% Ph.D candidate in School of Economics
% Fudan University, Shanghai 200433
% Nov. 2009
% please notice, we can not guarantee that these codes are without mistakes.
% You may use these at your own risks.
%-------------------------------------------
clc
clear
load data_200910weekex
y = data_200910weekex
n = size(y,1)
x = ones(n,1)
sn = 3% number of state
nk = 1% regressor number in mean equation
np = 3% p-term in GARCH
y_p = y(np+1:n)
x_p = x(np+1:n)
pi_pri = [18 2 22 28 22 2 16] % prior for pi
bols = inv(x'*x)*x'*y
s2ols = (y-x*bols)'*(y-x*bols)/(n-1)
xsquare=x'*x
indexSwitch =0
switch_1 = 0
switch_2 = 0
switch_3 = 0
P=[0.8 0.1 0.10.1 0.8 0.10.1 0.1 0.8]
%spec = garchset('distribution', 'T','p',0,'q',3)
%[coeff, errors,LLF,innovations,sigmas,summary] = garchfit(spec,y)
%garchdisp(coeff,errors)
% coeff.C = [0.0005]coeff.K = 0.00015coeff.ARCH = [0.197,0.26,0.292]
% default model: y(t) = C +e(t)h(t) = K + GARCH*h(t-1) + ARCH*e(t-1)^2
% beta = [0.00160.00160.0016]
% a_1 = [0.000740.20.260.29]% ARCH coeff. a0, a1, a2, a3 for state 1
% a_2 = [0.000740.20.260.29]
% a_3 = [0.000740.20.260.29]
beta = [-0.00110.02-0.0061]
a_1 = [0.00050.110.150.08]
a_2 = [0.00140.220.170.13]
a_3 = [0.00220.140.100.15]
var_err = (y-x*beta(1)).^2
beta_ = []
a1_ = []
a2_ = []
a3_ = []
P_ = []
nburn=0%number of burnin replications
nrep=30000%number of retained replications
ntotal=nburn+nrep
对garch模型做预测可以用matlab自带的garchfit()函数,该函数主要用于估计ARMAX / GARCH模型参数。garchfit()函数使用格式:
[Coeff,Errors,LLF,Innovations,Sigmas,Summary] = garchfit(Spec,Series,X)
Coeff——输入参数。接受由garchset,garchget,garchsim,garchinfer,和garchpred结构产生的参数。
Errors——系数的估计误差(即标准误差)的结构。
LLF——对于优化目标函数值与参数相关的估计发现Coeff。garchfit执行优化使用优化工具箱fmincon函数。
Innovations——创建(即残差)序列推导的时间序列列向量。
Sigmas——与创建相对应的条件标准偏差向量。
Summary——显示优化过程的摘要信息结构。
Spec——包含条件均值和方差规范的GARCH规范结构。它还包含估计所需的优化参数。通过调用garchset创建这个结构。
Series——观测的时间序列列向量。
X——观测数据的时间序列回归矩阵。
例如:
clc
spec = garchset('C',0,'K',0.0001,'GARCH',0.9,'ARCH',0.05) %指定模型的结构
[e,s,y]= garchsim(spec,1000)
[Coeff,Errors,LLF,Innovations,Sigmas,Summary] = garchfit(spec,y) %拟合参数
运行后得到的部分结果
需要。又称“广义ARCH模型(Generalized ARCH)”、“广义自回归条件异方差模型”
自从Engle(1982)提出ARCH模型分析时间序列的异方差性以后,
波勒斯列夫T.Bollerslev(1986)又提出了GARCH模型,GARCH模型是一个专门针对金融数据所量体订做的回归模型,除去和普通回归模型相同的之处,GARCH对误差的方差进行了进一步的建模。
欢迎分享,转载请注明来源:内存溢出
微信扫一扫
支付宝扫一扫
评论列表(0条)