| 1 |
function test_solve_functionality(M_, oo_, G, varargin) |
| 2 |
% Test heterogeneity.solve functionality and SSJ validation |
| 3 |
% |
| 4 |
% INPUTS |
| 5 |
% - M_ [structure]: Dynare model structure |
| 6 |
% - options_ [structure]: Dynare options structure |
| 7 |
% - oo_ [structure]: Dynare results structure |
| 8 |
% - ss [structure]: steady-state structure |
| 9 |
% - G [structure]: SSJ general equilibrium Jacobians for validation |
| 10 |
% - varargin [optional]: |
| 11 |
% varargin{1} - flag: if true, assert on validation errors (default: true) |
| 12 |
if nargin>3 && ~isempty(varargin{1}) |
| 13 |
flag = varargin{1}; |
| 14 |
else |
| 15 |
flag = true; |
| 16 |
end |
| 17 |
|
| 18 |
% Check that oo_.heterogeneity.dr structure contains expected fields |
| 19 |
assert(isfield(oo_.heterogeneity, 'dr'), 'oo_.heterogeneity.dr field missing'); |
| 20 |
dr = oo_.heterogeneity.dr; |
| 21 |
assert(isfield(dr, 'G'), 'dr.G field missing'); |
| 22 |
assert(isfield(dr, 'J_ha'), 'dr.J_ha field missing'); |
| 23 |
assert(isfield(dr, 'F'), 'dr.F field missing'); |
| 24 |
assert(isfield(dr, 'J'), 'dr.J field missing'); |
| 25 |
assert(isfield(dr, 'curlyYs'), 'dr.curlyYs field missing'); |
| 26 |
assert(isfield(dr, 'curlyDs'), 'dr.curlyDs field missing'); |
| 27 |
|
| 28 |
% Test comparison with SSJ results |
| 29 |
% General-equilibrium Jacobians comparison |
| 30 |
vars = intersect(fieldnames(G), fieldnames(dr.G)); |
| 31 |
for i=1:numel(vars) |
| 32 |
v = vars{i}; |
| 33 |
% Loop over shocks |
| 34 |
for j=1:M_.exo_nbr |
| 35 |
e = M_.exo_names{j}; |
| 36 |
M = abs(dr.G.(v).(e) - G.(v).(e)); |
| 37 |
fprintf('G.%s.%s vs SSJ reference residual: %.2e\n', v, e, max(M(:))); |
| 38 |
if flag |
| 39 |
assert(max(M(:)) <= 1e-3, sprintf('G.%s.%s differs from SSJ reference', v, e)); |
| 40 |
end |
| 41 |
end |
| 42 |
end |
| 43 |
end |