Application of the Trench Algorithm to Forecasting: Final Testing

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];

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

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

AR Simulation Example - n=n1=100

n = 100; Muz = 0. ; n1 = 100;
phi = {0.8};
theta = {};
sig = 5. ;
r = TacvfARMA[phi, theta, n]*(sig^2);
z = 
        SimulateGaussianARMA[phi, theta, n]*sig;
z1 = Take[z, n1];

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

AR Simulation Example - Fast

n = 100; Muz = 0. ; n1 = 90;
phi = {0.8};
theta = {};
sig = 8.0;
r = TacvfARMA[phi, theta, n]*(sig^2);
z = 
        SimulateGaussianARMA[phi, theta, n]*sig;
z1 = Take[z, n1];

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

ans

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

{Mean[errMMSE = (((znew - Most[zF // Flatten]))^2)], 
      MeanCI[errMMSE]}

Short[vF // Flatten, 3]

ARMA Simulation Example

n = 100; Muz = 0. ; n1 = 80;
phi = {0.8};
theta = {0.4};
sig = 9. ;
r = TacvfARMA[phi, theta, n]*(sig^2);
z = SimulateGaussianARMA[phi, theta, n]*sig;

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

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

{Mean[errMMSE = (((znew - Most[zF // Flatten]))^2)], 
      MeanCI[errMMSE]}

Short[vF // Flatten, 3]

ARMA Simulation Example

n = 400; Muz = 0. ; n1 = 200;
phi = {1.2399401603634308, -0.2653412932838738};
theta = {0.8436410920940121};
sig = 100.0;
r = TacvfARMA[phi, theta, n]*(sig^2);
z = SimulateGaussianARMA[phi, theta, n]*sig;

Testing computation from first principles

G = toe[Take[r, n1]];
GI = Inverse[G];
gk = Take[Drop[r, 1], n1];
r[[1]] - gk . GI . gk

G = toe[Take[r, n1]];
GI = TrenchInverse[G];
gk = Take[Drop[r, 1], n1];
r[[1]] - gk . GI . gk

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

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

{Mean[errMMSE = (((znew - Most[zF // Flatten]))^2)], 
      MeanCI[errMMSE]}

Short[vF // Flatten, 3]

FGN Simulation Example

m = 200; n1 = 200; n = n1 + m; H = 0.8; Muz = 0. ; 
    sig = 9. ;
r = Table[FGNAcf[k, H], {k, 0, n}]*(sig^2);
z = SimulateFGN[H, n];
z1 = Take[z, n1];

Variance[z]

Variance[SimulateFGN[H, (2^15)]]

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

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

{Mean[errMMSE = (((znew - Most[zF // Flatten]))^2)], 
      MeanCI[errMMSE]}

Short[vF // Flatten, 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

ansFit = FitFGN[z1, MeanMLEQ -> True]

Hz = HurstCoefficient /. Last[ansFit];
Muz = MuHat /. Last[ansFit];
r = 
        Table[FGNAcf[i - 1, Hz], {i, n + 1}]*
          Variance[Take[z, n1]];

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

{zF, vF} = ans;

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

Short[vF // Flatten, 5]

Short[zF // Flatten, 5]

zFFGN = zF;

Save Data

DeleteFile["d:/math/2006/Trench/data/FGNNile.m"]

Save["d:/math/2006/Trench/data/FGNNile.m", {zFFGN}]

ARMA Forecast

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

\(\(\(\(phi = Take[ARMACoefficients /. ans, 2];\)

    \(theta = Drop[ARMACoefficients /. ans, 2];\)

    \(Muz = MeanValue /. ans;\)

    \(sig = \ ResidualSd /. ans;\)

    \(\(r = TacvfARMA[phi, theta, n]*sig\^2\) \); \)\(\ \)\( (*VNB : \ 
        must\ be\ \(autocovariances!\)*) \)\)\)

TrenchForecast[z, r, Muz, n]

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

{zF, vF} = ans;

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

Naturally the out-of-sample mse is larger than the residual mse.

Short[z]

Short[zF]

Short[vF]

Computation from first principles.  This agrees with the residual sd.

G = toe[Take[r, n1]];
GI = Inverse[G];
gk = Take[Drop[r, 1], n1];
r[[1]] - gk . GI . gk // 
      Sqrt