forecast.m (993B)
1 % forecast.m [yLR misbehaved]=forecast(y,P,wellbehaved); 2 % 3 % Creates univariate forecasts of the LR level of a stationary variable 4 % by estimating an AR(P) model. 5 % 6 % wellbehaved is an optional parameter. If it is nonzero, then the forecast 7 % is compared to min(y) and max(y) to be sure it lies in this range. If 8 % not, then the average of the last wellbehaved values of the series is 9 % returned. 10 11 function [yLR,misbehaved]=forecast(y,P,wellbehaved); 12 13 N=size(y,2); 14 yLR=zeros(N,1)*NaN; 15 misbehaved=zeros(N,1); 16 17 for i=1:N; 18 19 [yi yilag]=lagx(y(:,i),P); 20 T=size(yi,1); 21 if ~any(isnan(yi)); 22 b=lstiny(yi,[ones(T,1) yilag]); 23 yLR(i)=b(1)/(1-sum(b(2:P+1))); 24 25 if exist('wellbehaved'); 26 if (yLR(i)<min(yi)) | (yLR(i)>max(yi)); 27 mrange=(T-wellbehaved+1):T; 28 yLR(i)=mean(yi(mrange)); 29 misbehaved(i)=1; 30 end; 31 if isnan(yLR(i)); 32 mrange=(T-wellbehaved+1):T; 33 yLR(i)=mean(yi(mrange)); 34 misbehaved(i)=1; 35 end; 36 end; 37 end; % any isnan 38 39 end; 40