2
I have the following process:yt=2+0.7yt-1+Et. I want to make pseudo predictions out of the sample, through rolling regressions and with mobile window containing 50 observations. The forecast should be performed using the true coefficients:y t+1=2+0.7yt and compare with the forecast for random walk, ie,y t+1=yt. If it was any AR (1) compared to an Andom walk, I can do it as follows:
set.seed(1)
T=100
e=rnorm(T)
rt(100,5) #Para gerar distribuição Student com 10 graus de liberdade
mu=2
phi=0.7
y=matrix(0,T,1)
y[1]=mu+e[1]
year_start=1
year_end=100
first_date=c(year_start)
final_date=c(year_end)
x=ts(e,start=first_date,frequency=1)
T=length(x)
R=round(T/2)
f=ts(0*1:(T-R-1),start=c(year_start+R+1),frequency=1)
frw=ts(0*1:(T-R-1),start=c(year_start+R+1),end=final_date,frequency=1)
Rolling Forecast:
ar=1
for (i in 1:length(f)) {
xt=window(x,start=c(year_start+i),end=c(year_start,R+i))
xt1=window(x,start=c(year_start+i-1),end=c(year_start,R+i-1))
for(p in 1:ar){xt1=cbind(xt1,lag(xt,-p))}
y=na.omit(xt1)
reg=lm(y[,1]~y[,2])
cond.x=rev(tail(xt,ar))
far1[i]=reg$coefficients%*%c(1,cond.x) frw[i]=tail(xt,1)
}
far1 #valores previstos pelo AR(1)
frw #valores previstos pelo RW
But I am not able to perform this procedure by incorporating true coefficients (mu=2 and Phi=0.7), using for example for (i in 2:R){y[i+1]=mu+phi*y[i]}
.
Is that the same question as that one? http://answall.com/questions/128074/pseudo-previs%C3%A3o-rolling
– Daniel Falbel
It seems so, but this one is more structured, with more information of my routine.
– Any