I wonder if I could ask for your kind help to double check whether the code below is ok. I need to forecast the rolling out of sample mean and variance of a number of series and its really crucial that I get the 'time subscripts' right. The model is a relatively simple ARMA+GARCH. My big worry is that I might inadvertently put, say, the predicted variance for period t+1 into period t, or something like that. Many thanks in advance for your help (as well as for all the help offered in the past!).
Best regards,
Valerio
Code: Select all
*
*******************************************************************
************** dep is the dependent variable ********************
*******************************************************************
*
source bjautofit2.src
source garchfore.src
dec vec[series] means(nr) vars(nr) sr(nr)
com window = 60
infobox(action=define,progress,lower=1,upper=nr)
do i=1,nr
{
clear dep mean var
set dep = y(i)
inquire(series=dep) start end
do time = start+window,end-1
{
@bjautofit2(diffs=0,noprint,constant,pmax=5,qmax=5,crit=aic) dep time-window time
com ar = %%autop, ma = %%autoq
equation armagarch dep ar ma
garch(p=1,q=1,print,model=armagarch,hseries=ht,resids=at,PMETHOD=SIMPLEX,PITERS=20) time-window+fix(%max(ar,ma)) time dep
if %converged==1
{
@garchfore(steps=1) ht at
uforecast(equation=armagarch,steps=1) m
com mean(time+1) = m(time+1)
com var(time+1) = ht(time+1)
}
else
{
com mean(time+1) = %na
com var(time+1) = %na
}
}
end do time
set means(i) start+window end = mean
set vars(i) start+window end = var
set sr(i) start+window end = means(i)/sqrt(vars(i))
infobox(current=i)
dis 'Portfolio nr: ' i
}
end do i
infobox(action=remove)
*