Application of the Trench Algorithm to Forecasting

Initialize

<< FGN.m

<< FitARMA.m

<< Statistics`

AR Simulation Test Error Conditions

n = 100; Muz = 0. ; n1 = 90;
r = TacvfARMA[phi, theta, n];
phi = {0.8};
theta = {};
z = SimulateGaussianARMA[phi, theta, n];
z1 = Take[z, n1];
r1 = Rest[r];

ans = TrenchForecast[z, r1, 0.0, n1, 1];

ans = TrenchForecast[z, r1, 0.0, n + 1, 1];

ans = TrenchForecast[z, r1, 0.0, 0, 1];

AR Simulation Example  - Fast One

n = 100; Muz = 0. ; n1 = 90;
r = TacvfARMA[phi, theta, n];
phi = {0.8};
theta = {};
z = SimulateGaussianARMA[phi, theta, n];
z1 = Take[z, n1];

ans = TrenchForecast[z, r, 0.0, n1, 1];

{zF, vF} = ans; znew = Drop[z, n1];

{Mean[errMMSE = (((znew - Most[zF]))^2)], 
      Mean[errM = (((znew - Mean[z1]))^2)], 
      MeanDifferenceCI[errMMSE, errM]}

Short[vF, 3]

AR Simulation Example

n = 100; Muz = 0. ; n1 = 80;
r = TacvfARMA[phi, theta, n];
phi = {0.8};
theta = {};
z = SimulateGaussianARMA[phi, theta, n];
z1 = Take[z, n1];

ans = TrenchForecast[z, r, 0.0, n1, 1];

{zF, vF} = ans; znew = Drop[z, n1];

{Mean[errMMSE = (((znew - Most[zF]))^2)], 
      Mean[errM = (((znew - Mean[z1]))^2)], 
      MeanDifferenceCI[errMMSE, errM]}

Short[vF, 3]

ARMA Simulation Example

n = 400; Muz = 0. ; n1 = 200;
r = TacvfARMA[phi, theta, n];
phi = {1.2399401603634308, -0.2653412932838738};
theta = {0.8436410920940121};
z = SimulateGaussianARMA[phi, theta, n];
z1 = Take[z, n1];

ans = TrenchForecast[z, r, 0.0, n1, 1];

{zF, vF} = ans; znew = Drop[z, n1];

{Mean[errMMSE = (((znew - Most[zF]))^2)], 
      Mean[errM = (((znew - Mean[z1]))^2)], 
      MeanDifferenceCI[errMMSE, errM]}

Short[vF, 3]

FGN Simulation Example

m = 200; n1 = 200; n = n1 + m; H = 0.8; 
    Muz = 0. ;
r = Table[FGNAcf[k, H], {k, 0, n - 1}];
z = SimulateFGN[H, n];
z1 = Take[z, n1];

ans = TrenchForecast[z, r, 0.0, n1, 1];

{zF, vF} = ans; znew = Drop[z, n1];

{Mean[errMMSE = (((znew - Most[zF]))^2)], 
      Mean[errM = (((znew - Mean[z1]))^2)], 
      MeanDifferenceCI[errMMSE, errM]}

Short[vF, 3]

Application to Nile Minimums

Percival & Walden comment in Sec 5.7 (p. 190), "Toussoun's record extends up to 1921.  It is complete for 622-1284.  For 1285-1470 there are scattered missing values."  We linearly interpolated to complete the record.

Initialize

z = ReadData["d:/math/2006/Trench/data/Minimum.1"];

n1 = 1284 - 622 + 1;
n = Length[z];
m = n - n1;
z1 = Take[z, n1]; znew = Drop[z, n1];

FGN Case

ans = FitFGN[z1, MeanMLEQ -> True]

Hz = HurstCoefficient /. Last[ans];
Muz = MuHat /. Last[ans];
r = Table[FGNAcf[i - 1, Hz], {i, n + 1}];

ans = TrenchForecast[z, r, Muz, n1, 1];

{zF, vF} = ans;

{Mean[errMMSE = (E1 = (((znew - Most[zF]))^2))], 
      Mean[errM = (((znew - Mean[z]))^2)], 
      MeanCI[errMMSE - errM]}

Save["d:/math/2006/Trench/code/E1.m", {E1}]

{E1[[73]], 
      zF[[73]], 
      znew[[73]], 
      znew[[73]] - 
        zF[[73]], (znew[[73]] - 
            zF[[73]])^2}

ans73 = 
      TrenchForecast[Take[z, n1 + 72], Take[r, n1 + 72 + 1], Muz, n1 + 72, 
        1]

Mean[znew]

Max[znew]

Max[Take[z, n1]]

ARMA Forecast

ans = FitARMA[z, {2, 0, 1}];
CoefARMA[ans]

phi = Take[ARMACoefficients /. ans, 2];
theta = Drop[ARMACoefficients /. ans, 2];
Muz = MeanValue /. ans;
r = TacvfARMA[phi, theta, n];

ans = TrenchForecast[z, r, Muz, n1, 1];

{zF, vF} = ans;

{Mean[errMMSE = (((E2 = (znew - Most[zF])))^2)], 
      Mean[errM = (((znew - Mean[z]))^2)], 
      MeanCI[errMMSE - errM]}

Save["d:/math/2006/Trench/code/E2.m", {E2}]

<< d:/math/2006/Trench/code/E1.m;

MeanCI[Abs[E2] - Abs[E1]]

MeanCI[(E1^2)  -  (E2^2)]

<< d:/math/2006/Trench/code/E2.m;

<< Graphics`

d = (E1^2)  -  (E2^2);
Histogram[d];

Median[d]

<< Statistics`

BoxWhiskerPlot[d];

Time Series Plots

<< d:/math/2006/Trench/code/E2.m;

<< d:/math/2006/Trench/code/E1.m;

TimeSeriesPlot[E1];

TimeSeriesPlot[E2];

Take[
      Sort[{Range[Length[E2]], E2} // Transpose, 
        Abs[#1[[2]]] > 
            Abs[#2[[2]]] &], 
      5]

Take[
      Sort[{Range[Length[E1]], E1} // Transpose, 
        Abs[#1[[2]]] > 
            Abs[#2[[2]]] &], 
      5]