您好,欢迎访问三七文档
当前位置:首页 > 医学/心理学 > 医学试题/课件 > 多元GARCH的Matlab程序
多元GARCH模型预测的Matlab程序function[parameters,loglikelihood,Ht,likelihoods,stdresid,stderrors,A,B,scores]=full_bekk_mvgarch(data,p,q,BEKKoptions);%PURPOSE:%ToEstimateafullBEKKmultivariateGARCHmodel.%%%USAGE:%[parameters,loglikelihood,Ht,likelihoods,stdresid,stderrors,A,B,scores]=full_bekk_mvgarch(data,p,q,options);%%%INPUTS:%data-Atbykmatrixofzeromeanresiduals%p-Thelaglengthoftheinnovationprocess%q-ThelaglengthoftheARprocess%options-(optional)Optionsfortheoptimization(fminunc)%%OUTPUTS:%parameters-A(k*(k+1))/2+p*k^2+q*k^2vectorofestimatedparameteters.F%oranyk^2setofInnovationorARparametersX,%reshape(X,k,k)willgivethecorrectmatrix%TorecoverC,useivech(parmaeters(1:(k*(k+1))/2)%loglikelihood-Theloglikelihoodofthefunctionattheoptimum%Ht-Akxkxt3dimensionmatrixofconditionalcovariances%likelihoods-Atby1vectorofindividuallikelihoods%stdresid-Atbykmatrixofmultivariatestandardizedresiduals%stderrors-AnumParams^2squarematrixofrobustStandadErrors(A^(-1)*B*A^(-1)*t^(-1))%A-Theestimatedinverseofthenon-robustStandarderrors%B-Theestimatedcovarianceoftehscores%scores-AtbynumParamsmatrixofindividualscores%needtotryandgetsomesmartstartginvaluesifsize(data,2)size(data,1)data=data';end[tk]=size(data);k2=k*(k+1)/2;scalaropt=optimset('fminunc');scalaropt=optimset(scalaropt,'TolFun',1e-1,'Display','iter','Diagnostics','on','DiffMaxChange',1e-2);startingparameters=scalar_bekk_mvgarch(data,p,q,scalaropt);CChol=startingparameters(1:(k*(k+1))/2);C=ivech(startingparameters(1:(k*(k+1))/2))*ivech(startingparameters(1:(k*(k+1))/2))';newA=[];newB=[];fori=1:pnewA=[newAdiag(ones(k,1))*startingparameters(((k*(k+1))/2)+i)];endfori=1:qnewB=[newBdiag(ones(k,1))*startingparameters(((k*(k+1))/2)+i+p)];endnewA=reshape(newA,k*k*p,1);newB=reshape(newB,k*k*q,1);startingparameters=[CChol;newA;newB];ifnargin=3|isempty(BEKKoptions)options=optimset('fminunc');options.Display='iter';options.Diagnostics='on';options.TolX=1e-4;options.TolFun=1e-4;options.MaxFunEvals=5000*length(startingparameters);options.MaxIter=5000*length(startingparameters);elseoptions=BEKKoptions;endparameters=fminunc('full_bekk_mvgarch_likelihood',startingparameters,options,data,p,q,k,k2,t);[loglikelihood,likelihoods,Ht]=full_bekk_mvgarch_likelihood(parameters,data,p,q,k,k2,t);loglikelihood=-loglikelihood;likelihoods=-likelihoods;%Standardizedresidualsstdresid=zeros(size(data));fori=1:tstdresid(i,:)=data(i,:)*Ht(:,:,i)^(-0.5);end%StdErrorsifnargout=6A=hessian_2sided('full_bekk_mvgarch_likelihood',parameters,data,p,q,k,k2,t);h=max(abs(parameters/2),1e-2)*eps^(1/3);hplus=parameters+h;hminus=parameters-h;likelihoodsplus=zeros(t,length(parameters));likelihoodsminus=zeros(t,length(parameters));fori=1:length(parameters)hparameters=parameters;hparameters(i)=hplus(i);[HOLDER,indivlike]=full_bekk_mvgarch_likelihood(hparameters,data,p,q,k,k2,t);likelihoodsplus(:,i)=indivlike;endfori=1:length(parameters)hparameters=parameters;hparameters(i)=hminus(i);[HOLDER,indivlike]=full_bekk_mvgarch_likelihood(hparameters,data,p,q,k,k2,t);likelihoodsminus(:,i)=indivlike;endscores=(likelihoodsplus-likelihoodsminus)./(2*repmat(h',t,1));B=cov(scores);A=A/t;stderrors=A^(-1)*B*A^(-1)*t^(-1);end
本文标题:多元GARCH的Matlab程序
链接地址:https://www.777doc.com/doc-5329340 .html