From 4a197150b81c84135ae32dfcf062b68a3c516ef3 Mon Sep 17 00:00:00 2001
From: Michel Juillard <michel.juillard@mjui.fr>
Date: Wed, 2 Nov 2011 21:20:10 +0100
Subject: [PATCH] adding new test

---
 tests/Makefile.am                          |  18 +-
 tests/kalman_filter_smoother/algo1.mod     |   9 +-
 tests/kalman_filter_smoother/algo2.mod     |  18 +-
 tests/kalman_filter_smoother/algo3.mod     |   9 +-
 tests/kalman_filter_smoother/algo4.mod     |  19 +-
 tests/kalman_filter_smoother/algo4a.mod    |   8 +-
 tests/kalman_filter_smoother/algo4b.mod    |  58 ++
 tests/kalman_filter_smoother/algoH1.mod    |   8 +-
 tests/kalman_filter_smoother/algoH2.mod    |  26 +-
 tests/kalman_filter_smoother/algoH3.mod    |   9 +-
 tests/kalman_filter_smoother/fs2000.mod    |  74 ++
 tests/kalman_filter_smoother/fs2000_1.mod  |  74 ++
 tests/kalman_filter_smoother/fs2000_2.mod  |  74 ++
 tests/kalman_filter_smoother/fs2000a.mod   |  85 +++
 tests/kalman_filter_smoother/fsdat_simul.m | 828 +++++++++++++++++++++
 15 files changed, 1282 insertions(+), 35 deletions(-)
 create mode 100644 tests/kalman_filter_smoother/algo4b.mod
 create mode 100644 tests/kalman_filter_smoother/fs2000.mod
 create mode 100644 tests/kalman_filter_smoother/fs2000_1.mod
 create mode 100644 tests/kalman_filter_smoother/fs2000_2.mod
 create mode 100644 tests/kalman_filter_smoother/fs2000a.mod
 create mode 100644 tests/kalman_filter_smoother/fsdat_simul.m

diff --git a/tests/Makefile.am b/tests/Makefile.am
index 09fb73485..a5cb20495 100644
--- a/tests/Makefile.am
+++ b/tests/Makefile.am
@@ -87,6 +87,21 @@ MODFILES = \
 	conditional_forecasts/fs2000_est.mod \
 	recursive/ls2003.mod \
 	recursive/ls2003_bayesian.mod
+	kalman_filter_smoother/algo1.mod \
+	kalman_filter_smoother/algo2.mod \
+	kalman_filter_smoother/algo3.mod \
+	kalman_filter_smoother/algo4.mod \
+	kalman_filter_smoother/algo4a.mod \
+	kalman_filter_smoother/algo4b.mod \
+	kalman_filter_smoother/algoH1.mod \
+	kalman_filter_smoother/algoH2.mod \
+	kalman_filter_smoother/algoH3.mod \
+	kalman_filter_smoother/fs2000.mod \
+	kalman_filter_smoother/fs2000_1.mod \
+	kalman_filter_smoother/fs2000_2.mod \
+	kalman_filter_smoother/fs2000a.mod \
+        kalman_filter_smoother/gen_data.mod \
+	kalman_filter_smoother/fsdat_simul.m
 
 EXTRA_DIST = \
 	$(MODFILES) \
@@ -119,7 +134,8 @@ EXTRA_DIST = \
 	missing/simulate_data_with_missing_observations.m \
 	objectives/sgu_ex1.mat \
 	conditional_forecasts/fsdat_simul.m \
-	recursive/data_ca1.m
+	recursive/data_ca1.m \
+	kalman_filter_smoother/fsdat_simul.m
 
 TARGETS =
 
diff --git a/tests/kalman_filter_smoother/algo1.mod b/tests/kalman_filter_smoother/algo1.mod
index c2a4bfb89..482240ba4 100644
--- a/tests/kalman_filter_smoother/algo1.mod
+++ b/tests/kalman_filter_smoother/algo1.mod
@@ -32,7 +32,6 @@ end;
 
 varobs dw dx dy z;
        
-//estimation(datafile=data,first_obs=1000,nobs=200,mh_replic=0);
 estimation(datafile=data,first_obs=1000,nobs=200,mh_replic=0,mode_compute=0,mode_file=algo1_mode);
 
 //checking smoother consistency
@@ -46,8 +45,12 @@ err = zeros(6,200);
 for t=2:200;
     err(:,t) = S(t,:)'-A*S(t-1,:)'-B*E(t,:)';
 end;
-disp(max(max(abs(err))));
+if max(max(abs(err))) > 1e-10;
+   error('Test fails')
+endif;
 
 d=load('data');
 dat = [d.dw d.dx d.dy d.z];
-disp(max(max(abs(dat(1000:1199,:)-S(:,[2:4 1])))));
\ No newline at end of file
+if max(max(abs(dat(1000:1199,:)-S(:,[2:4 1])))) > 1e-10;
+   error('Test fails');
+end;
\ No newline at end of file
diff --git a/tests/kalman_filter_smoother/algo2.mod b/tests/kalman_filter_smoother/algo2.mod
index a6d7ce4aa..d589792cd 100644
--- a/tests/kalman_filter_smoother/algo2.mod
+++ b/tests/kalman_filter_smoother/algo2.mod
@@ -32,7 +32,6 @@ end;
 
 varobs dw dx dy z;
        
-//estimation(datafile=data,first_obs=1000,nobs=200,mh_replic=0,kalman_algo=2);
 estimation(datafile=data,first_obs=1000,nobs=200,mh_replic=0,mode_compute=0,mode_file=algo1_mode,kalman_algo=2);
 
 //checking smoother consistency
@@ -46,11 +45,15 @@ err = zeros(6,200);
 for t=2:200;
     err(:,t) = S(t,:)'-A*S(t-1,:)'-B*E(t,:)';
 end;
-disp(max(max(abs(err))));
+if max(max(abs(err))) > 1e-10;
+   error('Test fails');
+end;
 
 d=load('data');
 dat = [d.dw d.dx d.dy d.z];
-disp(max(max(abs(dat(1000:1199,:)-S(:,[2:4 1])))));
+if max(max(abs(dat(1000:1199,:)-S(:,[2:4 1])))) > 1e-10;
+   error('Test fails');
+end;
 
 o1 = load('algo1_results');
 obj_endo={'SmoothedVariables'; 'FilteredVariables'; 'UpdatedVariables'};
@@ -64,7 +67,9 @@ for i=1:nobj_endo;
         var2 = eval(['oo_.' obj_endo{i} '.' M_.endo_names(j,:)]);
         err_endo(:,j) = var1-var2;
     end;
-    disp(max(max(abs(err_endo))));    
+    if max(max(abs(err_endo))) > 1e-10;
+       error('Test fails');
+    end;     
 end;
 
 
@@ -76,6 +81,7 @@ for i=1:nobj_exo;
         var2 = eval(['oo_.' obj_exo{i} '.' M_.exo_names(j,:)]);
         err_exo(:,j,i) = var1 - var2;
     end;
-    disp(max(max(abs(err_exo))));    
+    if max(max(abs(err_exo))) > 1e-10;
+       error('Test fails')
+    end;
 end;
-disp(max(max(max(abs(err_exo)))));    
diff --git a/tests/kalman_filter_smoother/algo3.mod b/tests/kalman_filter_smoother/algo3.mod
index 16ff3ff15..78fff75e8 100644
--- a/tests/kalman_filter_smoother/algo3.mod
+++ b/tests/kalman_filter_smoother/algo3.mod
@@ -36,7 +36,6 @@ end;
 varobs w x y;
        
 estimation(datafile=data,first_obs=1000,nobs=200,mh_replic=0,diffuse_filter);
-//estimation(datafile=data,first_obs=1000,nobs=200,mh_replic=0,mode_compute=0,mode_file=algo3_mode,diffuse_filter);
 
 //checking smoother consistency
 X = oo_.SmoothedVariables;
@@ -49,8 +48,12 @@ err = zeros(M_.endo_nbr,200);
 for t=2:200;
     err(:,t) = S(t,:)'-A*S(t-1,:)'-B*E(t,:)';
 end;
-disp(max(max(abs(err))));
+if max(max(abs(err))) > 1e-10;
+   error('Test fails');
+end;
 
 d=load('data');
 dat = [d.w d.x d.y];
-disp(max(max(abs(dat(1000:1199,:)-S(:,[7:9])))));
\ No newline at end of file
+if max(max(abs(dat(1000:1199,:)-S(:,[7:9])))) > 1e-10;
+   error('Test fails');
+end;
diff --git a/tests/kalman_filter_smoother/algo4.mod b/tests/kalman_filter_smoother/algo4.mod
index 22820f730..4e5276867 100644
--- a/tests/kalman_filter_smoother/algo4.mod
+++ b/tests/kalman_filter_smoother/algo4.mod
@@ -35,7 +35,6 @@ end;
 
 varobs w x y;
        
-//estimation(datafile=data,first_obs=1000,nobs=200,mh_replic=0,diffuse_filter);
 estimation(datafile=data,first_obs=1000,nobs=200,mh_replic=0,mode_compute=0,mode_file=algo3_mode,diffuse_filter,kalman_algo=4);
 
 //checking smoother consistency
@@ -49,11 +48,15 @@ err = zeros(M_.endo_nbr,200);
 for t=2:200;
     err(:,t) = S(t,:)'-A*S(t-1,:)'-B*E(t,:)';
 end;
-disp(max(max(abs(err))));
+if max(max(abs(err))) > 1e-10;
+   error('Test fails');
+end;
 
 d=load('data');
 dat = [d.w d.x d.y];
-disp(max(max(abs(dat(1000:1199,:)-S(:,[7:9])))));
+if max(max(abs(dat(1000:1199,:)-S(:,[7:9])))) > 1e-10;
+   error('Test fails');
+end;
 
 o1 = load('algo3_results');
 obj_endo={'SmoothedVariables'; 'FilteredVariables'; 'UpdatedVariables'};
@@ -67,7 +70,9 @@ for i=1:nobj_endo;
         var2 = eval(['oo_.' obj_endo{i} '.' M_.endo_names(j,:)]);
         err_endo(:,j) = var1-var2;
     end;
-    disp(max(max(abs(err_endo))));    
+    if max(max(abs(err_endo))) > 1e-10;
+       error('Test fails');
+    end;    
 end;
 
 
@@ -79,6 +84,8 @@ for i=1:nobj_exo;
         var2 = eval(['oo_.' obj_exo{i} '.' M_.exo_names(j,:)]);
         err_exo(:,j,i) = var1 - var2;
     end;
-    disp(max(max(abs(err_exo))));    
+    if max(max(abs(err_exo))) > 1e-10;
+       error('Test fails');
+    end;    
 end;
-disp(max(max(max(abs(err_exo)))));    
+
diff --git a/tests/kalman_filter_smoother/algo4a.mod b/tests/kalman_filter_smoother/algo4a.mod
index eec1cbaf5..9ca467501 100644
--- a/tests/kalman_filter_smoother/algo4a.mod
+++ b/tests/kalman_filter_smoother/algo4a.mod
@@ -47,8 +47,12 @@ err = zeros(M_.endo_nbr,200);
 for t=2:200;
     err(:,t) = S(t,:)'-A*S(t-1,:)'-B*E(t,:)';
 end;
-disp(max(max(abs(err))));
+if max(max(abs(err))) > 1e-10;
+   error('Test fails');
+end;
 
 d=load('data');
 dat = [d.dw d.dx d.y d.z];
-disp(max(max(abs(dat(1000:1199,:)-S(:,[2 3 7 1])))));
\ No newline at end of file
+if max(max(abs(dat(1000:1199,:)-S(:,[2 3 7 1])))) > 1e-10;
+   error('Test fails');
+end;
diff --git a/tests/kalman_filter_smoother/algo4b.mod b/tests/kalman_filter_smoother/algo4b.mod
new file mode 100644
index 000000000..9ca467501
--- /dev/null
+++ b/tests/kalman_filter_smoother/algo4b.mod
@@ -0,0 +1,58 @@
+var z dw dx dy dc1 dc2 y;
+varexo e_w e_x e_y e_z;
+
+parameters rho_w rho_x rho_y rho_z a1 a2 a3 b c;
+
+model(linear);
+dw = rho_w*dw(-1)+a1*(dc1(-1))+e_w;
+dx = rho_x*dx(-1)+a2*(dc1(-1))+e_x;
+dy = rho_y*dy(-1)+a3*(dc2(-1))+e_y;
+z = rho_z*z(-1)+dw-dx+e_z;
+dc1 = dc1(-1)+dx-b*dy-c*dw;
+dc2 = dc2(-1)+dx-b*dy;
+y = y(-1) + dy;
+end;
+
+estimated_params;
+rho_w, normal_pdf, 0.5,0.2;
+rho_x, normal_pdf, 0.5,0.2;
+rho_y, normal_pdf, 0.5,0.2;
+rho_z, normal_pdf, 0.8,0.2;
+
+a1, normal_pdf, 0.1,0.2;
+a2, normal_pdf,  -0.1,0.2;
+a3, normal_pdf,  0.1,0.2;
+b , normal_pdf,  1,0.2;
+c , normal_pdf,  1,0.2;
+
+stderr e_w, uniform_pdf,,, 0.01, 0.1;
+stderr e_x, uniform_pdf,,, 0.01, 0.1;
+stderr e_y, uniform_pdf,,, 0.01, 0.1;
+stderr e_z, uniform_pdf,,, 0.01, 0.1;
+end;
+
+varobs dw dx y z;
+       
+estimation(datafile=data,first_obs=1000,nobs=200,mh_replic=0,diffuse_filter);
+//estimation(datafile=data,first_obs=1000,nobs=200,mh_replic=0,mode_compute=0,mode_file=algo3_mode,diffuse_filter);
+
+//checking smoother consistency
+X = oo_.SmoothedVariables;
+S = [X.z X.dw X.dx X.dy X.dc1 X.dc2 X.y];
+X = oo_.SmoothedShocks;
+E = [X.e_w X.e_x X.e_y X.e_z];
+A = oo_.dr.ghx;
+B = oo_.dr.ghu;
+err = zeros(M_.endo_nbr,200);
+for t=2:200;
+    err(:,t) = S(t,:)'-A*S(t-1,:)'-B*E(t,:)';
+end;
+if max(max(abs(err))) > 1e-10;
+   error('Test fails');
+end;
+
+d=load('data');
+dat = [d.dw d.dx d.y d.z];
+if max(max(abs(dat(1000:1199,:)-S(:,[2 3 7 1])))) > 1e-10;
+   error('Test fails');
+end;
diff --git a/tests/kalman_filter_smoother/algoH1.mod b/tests/kalman_filter_smoother/algoH1.mod
index 46f2a7a97..cd9b7f4b6 100644
--- a/tests/kalman_filter_smoother/algoH1.mod
+++ b/tests/kalman_filter_smoother/algoH1.mod
@@ -48,10 +48,14 @@ err = zeros(6,200);
 for t=2:200;
     err(:,t) = S(t,:)'-A*S(t-1,:)'-B*E(t,:)';
 end;
-disp(max(max(abs(err))));
+if max(max(abs(err))) > 1e-10;
+   error('Test fails');
+end;
 
 d=load('data');
 dat = [d.dw d.dx d.dy d.z];
 X = oo_.SmoothedMeasurementErrors;
 ME = [X.dw X.dx X.dy X.z];
-disp(max(max(abs(dat(1000:1199,:)-S(:,[2:4 1])-ME))));
\ No newline at end of file
+if max(max(abs(dat(1000:1199,:)-S(:,[2:4 1])-ME))) > 1e-10;
+   error('Test fails');
+end;
diff --git a/tests/kalman_filter_smoother/algoH2.mod b/tests/kalman_filter_smoother/algoH2.mod
index 96b730810..2fb7e81b8 100644
--- a/tests/kalman_filter_smoother/algoH2.mod
+++ b/tests/kalman_filter_smoother/algoH2.mod
@@ -33,9 +33,8 @@ stderr z, normal_pdf, 0, 0.1;
 end;
 
 varobs dw dx dy z;
-       
-//estimation(datafile=data,first_obs=1000,nobs=200,mh_replic=0,kalman_algo=2);
-estimation(datafile=data,first_obs=1000,nobs=200,mh_replic=0,mode_compute=0,mode_file=algoH1_mode,kalman_algo=2);
+
+estimation(datafile=data,first_obs=1000,nobs=200,mh_replic=0,mode_compute=0,mode_file=algoH1_mode,kalman_algo=2,filtered_vars);
 
 //checking smoother consistency
 X = oo_.SmoothedVariables;
@@ -48,13 +47,17 @@ err = zeros(6,200);
 for t=2:200;
     err(:,t) = S(t,:)'-A*S(t-1,:)'-B*E(t,:)';
 end;
-disp(max(max(abs(err))));
+if max(max(abs(err))) > 1e-10;
+   error('Test fails');
+end;
 
 d=load('data');
 dat = [d.dw d.dx d.dy d.z];
 X = oo_.SmoothedMeasurementErrors;
 ME = [X.dw X.dx X.dy X.z];
-disp(max(max(abs(dat(1000:1199,:)-S(:,[2:4 1])-ME))));
+if max(max(abs(dat(1000:1199,:)-S(:,[2:4 1])-ME))) > 1e-10;
+   error('Test fails');
+end;
 
 o1 = load('algoH1_results');
 obj_endo={'SmoothedVariables'; 'FilteredVariables'; 'UpdatedVariables'};
@@ -68,7 +71,9 @@ for i=1:nobj_endo;
         var2 = eval(['oo_.' obj_endo{i} '.' M_.endo_names(j,:)]);
         err_endo(:,j) = var1-var2;
     end;
-    disp(max(max(abs(err_endo))));    
+    if max(max(abs(err_endo))) > 1e-10;
+       error('Test fails');
+    end;    
 end;
 
 
@@ -80,8 +85,11 @@ for i=1:nobj_exo;
         var2 = eval(['oo_.' obj_exo{i} '.' M_.exo_names(j,:)]);
         err_exo(:,j,i) = var1 - var2;
     end;
-    disp(max(max(abs(err_exo))));    
+    if max(max(abs(err_exo))) > 1e-10;
+       error('Test fails');
+    end;    
 end;
-disp(max(max(max(abs(err_exo)))));    
 
-disp(max(max(abs(o1.oo_.SmoothedMeasurementErrors.z - oo_.SmoothedMeasurementErrors.z)))); 
\ No newline at end of file
+if max(max(abs(o1.oo_.SmoothedMeasurementErrors.z - oo_.SmoothedMeasurementErrors.z))) > 1e-10;
+   error('Test fails');
+end; 
diff --git a/tests/kalman_filter_smoother/algoH3.mod b/tests/kalman_filter_smoother/algoH3.mod
index 38f4d93e8..d3f923d34 100644
--- a/tests/kalman_filter_smoother/algoH3.mod
+++ b/tests/kalman_filter_smoother/algoH3.mod
@@ -38,7 +38,6 @@ end;
 varobs w x y;
        
 estimation(datafile=data,first_obs=1000,nobs=200,mh_replic=0,diffuse_filter);
-//estimation(datafile=data,first_obs=1000,nobs=200,mh_replic=0,mode_compute=0,mode_file=algo3_mode,diffuse_filter);
 
 stoch_simul(irf=0);
 
@@ -53,10 +52,14 @@ err = zeros(M_.endo_nbr,200);
 for t=2:200;
     err(:,t) = S(t,:)'-A*S(t-1,:)'-B*E(t,:)';
 end;
-disp(max(max(abs(err))));
+if max(max(abs(err))) > 1e-10;
+   error('Test fails');
+end;
 
 d=load('data');
 dat = [d.w d.x d.y];
 X = oo_.SmoothedMeasurementErrors;
 ME = [X.w X.x X.y];
-disp(max(max(abs(dat(1000:1199,:)-S(:,[7:9])-ME))));
\ No newline at end of file
+if max(max(abs(dat(1000:1199,:)-S(:,[7:9])-ME))) > 1E-10;
+   error('Test fails');
+end;
diff --git a/tests/kalman_filter_smoother/fs2000.mod b/tests/kalman_filter_smoother/fs2000.mod
new file mode 100644
index 000000000..d56be54b8
--- /dev/null
+++ b/tests/kalman_filter_smoother/fs2000.mod
@@ -0,0 +1,74 @@
+// See fs2000.mod in the examples/ directory for details on the model
+
+var m P c e W R k d n l gy_obs gp_obs y dA;
+varexo e_a e_m;
+
+parameters alp bet gam mst rho psi del;
+
+alp = 0.33;
+bet = 0.99;
+gam = 0.003;
+mst = 1.011;
+rho = 0.7;
+psi = 0.787;
+del = 0.02;
+
+model;
+dA = exp(gam+e_a);
+log(m) = (1-rho)*log(mst) + rho*log(m(-1))+e_m;
+-P/(c(+1)*P(+1)*m)+bet*P(+1)*(alp*exp(-alp*(gam+log(e(+1))))*k^(alp-1)*n(+1)^(1-alp)+(1-del)*exp(-(gam+log(e(+1)))))/(c(+2)*P(+2)*m(+1))=0;
+W = l/n;
+-(psi/(1-psi))*(c*P/(1-n))+l/n = 0;
+R = P*(1-alp)*exp(-alp*(gam+e_a))*k(-1)^alp*n^(-alp)/W;
+1/(c*P)-bet*P*(1-alp)*exp(-alp*(gam+e_a))*k(-1)^alp*n^(1-alp)/(m*l*c(+1)*P(+1)) = 0;
+c+k = exp(-alp*(gam+e_a))*k(-1)^alp*n^(1-alp)+(1-del)*exp(-(gam+e_a))*k(-1);
+P*c = m;
+m-1+d = l;
+e = exp(e_a);
+y = k(-1)^alp*n^(1-alp)*exp(-alp*(gam+e_a));
+gy_obs = dA*y/y(-1);
+gp_obs = (P/P(-1))*m(-1)/dA;
+end;
+
+initval;
+k = 6;
+m = mst;
+P = 2.25;
+c = 0.45;
+e = 1;
+W = 4;
+R = 1.02;
+d = 0.85;
+n = 0.19;
+l = 0.86;
+y = 0.6;
+gy_obs = exp(gam);
+gp_obs = exp(-gam);
+dA = exp(gam);
+end;
+
+shocks;
+var e_a; stderr 0.014;
+var e_m; stderr 0.005;
+end;
+
+steady;
+
+check;
+
+estimated_params;
+alp, beta_pdf, 0.356, 0.02;
+bet, beta_pdf, 0.993, 0.002;
+gam, normal_pdf, 0.0085, 0.003;
+mst, normal_pdf, 1.0002, 0.007;
+rho, beta_pdf, 0.129, 0.223;
+psi, beta_pdf, 0.65, 0.05;
+del, beta_pdf, 0.01, 0.005;
+stderr e_a, inv_gamma_pdf, 0.035449, inf;
+stderr e_m, inv_gamma_pdf, 0.008862, inf;
+end;
+
+varobs gp_obs gy_obs;
+
+//estimation(order=1,datafile=fsdat_simul,nobs=192,loglinear,mh_replic=2000,mh_nblocks=2,mh_jscale=0.8,mode_check);
+estimation(order=1,datafile=fsdat_simul,nobs=192,loglinear,mh_replic=0,mode_compute=0);
diff --git a/tests/kalman_filter_smoother/fs2000_1.mod b/tests/kalman_filter_smoother/fs2000_1.mod
new file mode 100644
index 000000000..0a8eb3dbd
--- /dev/null
+++ b/tests/kalman_filter_smoother/fs2000_1.mod
@@ -0,0 +1,74 @@
+// See fs2000.mod in the examples/ directory for details on the model
+// For initial value of the parameter, the filter reaches steady state at period 137
+
+var m P c e W R k d n l gy_obs gp_obs y dA;
+varexo e_a e_m;
+
+parameters alp bet gam mst rho psi del;
+
+alp = 0.33;
+bet = 0.99;
+gam = 0.003;
+mst = 1.011;
+rho = 0.7;
+psi = 0.787;
+del = 0.02;
+
+model;
+dA = exp(gam+e_a);
+log(m) = (1-rho)*log(mst) + rho*log(m(-1))+e_m;
+-P/(c(+1)*P(+1)*m)+bet*P(+1)*(alp*exp(-alp*(gam+log(e(+1))))*k^(alp-1)*n(+1)^(1-alp)+(1-del)*exp(-(gam+log(e(+1)))))/(c(+2)*P(+2)*m(+1))=0;
+W = l/n;
+-(psi/(1-psi))*(c*P/(1-n))+l/n = 0;
+R = P*(1-alp)*exp(-alp*(gam+e_a))*k(-1)^alp*n^(-alp)/W;
+1/(c*P)-bet*P*(1-alp)*exp(-alp*(gam+e_a))*k(-1)^alp*n^(1-alp)/(m*l*c(+1)*P(+1)) = 0;
+c+k = exp(-alp*(gam+e_a))*k(-1)^alp*n^(1-alp)+(1-del)*exp(-(gam+e_a))*k(-1);
+P*c = m;
+m-1+d = l;
+e = exp(e_a);
+y = k(-1)^alp*n^(1-alp)*exp(-alp*(gam+e_a));
+gy_obs = dA*y/y(-1);
+gp_obs = (P/P(-1))*m(-1)/dA;
+end;
+
+initval;
+k = 6;
+m = mst;
+P = 2.25;
+c = 0.45;
+e = 1;
+W = 4;
+R = 1.02;
+d = 0.85;
+n = 0.19;
+l = 0.86;
+y = 0.6;
+gy_obs = exp(gam);
+gp_obs = exp(-gam);
+dA = exp(gam);
+end;
+
+shocks;
+var e_a; stderr 0.014;
+var e_m; stderr 0.005;
+end;
+
+steady;
+
+check;
+
+estimated_params;
+alp, beta_pdf, 0.356, 0.02;
+bet, beta_pdf, 0.993, 0.002;
+gam, normal_pdf, 0.0085, 0.003;
+mst, normal_pdf, 1.0002, 0.007;
+rho, beta_pdf, 0.129, 0.223;
+psi, beta_pdf, 0.65, 0.05;
+del, beta_pdf, 0.01, 0.005;
+stderr e_a, inv_gamma_pdf, 0.035449, inf;
+stderr e_m, inv_gamma_pdf, 0.008862, inf;
+end;
+
+varobs gp_obs gy_obs;
+
+estimation(order=1,datafile=fsdat_simul,nobs=192,loglinear,mh_replic=0,mode_compute=0);
diff --git a/tests/kalman_filter_smoother/fs2000_2.mod b/tests/kalman_filter_smoother/fs2000_2.mod
new file mode 100644
index 000000000..e6c9de570
--- /dev/null
+++ b/tests/kalman_filter_smoother/fs2000_2.mod
@@ -0,0 +1,74 @@
+// See fs2000.mod in the examples/ directory for details on the model
+// For initial value of the parameter, the filter reaches steady state at period 137
+
+var m P c e W R k d n l gy_obs gp_obs y dA;
+varexo e_a e_m;
+
+parameters alp bet gam mst rho psi del;
+
+alp = 0.33;
+bet = 0.99;
+gam = 0.003;
+mst = 1.011;
+rho = 0.7;
+psi = 0.787;
+del = 0.02;
+
+model;
+dA = exp(gam+e_a);
+log(m) = (1-rho)*log(mst) + rho*log(m(-1))+e_m;
+-P/(c(+1)*P(+1)*m)+bet*P(+1)*(alp*exp(-alp*(gam+log(e(+1))))*k^(alp-1)*n(+1)^(1-alp)+(1-del)*exp(-(gam+log(e(+1)))))/(c(+2)*P(+2)*m(+1))=0;
+W = l/n;
+-(psi/(1-psi))*(c*P/(1-n))+l/n = 0;
+R = P*(1-alp)*exp(-alp*(gam+e_a))*k(-1)^alp*n^(-alp)/W;
+1/(c*P)-bet*P*(1-alp)*exp(-alp*(gam+e_a))*k(-1)^alp*n^(1-alp)/(m*l*c(+1)*P(+1)) = 0;
+c+k = exp(-alp*(gam+e_a))*k(-1)^alp*n^(1-alp)+(1-del)*exp(-(gam+e_a))*k(-1);
+P*c = m;
+m-1+d = l;
+e = exp(e_a);
+y = k(-1)^alp*n^(1-alp)*exp(-alp*(gam+e_a));
+gy_obs = dA*y/y(-1);
+gp_obs = (P/P(-1))*m(-1)/dA;
+end;
+
+initval;
+k = 6;
+m = mst;
+P = 2.25;
+c = 0.45;
+e = 1;
+W = 4;
+R = 1.02;
+d = 0.85;
+n = 0.19;
+l = 0.86;
+y = 0.6;
+gy_obs = exp(gam);
+gp_obs = exp(-gam);
+dA = exp(gam);
+end;
+
+shocks;
+var e_a; stderr 0.014;
+var e_m; stderr 0.005;
+end;
+
+steady;
+
+check;
+
+estimated_params;
+alp, beta_pdf, 0.356, 0.02;
+bet, beta_pdf, 0.993, 0.002;
+gam, normal_pdf, 0.0085, 0.003;
+mst, normal_pdf, 1.0002, 0.007;
+rho, beta_pdf, 0.129, 0.223;
+psi, beta_pdf, 0.65, 0.05;
+del, beta_pdf, 0.01, 0.005;
+stderr e_a, inv_gamma_pdf, 0.035449, inf;
+stderr e_m, inv_gamma_pdf, 0.008862, inf;
+end;
+
+varobs gp_obs gy_obs;
+
+estimation(order=1,datafile=fsdat_simul,nobs=192,loglinear,mh_replic=0,mode_compute=0,kalman_algo=2);
diff --git a/tests/kalman_filter_smoother/fs2000a.mod b/tests/kalman_filter_smoother/fs2000a.mod
new file mode 100644
index 000000000..d0bda7c48
--- /dev/null
+++ b/tests/kalman_filter_smoother/fs2000a.mod
@@ -0,0 +1,85 @@
+// See fs2000.mod in the examples/ directory for details on the model
+// This version estimates the model in level rather than in growth rates
+
+var m P c e W R k d n l gy_obs gp_obs Y_obs P_obs y dA;
+varexo e_a e_m;
+
+parameters alp bet gam mst rho psi del;
+
+alp = 0.33;
+bet = 0.99;
+gam = 0.003;
+mst = 1.011;
+rho = 0.7;
+psi = 0.787;
+del = 0.02;
+
+model;
+dA = exp(gam+e_a);
+log(m) = (1-rho)*log(mst) + rho*log(m(-1))+e_m;
+-P/(c(+1)*P(+1)*m)+bet*P(+1)*(alp*exp(-alp*(gam+log(e(+1))))*k^(alp-1)*n(+1)^(1-alp)+(1-del)*exp(-(gam+log(e(+1)))))/(c(+2)*P(+2)*m(+1))=0;
+W = l/n;
+-(psi/(1-psi))*(c*P/(1-n))+l/n = 0;
+R = P*(1-alp)*exp(-alp*(gam+e_a))*k(-1)^alp*n^(-alp)/W;
+1/(c*P)-bet*P*(1-alp)*exp(-alp*(gam+e_a))*k(-1)^alp*n^(1-alp)/(m*l*c(+1)*P(+1)) = 0;
+c+k = exp(-alp*(gam+e_a))*k(-1)^alp*n^(1-alp)+(1-del)*exp(-(gam+e_a))*k(-1);
+P*c = m;
+m-1+d = l;
+e = exp(e_a);
+y = k(-1)^alp*n^(1-alp)*exp(-alp*(gam+e_a));
+gy_obs = dA*y/y(-1);
+gp_obs = (P/P(-1))*m(-1)/dA;
+Y_obs/Y_obs(-1) = gy_obs;
+P_obs/P_obs(-1) = gp_obs;
+end;
+
+initval;
+k = 6;
+m = mst;
+P = 2.25;
+c = 0.45;
+e = 1;
+W = 4;
+R = 1.02;
+d = 0.85;
+n = 0.19;
+l = 0.86;
+y = 0.6;
+gy_obs = exp(gam);
+gp_obs = exp(-gam);
+dA = exp(gam);
+end;
+
+shocks;
+var e_a; stderr 0.014;
+var e_m; stderr 0.005;
+end;
+
+unit_root_vars P_obs Y_obs;
+
+steady;
+
+check;
+
+estimated_params;
+alp, beta_pdf, 0.356, 0.02;
+bet, beta_pdf, 0.993, 0.002;
+gam, normal_pdf, 0.0085, 0.003;
+mst, normal_pdf, 1.0002, 0.007;
+rho, beta_pdf, 0.129, 0.223;
+psi, beta_pdf, 0.65, 0.05;
+del, beta_pdf, 0.01, 0.005;
+stderr e_a, inv_gamma_pdf, 0.035449, inf;
+stderr e_m, inv_gamma_pdf, 0.008862, inf;
+end;
+
+varobs P_obs Y_obs;
+
+observation_trends;
+P_obs (log(mst)-gam);
+Y_obs (gam);
+end;
+
+estimation(order=1,datafile=fsdat_simul,nobs=192,loglinear,mh_replic=0,
+           mode_compute=0,mh_nblocks=2,mh_drop=0.45,mh_jscale=0.65,diffuse_filter,smoother) P_obs gp_obs gy_obs;
+
diff --git a/tests/kalman_filter_smoother/fsdat_simul.m b/tests/kalman_filter_smoother/fsdat_simul.m
new file mode 100644
index 000000000..d4f4a8066
--- /dev/null
+++ b/tests/kalman_filter_smoother/fsdat_simul.m
@@ -0,0 +1,828 @@
+gy_obs          =[
+      1.0030045
+     0.99990934
+      1.0172778
+     0.99464043
+      1.0253423
+      1.0150215
+     0.97772557
+     0.97832186
+      1.0159561
+      1.0085937
+      1.0102649
+      1.0007604
+      1.0112596
+      1.0163279
+      1.0173204
+      1.0103896
+      1.0006493
+     0.99447124
+      1.0196405
+      1.0089304
+     0.99650737
+      1.0139707
+     0.97865842
+      1.0192225
+     0.99139628
+      1.0141362
+      1.0196612
+     0.97483476
+     0.99686151
+     0.99594464
+      1.0000642
+      1.0172243
+      1.0025773
+     0.97199728
+      1.0217815
+      1.0219949
+     0.99490252
+      1.0190728
+      1.0111337
+      1.0003792
+     0.98969164
+       1.010438
+      1.0216309
+      1.0016671
+      1.0357588
+     0.98803787
+      1.0093457
+      1.0177035
+     0.98548204
+      1.0274294
+      1.0141377
+      1.0091174
+     0.96427632
+      1.0083272
+      1.0007882
+     0.99038262
+      1.0031336
+     0.99500213
+     0.98203716
+      0.9889452
+       1.011632
+     0.99451949
+     0.97291047
+     0.98750871
+     0.99992418
+     0.97657318
+     0.99930448
+      1.0008515
+      1.0044064
+     0.98133792
+      1.0091702
+      1.0087023
+      1.0119876
+      1.0143019
+      1.0311061
+     0.99340471
+      1.0057428
+     0.99197259
+      1.0071019
+     0.99448853
+      1.0061819
+      1.0070088
+      0.9950913
+      1.0302318
+      0.9817693
+      1.0072885
+     0.97355282
+     0.98782586
+      1.0136674
+     0.99863956
+      1.0205668
+     0.99611384
+      1.0073805
+     0.99691529
+      1.0089194
+      1.0030467
+      1.0112006
+      1.0260523
+     0.97803331
+     0.99423374
+      1.0043727
+      1.0140173
+      1.0111473
+     0.99524348
+     0.99775943
+      0.9958619
+      0.9982344
+      1.0210212
+      1.0022288
+      1.0014801
+       1.011456
+      1.0124871
+     0.99843599
+     0.99324886
+     0.99912838
+       1.003327
+      1.0072071
+      1.0115223
+       1.009266
+      1.0070554
+      1.0129916
+      1.0053413
+      1.0051638
+     0.99212952
+      1.0214422
+     0.98716707
+     0.99905788
+     0.98877357
+     0.98568476
+     0.99767393
+      1.0061791
+     0.98423439
+     0.99492949
+     0.98786999
+     0.99754239
+      1.0168619
+     0.99472384
+      1.0041658
+     0.98123181
+      1.0112882
+     0.99245422
+      1.0010255
+      1.0017799
+      1.0089968
+      1.0072824
+     0.99768475
+      1.0044726
+      1.0118678
+      1.0056385
+      1.0276965
+      1.0025122
+      1.0065161
+      1.0234338
+     0.99760167
+     0.98922272
+      1.0101918
+       1.011615
+      1.0085286
+      1.0074455
+     0.98866757
+     0.99959012
+      1.0129881
+     0.99127881
+     0.97971901
+      1.0185314
+       1.020054
+      1.0132605
+     0.98063643
+     0.99490253
+      1.0101531
+      1.0004526
+      1.0059109
+     0.98974491
+      1.0062391
+      1.0216488
+     0.99398446
+     0.97786609
+      1.0019274
+     0.99587153
+      1.0095881
+      1.0111887
+     0.99457649
+     0.97896734
+       1.000172
+      1.0142951
+      1.0034224
+      1.0037242
+      1.0016059
+       1.016556
+     0.99687023
+      1.0117844
+      1.0059212
+     0.98083159
+     0.98638851
+      1.0128713
+      1.0096232
+      1.0115891
+      1.0011213
+      1.0147105
+      1.0066344
+      1.0164429
+     0.99825038
+     0.99403411
+
+];
+
+gp_obs          =[
+      1.0079715
+      1.0074573
+      1.0153107
+      1.0152677
+      1.0011653
+     0.99950061
+      1.0328311
+      1.0192317
+       1.009827
+     0.99588916
+       1.007474
+      1.0113061
+     0.98696624
+     0.99978663
+     0.98240542
+     0.98861723
+     0.99008763
+      1.0185076
+      1.0052452
+     0.99447194
+      1.0092685
+        1.01208
+      1.0105237
+     0.98513875
+      1.0165628
+     0.99485934
+      1.0050255
+      1.0140756
+      1.0093128
+      1.0155868
+      1.0107023
+     0.99212762
+      1.0095465
+      1.0028435
+      1.0069437
+      1.0070473
+      1.0145902
+      1.0186922
+      1.0059917
+      1.0113072
+      1.0107386
+     0.99769196
+     0.99793444
+      1.0050791
+     0.98307821
+      1.0107594
+     0.99689982
+     0.98667064
+      0.9991662
+     0.98274722
+     0.98422032
+     0.99393016
+      1.0118567
+     0.99912781
+      1.0023744
+      1.0086662
+      1.0164773
+      1.0169327
+      1.0372478
+      1.0314242
+      1.0004256
+      1.0110541
+      1.0076575
+      1.0119851
+      1.0055188
+      1.0213959
+      1.0234416
+      1.0264917
+      1.0292725
+      1.0385184
+      1.0200999
+      1.0107697
+       1.008583
+      1.0200332
+      1.0030413
+      1.0108659
+      1.0185145
+      1.0168619
+      1.0180462
+      1.0239657
+      1.0205509
+      1.0189973
+      1.0246446
+      1.0135089
+      1.0352973
+      1.0099289
+      1.0266474
+      1.0279829
+      1.0101653
+       1.041216
+      1.0103861
+      1.0114727
+      1.0054605
+      1.0190722
+      1.0114837
+      1.0179213
+       1.006082
+      1.0049696
+      1.0143629
+      0.9971036
+      1.0005602
+      1.0078403
+      1.0240222
+      1.0195063
+      1.0355136
+      1.0218743
+      1.0171331
+      1.0049817
+      1.0140974
+      1.0168431
+      1.0049966
+      1.0045568
+      1.0156414
+      1.0273055
+      1.0197653
+      1.0030624
+      1.0154993
+     0.99782084
+     0.99711648
+       1.014408
+      1.0057417
+     0.99936837
+      1.0096934
+      1.0095138
+      1.0057734
+      1.0114497
+      1.0059784
+      1.0328889
+      1.0098032
+      1.0041114
+      1.0101247
+      1.0181588
+      1.0115712
+      1.0227509
+      1.0065104
+      1.0110902
+      1.0298169
+      1.0089532
+      1.0368733
+      1.0123033
+      1.0060763
+      1.0150937
+      1.0239325
+     0.99555536
+     0.99861271
+      1.0076201
+     0.99941535
+      1.0119522
+      1.0129183
+     0.99288924
+      1.0260784
+      1.0144982
+      1.0121985
+      1.0234916
+        1.02215
+      1.0190118
+      1.0172679
+      1.0118398
+      1.0002123
+      1.0092124
+      1.0071943
+     0.99508468
+      1.0019303
+      1.0030733
+      0.9964198
+      1.0027298
+     0.99797614
+       1.006942
+     0.99793928
+      1.0083214
+      1.0283732
+      1.0111102
+       1.016936
+      1.0229061
+     0.98846454
+      1.0015387
+      1.0201769
+      1.0079822
+      1.0064007
+      1.0095543
+      1.0092207
+      1.0135485
+      1.0198974
+      1.0140252
+      1.0128686
+      1.0092903
+      1.0141974
+      1.0023492
+     0.99731455
+      1.0026598
+     0.99303643
+      1.0036469
+      1.0160975
+      1.0368378
+      1.0139625
+        1.01493
+      1.0113531
+      1.0114548
+     0.99833441
+     0.99648401
+     0.97645361
+      1.0154053
+        1.01703
+
+];
+
+Y_obs           =[
+              1
+     0.99690484
+      1.0111781
+      1.0028141
+      1.0251518
+      1.0371688
+      1.0118899
+     0.98720726
+      1.0001589
+      1.0057481
+      1.0130085
+      1.0107643
+      1.0190194
+      1.0323428
+      1.0466587
+      1.0540438
+      1.0516886
+      1.0431553
+      1.0597913
+      1.0657172
+      1.0592201
+      1.0701863
+      1.0458402
+      1.0620582
+      1.0504499
+      1.0615817
+      1.0782384
+      1.0500687
+      1.0439257
+      1.0368658
+      1.0339255
+      1.0481453
+      1.0477181
+      1.0167109
+      1.0354878
+      1.0544782
+      1.0463762
+      1.0624445
+      1.0705737
+      1.0679484
+      1.0546356
+      1.0620691
+      1.0806955
+      1.0793581
+      1.1121124
+      1.0971458
+      1.1034869
+      1.1181859
+      1.1006634
+      1.1250883
+      1.1362214
+      1.1423343
+      1.1036061
+      1.1089288
+      1.1067125
+      1.0940906
+      1.0942197
+      1.0862174
+        1.06525
+      1.0511907
+      1.0598182
+      1.0513331
+      1.0212391
+      1.0057433
+       1.002663
+     0.97623167
+     0.97253165
+     0.97037865
+     0.97178055
+     0.95011397
+     0.95627969
+     0.96197747
+     0.97096053
+     0.98225794
+      1.0103595
+      1.0007597
+       1.003498
+     0.99246608
+     0.99656347
+     0.98804749
+     0.99122491
+     0.99522926
+     0.98731605
+      1.0145434
+     0.99330816
+     0.99759216
+     0.96814048
+     0.95296183
+     0.96362471
+     0.95925977
+     0.97682205
+     0.96993138
+      0.9743074
+     0.96821818
+     0.97413308
+      0.9741753
+     0.98237142
+      1.0054193
+     0.98044807
+      0.9716773
+      0.9730455
+     0.98405828
+     0.99220103
+     0.98444001
+     0.97919493
+     0.97205233
+     0.96728223
+     0.98529893
+     0.98452324
+     0.98299888
+     0.99145042
+       1.000933
+     0.99636447
+     0.98660883
+     0.98273271
+     0.98305518
+     0.98725774
+     0.99577549
+       1.002037
+      1.0060879
+       1.016075
+      1.0184118
+      1.0205711
+      1.0096961
+      1.0281337
+      1.0122963
+      1.0083497
+     0.99411874
+       0.976799
+     0.97146842
+     0.97464304
+     0.95587292
+     0.94779791
+     0.93266339
+     0.92720128
+     0.94105864
+     0.93277798
+     0.93393927
+     0.91216657
+     0.92045028
+         0.9099
+     0.90792098
+     0.90669634
+     0.91268867
+     0.91696661
+     0.91164685
+     0.91311495
+     0.92197825
+     0.92461222
+     0.94930422
+      0.9488119
+     0.95232353
+     0.97275278
+     0.96734995
+     0.95356817
+     0.96075548
+     0.96936594
+     0.97489002
+     0.97933106
+     0.96499412
+     0.96157973
+     0.97156334
+     0.95983765
+     0.93655215
+     0.95207909
+     0.96912862
+     0.97938462
+     0.95701655
+     0.94891457
+     0.95606317
+     0.95351125
+     0.95641767
+     0.94315807
+     0.94639265
+     0.96503697
+     0.95601693
+     0.93087851
+     0.92980141
+     0.92266844
+     0.92925206
+     0.93743628
+     0.92900826
+      0.9049711
+     0.90213859
+     0.91342916
+     0.91384707
+     0.91456681
+     0.91316822
+     0.92671976
+     0.92058549
+     0.92936541
+     0.93228212
+     0.91010921
+     0.89349322
+     0.90336005
+     0.90997873
+     0.91856328
+     0.91668007
+     0.92838606
+       0.932016
+     0.94545438
+     0.94070026
+     0.93172987
+
+];
+
+P_obs           =[
+              1
+     0.99948573
+      1.0068249
+      1.0141211
+      1.0073149
+     0.99884398
+      1.0237035
+      1.0349636
+       1.036819
+      1.0247366
+      1.0242391
+      1.0275737
+      1.0065684
+     0.99838346
+     0.97281734
+     0.95346302
+      0.9355791
+      0.9461152
+     0.94338882
+     0.92988921
+      0.9311862
+     0.93529467
+     0.93784681
+     0.91501401
+     0.92360522
+     0.91049302
+     0.90754698
+     0.91365103
+     0.91499228
+     0.92260749
+     0.92533824
+     0.90949431
+     0.91106924
+     0.90594116
+     0.90491334
+      0.9039891
+     0.91060772
+     0.92132842
+     0.91934854
+     0.92268418
+     0.92545127
+     0.91517169
+     0.90513459
+     0.90224212
+     0.87734878
+     0.88013667
+     0.86906494
+     0.84776403
+     0.83895869
+     0.81373437
+     0.78998314
+     0.77594176
+     0.77982695
+     0.77098321
+     0.76538611
+     0.76608075
+     0.77458654
+     0.78354767
+     0.81282389
+     0.83627649
+     0.82873051
+     0.83181309
+     0.83149903
+     0.83551261
+     0.83305985
+     0.84648418
+     0.86195421
+     0.88047436
+     0.90177533
+     0.93232215
+     0.94445051
+      0.9472487
+     0.94786015
+     0.95992178
+     0.95499149
+     0.95788581
+      0.9684288
+     0.97731917
+     0.98739379
+      1.0033879
+      1.0159673
+      1.0269931
+      1.0436661
+      1.0492034
+      1.0765292
+      1.0784865
+      1.0971624
+      1.1171737
+      1.1193675
+      1.1526119
+      1.1550265
+      1.1585277
+      1.1560166
+      1.1671172
+      1.1706294
+      1.1805791
+      1.1786896
+      1.1756876
+      1.1820789
+       1.171211
+      1.1637997
+      1.1636684
+       1.179719
+      1.1912538
+      1.2187959
+      1.2326986
+      1.2418602
+      1.2388704
+      1.2449963
+      1.2538678
+      1.2508929
+      1.2474781
+       1.255148
+       1.274482
+      1.2862757
+      1.2813665
+      1.2888943
+      1.2787436
+      1.2678886
+       1.274325
+      1.2720952
+       1.263492
+      1.2652139
+      1.2667561
+       1.264558
+      1.2680362
+      1.2660431
+      1.2909605
+      1.2927921
+       1.288932
+      1.2910852
+      1.3012725
+      1.3048721
+      1.3196515
+      1.3181903
+       1.321309
+      1.3431543
+       1.344136
+      1.3730377
+      1.3773695
+      1.3754742
+      1.3825964
+      1.3985574
+      1.3861412
+      1.3767823
+      1.3764309
+      1.3678747
+      1.3718554
+      1.3768022
+      1.3617199
+      1.3798267
+      1.3863533
+      1.3905803
+      1.4061004
+      1.4202788
+      1.4313191
+      1.4406155
+      1.4444837
+      1.4367244
+      1.4379653
+      1.4371881
+      1.4243012
+        1.41826
+      1.4133617
+        1.40181
+      1.3965683
+      1.3865729
+      1.3855433
+      1.3755111
+      1.3758609
+      1.3962625
+      1.3994012
+      1.4083656
+      1.4233002
+      1.4037932
+      1.3973604
+      1.4095657
+      1.4095764
+      1.4080055
+      1.4095882
+      1.4108374
+      1.4164143
+      1.4283402
+      1.4343939
+      1.4392909
+      1.4406097
+      1.4468355
+      1.4412132
+      1.4305562
+      1.4252445
+      1.4103094
+      1.4059847
+      1.4141106
+      1.4429769
+      1.4489679
+      1.4559263
+      1.4593079
+      1.4627911
+       1.453154
+      1.4416665
+      1.4101485
+      1.4175823
+      1.4266407
+
+];
+
-- 
GitLab