Debian Codegraph @

tests/kalman_filter_smoother/algo4b.mod

raw
1 var z dw dx dy dc1 dc2 y;
2 varexo e_w e_x e_y e_z;
3
4 parameters rho_w rho_x rho_y rho_z a1 a2 a3 b c;
5
6 model(linear);
7 dw = rho_w*dw(-1)+a1*(dc1(-1))+e_w;
8 dx = rho_x*dx(-1)+a2*(dc1(-1))+e_x;
9 dy = rho_y*dy(-1)+a3*(dc2(-1))+e_y;
10 z = rho_z*z(-1)+dw-dx+e_z;
11 dc1 = dc1(-1)+dx-b*dy-c*dw;
12 dc2 = dc2(-1)+dx-b*dy;
13 y = y(-1) + dy;
14 end;
15
16 estimated_params;
17 rho_w, normal_pdf, 0.5,0.2;
18 rho_x, normal_pdf, 0.5,0.2;
19 rho_y, normal_pdf, 0.5,0.2;
20 rho_z, normal_pdf, 0.8,0.2;
21
22 a1, normal_pdf, 0.1,0.2;
23 a2, normal_pdf, -0.1,0.2;
24 a3, normal_pdf, 0.1,0.2;
25 b , normal_pdf, 1,0.2;
26 c , normal_pdf, 1,0.2;
27
28 stderr e_w, uniform_pdf,,, 0.01, 0.1;
29 stderr e_x, uniform_pdf,,, 0.01, 0.1;
30 stderr e_y, uniform_pdf,,, 0.01, 0.1;
31 stderr e_z, uniform_pdf,,, 0.01, 0.1;
32 end;
33
34 varobs dw dx y z;
35
36 estimation(datafile=data_algo,first_obs=1000,silent_optimizer,nobs=200,mh_replic=0,diffuse_filter,smoothed_state_uncertainty);
37 //estimation(datafile=data_algo,first_obs=1000,nobs=200,mh_replic=0,mode_compute=0,mode_file='algo3/Output/algo3_mode',diffuse_filter);
38
39 //checking smoother consistency
40 X = oo_.SmoothedVariables;
41 S = [X.z X.dw X.dx X.dy X.dc1 X.dc2 X.y];
42 X = oo_.SmoothedShocks;
43 E = [X.e_w X.e_x X.e_y X.e_z];
44 A = oo_.dr.ghx;
45 B = oo_.dr.ghu;
46 err = zeros(M_.endo_nbr,200);
47 for t=2:200;
48 err(:,t) = S(t,:)'-A*S(t-1,:)'-B*E(t,:)';
49 end;
50 if max(max(abs(err))) > 1e-10;
51 error('Test fails');
52 end;
53
54 d=load('data_algo');
55 dat = [d.dw d.dx d.y d.z];
56 if max(max(abs(dat(1000:1199,:)-S(:,[2 3 7 1])))) > 1e-10;
57 error('Test fails');
58 end;