forecast static method
h-step ahead forecast (%95 band: assuming iid errors, rough approximation)
Implementation
static ({List<double> point, List<double> lower, List<double> upper})
forecast(List<double> history, SarimaFit fit, int h, {double z=1.96}) {
final p=fit.order.p, P=fit.order.P, d=fit.order.d, D=fit.order.D, s=fit.order.s;
// Bring the history into the differenced space
final yHist = differenceND(history, d, s, D);
final y = List<double>.from(yHist);
// For forecasting we assume future innovations e=0; we do not track them here.
for (int step=0; step<h; step++) {
final t = y.length;
double arPart=0.0, sarPart=0.0;
for (int i=1;i<=p;i++){
final idx=t-i; if (idx>=0) arPart += fit.ar[i-1] * (y[idx]-fit.mu);
}
for (int I=1; I<=P; I++){
final idx=t - I*s; if (idx>=0) sarPart += fit.sar[I-1] * (y[idx]-fit.mu);
}
// MA/sMA gelecekte bilinmediği için 0 kabul edilir (yaygın pratik)
final yhat = fit.mu + arPart + sarPart;
y.add(yhat);
}
final difF = y.sublist(yHist.length); // forecasts in differenced space
final point = invertND(history, difF, d, s, D); // invert back to level
// Band ~ sqrt(sigma2 * i)
final lower = <double>[], upper = <double>[];
for (int i=1;i<=h;i++){
final band = math.sqrt(fit.sigma2 * i);
lower.add(point[i-1] - z*band);
upper.add(point[i-1] + z*band);
}
return (point: point, lower: lower, upper: upper);
}