%% Test for Structural Break in Volatility
% Conduct cusum of squares tests to assess whether there are structural changes in volatility in the equation for food demand around World War II. Implement forward and backward recursive regressions to obtain recursive residuals for the test statistics. This example follows from Test Consumption Model for Structural Change.
% Load and process the U.S. food consumption data set.

load Data_Consumption

LP = log(Data(:,1)); % Food price index
LI = log(Data(:,2)); % Disposable income index
LQ = log(Data(:,3)); % Food consumption index

%
% Conduct forward and backward cusum of squares tests using a 5% level of significance for each test. Plot the cusum of squares and critical region bands. Request to return:
% The two test decisions
% Whether the recursive residual crosses the critical region at each recursive regression iteration.

[h,H] = cusumtest([LP,LI],LQ,'Test','cusumsq','Plot','on',...
    'Direction',{'forward','backward'},'Display','off')

% h(1) = 0 indicates that the forward cusum of squares test does not reject the null hypothesis of constant volatility at 5% level.
% h(2) = 1 indicates that the backward cusum of squares test rejects the null hypothesis at 5% level.
% H is a 2-by-28 logical matrix. The first row corresponds to the forward cusum of squares test. Because it contains all zeros, the recursive residuals never cross into the critical region. The second row corresponds to the backward cusum of squares test. The recursive residual corresponding to the 16th recursive regression crosses into the critical region, and so the null hypothesis is rejected.
% Copyright 2012 The MathWorks, Inc.