Page 1 of 1

Dynamic EGARCH forecast

Posted: Thu Aug 22, 2013 7:03 am
by likykiki
Hi, I'm using EGARCH model of Baillie, Bollerslev and Mikkelson(1996), "Fractionally Integrated Generalized Autoregressive Conditional Heteroskedasticity", the EGARCH code is from TomDoan,
what i'm trying to do is to forecast GBP's volatility dynamicly, the estimation window is 500, and rolling forward daily, until the full sample is reached.
but when i run the code, it writes:

## SR10. Missing Values And/Or SMPL Options Leave No Usable Data Points
The Error Occurred At Location 1509, Line 44 of loop/block

could someone help? many thanks here is my code:

Code: Select all

all 3908
open data o:\GBP.xlsx
data(format=xlsx,org=obs) /
close data

set ph / = log(hi)
set pl / = log(lo)
set r  / = (((ph-pl)**2.0)/(4*log(2)))**0.5

dofor tau2 = 1 5 20 60 120 240
 
comp step =fix(%IF(tau2>20,20,tau2))
comp tau1=fix(%max(1,tau2-19))

comp k=0


do i=500,3908-tau2, step

comp k=k+1

linreg(noprint) r i-499 i
#r{1 to 3}

frml(lastreg,vector=mu) meanf
compute omega=log(%seesq),delta=0.0
nonlin(parmset=meanparms) mu

clear u h
compute gstart=%regstart(),gend=%regend()

nonlin(parmset=garchparms) omega delta
frml varf = omega+log(1+delta*gap)
frml logl = u=r-meanf,h=exp(varf),%logdensity(h,u)
maximize(parmset=meanparms+garchparms) logl gstart gend
compute omega0=omega

nonlin(parmset=garchparms) omega delta psi1 phi1 phi2 theta gamma
compute psi1=-.8,phi1=1.0,phi2=0.0,theta=-.1,gamma=.2

compute uupresample=exp(omega0)
set uuadj = uupresample
set h     = uupresample

set x     = 0.0
set ax    = 0.0

frml varf = omega+(1-phi1)*(1-phi2)*omega+$
  log(1+delta*gap)-(phi1+phi2)*log(1+delta*gap{1})+phi1*phi2*log(1+delta*gap{2})+$
  (phi1+phi2)*log(h{1})-phi1*phi2*log(h{2})+$
  theta*(x{1}+psi1*x{2})+gamma*(ax{1}+psi1*ax{2})
frml logl = u=r-meanf,h=exp(varf),x=u/sqrt(h),ax=abs(x)-sqrt(2.0/%pi),%logdensity(h,u)
maximize(parmset=meanparms+garchparms,trace,iters=500) logl gstart gend


do j = tau1,tau2


set ract j j = r(i+j)
set rfor j j = exp(u+h+x+ax+%logdensity(h,u))

end do j

stat(noprint) ract tau1 tau2
set ractbar k k = %mean

stat(noprint) rfor tau1 tau2
set rforbar k k = %mean

end do i

linreg(noprint) ractbar 1 k
#constant rforbar

comp a=%beta(1);comp as=%stderrs(1)
comp b=%beta(2);comp bs=%stderrs(2)
comp rsq=%rsquared

test(noprint)
# 1 2
# 0.0 1.0
comp fstat=%cdstat
set error2 1 k = (ractbar-rforbar)**2.0
stat(noprint) error2 1 k
comp mse=(%mean*k/(k-1))**0.5

disp tau1 tau2 mse 100*a 100*as b bs rsq fstat
end dofor tau2

Re: Dynamic EGARCH forecast

Posted: Thu Aug 22, 2013 9:16 am
by TomDoan
Please don't make multiple posts.

That's on the MAXIMIZE inside the (double) loop. Have you been able to get that to work properly outside the loop first?

Re: Dynamic EGARCH forecast

Posted: Thu Aug 22, 2013 9:28 am
by likykiki
TomDoan wrote:Please don't make multiple posts.

That's on the MAXIMIZE inside the (double) loop. Have you been able to get that to work properly outside the loop first?
Sorry about multiple posts, I just realized i should post this question in the the Help with Programming section, and i haven't delete this one.

about the question, I have run the code first,and it works well, Just the replication of your work of Baillie, Bollerslev and Mikkelson(1996), "Fractionally Integrated Generalized Autoregressive Conditional Heteroskedasticity"
Now i'm worrying about the loop, is it seems good? and what do you mean by "That's on the MAXIMIZE inside the (double) loop"? Do you mean that i put the MAXIMIZE in the wrong place?

Re: Dynamic EGARCH forecast

Posted: Thu Aug 22, 2013 9:44 pm
by TomDoan
The problem is that your LINREG, once you put it inside the loop, is forcing a data range which includes missing values (for the first few values of I). You are then using the %REGSTART() and %REGEND() off of that for the range on the MAXIMIZE. However, %REGSTART() and %REGEND() will be the start and end points of the range that you gave on the LINREG, and so will be wrong for the GARCH model.

What you had worked before you put it in the loop because you let the LINREG find its own range so the start and end were correct for the subsequent GARCH model.