📄 gengarch.src
字号:
/*
** GENGARCH.g
**
** Purpose : generate realizations from GARCH(p,q) processes
**
** Format : eps = GENGARCH(omega,alpha,beta,T_0,T,n);
**
** Input : omega : scalar, constant in conditional variance equation
** alpha : (qx1) vector, parameters of lagged squared redisuals
** in conditional variance equation
** beta : (px1) vector, parameters of lagged conditional variance
** in conditional variance equation
** nu : scalar, indicating whether disturbances are to be
** drawn from standard normal distribution (nu=0), or from
** t-distribution with nu degrees of freedom
** T_0 : scalar, number of initial observations to be discarded
** T : scalar, the length of the series to be generated
** n : scalar, the number of generated series
**
** Output : eps : T x n, the generated series
**
** Globals : none
**
** Remarks : Setting beta={} will generate realizations from an ARCH(q) process
**
** Written by Dick van Dijk
**
** First attempt on 28 March 1996
** Last revision on 17 July 1996
**
*/
proc gengarch(omega,alpha,beta,nu,T_0,T,n);
local p,q,eps_1,h_1,eps,i,z;
/* determine orders of GARCH process */
p=rows(beta);
q=rows(alpha);
if (rows(n) GT 1);
z=n;
n=cols(n);
endif;
/* Starting values for lagged residuals are set equal to zero, while lagged
conditional variances are set equal to unconditional variance */
eps_1=zeros(q+1,n);
if (sumc(alpha)+sumc(beta) /= 1);
h_1=ones(p+1,n)*(omega/(1-sumc(alpha)-sumc(beta)));
else;
h_1=ones(p+1,n);
endif;
/* extend alpha and beta to avoid trimming problems below */
alpha=alpha|0;
beta=beta|0;
eps=zeros(T_0+T,n);
i=0;
do until (i==T_0+T);
i=i+1;
h_1=(omega + alpha'(eps_1.*eps_1) + beta'h_1)|trimr(h_1,0,1);
if (nu==-1);
eps_1=(sqrt(h_1[1,.]).*z[i,.])|trimr(eps_1,0,1);
elseif (nu==0);
eps_1=(sqrt(h_1[1,.]).*rndn(1,n))|trimr(eps_1,0,1);
else;
eps_1=(sqrt((nu-2)/nu).*sqrt(h_1[1,.]).*rndn(1,n)./
sqrt(sumc(rndn(nu,n).^2)'./nu))|trimr(eps_1,0,1);
endif;
eps[i,.]=eps_1[1,.];
endo;
retp(eps[T_0+1:T_0+T,.]);
endp;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -