Matlab中做GARCH Estimation
发布:yhw1234 | 分类:Matlab软件培训
关于本站
人大经济论坛-经管之家:分享大学、考研、论文、会计、留学、数据、经济学、金融学、管理学、统计学、博弈论、统计年鉴、行业分析包括等相关资源。
经管之家是国内活跃的在线教育咨询平台!
获取电子版《CDA一级教材》
完整电子版已上线CDA网校,累计已有10万+在读~ 教材严格按考试大纲编写,适合CDA考生备考,也适合业务及数据分析岗位的从业者提升自我。
TOP热门关键词
免费学术公开课,扫码加入![]() |
可以参见我的博客:
http://hi.baidu.com/%B5%E7%C4%D4%BE%AB%C1%E9ghost/blog/item/d49bb68b6d83ec779e2fb49d.html
Matlab中做GARCH Estimation
先看懂matlab中的帮助:
U(t) = sqrt(H(t))*v(t), where v(t) is an i.i.d. sequence ~ N(0,1).
The GARCH(P,Q) coefficients K, A, B are subject to constraints:
(1) K > 0
(2) A(i) >= 0 for i = 1,2,...P
(3) B(i) >= 0 for i = 1,2,...Q
(4) sum(A(i) + B(j)) < 1 for i = 1,2,...P and j = 1,2,...Q
The coefficient vectors A and B are each entered as comma-separated lists. The
number of elements in A and B determines the model orders P and Q, respectively.
When you have entered the desired process parameters, click the SIMULATE button
to create time sequences of length N of innovations U(t) and conditional
variance H(t). The sequence U(t) will then appear in the top plot, and the
conditional volatility (the square root of H(t)) will appear in the bottom plot.
To estimate, and make forecasts from, the GARCH(P,Q) parameters from the U(t)
process you just simulated (i.e., to reverse-engineer the process for
comparison), click the FORECAST button. The parameters K, A, B are then
estimated via Maximum Likelihood and displayed in the corresponding ESTIMATED
frame.
To estimate GARCH parameters, we must, by necessity, also re-construct an
estimate of the H(t) time series. The square root of this re-constructed
estimate is then plotted along with the original conditional volatility you
previously simulated for comparison. The last 100 samples of the lower plot are
reserved for the forecast sequence of conditional volatility based on the
estimated parameters. Close inspection will reveal that the volatility forecast
approaches the unconditional volatility of the GARCH process, which is indicated
as a horizontal line in the lower plot. A vertical line 100 samples from the
right-hand edge of the lower plot indicates the region reserved for the
volatility forecast.
操作图像:

function garchgui()
%GARCHGUI Garch Estimation Demo.
% Author(s): C.F.Garvin, 05-04-98
% Copyright 1995-2002 The MathWorks, Inc.
% $Revision: 1.9 $ $Date: 2002/04/14 21:44:01 $
%Focus garchgui if already open
gobj = findobj('Tag','GARCHGUI');
if ~isempty(gobj)
figure(gobj)
return
end
%Figure spacing parameters
bspc = 5;
bwid = 80;
bhgt = 20;
%Build the figure window
fig = figure('Numbertitle','off','Tag','GARCHGUI',...
'Name','GARCH Estimation Demo...');
figpos = get(fig,'Position');
rgt = figpos(3)-bspc;
top = figpos(4);
%Callbacks
collectparams = [...
'clear all,'...
'pobj = findobj(gcf,''Tag'',''paramp'');'...
'qobj = findobj(gcf,''Tag'',''paramq'');'...
'kobj = findobj(gcf,''Tag'',''paramk'');'...
'nobj = findobj(gcf,''Tag'',''paramn'');'...
'k = str2double(get(kobj,''String''));'...
'pstr = get(pobj,''String'');'...
'qstr = get(qobj,''String'');'...
'n = str2double(get(nobj,''String''));'...
'pstr = ['','' pstr '',''];'...
'qstr = ['','' qstr '',''];'...
'i = find(pstr == '','');'...
'for j = 1:length(i)-1,'...
'p(j) = str2double(pstr(i(j)+1:i(j+1)-1));'...
'end,'...
'i = find(qstr == '','');'...
'for j = 1:length(i)-1,'...
'q(j) = str2double(qstr(i(j)+1:i(j+1)-1));'...
'end,'...
'if isnan(k) | any(isnan(p)) | any(isnan(q)) | isnan(n),'...
'errordlg(''Please enter valid garch parameters.'');'...
'set(findobj(''Tag'',''GARCHGUI''),''Pointer'',''arrow''),'...
'return;'...
'end,'...
'if n < 101,'...
'errordlg(''N must be greater than 100.'');'...
'return,'...
'end,'...
];
simulate = [...
'try,'...
'set(findobj(gcf,''Tag'',''volfor''),''Visible'',''off'');'...
'set(findobj(gcf,''Tag'',''threshold''),''Visible'',''off'');'...
'set(findobj(gcf,''Tag'',''fcline''),''Visible'',''off'');'...
collectparams,...
';[ts,va] = ugarchsim(k,p'',q'',n);'...
'tobj = findobj(gcf,''Tag'',''timeseries'');'...
'set(tobj,''Xdata'',1:n,''Ydata'',ts,''Visible'',''on'');'...
'aobj = findobj(gcf,''Tag'',''volact'');'...
'set(aobj,''Xdata'',1:n,''Ydata'',sqrt(va),''Visible'',''on'');'...
'set(findobj(gcf,''Type'',''axes''),''Xlim'',[-inf inf],''Ylim'',[-inf inf]);'...
'catch,'...
'errordlg(lasterr),'...
'end,'...
'set(findobj(''Type'',''figure''),''Pointer'',''arrow''),'...
];
forecast = [...
'warning off,'...
'set(gcf,''Pointer'',''watch''),'...
'try,'...
collectparams,...
';tsax = findobj(gcf,''Type'',''axes'');'...
'ch = get(tsax,''Children'');'...
'u = get(ch{2},''Ydata'');'...
'[k,a,b] = ugarch(u(:),length(p),length(q));'...
'astr = [];bstr = [];'...
'for i = 1:length(a),'...
'astr = [astr '' '' num2str(a(i),2)];'...
'end,'...
'for i = 1:length(b),'...
'bstr = [bstr '' '' num2str(b(i),2)];'...
'end,'...
'set(findobj(''Tag'',''estk''),''String'',num2str(k,2));'...
'set(findobj(''Tag'',''esta''),''String'',astr);'...
'set(findobj(''Tag'',''estb''),''String'',bstr);'...
'[v,h] = ugarchpred(u(1:n-100)'',k,a,b,100);'...
'fobj = findobj(gcf,''Tag'',''volfor'');'...
'newv = [sqrt(h);sqrt(v)];'...
'set(fobj,''Xdata'',1:n,''Ydata'',newv,''Visible'',''on'');'...
'tobj = findobj(gcf,''Tag'',''threshold'');'...
'sig = sqrt((k / (1 - (sum(a) + sum(b)) ) ));'...
'set(tobj,''Xdata'',1:n,''Ydata'',sig(ones(n,1)),''Visible'',''on'');'...
'lobj = findobj(gcf,''Tag'',''fcline'');'...
'vobj = findobj(gcf,''Tag'',''volact'');'...
'volact = get(vobj,''Ydata'');'...
'set(lobj,''Xdata'',[n-100 n-100],''Ydata'',[min([volact sig]) max([volact sig])],''Visible'',''on'');'...
'catch,'...
'errordlg(lasterr),'...
'end,'...
'set(findobj(''Type'',''figure''),''Pointer'',''arrow''),'...
'warning on,'...
];
helpstring = {...
'GARCH (Generalized Auto-Regressive Conditional Heteroskedastic) Demonstration:';...
'';...
'Within the ACTUAL frame, enter the true GARCH(P,Q) model parameters of the ';...
'process you want to simulate. The parameters you enter correspond to the ';...
'following GARCH(P,Q) model for the conditional variance, H(t), and innovations,';...
'U(t), sequences:';...
'';...
' H(t) = K + A(1)*H(t-1) + A(2)*H(t-2) + ... + A(P)*H(t-P)';...
' + B(1)*U^2(t-1)+ B(2)*U^2(t-2) + ... + B(Q)*U^2(t-Q)';...
'';...
'for time steps t = 1, 2, ... N (N > 100).';...
'';...
'Note that U and H are related:';...
' ';...
' U(t) = sqrt(H(t))*v(t), where v(t) is an i.i.d. sequence ~ N(0,1).';...
' ';...
'The GARCH(P,Q) coefficients K, A, B are subject to constraints:';...
' (1) K > 0';...
' (2) A(i) >= 0 for i = 1,2,...P';...
' (3) B(i) >= 0 for i = 1,2,...Q';...
' (4) sum(A(i) + B(j)) < 1 for i = 1,2,...P and j = 1,2,...Q';...
'';...
'The coefficient vectors A and B are each entered as comma-separated lists. The ';...
'number of elements in A and B determines the model orders P and Q, respectively.';...
'';...
'When you have entered the desired process parameters, click the SIMULATE button';...
'to create time sequences of length N of innovations U(t) and conditional ';...
'variance H(t). The sequence U(t) will then appear in the top plot, and the ';...
'conditional volatility (the square root of H(t)) will appear in the bottom plot.';...
'';...
'To estimate, and make forecasts from, the GARCH(P,Q) parameters from the U(t) ';...
'process you just simulated (i.e., to reverse-engineer the process for ';...
'comparison), click the FORECAST button. The parameters K, A, B are then ';...
'estimated via Maximum Likelihood and displayed in the corresponding ESTIMATED ';...
'frame. ';...
'';...
'To estimate GARCH parameters, we must, by necessity, also re-construct an ';...
'estimate of the H(t) time series. The square root of this re-constructed ';...
'estimate is then plotted along with the original conditional volatility you ';...
'previously simulated for comparison. The last 100 samples of the lower plot are';...
'reserved for the forecast sequence of conditional volatility based on the ';...
'estimated parameters. Close inspection will reveal that the volatility forecast';...
'approaches the unconditional volatility of the GARCH process, which is indicated';...
'as a horizontal line in the lower plot. A vertical line 100 samples from the ';...
'right-hand edge of the lower plot indicates the region reserved for the ';...
'volatility forecast.';...
};
%Store help string for later use
uicontrol('Visible','off','Tag','helpstring','String',helpstring);
garchhelp = [...
'helpwin(get(findobj(''Tag'',''helpstring''),''String''),''GARCH Estimation Demo Help'');'...
];
%Build uicontrols
uicontrol('Enable','off','Position',[rgt-3*bspc-bwid top-6*bspc-9*bhgt 2*bspc+bwid bspc+9*bhgt]);
uicontrol('Style','text','String','Actual','Position',[rgt-2*bspc-bwid top-4*bspc-bhgt bwid/2 bhgt]);
uicontrol('Style','text','String','K:','Horizontalalignment','left',...
'Position',[rgt-2*bspc-bwid top-3*bspc-2*bhgt bwid bhgt]);
uicontrol('Style','edit','Tag','paramk','Position',[rgt-2*bspc-bwid top-2*bspc-3*bhgt bwid bhgt]);
uicontrol('Style','text','String','A:','Horizontalalignment','left',...
'Position',[rgt-2*bspc-bwid top-4*bspc-4*bhgt bwid bhgt]);
uicontrol('Style','edit','Tag','paramp','Position',[rgt-2*bspc-bwid top-3*bspc-5*bhgt bwid bhgt]);
uicontrol('Style','text','String','B:','Horizontalalignment','left',...
'Position',[rgt-2*bspc-bwid top-5*bspc-6*bhgt bwid bhgt]);
uicontrol('Style','edit','Tag','paramq','Position',[rgt-2*bspc-bwid top-4*bspc-7*bhgt bwid bhgt]);
uicontrol('Style','text','String','N:','Horizontalalignment','left',...
'Position',[rgt-2*bspc-bwid top-6*bspc-8*bhgt bwid bhgt]);
uicontrol('Style','edit','Tag','paramn','Position',[rgt-2*bspc-bwid top-5*bspc-9*bhgt bwid bhgt])
uicontrol('Enable','off','Position',[rgt-3*bspc-bwid top-6*bspc-14*bhgt 2*bspc+bwid bspc+4*bhgt]);
uicontrol('Style','text','String','Estimated','Position',[rgt-2*bspc-bwid top-8*bspc-10*bhgt bwid*2/3 bhgt]);
uicontrol('Style','text','String','K:','Position',[rgt-2*bspc-bwid top-9*bspc-11*bhgt bwid/2 bhgt]);
uicontrol('Style','edit','Tag','estk','Position',[rgt-1*bspc-bwid/1.5 top-8*bspc-11*bhgt bwid/2 bhgt]);
uicontrol('Style','text','String','A:','Position',[rgt-2*bspc-bwid top-9*bspc-12*bhgt bwid/2 bhgt]);
uicontrol('Style','edit','Tag','esta','Position',[rgt-1*bspc-bwid/1.5 top-8*bspc-12*bhgt bwid/2 bhgt]);
uicontrol('Style','text','String','B:','Position',[rgt-2*bspc-bwid top-9*bspc-13*bhgt bwid/2 bhgt]);
uicontrol('Style','edit','Tag','estb','Position',[rgt-1*bspc-bwid/1.5 top-8*bspc-13*bhgt bwid/2 bhgt]);
uicontrol('Enable','off','Position',[rgt-3*bspc-bwid top-4*bspc-19*bhgt 2*bspc+bwid bspc+3.7*bhgt]);
uicontrol('String','Simulate','Callback',simulate,...
'Position',[rgt-2*bspc-bwid top-9*bspc-15*bhgt bwid bhgt]);
uicontrol('String','Forecast','Callback',forecast,...
'Position',[rgt-2*bspc-bwid top-10*bspc-16*bhgt bwid bhgt]);
uicontrol('String','Help','Callback',garchhelp,...
'Position',[rgt-2*bspc-bwid top-11*bspc-17*bhgt bwid bhgt]);
%Build subplots and initialize figures with data
subplot(2,1,1)
h = plot(ones(100,1)); %Time series object
set(h,'Tag','timeseries','Visible','off')
title('Time Series','Fontweight','bold')
axpos = get(gca,'Position');
set(gca,'Position',[.075 axpos(2) .71 axpos(4)],'Fontweight','bold')
grid on
subplot(2,1,2)
h = plot(ones(100,1),'-','Color','b'); %Actual volatility object
hold on
set(h,'Tag','volact','Visible','off')
h = plot(ones(100,1),'-','Color','k');
set(h,'Tag','threshold','Visible','off')
h = plot(ones(100,1),'-','Color','r'); %Forecast volatility object
set(h,'Tag','volfor','Visible','off')
h = plot([1 1],[1 1],'-','Color','k');
hold off
set(h,'Tag','fcline','Visible','off');
title('Volatility','Fontweight','bold')
xlabel('Blue = Simulated Red = Forecasted','Fontweight','bold')
axpos = get(gca,'Position');
set(gca,'Position',[.075 axpos(2) .71 axpos(4)],'Fontweight','bold')
grid on
%GUI cleanup
set(findobj(gcf,'Style','edit'),'Backgroundcolor','white','Horizontalalignment','left')
set(findobj(gcf,'Type','uicontrol'),'Units','normal')
免流量费下载资料----在经管之家app可以下载论坛上的所有资源,并且不额外收取下载高峰期的论坛币。
涵盖所有经管领域的优秀内容----覆盖经济、管理、金融投资、计量统计、数据分析、国贸、财会等专业的学习宝库,各类资料应有尽有。
来自五湖四海的经管达人----已经有上千万的经管人来到这里,你可以找到任何学科方向、有共同话题的朋友。
经管之家(原人大经济论坛),跨越高校的围墙,带你走进经管知识的新世界。
扫描下方二维码下载并注册APP
您可能感兴趣的文章
- Matlab软件 ... | 数字媒体技术专业课程_数字媒体技 ...
- Matlab软件 ... | MATLAB科学计算与可视化仿真宝典
- Matlab软件 ... | 【分享】MATLAB Programming Fun ...
- Matlab软件 ... | 关于使用MF-DFA方法计算广义Hurs ...
- Matlab软件 ... | 【转贴】写给matlab新手的几句话
- Matlab软件 ... | Mathematics for Business, Scie ...
- Matlab软件 ... | 用matlab和1stop解非线性规划出错 ...
- Matlab软件 ... | 广深地区第一次地区性MATLAB研讨 ...
人气文章
本文标题:Matlab中做GARCH Estimation
本文链接网址:https://bbs.pinggu.org/jg/ruanjianpeixun_matlabruanjianpeixun_461548_1.html
2.转载的文章仅代表原创作者观点,与本站无关。其原创性以及文中陈述文字和内容未经本站证实,本站对该文以及其中全部或者部分内容、文字的真实性、完整性、及时性,不作出任何保证或承若;
3.如本站转载稿涉及版权等问题,请作者及时联系本站,我们会及时处理。



