| 1 |
var white_noise ar1; |
| 2 |
varexo e; |
| 3 |
|
| 4 |
parameters phi; |
| 5 |
|
| 6 |
phi=0.9; |
| 7 |
|
| 8 |
model; |
| 9 |
white_noise=e; |
| 10 |
ar1=phi*ar1(-1)+e; |
| 11 |
|
| 12 |
end; |
| 13 |
|
| 14 |
shocks; |
| 15 |
var e = 1; |
| 16 |
end; |
| 17 |
|
| 18 |
options_.SpectralDensity.trigger=1; |
| 19 |
|
| 20 |
options_.bandpass.indicator=0; |
| 21 |
|
| 22 |
stoch_simul(order=1,nofunctions,hp_filter=0,irf=0,periods=1000000,filtered_theoretical_moments_grid=2048); |
| 23 |
send_endogenous_variables_to_workspace; |
| 24 |
|
| 25 |
white_noise_sample=white_noise; |
| 26 |
|
| 27 |
theoretical_spectrum_white_noise=1^2/(2*pi); %Hamilton (1994), 6.1.9 |
| 28 |
if max(abs(oo_.SpectralDensity.density(strmatch('white_noise',M_.endo_names,'exact'),:)-theoretical_spectrum_white_noise))>1e-10 |
| 29 |
error('Spectral Density is wrong') |
| 30 |
end |
| 31 |
|
| 32 |
theoretical_spectrum_AR1=1/(2*pi)*(1^2./(1+phi^2-2*phi*cos(oo_.SpectralDensity.freqs))); %Hamilton (1994), 6.1.13 |
| 33 |
if max(abs(oo_.SpectralDensity.density(strmatch('ar1',M_.endo_names,'exact'),:)-theoretical_spectrum_AR1'))>1e-10 |
| 34 |
error('Spectral Density is wrong') |
| 35 |
end |
| 36 |
|
| 37 |
stoch_simul(order=1,nofunctions,hp_filter=1600,irf=0,periods=0); |
| 38 |
lambda=options_.hp_filter; |
| 39 |
Kalman_gain=(4*lambda*(1 - cos(oo_.SpectralDensity.freqs)).^2 ./ (1 + 4*lambda*(1 - cos(oo_.SpectralDensity.freqs)).^2)); |
| 40 |
theoretical_spectrum_white_noise_hp_filtered=1^2/(2*pi)*Kalman_gain.^2; %Hamilton (1994), 6.1.9 |
| 41 |
if max(abs(oo_.SpectralDensity.density(strmatch('white_noise',M_.endo_names,'exact'),:)-theoretical_spectrum_white_noise_hp_filtered'))>1e-10 |
| 42 |
error('Spectral Density is wrong') |
| 43 |
end |
| 44 |
|
| 45 |
theoretical_spectrum_AR1_hp_filtered=1/(2*pi)*(1^2./(1+phi^2-2*phi*cos(oo_.SpectralDensity.freqs))).*Kalman_gain.^2; %Hamilton (1994), 6.1.13 |
| 46 |
if max(abs(oo_.SpectralDensity.density(strmatch('ar1',M_.endo_names,'exact'),:)-theoretical_spectrum_AR1_hp_filtered'))>1e-10 |
| 47 |
error('Spectral Density is wrong') |
| 48 |
end |
| 49 |
|
| 50 |
options_.hp_filter=0; |
| 51 |
stoch_simul(order=1,nofunctions,bandpass_filter=[6 32],irf=0); |
| 52 |
|
| 53 |
theoretical_spectrum_white_noise=repmat(theoretical_spectrum_white_noise,1,options_.filtered_theoretical_moments_grid); |
| 54 |
passband=oo_.SpectralDensity.freqs>=2*pi/options_.bandpass.passband(2) & oo_.SpectralDensity.freqs<=2*pi/options_.bandpass.passband(1); |
| 55 |
if max(abs(oo_.SpectralDensity.density(strmatch('white_noise',M_.endo_names,'exact'),passband)-theoretical_spectrum_white_noise(passband)))>1e-10 |
| 56 |
error('Spectral Density is wrong') |
| 57 |
end |
| 58 |
if max(abs(oo_.SpectralDensity.density(strmatch('white_noise',M_.endo_names,'exact'),~passband)-0))>1e-10 |
| 59 |
error('Spectral Density is wrong') |
| 60 |
end |
| 61 |
|
| 62 |
if max(abs(oo_.SpectralDensity.density(strmatch('ar1',M_.endo_names,'exact'),passband)-theoretical_spectrum_AR1(passband)'))>1e-10 |
| 63 |
error('Spectral Density is wrong') |
| 64 |
end |
| 65 |
if max(abs(oo_.SpectralDensity.density(strmatch('ar1',M_.endo_names,'exact'),~passband)-0))>1e-10 |
| 66 |
error('Spectral Density is wrong') |
| 67 |
end |
| 68 |
|
| 69 |
|
| 70 |
% [pow,f]=psd(a_sample,1024,1,[],512); |
| 71 |
% figure |
| 72 |
% plot(f,pow/(2*pi)) |
| 73 |
% |
| 74 |
% % figure |
| 75 |
% % [pow,f]=psd(a_sample,1000,1,[],500); |
| 76 |
% % plot(f(3:end)*2*pi,pow(3:end)/(2*pi)); |