Skip to content
Snippets Groups Projects

Compare revisions

Changes are shown as if the source revision was being merged into the target revision. Learn more about comparing revisions.

Source

Select target project
No results found
Select Git revision

Target

Select target project
  • giovanma/dynare
  • giorgiomas/dynare
  • Vermandel/dynare
  • Dynare/dynare
  • normann/dynare
  • MichelJuillard/dynare
  • wmutschl/dynare
  • FerhatMihoubi/dynare
  • sebastien/dynare
  • lnsongxf/dynare
  • rattoma/dynare
  • CIMERS/dynare
  • FredericKarame/dynare
  • SumuduK/dynare
  • MinjeJeon/dynare
  • camilomrch/dynare
  • DoraK/dynare
  • avtishin/dynare
  • selma/dynare
  • claudio_olguin/dynare
  • jeffjiang07/dynare
  • EthanSystem/dynare
  • stepan-a/dynare
  • wjgatt/dynare
  • JohannesPfeifer/dynare
  • gboehl/dynare
  • chskcau/dynare-doc-fixes
27 results
Select Git revision
Show changes
Showing
with 946 additions and 40 deletions
...@@ -50,13 +50,10 @@ end; ...@@ -50,13 +50,10 @@ end;
steady(nocheck); steady(nocheck);
options_.ep.stochastic.order = 0; //options_.ep.stochastic.order = 0;
set_dynare_seed(2009);
ts = extended_path([], 200, [], options_, M_, oo_); Simulated_time_series = extended_path([], 200, [], options_, M_, oo_);
ts.save('rbcii-sim-data'); Simulated_time_series.save('rbcii-sim-data');
options_.ep.stochastic.order = 1;
ts1_4 = extended_path([], 200, [], options_, M_, oo_);
@#else @#else
......
...@@ -49,9 +49,10 @@ shocks; ...@@ -49,9 +49,10 @@ shocks;
stderr 0.10; stderr 0.10;
end; end;
extended_path(periods=200,lmmcp); set_dynare_seed(2009);
extended_path(periods=200,order=0,lmmcp);
if any(oo_.endo_simul(strmatch('i',M_.endo_names,'exact'),:)<-1e-6) if any(Simulated_time_series.i.data<-1e-6)
error('lmmcp tag did not work.') error('lmmcp tag did not work.')
end end
...@@ -59,10 +60,10 @@ ds = dseries('rbcii-sim-data.mat'); ...@@ -59,10 +60,10 @@ ds = dseries('rbcii-sim-data.mat');
if isoctave if isoctave
tolerance=5e-5; tolerance=5e-5;
else else
tolerance=1e-6; tolerance=1e-5;
end end
if any(abs(transpose(oo_.endo_simul(strmatch('i',M_.endo_names,'exact'),:))-ds.Investment.data)>tolerance) if any(abs(Simulated_time_series.i.data-ds.Investment.data)>tolerance)
error('Simulation with lmmcp returns different results.') error('Simulation with lmmcp returns different results.')
end end
......
...@@ -47,7 +47,7 @@ s2df = 1; ...@@ -47,7 +47,7 @@ s2df = 1;
// form expression for the joint posterior marginal distribution of β, a Gibbs // form expression for the joint posterior marginal distribution of β, a Gibbs
// sampling algorithm is used (the prior for β and the inverse of σ² are independent). // sampling algorithm is used (the prior for β and the inverse of σ² are independent).
gibbslength = 1000000; // Set the number of iterations in Gibbs gibbslength = 300000; // Set the number of iterations in Gibbs
burnin = 10000; // Set the number of iterations to be discarded (try to remove the effects of the initial condition). burnin = 10000; // Set the number of iterations to be discarded (try to remove the effects of the initial condition).
steps = 10; // Do not record all iterations (try to remove the dependence between the draws). steps = 10; // Do not record all iterations (try to remove the dependence between the draws).
......
...@@ -50,14 +50,14 @@ s2df = 1; ...@@ -50,14 +50,14 @@ s2df = 1;
// form expression for the joint posterior marginal distribution of β, a Gibbs // form expression for the joint posterior marginal distribution of β, a Gibbs
// sampling algorithm is used (the prior for β and the inverse of σ² are independent). // sampling algorithm is used (the prior for β and the inverse of σ² are independent).
gibbslength = 1000000; // Set the number of iterations in Gibbs gibbslength = 100000; // Set the number of iterations in Gibbs
burnin = 10000; // Set the number of iterations to be discarded (try to remove the effects of the initial condition). burnin = 10000; // Set the number of iterations to be discarded (try to remove the effects of the initial condition).
steps = 10; // Do not record all iterations (try to remove the dependence between the draws). steps = 10; // Do not record all iterations (try to remove the dependence between the draws).
ds = olsgibbs(ds, 'eqols', beta0, V0, s2priormean, s2df, gibbslength, burnin, steps, {'eqols', 'eqols_olsgibbs_fit'}, 'olsgibbs_eq',{'b2'; 'b3'}); ds = olsgibbs(ds, 'eqols', beta0, V0, s2priormean, s2df, gibbslength, burnin, steps, {'eqols', 'eqols_olsgibbs_fit'}, 'olsgibbs_eq',{'b2'; 'b3'});
// Since we use a diffuse prior for β, the posterior mean of β should be close to the OLS estimate. // Since we use a diffuse prior for β, the posterior mean of β should be close to the OLS estimate.
if max(abs(oo_.ols.ols_eq.beta-oo_.olsgibbs.olsgibbs_eq.posterior.mean.beta))>.1 if max(abs(oo_.ols.ols_eq.beta-oo_.olsgibbs.olsgibbs_eq.posterior.mean.beta))>.01
error('Something is wrong in the Gibbs sampling routine (univariate model)') error('Something is wrong in the Gibbs sampling routine (univariate model)')
end end
......
function [incTestFailed] = expect_error(fn, description, testFailed, show_message)
if nargin < 3
show_message = false;
end
try
fn();
incTestFailed = testFailed+1;
fprintf('❌ Expected error for: %s\n', description);
catch ME
fprintf('✔ Correctly threw error for: %s\n', description);
if show_message
fprintf(' Error message: %s\n', ME.message);
end
incTestFailed = testFailed;
end
end
\ No newline at end of file
heterogeneity_dimension households;
var(heterogeneity=households)
c // Consumption
a // Assets
e // Idiosyncratic (log-)efficiency
Va // Derivative of the value function w.r.t assets
;
varexo(heterogeneity=households) eps_e; // Idiosyncratic efficiency shock
var
r // Rate of return on capital net of depreciation
w // Wage rate
Y // Aggregate output
K // Aggregate capital
Z // Aggregate productivity
;
varexo eps_Z; // Aggregate productivity shock
parameters
L // Labor
alpha // Share of capital in production fuction
beta // Subjective discount rate of houselholds
delta // Capital depreciation rate
eis // Elasticity of intertemporal substitution
rho_e // Earning shock persistence
sig_e // Earning shock innovation std err
rho_Z // Aggregate TFP shock persistence
sig_Z // Aggregate TFP shock innovation std err
Z_ss // Aggregate TFP shock average value
;
model(heterogeneity=households);
c^(-1/eis)-beta*Va(+1)=0 ⟂ a>=0;
(1+r)*a(-1)+w*e-c-a;
Va = (1+r)*c^(-1/eis);
log(e) - rho_e*log(e(-1)) - eps_e;
end;
model;
Z * K(-1)^alpha * L^(1 - alpha) - Y;
alpha * Z * (K(-1) / L)^(alpha - 1) - delta - r;
(1 - alpha) * Z * (K(-1) / L)^alpha - w;
K - SUM(a);
log(Z) - rho_Z*log(Z(-1)) - (1-rho_Z)*log(Z_ss) - eps_Z;
end;
alpha = 0.11;
beta = 0.9819527880123727;
eis = 1;
delta = 0.025;
L = 1;
rho_e = 0.966;
sig_e = 0.5*sqrt(1-rho_e^2);
rho_Z = 0.8;
sig_Z = 0.014;
Z_ss = 0.8816;
shocks(heterogeneity=households);
var eps_e; stderr sig_e;
end;
shocks;
var eps_Z; stderr sig_Z;
end;
verbatim;
skipline()
disp('*** TESTING: hank.check_steady_state_input.m - Discretized AR(1) case ***');
load('ks_ar1_ss.mat');
verbose = true;
options_.hank.nowarningredundant = false;
options_.hank.nowarningdgrids = false;
testFailed = 0;
%% === OUTPUTS ===
try
[out_ss, sizes] = hank.check_steady_state_input(M_, options_, base_struct);
if ~(sizes.n_e == numel(fieldnames(base_struct.shocks.grids)) && ...
sizes.n_a == numel(fieldnames(base_struct.pol.grids)) && ...
sizes.N_e == numel(base_struct.shocks.grids.e) && ...
sizes.n_pol == numel(fieldnames(base_struct.pol.values)) && ...
sizes.agg == numel(fieldnames(base_struct.agg)) && ...
sizes.shocks.e == numel(base_struct.shocks.grids.e) && ...
sizes.pol.N_a == numel(base_struct.pol.grids.a) && ...
sizes.pol.states.a == sizes.pol.N_a && ...
sizes.d.N_a == sizes.pol.N_a && sizes.d.states.a == sizes.pol.states.a)
testFailed = testFailed+1;
dprintf('The `sizes` output is not correct!');
end
if ~(iscolumn(out_ss.shocks.grids.e) && iscolumn(out_ss.pol.grids.a) && ...
iscolumn(out_ss.d.grids.a) && ...
size(out_ss.shocks.grids.e,1) == sizes.shocks.e && ...
size(out_ss.pol.grids.a,1) == sizes.pol.states.a && ...
size(out_ss.d.grids.a,1) == sizes.d.states.a && ...
numel(fieldnames(out_ss.agg)) == sizes.agg)
testFailed = testFailed+1;
dprintf('The `out_ss` output is not correct!');
end
catch ME
testFailed = testFailed+2;
dprintf('Outputs `sizes` or `out_ss` are not correct!')
end
%% === NON-STRUCT FIELDS ===
% ss is not a struct
ss = 123;
testFailed = expect_error(@() hank.check_steady_state_input(M_, options_, ss), ...
'ss is not a struct', testFailed, verbose);
% ss.shocks is not a struct
ss = base_struct;
ss.shocks = 1;
testFailed = expect_error(@() hank.check_steady_state_input(M_, options_, ss), ...
'ss.shocks is not a struct', testFailed, verbose);
% ss.shocks.grids is not a struct
ss = base_struct;
ss.shocks.grids = 42;
testFailed = expect_error(@() hank.check_steady_state_input(M_, options_, ss), ...
'ss.shocks.grids is not a struct', testFailed, verbose);
% ss.shocks.Pi is not a struct
ss = base_struct;
ss.shocks.Pi = "not_a_struct";
testFailed = expect_error(@() hank.check_steady_state_input(M_, options_, ss), ...
'ss.shocks.Pi is not a struct', testFailed, verbose);
% ss.shocks.w is not a struct
ss = base_struct;
ss.shocks = rmfield(ss.shocks, 'Pi');
ss.shocks.w = "not_a_struct";
testFailed = expect_error(@() hank.check_steady_state_input(M_, options_, ss), ...
'ss.shocks.w is not a struct', testFailed, verbose);
% ss.pol is not a struct
ss = base_struct;
ss.pol = pi;
testFailed = expect_error(@() hank.check_steady_state_input(M_, options_, ss), ...
'ss.pol is not a struct', testFailed, verbose);
% ss.pol.grids is not a struct
ss = base_struct;
ss.pol.grids = "grid";
testFailed = expect_error(@() hank.check_steady_state_input(M_, options_, ss), ...
'ss.pol.grids is not a struct', testFailed, verbose);
% ss.pol.values is not a struct
ss = base_struct;
ss.pol.values = "values";
testFailed = expect_error(@() hank.check_steady_state_input(M_, options_, ss), ...
'ss.pol.values is not a struct', testFailed, verbose);
% ss.d is not a struct
ss = base_struct;
ss.d = 1;
testFailed = expect_error(@() hank.check_steady_state_input(M_, options_, ss), ...
'ss.d is not a struct', testFailed, verbose);
% ss.d.grids is not a struct
ss = base_struct;
ss.d.grids = "grid";
testFailed = expect_error(@() hank.check_steady_state_input(M_, options_, ss), ...
'ss.d.grids is not a struct', testFailed, verbose);
% ss.agg is not a struct
ss = base_struct;
ss.agg = 0;
testFailed = expect_error(@() hank.check_steady_state_input(M_, options_, ss), ...
'ss.agg is not a struct', testFailed, verbose);
%% === SHOCKS TESTS ===
% Missing `shocks` field
ss = base_struct;
ss = rmfield(ss, 'shocks');
testFailed = expect_error(@() hank.check_steady_state_input(M_, options_, ss), ...
'Missing `shocks` field', testFailed, verbose);
% Missing `shocks.grids`
ss = base_struct;
ss.shocks = rmfield(ss.shocks, 'grids');
testFailed = expect_error(@() hank.check_steady_state_input(M_, options_, ss), ...
'Missing `shocks.grids`', testFailed, verbose);
% Wrong type for `shocks.grids.e`
ss = base_struct;
ss.shocks.grids.e = ones(3,3); % invalid: cell array
testFailed = expect_error(@() hank.check_steady_state_input(M_, options_, ss), ...
'shocks.grids.e are not dense real vectors', testFailed, verbose);
% Missing both `shocks.Pi` and `shocks.w`
ss = base_struct;
ss.shocks = rmfield(ss.shocks, 'Pi');
testFailed = expect_error(@() hank.check_steady_state_input(M_, options_, ss), ...
'No discretization method (Pi or w) provided', testFailed, verbose);
% Both `shocks.Pi` and `shocks.w` provided (mutual exclusivity)
ss = base_struct;
ss.shocks.w = struct('e', ones(size(ss.shocks.Pi.e,1),1));
testFailed = expect_error(@() hank.check_steady_state_input(M_, options_, ss), ...
'Both Pi and w should not coexist', testFailed, verbose);
% AR(1) Tests
% Shock grid not in var(heterogeneity=) list
ss = base_struct;
ss.shocks.grids.fake_shock = ss.shocks.grids.e;
testFailed = expect_error(@() hank.check_steady_state_input(M_, options_, ss), ...
'Shock grid symbol not in heterogeneity declaration', testFailed, verbose);
% Missing Markov matrix for a shock
ss = base_struct;
ss.shocks.Pi = rmfield(ss.shocks.Pi, 'e');
testFailed = expect_error(@() hank.check_steady_state_input(M_, options_, ss), ...
'Missing Pi entry for a declared shock', testFailed, verbose);
% Wrong type for `shocks.grids.Pi.e`
ss = base_struct;
ss.shocks.Pi.e = speye(numel(ss.shocks.grids.e));
testFailed = expect_error(@() hank.check_steady_state_input(M_, options_, ss), ...
'shocks.Pi.e are not dense real matrices', testFailed, verbose);
% Markov matrix wrong row number
ss = base_struct;
ss.shocks.Pi.e = rand(3, 7); % Should be square matching grid
testFailed = expect_error(@() hank.check_steady_state_input(M_, options_, ss), ...
'Pi row count mismatch with grid', testFailed, verbose);
% Markov matrix wrong column number
ss = base_struct;
ss.shocks.Pi.e = rand(7, 3); % Should be square matching grid
testFailed = expect_error(@() hank.check_steady_state_input(M_, options_, ss), ...
'Pi column count mismatch with grid', testFailed, verbose);
% Markov matrix has negative elements
ss = base_struct;
ss.shocks.Pi.e(1,1) = -0.1;
testFailed = expect_error(@() hank.check_steady_state_input(M_, options_, ss), ...
'Negative elements in Pi', testFailed, verbose);
% Markov matrix does not sum to 1
ss = base_struct;
ss.shocks.Pi.e = ss.shocks.Pi.e * 2;
testFailed = expect_error(@() hank.check_steady_state_input(M_, options_, ss), ...
'Rows of Pi not summing to 1', testFailed, verbose);
%% === POLICY TESTS ===
% Missing `pol` field
ss = base_struct;
ss = rmfield(ss, 'pol');
testFailed = expect_error(@() hank.check_steady_state_input(M_, options_, ss), ...
'Missing `pol` field', testFailed, verbose);
% Missing `pol.grids`
ss = base_struct;
ss.pol = rmfield(ss.pol, 'grids');
testFailed = expect_error(@() hank.check_steady_state_input(M_, options_, ss), ...
'Missing `pol.grids`', testFailed, verbose);
% Missing one state grid
ss = base_struct;
ss.pol.grids = rmfield(ss.pol.grids, 'a');
testFailed = expect_error(@() hank.check_steady_state_input(M_, options_, ss), ...
'Missing state grid for a', testFailed, verbose);
% Wrong type for `pol.grids.a`
ss = base_struct;
ss.pol.grids.a = ones(3, 3); % should be a vector
testFailed = expect_error(@() hank.check_steady_state_input(M_, options_, ss), ...
'pol.grids.a should be a vector', testFailed, verbose);
% Missing `pol.values`
ss = base_struct;
ss.pol = rmfield(ss.pol, 'values');
testFailed = expect_error(@() hank.check_steady_state_input(M_, options_, ss), ...
'Missing `pol.values`', testFailed, verbose);
% Missing policy value for declared variable
ss = base_struct;
ss.pol.values = rmfield(ss.pol.values, 'a');
testFailed = expect_error(@() hank.check_steady_state_input(M_, options_, ss), ...
'Missing policy value for a', testFailed, verbose);
% Wrong type for `pol.values.a`
ss = base_struct;
ss.pol.values.a = rand(2, 2, 2);
testFailed = expect_error(@() hank.check_steady_state_input(M_, options_, ss), ...
'pol.values.a should be a matrix', testFailed, verbose);
% Incompatible policy matrix row size (shocks × states)
ss = base_struct;
ss.pol.values.a = rand(99, size(ss.pol.values.a, 2));
testFailed = expect_error(@() hank.check_steady_state_input(M_, options_, ss), ...
'Wrong number of rows in policy matrix', testFailed, verbose);
% Incompatible policy matrix column size
ss = base_struct;
ss.pol.values.a = rand(size(ss.pol.values.a, 1), 99);
testFailed = expect_error(@() hank.check_steady_state_input(M_, options_, ss), ...
'Wrong number of columns in policy matrix', testFailed, verbose);
%% === DISTRIBUTION TESTS ===
% Missing `d` field
ss = base_struct;
ss = rmfield(ss, 'd');
testFailed = expect_error(@() hank.check_steady_state_input(M_, options_, ss), ...
'Missing distribution structure `d`', testFailed, verbose);
% Wrong type for `ss.d.grids.a`
ss = base_struct;
ss.d.grids.a = rand(3, 3); % not a vector
testFailed = expect_error(@() hank.check_steady_state_input(M_, options_, ss), ...
'd.grids.a should be a vector', testFailed, verbose);
% Missing `d.hist`
ss = base_struct;
ss.d = rmfield(ss.d, 'hist');
testFailed = expect_error(@() hank.check_steady_state_input(M_, options_, ss), ...
'Missing d.hist', testFailed, verbose);
% Wrong type for `ss.d.hist`
ss = base_struct;
ss.d.hist = rand(2,2,2);
testFailed = expect_error(@() hank.check_steady_state_input(M_, options_, ss), ...
'd.hist should be a matrix', testFailed, verbose);
% Wrong row size in `d.hist`
ss = base_struct;
ss.d.hist = rand(99, size(ss.d.hist,2));
testFailed = expect_error(@() hank.check_steady_state_input(M_, options_, ss), ...
'Wrong number of rows in d.hist', testFailed, verbose);
% Wrong column size in `d.hist`
ss = base_struct;
ss.d.hist = rand(size(ss.d.hist,1), 99);
testFailed = expect_error(@() hank.check_steady_state_input(M_, options_, ss), ...
'Wrong number of columns in d.hist', testFailed, verbose);
%% === AGGREGATES TESTS ===
% Missing `agg` field
ss = base_struct;
ss = rmfield(ss, 'agg');
testFailed = expect_error(@() hank.check_steady_state_input(M_, options_, ss), ...
'Missing `agg` field', testFailed, verbose);
% Remove one required aggregate variable
ss = base_struct;
ss.agg = rmfield(ss.agg, 'r'); % remove interest rate
testFailed = expect_error(@() hank.check_steady_state_input(M_, options_, ss), ...
'Missing aggregate variable r', testFailed, verbose);
% Wrong type for `ss.agg.r`
ss = base_struct;
ss.agg.r = 'non-numeric';
testFailed = expect_error(@() hank.check_steady_state_input(M_, options_, ss), ...
'agg.r should be numeric', testFailed, verbose);
%% === PERMUTATION TESTS ===
% pol.shocks is not a string or cellstr
ss = base_struct;
ss.pol.shocks = 123;
testFailed = expect_error(@() hank.check_steady_state_input(M_, options_, ss), ...
'pol.shocks is not a string array or cellstr', testFailed, verbose);
% pol.shocks has wrong names
ss = base_struct;
ss.pol.shocks = {'wrong_name'};
testFailed = expect_error(@() hank.check_steady_state_input(M_, options_, ss), ...
'pol.shocks fieldnames is not consistent', testFailed, verbose);
% pol.states is not a string or cellstr
ss = base_struct;
ss.pol.states = 42;
testFailed = expect_error(@() hank.check_steady_state_input(M_, options_, ss), ...
'pol.states is not a string array or cellstr', testFailed, verbose);
% pol.states has wrong names
ss = base_struct;
ss.pol.states = {'bad_state'};
testFailed = expect_error(@() hank.check_steady_state_input(M_, options_, ss), ...
'pol.states not matching state_var', testFailed, verbose);
% d.shocks is not a string or cellstr
ss = base_struct;
ss.d.shocks = 3.14;
testFailed = expect_error(@() hank.check_steady_state_input(M_, options_, ss), ...
'd.shocks is not a string array or cellstr', testFailed, verbose);
% d.shocks inconsistent with pol.shocks
ss = base_struct;
ss.d.shocks = {'ghost_shock'};
testFailed = expect_error(@() hank.check_steady_state_input(M_, options_, ss), ...
'd.shocks not matching pol.shocks', testFailed, verbose);
% d.states is not a string or cellstr
ss = base_struct;
ss.d.states = true;
testFailed = expect_error(@() hank.check_steady_state_input(M_, options_, ss), ...
'd.states is not a string array or cellstr', testFailed, verbose);
% d.states inconsistent with pol.states
ss = base_struct;
ss.d.states = {'phantom_state'};
testFailed = expect_error(@() hank.check_steady_state_input(M_, options_, ss), ...
'd.states not matching pol.states', testFailed, verbose);
%% === REDUNDANCY TESTS ===
% shocks.Pi contains redundant entry (not in shocks.grids)
ss = base_struct;
ss.shocks.Pi.extra = eye(length(ss.shocks.grids.e)); % not listed in shocks.grids
try
[out_ss, sizes] = hank.check_steady_state_input(M_, options_, ss);
disp('✔ Redundant shocks.Pi entry accepted (warning expected)');
catch ME
testFailed = testFailed+1;
fprintf('❌ Unexpected error from redundant shocks.Pi entry: %s\n', ME.message);
end
% pol.values contains redundant field (not in model's pol_symbs)
ss = base_struct;
ss.pol.values.redundant_var = ones(size(ss.pol.values.a));
try
[out_ss, sizes] = hank.check_steady_state_input(M_, options_, ss);
disp('✔ Redundant pol.values field accepted (warning expected)');
catch ME
testFailed = testFailed+1;
fprintf('❌ Unexpected error from redundant pol.values field: %s\n', ME.message);
end
% d.grids contains redundant field (not a declared state)
ss = base_struct;
ss.d.grids.not_a_state = [0;1;2]; % not in M_.heterogeneity.state_var
try
[out_ss, sizes] = hank.check_steady_state_input(M_, options_, ss);
disp('✔ Redundant d.grids field accepted (warning expected)');
catch ME
testFailed = testFailed+1;
fprintf('❌ Unexpected error from redundant d.grids field: %s\n', ME.message);
end
% agg contains extra field (not in M_.endo_names)
ss = base_struct;
ss.agg.extra_agg = 999;
try
[out_ss, sizes] = hank.check_steady_state_input(M_, options_, ss);
disp('✔ Redundant agg field accepted (warning expected)');
catch ME
testFailed = testFailed+1;
fprintf('❌ Unexpected error from redundant agg field: %s\n', ME.message);
end
skipline()
disp('*** TESTING: hank.check_steady_state_input.m - Discretized i.i.d case ***');
load 'ks_iid_ss.mat';
verbose = true;
%% === OUTPUTS ===
try
[out_ss, sizes] = hank.check_steady_state_input(M_, options_, base_struct);
N_a = numel(base_struct.pol.grids.a)*numel(base_struct.pol.grids.e);
if ~(sizes.n_e == numel(fieldnames(base_struct.shocks.grids)) && ...
sizes.n_a == numel(fieldnames(base_struct.pol.grids)) && ...
sizes.N_e == numel(base_struct.shocks.grids.eps_e) && ...
sizes.n_pol == numel(fieldnames(base_struct.pol.values)) && ...
sizes.agg == numel(fieldnames(base_struct.agg)) && ...
sizes.shocks.eps_e == numel(base_struct.shocks.grids.eps_e) && ...
sizes.pol.N_a == N_a && sizes.pol.states.a == numel(base_struct.pol.grids.a) && ...
sizes.pol.states.e == numel(base_struct.pol.grids.e) && ...
sizes.d.N_a == sizes.pol.N_a && sizes.d.states.a == sizes.pol.states.a)
testFailed = testFailed+1;
dprintf('The `sizes` output is not correct!');
end
if ~(iscolumn(out_ss.shocks.grids.eps_e) && iscolumn(out_ss.pol.grids.a) && ...
iscolumn(out_ss.pol.grids.e) && iscolumn(out_ss.d.grids.a) && ...
iscolumn(out_ss.d.grids.e) && ...
size(out_ss.shocks.grids.eps_e,1) == sizes.shocks.eps_e && ...
size(out_ss.pol.grids.a,1) == sizes.pol.states.a && ...
size(out_ss.pol.grids.e,1) == sizes.pol.states.e && ...
size(out_ss.d.grids.a,1) == sizes.d.states.a && ...
size(out_ss.d.grids.e,1) == sizes.d.states.e && ...
numel(fieldnames(out_ss.agg)) == sizes.agg)
testFailed = testFailed+1;
dprintf('The `out_ss` output is not correct!');
end
catch ME
testFailed = testFailed+2;
dprintf('Outputs `sizes` or `out_ss` are not correct!')
end
%% === NON-STRUCT FIELDS ===
% ss is not a struct
ss = 123;
testFailed = expect_error(@() hank.check_steady_state_input(M_, options_, ss), ...
'ss is not a struct', testFailed, verbose);
% ss.shocks is not a struct
ss = base_struct;
ss.shocks = 1;
testFailed = expect_error(@() hank.check_steady_state_input(M_, options_, ss), ...
'ss.shocks is not a struct', testFailed, verbose);
% ss.shocks.grids is not a struct
ss = base_struct;
ss.shocks.grids = 42;
testFailed = expect_error(@() hank.check_steady_state_input(M_, options_, ss), ...
'ss.shocks.grids is not a struct', testFailed, verbose);
% ss.shocks.w is not a struct
ss = base_struct;
ss.shocks.w = "not_a_struct";
testFailed = expect_error(@() hank.check_steady_state_input(M_, options_, ss), ...
'ss.shocks.w is not a struct', testFailed, verbose);
% ss.pol is not a struct
ss = base_struct;
ss.pol = pi;
testFailed = expect_error(@() hank.check_steady_state_input(M_, options_, ss), ...
'ss.pol is not a struct', testFailed, verbose);
% ss.pol.grids is not a struct
ss = base_struct;
ss.pol.grids = "grid";
testFailed = expect_error(@() hank.check_steady_state_input(M_, options_, ss), ...
'ss.pol.grids is not a struct', testFailed, verbose);
% ss.pol.values is not a struct
ss = base_struct;
ss.pol.values = "values";
testFailed = expect_error(@() hank.check_steady_state_input(M_, options_, ss), ...
'ss.pol.values is not a struct', testFailed, verbose);
% ss.d is not a struct
ss = base_struct;
ss.d = 1;
testFailed = expect_error(@() hank.check_steady_state_input(M_, options_, ss), ...
'ss.d is not a struct', testFailed, verbose);
% ss.d.grids is not a struct
ss = base_struct;
ss.d.grids = "grid";
testFailed = expect_error(@() hank.check_steady_state_input(M_, options_, ss), ...
'ss.d.grids is not a struct', testFailed, verbose);
% ss.agg is not a struct
ss = base_struct;
ss.agg = 0;
testFailed = expect_error(@() hank.check_steady_state_input(M_, options_, ss), ...
'ss.agg is not a struct', testFailed, verbose);
%% === SHOCKS TESTS ===
% Missing `shocks` field
ss = base_struct;
ss = rmfield(ss, 'shocks');
testFailed = expect_error(@() hank.check_steady_state_input(M_, options_, ss), ...
'Missing `shocks` field', testFailed, verbose);
% Missing `shocks.grids`
ss = base_struct;
ss.shocks = rmfield(ss.shocks, 'grids');
testFailed = expect_error(@() hank.check_steady_state_input(M_, options_, ss), ...
'Missing `shocks.grids`', testFailed, verbose);
% Wrong type for `shocks.grids.eps_e`
ss = base_struct;
ss.shocks.grids.eps_e = ones(3,3); % invalid: cell array
testFailed = expect_error(@() hank.check_steady_state_input(M_, options_, ss), ...
'shocks.grids.eps_e are not dense real vectors', testFailed, verbose);
% Missing both `shocks.Pi` and `shocks.w`
ss = base_struct;
ss.shocks = rmfield(ss.shocks, 'w');
testFailed = expect_error(@() hank.check_steady_state_input(M_, options_, ss), ...
'No discretization method (Pi or w) provided', testFailed, verbose);
% Both `shocks.Pi` and `shocks.w` provided (mutual exclusivity)
ss = base_struct;
ss.shocks.Pi = struct('e', ones(size(ss.pol.grids.e,1)));
testFailed = expect_error(@() hank.check_steady_state_input(M_, options_, ss), ...
'Both Pi and w should not coexist', testFailed, verbose);
% AR(1) Tests
% Shock grid not in var(heterogeneity=) list
ss = base_struct;
ss.shocks.grids.fake_shock = ss.shocks.grids.eps_e;
testFailed = expect_error(@() hank.check_steady_state_input(M_, options_, ss), ...
'Shock grid symbol not in heterogeneity declaration', testFailed, verbose);
% Missing Markov matrix for a shock
ss = base_struct;
ss.shocks.w = rmfield(ss.shocks.w, 'eps_e');
testFailed = expect_error(@() hank.check_steady_state_input(M_, options_, ss), ...
'Missing w entry for a declared shock', testFailed, verbose);
% Wrong type for `shocks.grids.w.e`
ss = base_struct;
ss.shocks.w.eps_e = speye(numel(ss.shocks.grids.eps_e));
testFailed = expect_error(@() hank.check_steady_state_input(M_, options_, ss), ...
'shocks.w.eps_e are not dense real vectors', testFailed, verbose);
% Gauss-Hermite weights count
ss = base_struct;
ss.shocks.w.eps_e = rand(sizes.N_e, 1);
testFailed = expect_error(@() hank.check_steady_state_input(M_, options_, ss), ...
' row count mismatch with grid', testFailed, verbose);
% Gauss-Hermite weights have negative elements
ss = base_struct;
ss.shocks.w.eps_e(1) = -0.1;
testFailed = expect_error(@() hank.check_steady_state_input(M_, options_, ss), ...
'Negative elements in Pi', testFailed, verbose);
% Gauss-Hermite weights do not sum to 1
ss = base_struct;
ss.shocks.w.eps_e = ss.shocks.w.eps_e * 2;
testFailed = expect_error(@() hank.check_steady_state_input(M_, options_, ss), ...
'Rows of Pi not summing to 1', testFailed, verbose);
%% === POLICY TESTS ===
% Missing `pol` field
ss = base_struct;
ss = rmfield(ss, 'pol');
testFailed = expect_error(@() hank.check_steady_state_input(M_, options_, ss), ...
'Missing `pol` field', testFailed, verbose);
% Missing `pol.grids`
ss = base_struct;
ss.pol = rmfield(ss.pol, 'grids');
testFailed = expect_error(@() hank.check_steady_state_input(M_, options_, ss), ...
'Missing `pol.grids`', testFailed, verbose);
% Missing one state grid
ss = base_struct;
ss.pol.grids = rmfield(ss.pol.grids, 'a');
testFailed = expect_error(@() hank.check_steady_state_input(M_, options_, ss), ...
'Missing state grid for a', testFailed, verbose);
% Wrong type for `pol.grids.a`
ss = base_struct;
ss.pol.grids.a = ones(3, 3); % should be a vector
testFailed = expect_error(@() hank.check_steady_state_input(M_, options_, ss), ...
'pol.grids.a should be a vector', testFailed, verbose);
% Missing `pol.values`
ss = base_struct;
ss.pol = rmfield(ss.pol, 'values');
testFailed = expect_error(@() hank.check_steady_state_input(M_, options_, ss), ...
'Missing `pol.values`', testFailed, verbose);
% Missing policy value for declared variable
ss = base_struct;
ss.pol.values = rmfield(ss.pol.values, 'a');
testFailed = expect_error(@() hank.check_steady_state_input(M_, options_, ss), ...
'Missing policy value for a', testFailed, verbose);
% Wrong type for `pol.values.a`
ss = base_struct;
ss.pol.values.a = rand(2, 2, 2);
testFailed = expect_error(@() hank.check_steady_state_input(M_, options_, ss), ...
'pol.values.a should be a matrix', testFailed, verbose);
% Incompatible policy matrix row size (shocks × states)
ss = base_struct;
ss.pol.values.a = rand(99, size(ss.pol.values.a, 2));
testFailed = expect_error(@() hank.check_steady_state_input(M_, options_, ss), ...
'Wrong number of rows in policy matrix', testFailed, verbose);
% Incompatible policy matrix column size
ss = base_struct;
ss.pol.values.a = rand(size(ss.pol.values.a, 1), 99);
testFailed = expect_error(@() hank.check_steady_state_input(M_, options_, ss), ...
'Wrong number of columns in policy matrix', testFailed, verbose);
%% === DISTRIBUTION TESTS ===
% Missing `d` field
ss = base_struct;
ss = rmfield(ss, 'd');
testFailed = expect_error(@() hank.check_steady_state_input(M_, options_, ss), ...
'Missing distribution structure `d`', testFailed, verbose);
% Wrong type for `ss.d.grids.a`
ss = base_struct;
ss.d.grids.a = rand(3, 3); % not a vector
testFailed = expect_error(@() hank.check_steady_state_input(M_, options_, ss), ...
'd.grids.a should be a vector', testFailed, verbose);
% Missing `d.hist`
ss = base_struct;
ss.d = rmfield(ss.d, 'hist');
testFailed = expect_error(@() hank.check_steady_state_input(M_, options_, ss), ...
'Missing d.hist', testFailed, verbose);
% Wrong type for `ss.d.hist`
ss = base_struct;
ss.d.hist = rand(2,2,2);
testFailed = expect_error(@() hank.check_steady_state_input(M_, options_, ss), ...
'd.hist should be a matrix', testFailed, verbose);
% Wrong row size in `d.hist`
ss = base_struct;
ss.d.hist = rand(99, size(ss.d.hist,2));
testFailed = expect_error(@() hank.check_steady_state_input(M_, options_, ss), ...
'Wrong number of rows in d.hist', testFailed, verbose);
% Wrong column size in `d.hist`
ss = base_struct;
ss.d.hist = rand(size(ss.d.hist,1), 99);
testFailed = expect_error(@() hank.check_steady_state_input(M_, options_, ss), ...
'Wrong number of columns in d.hist', testFailed, verbose);
%% === AGGREGATES TESTS ===
% Missing `agg` field
ss = base_struct;
ss = rmfield(ss, 'agg');
testFailed = expect_error(@() hank.check_steady_state_input(M_, options_, ss), ...
'Missing `agg` field', testFailed, verbose);
% Remove one required aggregate variable
ss = base_struct;
ss.agg = rmfield(ss.agg, 'r'); % remove interest rate
testFailed = expect_error(@() hank.check_steady_state_input(M_, options_, ss), ...
'Missing aggregate variable r', testFailed, verbose);
% Wrong type for `ss.agg.r`
ss = base_struct;
ss.agg.r = 'non-numeric';
testFailed = expect_error(@() hank.check_steady_state_input(M_, options_, ss), ...
'agg.r should be numeric', testFailed, verbose);
%% === PERMUTATION TESTS ===
% pol.shocks is not a string or cellstr
ss = base_struct;
ss.pol.shocks = 123;
testFailed = expect_error(@() hank.check_steady_state_input(M_, options_, ss), ...
'pol.shocks is not a string array or cellstr', testFailed, verbose);
% pol.shocks has wrong names
ss = base_struct;
ss.pol.shocks = {'wrong_name'};
testFailed = expect_error(@() hank.check_steady_state_input(M_, options_, ss), ...
'pol.shocks not matching exo_names', testFailed, verbose);
% pol.states is not a string or cellstr
ss = base_struct;
ss.pol.states = 42;
testFailed = expect_error(@() hank.check_steady_state_input(M_, options_, ss), ...
'pol.states is not a string array or cellstr', testFailed, verbose);
% pol.states has wrong names
ss = base_struct;
ss.pol.states = {'bad_state'};
testFailed = expect_error(@() hank.check_steady_state_input(M_, options_, ss), ...
'pol.states not matching state_var', testFailed, verbose);
% d.shocks is not a string or cellstr
ss = base_struct;
ss.d.shocks = 3.14;
testFailed = expect_error(@() hank.check_steady_state_input(M_, options_, ss), ...
'd.shocks is not a string array or cellstr', testFailed, verbose);
% d.shocks inconsistent with pol.shocks
ss = base_struct;
ss.d.shocks = {'ghost_shock'};
testFailed = expect_error(@() hank.check_steady_state_input(M_, options_, ss), ...
'd.shocks not matching pol.shocks', testFailed, verbose);
% d.states is not a string or cellstr
ss = base_struct;
ss.d.states = true;
testFailed = expect_error(@() hank.check_steady_state_input(M_, options_, ss), ...
'd.states is not a string array or cellstr', testFailed, verbose);
% d.states inconsistent with pol.states
ss = base_struct;
ss.d.states = {'phantom_state'};
testFailed = expect_error(@() hank.check_steady_state_input(M_, options_, ss), ...
'd.states not matching pol.states', testFailed, verbose);
%% === REDUNDANCY TESTS ===
options_.hank.nowarningredundant = false;
% shocks.w contains redundant entry (not in shocks.grids)
ss = base_struct;
ss.shocks.xtra = ones(length(ss.shocks.grids.eps_e)); % not listed in shocks.grids
try
[out_ss, sizes] = hank.check_steady_state_input(M_, options_, ss);
disp('✔ Redundant shocks.Pi entry accepted (warning expected)');
catch ME
testFailed = testFailed+1;
fprintf('❌ Unexpected error from redundant shocks.Pi entry: %s\n', ME.message);
end
% pol.values contains redundant field (not in model's pol_symbs)
ss = base_struct;
ss.pol.values.redundant_var = ones(size(ss.pol.values.a));
try
[out_ss, sizes] = hank.check_steady_state_input(M_, options_, ss);
disp('✔ Redundant pol.values field accepted (warning expected)');
catch ME
testFailed = testFailed+1;
fprintf('❌ Unexpected error from redundant pol.values field: %s\n', ME.message);
end
% d.grids contains redundant field (not a declared state)
ss = base_struct;
ss.d.grids.not_a_state = [0;1;2]; % not in M_.heterogeneity.state_var
try
[out_ss, sizes] = hank.check_steady_state_input(M_, options_, ss);
disp('✔ Redundant d.grids field accepted (warning expected)');
catch ME
testFailed = testFailed+1;
fprintf('❌ Unexpected error from redundant d.grids field: %s\n', ME.message);
end
% agg contains extra field (not in M_.endo_names)
ss = base_struct;
ss.agg.extra_agg = 999;
try
[out_ss, sizes] = hank.check_steady_state_input(M_, options_, ss);
disp('✔ Redundant agg field accepted (warning expected)');
catch ME
testFailed = testFailed+1;
fprintf('❌ Unexpected error from redundant agg field: %s\n', ME.message);
end
if testFailed > 0
error('Some unit tests associated with the routine `hank.check_steady_state_input` failed!');
end
end;
\ No newline at end of file
Source diff could not be displayed: it is stored in LFS. Options to address this: view the blob.
Source diff could not be displayed: it is stored in LFS. Options to address this: view the blob.
...@@ -97,22 +97,22 @@ plot(id, zeros(1,length(id)), 'or') ...@@ -97,22 +97,22 @@ plot(id, zeros(1,length(id)), 'or')
hold off hold off
figure(4) figure(4)
plot(endogenousvariables.i,'-k','linewidth',2) plot(endogenousvariables(1Y:100Y).i,'-k','linewidth',2)
hold on hold on
plot(SimulatedData.i(1Y:100Y),'--r','linewidth',2) plot(SimulatedData(1Y:100Y).i,'--r','linewidth',2)
hold off hold off
title('Nominal interest rate') title('Nominal interest rate')
figure(5) figure(5)
plot(endogenousvariables.y,'-k','linewidth',2) plot(endogenousvariables(1Y:100Y).y,'-k','linewidth',2)
hold on hold on
plot(SimulatedData.y(1Y:100Y),'--r','linewidth',2) plot(SimulatedData(1Y:100Y).y,'--r','linewidth',2)
hold off hold off
title('Output gap') title('Output gap')
figure(6) figure(6)
plot(endogenousvariables.pi,'-k','linewidth',2) plot(endogenousvariables(1Y:100Y).pi,'-k','linewidth',2)
hold on hold on
plot(SimulatedData.pi(1Y:100Y),'--r','linewidth',2) plot(SimulatedData(1Y:100Y).pi,'--r','linewidth',2)
hold off hold off
title('Inflation gap') title('Inflation gap')
...@@ -7,7 +7,7 @@ estimation(order=1,datafile='Trend_loglin_no_prefilt_first_obs_MC_Exp_AR1_trend_ ...@@ -7,7 +7,7 @@ estimation(order=1,datafile='Trend_loglin_no_prefilt_first_obs_MC_Exp_AR1_trend_
mode_compute=4,silent_optimizer,first_obs=1000,loglinear,smoother,forecast=100,prefilter=0, mode_compute=4,silent_optimizer,first_obs=1000,loglinear,smoother,forecast=100,prefilter=0,
mcmc_jumping_covariance='Trend_loglin_no_prefilt_first_obs_MC_MCMC_jump_covar', mcmc_jumping_covariance='Trend_loglin_no_prefilt_first_obs_MC_MCMC_jump_covar',
filtered_vars, filter_step_ahead = [1,2,4], filtered_vars, filter_step_ahead = [1,2,4],
mh_nblocks=1,mh_jscale=0.3,no_posterior_kernel_density) P_obs Y_obs junk2; mh_nblocks=1,mh_jscale=0.3,no_posterior_kernel_density,nograph,sub_draws=100) P_obs Y_obs junk2;
load('Trend_loglin_no_prefilt_first_obs_MC_Exp_AR1_trend_data_with_constant'); load('Trend_loglin_no_prefilt_first_obs_MC_Exp_AR1_trend_data_with_constant');
@#include "../Trend_load_data_common.inc" @#include "../Trend_load_data_common.inc"
......
...@@ -7,7 +7,7 @@ estimation(order=1,datafile='Trend_loglin_prefilt_first_obs_MC_Exp_AR1_trend_dat ...@@ -7,7 +7,7 @@ estimation(order=1,datafile='Trend_loglin_prefilt_first_obs_MC_Exp_AR1_trend_dat
mode_compute=4,silent_optimizer,first_obs=1000,loglinear,smoother,forecast=100,prefilter=1, mode_compute=4,silent_optimizer,first_obs=1000,loglinear,smoother,forecast=100,prefilter=1,
mcmc_jumping_covariance='Trend_loglin_prefilt_first_obs_MC_MCMC_jump_covar_prefilter', mcmc_jumping_covariance='Trend_loglin_prefilt_first_obs_MC_MCMC_jump_covar_prefilter',
filtered_vars, filter_step_ahead = [1,2,4], filtered_vars, filter_step_ahead = [1,2,4],
mh_nblocks=1,mh_jscale=1e-4,no_posterior_kernel_density) P_obs Y_obs junk2; mh_nblocks=1,mh_jscale=1e-4,no_posterior_kernel_density,nograph,sub_draws=100) P_obs Y_obs junk2;
load('Trend_loglin_prefilt_first_obs_MC_Exp_AR1_trend_data_with_constant'); load('Trend_loglin_prefilt_first_obs_MC_Exp_AR1_trend_data_with_constant');
@#include "../Trend_load_data_common.inc" @#include "../Trend_load_data_common.inc"
......
...@@ -7,7 +7,7 @@ estimation(order=1,datafile='Trend_loglinear_no_prefilter_MC_Exp_AR1_trend_data_ ...@@ -7,7 +7,7 @@ estimation(order=1,datafile='Trend_loglinear_no_prefilter_MC_Exp_AR1_trend_data_
mode_compute=4,silent_optimizer,first_obs=1,loglinear,diffuse_filter,smoother,forecast=100,prefilter=0, mode_compute=4,silent_optimizer,first_obs=1,loglinear,diffuse_filter,smoother,forecast=100,prefilter=0,
mcmc_jumping_covariance='Trend_loglinear_no_prefilter_MC_MCMC_jump_covar', mcmc_jumping_covariance='Trend_loglinear_no_prefilter_MC_MCMC_jump_covar',
filtered_vars, filter_step_ahead = [1,2,4], filtered_vars, filter_step_ahead = [1,2,4],
mh_nblocks=1,mh_jscale=0.3) P_obs Y_obs junk2; mh_nblocks=1,mh_jscale=0.3,no_posterior_kernel_density,nograph,sub_draws=100) P_obs Y_obs junk2;
load('Trend_loglinear_no_prefilter_MC_Exp_AR1_trend_data_with_constant'); load('Trend_loglinear_no_prefilter_MC_Exp_AR1_trend_data_with_constant');
@#include "../Trend_load_data_common.inc" @#include "../Trend_load_data_common.inc"
......
...@@ -7,7 +7,7 @@ estimation(order=1,datafile='Trend_loglinear_prefilter_MC_Exp_AR1_trend_data_wit ...@@ -7,7 +7,7 @@ estimation(order=1,datafile='Trend_loglinear_prefilter_MC_Exp_AR1_trend_data_wit
mode_compute=4,silent_optimizer,first_obs=1,loglinear,smoother,forecast=100,prefilter=1, mode_compute=4,silent_optimizer,first_obs=1,loglinear,smoother,forecast=100,prefilter=1,
mcmc_jumping_covariance='Trend_loglinear_prefilter_MC_MCMC_jump_covar_prefilter', mcmc_jumping_covariance='Trend_loglinear_prefilter_MC_MCMC_jump_covar_prefilter',
filtered_vars, filter_step_ahead = [1,2,4], filtered_vars, filter_step_ahead = [1,2,4],
mh_nblocks=1,mh_jscale=1e-4) P_obs Y_obs junk2; mh_nblocks=1,mh_jscale=1e-4,no_posterior_kernel_density,nograph,sub_draws=100) P_obs Y_obs junk2;
load('Trend_loglinear_prefilter_MC_Exp_AR1_trend_data_with_constant'); load('Trend_loglinear_prefilter_MC_Exp_AR1_trend_data_with_constant');
@#include "../Trend_load_data_common.inc" @#include "../Trend_load_data_common.inc"
......
...@@ -6,7 +6,7 @@ generate_trend_stationary_AR1(M_.fname); ...@@ -6,7 +6,7 @@ generate_trend_stationary_AR1(M_.fname);
estimation(order=1,datafile='Trend_no_prefilter_MC_AR1_trend_data_with_constant',mh_replic=400,silent_optimizer, estimation(order=1,datafile='Trend_no_prefilter_MC_AR1_trend_data_with_constant',mh_replic=400,silent_optimizer,
mode_compute=4,first_obs=1,smoother,mh_nblocks=1,mh_jscale=0.3, mode_compute=4,first_obs=1,smoother,mh_nblocks=1,mh_jscale=0.3,
filtered_vars, filter_step_ahead = [1,2,4], filtered_vars, filter_step_ahead = [1,2,4],
mcmc_jumping_covariance='Trend_no_prefilter_MC_MCMC_jump_covar',forecast=100,prefilter=0) P_obs Y_obs junk2; mcmc_jumping_covariance='Trend_no_prefilter_MC_MCMC_jump_covar',forecast=100,prefilter=0,no_posterior_kernel_density,nograph,sub_draws=100) P_obs Y_obs junk2;
load('Trend_no_prefilter_MC_AR1_trend_data_with_constant'); load('Trend_no_prefilter_MC_AR1_trend_data_with_constant');
@#include "../Trend_load_data_common.inc" @#include "../Trend_load_data_common.inc"
......
...@@ -7,7 +7,7 @@ estimation(order=1,datafile='Trend_no_prefilter_first_obs_MC_AR1_trend_data_with ...@@ -7,7 +7,7 @@ estimation(order=1,datafile='Trend_no_prefilter_first_obs_MC_AR1_trend_data_with
mh_replic=400,mode_compute=4,silent_optimizer,first_obs=1000,smoother,forecast=100,prefilter=0, mh_replic=400,mode_compute=4,silent_optimizer,first_obs=1000,smoother,forecast=100,prefilter=0,
mcmc_jumping_covariance='Trend_no_prefilter_first_obs_MC_MCMC_jump_covar', mcmc_jumping_covariance='Trend_no_prefilter_first_obs_MC_MCMC_jump_covar',
filtered_vars, filter_step_ahead = [1,2,4], filtered_vars, filter_step_ahead = [1,2,4],
mh_nblocks=1,mh_jscale=0.3,no_posterior_kernel_density) P_obs Y_obs junk2; mh_nblocks=1,mh_jscale=0.3,no_posterior_kernel_density,nograph,sub_draws=100) P_obs Y_obs junk2;
load('Trend_no_prefilter_first_obs_MC_AR1_trend_data_with_constant'); load('Trend_no_prefilter_first_obs_MC_AR1_trend_data_with_constant');
@#include "../Trend_load_data_common.inc" @#include "../Trend_load_data_common.inc"
......
...@@ -7,7 +7,7 @@ estimation(order=1,datafile='Trend_prefilter_MC_AR1_trend_data_with_constant',mh ...@@ -7,7 +7,7 @@ estimation(order=1,datafile='Trend_prefilter_MC_AR1_trend_data_with_constant',mh
first_obs=1,smoother,prefilter=1, first_obs=1,smoother,prefilter=1,
mh_nblocks=1,mh_jscale=1e-4, mh_nblocks=1,mh_jscale=1e-4,
filtered_vars, filter_step_ahead = [1,2,4], filtered_vars, filter_step_ahead = [1,2,4],
mcmc_jumping_covariance='Trend_prefilter_MC_MCMC_jump_covar_prefilter',forecast=100) P_obs Y_obs junk2; mcmc_jumping_covariance='Trend_prefilter_MC_MCMC_jump_covar_prefilter',forecast=100,no_posterior_kernel_density,nograph,sub_draws=100) P_obs Y_obs junk2;
load('Trend_prefilter_MC_AR1_trend_data_with_constant'); load('Trend_prefilter_MC_AR1_trend_data_with_constant');
@#include "../Trend_load_data_common.inc" @#include "../Trend_load_data_common.inc"
......
...@@ -7,7 +7,7 @@ estimation(order=1,datafile='Trend_prefilter_first_obs_MC_AR1_trend_data_with_co ...@@ -7,7 +7,7 @@ estimation(order=1,datafile='Trend_prefilter_first_obs_MC_AR1_trend_data_with_co
first_obs=1000,smoother,prefilter=1, first_obs=1000,smoother,prefilter=1,
mh_nblocks=1,mh_jscale=1e-4, mh_nblocks=1,mh_jscale=1e-4,
filtered_vars, filter_step_ahead = [1,2,4], filtered_vars, filter_step_ahead = [1,2,4],
mcmc_jumping_covariance='Trend_prefilter_first_obs_MC_MCMC_jump_covar_prefilter',forecast=100,no_posterior_kernel_density) P_obs Y_obs junk2; mcmc_jumping_covariance='Trend_prefilter_first_obs_MC_MCMC_jump_covar_prefilter',forecast=100,no_posterior_kernel_density,nograph,sub_draws=100) P_obs Y_obs junk2;
load('Trend_prefilter_first_obs_MC_AR1_trend_data_with_constant'); load('Trend_prefilter_first_obs_MC_AR1_trend_data_with_constant');
@#include "../Trend_load_data_common.inc" @#include "../Trend_load_data_common.inc"
......
...@@ -389,13 +389,22 @@ varobs yg inom pi; ...@@ -389,13 +389,22 @@ varobs yg inom pi;
else else
disp('smoother redux successfully recovers full k-step ahead variables results!') disp('smoother redux successfully recovers full k-step ahead variables results!')
end end
//run PKF with MCMC
options_.smoother_redux=false;
estimation(
datafile=dataobsfile2, mode_file=NKM_mh_mode_saved,
mode_compute=0, nobs=120, first_obs=1,
mh_replic=50, plot_priors=0, smoother,
consider_all_endogenous,heteroskedastic_filter,filter_step_ahead=[1:8],smoothed_state_uncertainty);
// use inversion filter (note that IF provides smoother together with likelihood) // use inversion filter (note that IF provides smoother together with likelihood)
occbin_setup(likelihood_inversion_filter,smoother_inversion_filter); occbin_setup(likelihood_inversion_filter,smoother_inversion_filter);
estimation( estimation(
datafile=dataobsfile2, mode_file=NKM_mh_mode_saved, datafile=dataobsfile2, mode_file=NKM_mh_mode_saved,
mode_compute=0, nobs=120, first_obs=1, mode_compute=0, nobs=120, first_obs=1,
mh_replic=0, plot_priors=0, smoother, mh_replic=50, plot_priors=0, smoother,
consider_all_endogenous,heteroskedastic_filter,filter_step_ahead=[1:8],smoothed_state_uncertainty); consider_all_endogenous,heteroskedastic_filter,filter_step_ahead=[1:8],smoothed_state_uncertainty);
// show initial condition effect of IF // show initial condition effect of IF
...@@ -417,6 +426,12 @@ varobs yg inom pi; ...@@ -417,6 +426,12 @@ varobs yg inom pi;
legend('PKF','IF') legend('PKF','IF')
occbin_write_regimes(smoother); occbin_write_regimes(smoother);
estimation(
datafile=dataobsfile2, mode_file=NKM_mh_mode_saved,
mode_compute=0, nobs=120, first_obs=1,
mh_replic=50, plot_priors=0, smoother,
consider_all_endogenous,heteroskedastic_filter,filter_step_ahead=[1:8],smoothed_state_uncertainty);
write_latex_dynamic_model; write_latex_dynamic_model;
collect_latex_files; collect_latex_files;
[status, cmdout]=system(['pdflatex -halt-on-error -interaction=nonstopmode ' M_.fname '_TeX_binder.tex']); [status, cmdout]=system(['pdflatex -halt-on-error -interaction=nonstopmode ' M_.fname '_TeX_binder.tex']);
......
...@@ -8,7 +8,7 @@ ...@@ -8,7 +8,7 @@
@#endif @#endif
@#ifndef ALGO_SIR @#ifndef ALGO_SIR
@#define ALGO_SIR = 1 @#define ALGO_SIR = 0
@#endif @#endif
@#ifndef ALGO_APF @#ifndef ALGO_APF
...@@ -24,7 +24,7 @@ ...@@ -24,7 +24,7 @@
@#endif @#endif
@#ifndef ALGO_ONLINE @#ifndef ALGO_ONLINE
@#define ALGO_ONLINE = 0 @#define ALGO_ONLINE = 1
@#endif @#endif
@#ifndef MCMC @#ifndef MCMC
...@@ -105,7 +105,7 @@ varobs y l i ; ...@@ -105,7 +105,7 @@ varobs y l i ;
%datatomfile('mysample') %datatomfile('mysample')
%return; %return;
data(file='./mysample.m',first_obs=801Y,nobs=200); %no measurement errors added in the simulated data data(file='./mysample.m',first_obs=801Y,nobs=50); %no measurement errors added in the simulated data
@#if LINEAR_KALMAN @#if LINEAR_KALMAN
estimation(nograph,order=1,mode_compute=8,silent_optimizer,mh_replic=0,additional_optimizer_steps=[8 4],mode_check); estimation(nograph,order=1,mode_compute=8,silent_optimizer,mh_replic=0,additional_optimizer_steps=[8 4],mode_check);
...@@ -150,9 +150,12 @@ estimation(order=3,nograph,filter_algorithm=gf,proposal_approximation=montecarlo ...@@ -150,9 +150,12 @@ estimation(order=3,nograph,filter_algorithm=gf,proposal_approximation=montecarlo
@#endif @#endif
@#if ALGO_ONLINE @#if ALGO_ONLINE
estimation(order=1,nograph,mode_compute=11,mh_replic=0,particle_filter_options=('liu_west_delta',0.9)); % estimation(order=1,nograph,mode_compute=11,mh_replic=0,particle_filter_options=('liu_west_delta',0.9));
estimation(order=2,nograph,number_of_particles=10000,mode_compute=11,mh_replic=0,particle_filter_options=('liu_west_delta',0.9)); % estimation(order=2,nograph,number_of_particles=10000,mode_compute=11,mh_replic=0,particle_filter_options=('liu_west_delta',0.9));
estimation(order=3,nograph,number_of_particles=10000,mode_compute=11,mh_replic=0,particle_filter_options=('liu_west_delta',0.9)); % estimation(order=3,nograph,number_of_particles=10000,mode_compute=11,mh_replic=0,particle_filter_options=('liu_west_delta',0.9));
estimation(order=1,posterior_sampling_method='online',posterior_sampler_options=('particles',1000));
estimation(order=2,posterior_sampling_method='online',posterior_sampler_options=('particles',1000));
estimation(order=3,posterior_sampling_method='online',filter_algorithm=nlkf,proposal_approximation=montecarlo,number_of_particles=100,posterior_sampler_options=('particles',100));
@#endif @#endif
@#if MCMC @#if MCMC
...@@ -187,9 +190,7 @@ estimation(order=3,filter_algorithm=nlkf,number_of_particles=10000,proposal_appr ...@@ -187,9 +190,7 @@ estimation(order=3,filter_algorithm=nlkf,number_of_particles=10000,proposal_appr
@#endif @#endif
@#if SMC @#if SMC
% estimation(order=1,nograph,posterior_sampling_method='hssmc'); estimation(order=1,posterior_sampling_method='hssmc',posterior_sampler_options=('particles',1000));
% estimation(order=2,nograph,posterior_sampling_method='hssmc',filter_algorithm=nlkf,proposal_approximation=montecarlo); estimation(order=2,posterior_sampling_method='hssmc',posterior_sampler_options=('particles',1000));
% estimation(order=2,nograph,posterior_sampling_method='hssmc',number_of_particles=10000); estimation(order=3,posterior_sampling_method='hssmc',filter_algorithm=nlkf,proposal_approximation=montecarlo,number_of_particles=500,posterior_sampler_options=('particles',500));
% estimation(order=3,nograph,posterior_sampling_method='hssmc',number_of_particles=10000,filter_algorithm=apf,resampling=none);%,posterior_sampler_options=('particles',1000));
estimation(order=3,nograph,posterior_sampling_method='hssmc',filter_algorithm=nlkf,proposal_approximation=montecarlo);
@#endif @#endif
//File testing error message if initial state vector is not positive definite
@#include "first_spec_common.inc"
varobs q ca;
shocks;
var eeps = 0.04^2;
var nnu = 0.03^2;
var q = 0.01^2;
var ca = 0.01^2;
end;
stoch_simul(order=3,periods=200, irf=0);
send_endogenous_variables_to_workspace;
save('my_data.mat','q','ca');
estimation(datafile='my_data.mat',order=2,mode_compute=0,mh_replic=0,filter_algorithm=sis,nonlinear_filter_initialization=2
,cova_compute=0, %tell program that no covariance matrix was computed
posterior_sampling_method='hssmc',
posterior_sampler_options=('steps',5,
'lambda',2,
'particles', 200,
'scale',.5,
'target', .25)
);
\ No newline at end of file