Hi
I'm new to Stata and coding in general.
I have tried making a code to generate an out of sample test of GARCH.
The idea is to investigate the forecasting abilities of various GARCH-models, and compare them against the realised volatility. More precisely i'm trying to compare the forecasts of volatility.
I will estimate the model through an in-sample period of about 10 years, and then do a rolling window forecast of the out-of-sample. (adding one and deleting one in the end -first in last out) So the period stays the same but with more and more out-of-sample forecasts included.
I'm trying to end up with a list of forecasted variance or standard deviations that I can compare to the realised volatility. One for each forecasted step forward. The shocks to the economy are known, as the out-of-sample period is in the past.
The return is given by the S&P500 index.
Looking elsewhere I know I need to start with defining the time in locals, so I can simply move them forward when I re-estimate the model, but I can't seem to get this to work. I simply can't seem to get around it. My return is given by the variable name returnSP500
Below is the code with the locals. The code is of course longer than that. But getting past the first four lines is already a problem.
Thank you
I'm new to Stata and coding in general.
I have tried making a code to generate an out of sample test of GARCH.
The idea is to investigate the forecasting abilities of various GARCH-models, and compare them against the realised volatility. More precisely i'm trying to compare the forecasts of volatility.
I will estimate the model through an in-sample period of about 10 years, and then do a rolling window forecast of the out-of-sample. (adding one and deleting one in the end -first in last out) So the period stays the same but with more and more out-of-sample forecasts included.
I'm trying to end up with a list of forecasted variance or standard deviations that I can compare to the realised volatility. One for each forecasted step forward. The shocks to the economy are known, as the out-of-sample period is in the past.
The return is given by the S&P500 index.
Looking elsewhere I know I need to start with defining the time in locals, so I can simply move them forward when I re-estimate the model, but I can't seem to get this to work. I simply can't seem to get around it. My return is given by the variable name returnSP500
Below is the code with the locals. The code is of course longer than that. But getting past the first four lines is already a problem.
Code:
// I want to be able to the sample one or five periods at a time. I thought I needed some macros to help me// //define where to stop the in-sample and start the out of sample from.// local start = 1 month_id //I want to start my first in-sample when i'm in the first period of my dataset// local frequency = 5 //This should be how often the parameters are re-estimated in the out-of sample. I'm not sure I need it, and thinking about setting it to 1.// local end if month_id==2005m1 //End of in-sample period// //I Should do a loop, as I want Stata to give me the out-of-sample conditional variance with re-estimated parameters// foreach var of varlist returnSP500 { /* Start log */ log using “`output’GARCH_predict_returnSP500.log”, replace //Estimating the in-sample parameters.// arch returnSP500 in `start'/`end', arch(1/1) garch(1/1) //and getting the conditional variances and mean// predict v_returnSP500, variance predict r_returnSP500, xb //Generating the parameters// gen arch_returnSP500 = [ARCH]_b[L.arch] gen garch_returnSP500 = [ARCH]_b[L.garch] gen cons_returnSP500 = [ARCH]_b[_cons] gen capture_returnSP500 = 0 //moving one period forward// local time_r_returnSP500 = `start’ + `frequency’ //as long as I'm still in real time// while `time_r_returnSP500’ < 2018m1
Comment