Forecast using recursive (expanding) estimation window
Moderators: EViews Gareth, EViews Moderator, EViews Jason, EViews Matt
Forecast using recursive (expanding) estimation window
Hi,
I have understand how to estimate an ols regression using a rolling window and take the forecasts. I was wondering what changes should I do in order to estimate the model using and expanding window; I guess some changes inside the loop are needed.
Can anyone help me?
Thanks in advance.
Apostolos
I have understand how to estimate an ols regression using a rolling window and take the forecasts. I was wondering what changes should I do in order to estimate the model using and expanding window; I guess some changes inside the loop are needed.
Can anyone help me?
Thanks in advance.
Apostolos
- Attachments
-
- rolling window, 1-step ahead forecast.prg
- (1.7 KiB) Downloaded 1596 times
-
EViews Gareth
- Fe ddaethom, fe welon, fe amcangyfrifon
- Posts: 13604
- Joined: Tue Sep 16, 2008 5:38 pm
Re: Forecast using recursive (expanding) estimation window
You probably need to change the smpl part of the loop, but without knowing exactly what you're trying to do, it is hard to say.
Re: Forecast using recursive (expanding) estimation window
Hi EViews Gareth,
Thank you very much for your reply. Let me explain what i want to do.
I regress by ols stock return on dividend yields. The in-sample period is from 1973:03 to 1984:12 and the out-of-sample from 1985:01 to 2012:01.
So, the basic idea is:
1st step: estimate the model in-sample uisng data from 1973:03 to 1984:12 and then forecast 1985:01
2nd step: estimate the model in-sample uisng data from 1973:03 to 1985:01 and then forecast 1985:02
3rd step: estimate the model in-sample uisng data from 1973:03 to 1985:02 and then forecast 1985:03
and so on and so forth until the last step
last step: estimate the model in-sample uisng data from 1973:03 to 2011:12 and then forecast 2012:01
I hope now is mode clear.
Thank you very much for your reply. Let me explain what i want to do.
I regress by ols stock return on dividend yields. The in-sample period is from 1973:03 to 1984:12 and the out-of-sample from 1985:01 to 2012:01.
So, the basic idea is:
1st step: estimate the model in-sample uisng data from 1973:03 to 1984:12 and then forecast 1985:01
2nd step: estimate the model in-sample uisng data from 1973:03 to 1985:01 and then forecast 1985:02
3rd step: estimate the model in-sample uisng data from 1973:03 to 1985:02 and then forecast 1985:03
and so on and so forth until the last step
last step: estimate the model in-sample uisng data from 1973:03 to 2011:12 and then forecast 2012:01
I hope now is mode clear.
-
EViews Gareth
- Fe ddaethom, fe welon, fe amcangyfrifon
- Posts: 13604
- Joined: Tue Sep 16, 2008 5:38 pm
Re: Forecast using recursive (expanding) estimation window
So it sounds as though you only need to change the second part of the sample statement (i.e. the last date) instead of both parts, and keep the starting date fixed.
Re: Forecast using recursive (expanding) estimation window
Thanks for your reply.
Are you talking about this part:?
set sample for estimation period
%first=@otod(@dtoo(%start)+!i-1)
%last=@otod(@dtoo(%start)+!i+window-2)
sample{%first}{%last}
Yes, but I think it should be the opposite. I need to keep the starting date (%first) fixed and increase at every step the last date (%last).
I estimate the model in-sample from the 1st-142nd observation and then forecast the 143.
Then, estimate from the 1st-143rd and forecast 144 and so on and so forth.
The first part has to be fixed at the begining of my sample and the second part will always increase by one.
Is that correct? What do you think?
Are you talking about this part:?
set sample for estimation period
%first=@otod(@dtoo(%start)+!i-1)
%last=@otod(@dtoo(%start)+!i+window-2)
sample{%first}{%last}
Yes, but I think it should be the opposite. I need to keep the starting date (%first) fixed and increase at every step the last date (%last).
I estimate the model in-sample from the 1st-142nd observation and then forecast the 143.
Then, estimate from the 1st-143rd and forecast 144 and so on and so forth.
The first part has to be fixed at the begining of my sample and the second part will always increase by one.
Is that correct? What do you think?
-
EViews Gareth
- Fe ddaethom, fe welon, fe amcangyfrifon
- Posts: 13604
- Joined: Tue Sep 16, 2008 5:38 pm
Re: Forecast using recursive (expanding) estimation window
Isn't that what I said?
Re: Forecast using recursive (expanding) estimation window
Dear All,
First of all, I'd like congratulate you all for the terrific job you've been doing. It's quite amazing how much information we can get here.
So, moving to my problem here we go:
I'm also trying to obtain forecasts from a VAR, using "recursive (expanding) estimation window". After cheking a lot of tips here in the forum here is what I've done so far:
With this code I managed to produce the estimates I want. However, I'd also like to automatize the compilation of the forecasts that I've produced.
I mean, I'd like to generete a series with the last forecasted value of each model. For example, in the first loop I generate the serie y_0_1 with the forecast until the 64th period, I'd like to keep record of it in a different serie (let's call it y_hat_12), then do the same with forecest of 65th period of the serie y_0_1...
So in the end, I'd have a series of the rolling var forecast for 12 periods ahead of the series y, and I'd be able to compare it with the real data. Is there any possible way to do that?
Thanks so much in advance.
Best regards,
dmilanc
First of all, I'd like congratulate you all for the terrific job you've been doing. It's quite amazing how much information we can get here.
So, moving to my problem here we go:
I'm also trying to obtain forecasts from a VAR, using "recursive (expanding) estimation window". After cheking a lot of tips here in the forum here is what I've done so far:
Code: Select all
'create some data
create u 300
series y=nrnd
series x1=nrnd
series x2=nrnd
series x3=nrnd
series z=nrnd
'define loop
for !i=1 to 300
smpl @first @first+50+!i
var var1.ls 1 2 y x1 x2 x3 @ z
' Dynamic Forecast VAR
var1.makemodel(mod1)
smpl @first @first+50+!i+12
mod1.solve(d=d) 'dinamic
series y_0_{!i} = y_0
next
smpl @all
I mean, I'd like to generete a series with the last forecasted value of each model. For example, in the first loop I generate the serie y_0_1 with the forecast until the 64th period, I'd like to keep record of it in a different serie (let's call it y_hat_12), then do the same with forecest of 65th period of the serie y_0_1...
So in the end, I'd have a series of the rolling var forecast for 12 periods ahead of the series y, and I'd be able to compare it with the real data. Is there any possible way to do that?
Thanks so much in advance.
Best regards,
dmilanc
-
EViews Gareth
- Fe ddaethom, fe welon, fe amcangyfrifon
- Posts: 13604
- Joined: Tue Sep 16, 2008 5:38 pm
Re: Forecast using recursive (expanding) estimation window
I'm not sure I fully understand, but don't you just want to change this line:
to be:
Code: Select all
series y_0_{!i} = y_0
Code: Select all
series y_hat_12 = y_0
Re: Forecast using recursive (expanding) estimation window
Thanks for your prompt response Gareth. But, that's not exactly what I want to do. Let me try to explain it better:
What I do want is to keep record of the last forecast generated in each loop.
Example:
First loop: forecast from var generate series y_0_1 with forecast until the 64th period for y. Then y_hat_12 would keep record of the 64th value of y_0_1 as its first value.
Second loop: forecast from var generate series y_0_2 with forecast until the 65th period for y. Then y_hat_12 would keep record of the 65th value of y_0_2 as its second value.
Third loop: forecast from var generate series y_0_3 with forecast until the 66th period for y. Then y_hat_12 would keep record of the 66th value of y_0_3 as its third value.
And so goes on...
Is it better now?
tks once again.
Regards,
dmilanc
What I do want is to keep record of the last forecast generated in each loop.
Example:
First loop: forecast from var generate series y_0_1 with forecast until the 64th period for y. Then y_hat_12 would keep record of the 64th value of y_0_1 as its first value.
Second loop: forecast from var generate series y_0_2 with forecast until the 65th period for y. Then y_hat_12 would keep record of the 65th value of y_0_2 as its second value.
Third loop: forecast from var generate series y_0_3 with forecast until the 66th period for y. Then y_hat_12 would keep record of the 66th value of y_0_3 as its third value.
And so goes on...
Is it better now?
tks once again.
Regards,
dmilanc
-
EViews Gareth
- Fe ddaethom, fe welon, fe amcangyfrifon
- Posts: 13604
- Joined: Tue Sep 16, 2008 5:38 pm
Re: Forecast using recursive (expanding) estimation window
The code I posted does that.
Re: Forecast using recursive (expanding) estimation window
Hi Gareth,
I'm sorry but it doesn't. Cause in the end y_hat_12 will be exactly the same as the last y_0, or to put it equivalently to my code, it would y_hat_12 would be equal to y_0_300... But, what I'd really like is to get, at the end of all loops, a series (y_hat_12 ) that would look like this:
y_hat_12:
1- 64th value of y_0_1
2- 65th value of y_0_2
3- 66th value of y_0_3
4- 67th value of y_0_4
5- 68th value of y_0_5
(...)
Do you see the difference now?
Tks,
Best
dmilanc
I'm sorry but it doesn't. Cause in the end y_hat_12 will be exactly the same as the last y_0, or to put it equivalently to my code, it would y_hat_12 would be equal to y_0_300... But, what I'd really like is to get, at the end of all loops, a series (y_hat_12 ) that would look like this:
y_hat_12:
1- 64th value of y_0_1
2- 65th value of y_0_2
3- 66th value of y_0_3
4- 67th value of y_0_4
5- 68th value of y_0_5
(...)
Do you see the difference now?
Tks,
Best
dmilanc
-
EViews Gareth
- Fe ddaethom, fe welon, fe amcangyfrifon
- Posts: 13604
- Joined: Tue Sep 16, 2008 5:38 pm
Re: Forecast using recursive (expanding) estimation window
My bad, I hadn't notice you were doing a fixed starting point window.Hi Gareth,
I'm sorry but it doesn't. Cause in the end y_hat_12 will be exactly the same as the last y_0,
Try this:
Code: Select all
smpl @first @first+50+!i+12
mod1.solve(d=d) 'dinamic
smpl @first+50+!i+12 @first+50+!i+12
series y_hat_12 = y_0
Re: Forecast using recursive (expanding) estimation window
Hi Gareth,
I guess we are getting close to make it work. Thank you, for all your help.
However, after changing the code, as suggested by you, I got the following Error message:
Error in sample: attempt to set sample outside of workfile range.
Structure/Resize (from\WORKFILE\PROC menu) can expand the workfile range in "SMPL @FIRST+50+238+12 @FIRST+50+238+12".
What am I doing wrong?
Best,
Dmilanc
I guess we are getting close to make it work. Thank you, for all your help.
However, after changing the code, as suggested by you, I got the following Error message:
Error in sample: attempt to set sample outside of workfile range.
Structure/Resize (from\WORKFILE\PROC menu) can expand the workfile range in "SMPL @FIRST+50+238+12 @FIRST+50+238+12".
What am I doing wrong?
Best,
Dmilanc
-
EViews Gareth
- Fe ddaethom, fe welon, fe amcangyfrifon
- Posts: 13604
- Joined: Tue Sep 16, 2008 5:38 pm
Re: Forecast using recursive (expanding) estimation window
You only have 300 observations, yet you are running the loop from 1 to 300, and setting the sample to be the i+63th observation. As soon as the loop runs higher than 237 that will cause a problem since 238+63 doesn't exist in the workfile. Either increase your observations or decrease the loop size.
Re: Forecast using recursive (expanding) estimation window
Thanks Gareth. I guess I see what your point is... The problem is that y_hat_12 cant have a sample bigger than 300, right?
I'll try to figure something out here.
Thanks again.
Best,
Dmilanc
I'll try to figure something out here.
Thanks again.
Best,
Dmilanc
Who is online
Users browsing this forum: No registered users and 2 guests
