%% Compute Estimated Standard Errors
% Load the US equity index data set Data_EquityIdx.

load Data_EquityIdx

% The table DataTable includes the time series variable NYSE, which contains daily NYSE composite closing prices from January 1990 through December 1995.
% Convert the table to a timetable.

dt = datetime(dates,'ConvertFrom','datenum','Format','yyyy-MM-dd');
TT = table2timetable(DataTable,'RowTimes',dt);

% Suppose that an ARIMA(1,1,1) model is appropriate to model NYSE composite series during the sample period
% Fit an ARIMA(1,1,1) model to the data, and return the estimated parameter covariance matrix.

Mdl = arima(1,1,1);
[EstMdl,EstParamCov] = estimate(Mdl,TT{:,"NYSE"});
EstParamCov

% EstMdl is a fully specified, estimated arima model object. Rows and columns of EstParamCov correspond to the rows in the table of estimates and inferences; for example, \widehat{\rm Cov}\left(\hat \phi_1,\hat \theta_1\right) = -0.024.
% Compute estimated parameter standard errors by taking the square root of the diagonal elements of the covariance matrix.

estParamSE = sqrt(diag(EstParamCov))

% Compute a Wald-based 95% confidence interval on \phi.

T = size(TT,1); % Effective sample size
phihat = EstMdl.AR{1};
sephihat = estParamSE(2);
ciphi = phihat + tinv([0.025 0.975],T - 3)*sephihat

% The interval contains 0, which suggests that \phi is insignificant.
% Copyright 2020 The MathWorks, Inc.