Excelente Arma Matlab
Excelente Arma Matlab
384 Time Series Analysis, Fall 2007 Recitation by Paul Schrimpf Supplementary to lectures given by Anna Mikusheva September 17, 2007
Recitation 2
clear; a = [1 0.5]; % AR coeffs b = [1 0.4 0.3]; % MA coeffs T = 1000; e = randn(T,1); % generate gaussian white noise y = filter(b,a,e); % generate y
The filter function can be used to generate data from an ARMA model, or apply a lter to a series.
Impulse-Response
To graph the impulse response of an ARMA, use fvtool
1 2
Sample Covariances
1 2 3 4
Cite as: Paul Schrimpf, course materials for 14.384 Time Series Analysis, Fall 2007. MIT OpenCourseWare (http://ocw.mit.edu), Massachusetts Institute of Technology. Downloaded on [DD Month YYYY].
Spectral Analysis
Spectral Analysis
Population spectral density for an ARMA:
1 2 3 4
% population density w = 0:0.1:pi; % frequencies to compute density at h = freqz(b,a,w); % returns frequency response = b(e{iw})/a(e{iw}) sd = abs(h).2./sqrt(2*pi); % make into density
Estimating the Spectral Density Parametric methods These estimate an AR(p) and use it to compute the spectrum.
1 2 3 4 5
[sdc wc] = pcov(y,8); % estimate spectral density by fitting AR(8) [sdy wy] = pyulear(y,8); % estimate spectral density by fitting AR(8) % using % the Yulewalker equations
Non-parametric methods
1 Denition 1. The sample periodogram of {xt }T is S() = T | t=1 T t=1
eit xt |2
Remark 2. The sample periodogram is equal to the Fourier transform of the sample autocovariances 1 S () = | T
T T 1
e
t=1
it
xt | =
k eik
k=T 1
using sample
t=1
eit xt |2 d
where hT () is some kernel weighting function. A smoothed periodogram is a weighting moving average of the sample periodogram. The following code estimates a smoothed periodogram using a Parzen kernel with band width T .
Cite as: Paul Schrimpf, course materials for 14.384 Time Series Analysis, Fall 2007. MIT OpenCourseWare (http://ocw.mit.edu), Massachusetts Institute of Technology. Downloaded on [DD Month YYYY].
Filtering
1 2
Denition 4. A weighted covariance estimate of the spectrum is: S () = where gT (k) is some kernel.
ST
k gT (k)eik
k=ST
1 2 3 4 5 6 7 8 9 10
% bartlett weighted covariances wb = 0:0.1:pi; rT = sqrt(T); [c t]=xcov(y,'biased'); weight = 1abs(t)/rT; weight(abs(t)>rT) = 0; for j=1:length(wb) sdb(j) = sum(c.*weight.*exp(i*wb(j)*t)); end sdb = sdb / sqrt(2*pi);
Filtering
See: http://ideas.repec.org/c/wpa/wuwppr/0507001.html for code for common lters.
clear; close all; % closes all open figure windows % a b T e y model: y t = 0.9 y {t1} + b(L) e t = [1 0.7]; % AR coeffs = [1 0.3 2]; % MA coeffs = 200; = randn(T,1); % generate gaussian white noise = filter(b,a,e); % generate y
Cite as: Paul Schrimpf, course materials for 14.384 Time Series Analysis, Fall 2007. MIT OpenCourseWare (http://ocw.mit.edu), Massachusetts Institute of Technology. Downloaded on [DD Month YYYY].
% create an impulse response fvtool(b,a,'impulse'); % calculate and plot sample autocovariances [c lags]=xcov(y,'biased'); figure; plot(lags,c); title('Sample Covariances'); % estimate spectral density % parametric [sdc wc] = pcov(y,8); % estimate spectral density by fitting AR(8) [sdy wy] = pyulear(y,8); % estimate spectral density by fitting AR(8) % using % the Yulewalker equations % nonparametric [sdp wp] = periodogram(y,[],'onesided'); % estimate using unsmoothed % periodogram rT = round(sqrt(T))*3; [sdw ww] = pwelch(y,parzenwin(rT),rT1,[],'onesided'); % smoothed periodogram % bartlett weighted covariances [c lags]=xcov(y,'biased'); t = (T1):(T1); weight = 1abs(t')/rT; weight(abs(t')>rT) = 0; wb = ww; for j=1:length(wb) sdb(j) = sum(c.*weight.*exp(i*wb(j)*((T1):(T1))')); end sdb = sdb / sqrt(2*pi); % population density w = wb; h = freqz(b,a,w); sd = abs(h).2./sqrt(2*pi); figure; plot(wp,sdp,wc,sdc,ww,sdw,wb,sdb,wy,sdy,w,sd); legend('raw periodogram','parametric AR','smoothed periodogram', ... 'bartlett weighted cov','YuleWalker','population density');
Cite as: Paul Schrimpf, course materials for 14.384 Time Series Analysis, Fall 2007. MIT OpenCourseWare (http://ocw.mit.edu), Massachusetts Institute of Technology. Downloaded on [DD Month YYYY].
ARMA(1,2) 15
10
10
15
50
100 t
150
200
Impulse Response
2.5
Amplitude
1.5
0.5
0 0 5 10 Samples 15 20 25
Cite as: Paul Schrimpf, course materials for 14.384 Time Series Analysis, Fall 2007. MIT OpenCourseWare (http://ocw.mit.edu), Massachusetts Institute of Technology. Downloaded on [DD Month YYYY].
Cite as: Paul Schrimpf, course materials for 14.384 Time Series Analysis, Fall 2007. MIT OpenCourseWare (http://ocw.mit.edu), Massachusetts Institute of Technology. Downloaded on [DD Month YYYY].
70 raw periodogram parametric AR smoothed periodogram bartlett weighted cov YuleWalker population density
60
50
40
30
20
10
0.5
1.5
2.5
3.5
Cite as: Paul Schrimpf, course materials for 14.384 Time Series Analysis, Fall 2007. MIT OpenCourseWare (http://ocw.mit.edu), Massachusetts Institute of Technology. Downloaded on [DD Month YYYY].