Fully automated ARIMA code. Does the following:
1) Checks for stationarity and if nonstationary, makes the difference adjustments for Ith order accordingly.
2) Checks for White Noise on the stationary series using Ljung Box
3) If not a White Noise, AR-MA combination is run and the one with the best Bayesian Information Criterion is selected.
With a slight tweak in garchfit code, explanatory variables can be included as well.
Sections to customize:
%Loading Data%
%Inputs%
Requires 'Econometrics Toolbox'
tic
%Loading Data%
load Nifty.mat;
%Inputs%
Input = Close;
WNLagPeriod = 10; %White Noise Lag Period%
MaxI = 5; %Maximum integrand period%
MaxAR = 5; %Maximum AR lookback%
MaxMA = 5; %Maximum MA lookback%
%Checking for I(n) process%
VarianceMatrix = zeros(MaxI,1);
for I = 1: MaxI
VarianceMatrix(I,1) = var(diff(Input,I));
end
%Start Iterations%
if LBTestH == 0
disp(['The process is white noise at I = ', num2str(I)]);
else
%Selecting AR & MA Process based on AIC%
Z = zeros(MaxAR + 1,MaxMA+1);
for MA = 0: MaxMA
for AR = 0: MaxAR
i = AR + 1;
j = MA + 1;
spec = garchset('R', AR, 'M', MA, 'P', 0, 'Q', 0);
[Coeff,~,LLF,~,~,~] = garchfit(spec,StationaryInput);
Parameters = garchcount(Coeff);
[~,BIC] = aicbic(LLF,Parameters,row1);
Z(i,j) = BIC;
end
end