% % Generates ARIMA models for the yield data set. % % 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; clear functions; clear; rehash; clc; if( exist('/home/weatherw/Trash/Poularikas/AdaptiveFilteringCode') ) addpath('/home/weatherw/Trash/Poularikas/AdaptiveFilteringCode'); end addpath( '../Chapter2/' ); addpath( '../Chapter4/' ); Y_all = load_yield_data(); n_all = length(Y_all); n = n_all - 3; Y = Y_all(1:n); % hold out Jan,Feb,March 1974 for testing fh = figure; p_data = plot( 1:n, Y, '-bx' ); axis tight; hold on; xlabel( 'Time' ); ylabel( 'montly difference between yeild on mortgages and on govenment loans' ); saveas( gcf, '../../WriteUp/Graphics/Chapter5/yield_data_plt', 'epsc' ); % plot the sample autocorrelation function ... DONE elsewhere % plot the sample partial autocorrelation function ... DONE elsewhere % estimate the parameters of an AR(1) model (using only the in-sample data): [muhat,sigmahat,muci,sigmaci] = normfit(Y,0.05); fprintf('mean estimate = %10.6f; standard error = %10.6f\n',muhat,diff(muci)); % assume a particular model based on the above plots ... AR(1) say % estimate the coefficients of the model (in R) ... see the file model_yield_section_5_8_2.R % compute the one-step-ahead predicitions, z_n(1), and their residuals using the estimated % model coefficients % %muhat = 0.97; % ... books value phi = 0.85; sigma = sqrt(0.024); % Note: % Y_n_l(1) = y_1(1) ... and so should be compared with y(2) % Y_n_l(2) = y_2(1) ... and so should be compared with y(3) ... etc % % Y_n_l(n) = y_n(1) Y_n_l = muhat + phi * ( Y - muhat ); figure(fh); hold on; plot( 2:n, Y_n_l(1:end-1), '-rx' ); title( 'Raw Yield Data (in blue) and AR(1) predictions (in red)' ); saveas( gcf, '../../WriteUp/Graphics/Chapter5/yield_data_plt', 'epsc' ); res = Y(2:end) - Y_n_l(1:end-1); % the residuals % plot the sample autocorrelation function of the residuals plot_SACF( res ); saveas( gcf, '../../WriteUp/Graphics/Chapter5/yield_data_res_SACF', 'epsc' ); % compute the Portmanteau statistic Q ... skipped for time % compute three forecasts (and their variances) ... skipped for time