Garch meanForecast in loop?

1 view (last 30 days)
Patrick
Patrick on 3 Jun 2011
Hey,
I want to do a Garchforecast for the past. I make a loop to calculate the forecast for each period from the past. Let's assume that "r" is a double array 20x1.
For some reason, I still get only one meanForecast. Thanks in advance,
Patrick
k = [];
i=20;
for i=1:i
k = [i,1];
i=i+1;
[coeff,errors,LLF,eFit,sFit] = garchfit(spec,r);
horizon = 1;
[sigmaForecast,meanForecast,sigmaTotal,meanRMSE] = ...
garchpred(coeff,r(1:i+1,1),horizon);
end

Answers (1)

Oleg Komarov
Oleg Komarov on 3 Jun 2011
  • You're overwtiting everytime the variables
  • ??for i:1:i?? DO NOT increase the looping index i inside the loop
  • DO NOT use i,j since they are matlab built ins
  • Preallocate before the loop for speed
coeff(k,n)
for ii = 1:n
[coeff(:,ii),errorr(:,ii),...]
end

Categories

Find more on Conditional Variance Models in Help Center and File Exchange

Tags

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!