% % Written by: % -- % John L. Weatherwax 2009-04-21 % % email: wax@alum.mit.edu % % Please send comments and especially bug reports to the % above email address. % %----- close all; clc; clear; npts = 200; % If alpha_x and alpha_y are of the same sign then % x_t and y_t seem to move in the same direction following each other % alpha_x = -0.2; % this ordering of signs (+/-) seems to work in that the resulting series looks very much like the one from the book alpha_y = 0.2; gamma = 1.0; % generate two random noise sequences: t = 1.0; epsilon_x = t * randn(1,npts); epsilon_y = t * randn(1,npts); x_t = zeros(1,npts); y_t = zeros(1,npts); for ii=2:npts spread_tm1 = x_t(ii-1) - gamma * y_t(ii-1); x_t(ii) = x_t(ii-1) + alpha_x * spread_tm1 + epsilon_x(ii); y_t(ii) = y_t(ii-1) + alpha_y * spread_tm1 + epsilon_y(ii); end figure; hx_t = plot( x_t, '-o' ); hold on; hy_t = plot( y_t, '-dr' ); title('Cointegrated Time Series'); %axis([ -10 110, -3.5, +3.5 ] ); legend( [ hx_t, hy_t ], {'x_t','y_t'}, 'location', 'best' ); if( 0 ) saveas( gcf, '../../WriteUp/Graphics/Chapter5/cointegration_example', 'eps' ); end % compute the spread series: spread = x_t - gamma * y_t; fprintf('mean spread= %10.6f; std spread= %10.6f\n', mean(spread), std(spread)); figure; plot( spread, '-o' ); title('The Spread of Two Cointegrated Time Series'); %axis([ -10 110, -3.5, +3.5 ] ); if( 0 ) saveas( gcf, '../../WriteUp/Graphics/Chapter5/cointegration_spread', 'eps' ); end return; % compute the spread autocorrelation function: sacf = acf( spread );