markov.stat.rice.edu% matlab < M A T L A B (R) > (c) Copyright 1984-98 The MathWorks, Inc. All Rights Reserved Version 5.2.1.1420 Apr 30 1998 To get started, type one of these: helpwin, helpdesk, or demo. For product information, type tour or visit www.mathworks.com. >> %this is a comment: I like lots of help, so ... >> helpwin >> helpdesk >> %OK, here's another Dow-Jones data set -- from a much earlier time >> dowj=dlmread('dowj.dat') dowj = 110.9400 110.6900 110.4300 110.5600 110.7500 110.8400 110.4600 110.5600 110.4600 110.0500 109.6000 109.3100 109.3100 109.2500 109.0200 108.5400 108.7700 109.0200 109.4400 109.3800 109.5300 109.8900 110.5600 110.5600 110.7200 111.2300 111.4800 111.5800 111.9000 112.1900 112.0600 111.9600 111.6800 111.3600 111.4200 112.0000 112.2200 112.7000 113.1500 114.3600 114.6500 115.0600 115.8600 116.4000 116.4400 116.8800 118.0700 118.5100 119.2800 119.7900 119.7000 119.2800 119.6600 120.1400 120.9700 121.1300 121.5500 121.9600 122.2600 123.7900 124.1100 124.1400 123.3700 123.0200 122.8600 123.0200 123.1100 123.0500 123.0500 122.8300 123.1800 122.6700 122.7300 122.8600 122.6700 122.0900 122.0000 121.2300 >> %Whoops; forgot to put a ; after the dlmread statement. >> %Oh, well, now you have the data >> size(dowj) ans = 78 1 >> %It's a column vector. >> plot(dowj) >> %Looks nonstationary -- generally a bull market trend >> %Now save it as a file >> print -deps2 >> %Take logs and differences in an effort to get stationarity >> ldowj=log10(dowj); >> dldowj=ldowj(2:78)-ldowj(1:77); >> plot(dldowj) >> %Looks much more stationary!!!! >> print -deps2 >> %Look at the matlab equivalent of the qqnorm from Splus >> normplot(dldowj) >> %Not bad, except for 3 values on the upper end >> print -deps2 >> %typed in the function autocov, which you can download >> %it is saved in the file 'autocov.m' in the working directory >> %I am adding my current directory to the path so matlab will find it: >> path(path,'/home/dcox/Instruct/Stat421/Lessons/Ch2c/Matlab') >> help autocov AUTOCOV(TSERIES) sample autocovariance function TSERIES must be a column vector returns a column vector >> ac=autocov(dldowj); >> %Now the autocorrelation function: >> acf=ac/ac(1); >> plot(acf) >> %Adding the lines for the informal white noise test >> length(dldowj) ans = 77 >> length(acf) ans = 19 >> hold on >> plot([1 19],-ones(2)*2/sqrt(77)) >> plot([1 19],+ones(2)*2/sqrt(77)) >> print -deps2 >> %Hmm. Looks like the acf values at lags 1 and 2 are signficant >> %Hmm. Looks like the geometric random walk (=> dldowj is a white noise) >> % is not tenable here. >> % Now let's do a periodogram. >> %So I wrote another function pdgrm.m >> Idldowj=pdgrm(dldowj); >> size(Idldowj) ans = 38 1 >> %No unrequested padding like Splus forced on me; that's good >> plot(Idldowj) >> %Clearly a very strong low frequency component here >> print -deps2 >> plot(10*log10(Idldowj)) >> print -deps2 >> quit