www.gusucode.com > econ 案例源码程序 matlab代码 > econ/ForecastObservationsFromAGjrModelObjectExample.m
%% Forecast GJR Model Conditional Variances % Forecast conditional variances from a fully specified |gjr| % model object. That is, forecast from an estimated |gjr| model % or a known |gjr| model in which you specify all parameter values. This % example follows from <docid:econ_ug.bupeold-1>. %% % Load the Nelson-Plosser data set. Convert the yearly stock price indices % (|SP|) to returns. % Copyright 2015 The MathWorks, Inc. load Data_NelsonPlosser; sp = price2ret(DataTable.SP); %% % Create a GJR(1,1) model and fit it to the return series. Mdl = gjr('GARCHLags',1,'ARCHLags',1,'LeverageLags',1); EstMdl = estimate(Mdl,sp); %% % Forecast the conditional variance of the nominal return series 10 years % into the future using the estimated GJR model. Specify the entire % return series as presample observations. The software infers presample % conditional variances using the presample observations and the model. numPeriods = 10; vF = forecast(EstMdl,numPeriods,'Y0',sp); %% % Plot the forecasted conditional variances of the nominal returns. Compare % the forecasts to the observed conditional variances. v = infer(EstMdl,sp); nV = size(v,1); dates = dates((end - nV + 1):end); figure; plot(dates,v,'k:','LineWidth',2); hold on; plot(dates(end):dates(end) + 10,[v(end);vF],'r','LineWidth',2); title('Forecasted Conditional Variances of Returns'); ylabel('Conditional variances'); xlabel('Year'); axis tight; legend({'Estimation Sample Cond. Var.','Forecasted Cond. var.'},... 'Location','NorthWest');