forecast static method

({List<double> lower, List<double> point, List<double> upper}) forecast(
  1. List<double> history,
  2. SarimaFit fit,
  3. int h, {
  4. double z = 1.96,
})

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.arComb.length, d = fit.order.d, D = fit.order.D, s = fit.order.s;
  final yHist = differenceND(history, d, s, D);
  final y = List<double>.from(yHist);

  for (int step = 0; step < h; step++) {
    final t = y.length;
    double arPart = 0.0;
    for (int i = 1; i <= p; i++) {
      final idx = t - i;
      if (idx >= 0) arPart += fit.arComb[i - 1] * (y[idx] - fit.mu);
    }
    final yhat = fit.mu + arPart; // gelecekte MA=0
    y.add(yhat);
  }
  final difF = y.sublist(yHist.length);
  final point = invertND(history, difF, d, s, D);
  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);
}