% % 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; drawnow; clc; clear; clear functions; save_plots = 0; % calculate the correlation of these residuals: if( exist('/home/weatherw/Trash/Poularikas/AdaptiveFilteringCode') ) addpath('/home/weatherw/Trash/Poularikas/AdaptiveFilteringCode'); end addpath( '../Chapter4/' ); Y_save = load_spy_data(); n = length(Y_save); % take logarithmic transformation (if desired): %Y_save = log(Y_save); % consider a period of data much more recently: nF = 0.05*n; Y_save = Y_save(n-nF:n); n = length(Y_save); % downsample our data (don't include the last two months): n = length(Y_save)-2*4; Y = Y_save(1:n); Y_test = Y_save( (n+1):end ); fh = figure; plot( Y, 'x-' ); xlabel( 'Time (weeks)' ); ylabel( 'Weekly SPY closing prices' ); if( save_plots ) saveas(gcf, '../../WriteUp/Graphics/Chapter5/spy_plt', 'epsc' ); end axis tight; fprintf('s^2(Y)= %10.6f, s^2(diff(Y))= %10.6f, s^2(diff(Y,2))= %10.6f, s^2(diff(Y,3))= %10.6f\n',var(Y),var(diff(Y)),var(diff(Y,2)),var(diff(Y,3))) % non-statonary ... take first differences and plot: YD = diff(Y); nd = length(YD); figure; plot( YD, 'x-' ); xlabel( 'Time (weeks)' ); ylabel( 'Difference in Weekly SPY closing prices' ); if( save_plots ) saveas(gcf, '../../WriteUp/Graphics/Chapter5/spy_diff_plt', 'epsc' ); end r_k = plot_SACF( YD ); title( 'sample autocorrelation function of z_t-z_{t-1}' ); if( save_plots ) saveas(gcf, '../../WriteUp/Graphics/Chapter5/spy_diff_z_t_sacf', 'epsc' ); end phi_kk = plot_SPACF( r_k(2:end), nd ); title( 'sample partial autocorrelation function of z_t-z_{t-1}' ); if( save_plots ) saveas( gcf, '../../WriteUp/Graphics/Chapter5/spy_diff_spacf', 'epsc' ); end % determine an approporite ARIMA model % calculate the forecasts and 95% prediction intervals for the next 3 weeks closing prices