%% Estimate GJR Model
% Fit a GJR model to an annual time series of stock price index returns from 1861-1970.
% Load the Nelson-Plosser data set. Convert the yearly stock price indices (SP) to returns. Plot the returns.

load Data_NelsonPlosser;
sp = price2ret(DataTable.SP);

figure;
plot(dates(2:end),sp);
hold on;
plot([dates(2) dates(end)],[0 0],'r:'); % Plot y = 0
hold off;
title('Returns');
ylabel('Return (%)');
xlabel('Year');
axis tight;

% The return series does not seem to have a conditional mean offset, and seems to exhibit volatility clustering. That is, the variability is smaller for earlier years than it is for later years. For this example, assume that an GJR(1,1) model is appropriate for this series.
%
% Create a GJR(1,1) model. The conditional mean offset is zero by default. The software includes a conditional variance model constant by default.

Mdl = gjr('GARCHLags',1,'ARCHLags',1,'LeverageLags',1);

%
% Fit the GJR(1,1) model to the data.

EstMdl = estimate(Mdl,sp);

% EstMdl is a fully specified gjr model object. That is, it does not contain NaN values. You can assess the adequacy of the model by generating residuals using infer, and then analyzing them.
% To simulate conditional variances or responses, pass EstMdl to simulate.
% To forecast innovations, pass EstMdl to forecast.
% Copyright 2015 The MathWorks, Inc.