Problem with a rolling regression

Use this forum to post questions about syntax problems or general programming issues. Questions on implementing a particular aspect of econometrics should go in "Econometrics Issues" below.
PeterF
Posts: 60
Joined: Thu Apr 12, 2012 2:03 pm

Problem with a rolling regression

Unread post by PeterF »

Dear Tom,

I have developed a model to forecast the price development of Bitcoins. I have four lagged independent variables without a constant in a linear regression. However, the residuals are autorcorrelated. A test with BJAUTOFIT procedure leads to the conclusion that the best results were obtained with an ARIMA(0,1,5) model. I estimated the model over the full range of daily data from January 1, 2020 until the recent Friday, June 13, 2025. The fit is rather high and combining the forecasts of the linear model and for its residuals is very good.

My problem begun when I wanted to test how the fit of the model forecast for t+5 is, if the model starts using the data form the first available day until June 30, 2022 and re-estimate the parameters with ever new day until the end of the data sample. I used the following code.

Code: Select all

clear yhat5
do regend=2022:07:01, ende
comp number= regend-2022:07:01+1
   linreg(noprint) BTC regstart regend btcresids
   # Var1{5} Var2{5} Var3{5} Var4{5}
   prj btc_est1 regstart+5 regend+5
disp number btc_est1(regend+5)

*   BoxJenk(noprint,AR=0,Diff=1,MA=||1,2,5||,define=btc_forec1,Maxl) btcresids regstart+5 regend
*   set resfit = %na
*   set resfit = btcresids-%resids
*   uforecast(equation=btc_forec1) resfit ende+1 ende+5
*   set btc_for1 regstart+11 regend+5 = btc_est1+resfit
*   set yhat5 regend regend = btc_For1(regend+5)

end do
If I run that code for the linear regression part only, it works well. However, if I un-comment the line with the BoxJenk instruction the programm executes only a few loops and then gets caught in an infinte loop. I can close Rats only via the windows task-manager. What did I made wrong with that code?

Thank you very much for help in advance.

Best regards
PeterF
TomDoan
Posts: 7728
Joined: Wed Nov 01, 2006 4:36 pm

Re: Problem with a rolling regression

Unread post by TomDoan »

It seems to work fine when I do it with random data. I would need to see the more complete program to see if there is something about how you are setting the loop control values. If you are having problems with an apparent infinite loop, you probably can only debug it by taking the NOPRINT off the BOXJENK.

Is BTC something like the log of the price? What are the VAR variables? If you are getting I(1) residuals, are you thinking that BTC should be cointegrated with them? If so, you wouldn't see the I(1) residuals.
PeterF
Posts: 60
Joined: Thu Apr 12, 2012 2:03 pm

Re: Problem with a rolling regression

Unread post by PeterF »

Dear Tom,

thank you for your answser. The problem was the data, which i found out inbetween. As I used the prices of bitcoins as independent variable and other financial time series as explanatory variables, the data had missing values on exchange holidays. After i adjusted the data by the previous close on market holidays, the BoxJenk instruction worked also well inside the loop.

Best regards
PeterF
Post Reply