Skip to content
GitLab
Menu
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
Marco Ratto
dynare
Commits
91b4cfd3
Commit
91b4cfd3
authored
Jul 15, 2020
by
MichelJuillard
Browse files
fixes handling of periods in histval_file/initval_file
parent
a9fea692
Changes
3
Hide whitespace changes
Inline
Side-by-side
matlab/histvalf.m
View file @
91b4cfd3
...
...
@@ -30,29 +30,6 @@ function [endo_histval, exo_histval, exo_det_histval] = histvalf(M, options)
% You should have received a copy of the GNU General Public License
% along with Dynare. If not, see <http://www.gnu.org/licenses/>.
if
~
isfield
(
options
,
'nobs'
)
||
isempty
(
options
.
nobs
)
options
.
nobs
=
M
.
orig_maximum_lag
;
end
if
~
isfield
(
options
,
'first_obs'
)
||
isempty
(
options
.
first_obs
)
if
isfield
(
options
,
'first_simulation_period'
)
options
.
first_obs
=
options
.
first_simulation_period
...
-
options
.
nobs
;
else
options
.
first_obs
=
1
;
end
elseif
isfield
(
options
,
'first_simulation_period'
)
nobs
=
options
.
first_simulation_period
-
opions_
.
first_obs
;
if
options
.
nobs
~=
nobs
error
(
sprintf
([
'HISTVALF: first_obs = %d and'
,
...
' first_simulation_period = %d'
,
...
' don
''
t provide for the number of'
...
' lags in the model.'
],
...
options
.
first_obs
,
...
options
.
first_simulation_period
))
end
end
series
=
histvalf_initvalf
(
'HISTVAL'
,
M
,
options
);
% capture the difference between stochastic and
% perfect foresight setup
...
...
matlab/histvalf_initvalf.m
View file @
91b4cfd3
...
...
@@ -129,6 +129,24 @@ nobs0 = series.nobs;
first_obs_ispresent
=
false
;
last_obs_ispresent
=
false
;
if
~
isfield
(
options
,
'first_obs'
)
||
isempty
(
options
.
first_obs
)
if
isfield
(
options
,
'first_simulation_period'
)
options
.
first_obs
=
options
.
first_simulation_period
...
-
M
.
orig_maximum_lag
;
end
elseif
isfield
(
options
,
'first_simulation_period'
)
nobs
=
options
.
first_simulation_period
-
opions_
.
first_obs
;
if
M
.
orig_maximum_lag
~=
nobs
error
(
sprintf
([
'HISTVALF: first_obs = %d and'
,
...
' first_simulation_period = %d'
,
...
' don
''
t provide for the number of'
...
' lags in the model.'
],
...
options
.
first_obs
,
...
options
.
first_simulation_period
))
end
end
if
isfield
(
options
,
'first_obs'
)
i
=
options
.
first_obs
;
if
i
<
1
...
...
tests/histval_initval_file/sim_exo_lead_lag_initvalf.mod
View file @
91b4cfd3
...
...
@@ -24,6 +24,12 @@ model;
end;
initval_file(series = ds);
if oo_.initval_series.dates(1) ~= dates('1Y');
error("Wrong initial date in oo_.initval_series");
end;
if oo_.initval_series{'x'}.data(6) ~= 0.9;
error("Wrond value for x");
end;
perfect_foresight_setup(periods=200);
perfect_foresight_solver(maxit=100);
...
...
@@ -42,6 +48,55 @@ data1(8, 6) = 0.9; //shock to x in period 2
ds1 = dseries(data1, '1Y', {'c', 'cmav', 'k', 'z_backward', 'z_forward', 'x'});
initval_file(series = ds1, first_obs = 3, last_obs = 210, nobs = 208);
if oo_.initval_series.dates(1) ~= dates('1Y');
error("Wrong initial date in oo_.initval_series");
end;
if oo_.initval_series{'x'}.data(6) ~= 0.9;
error("Wrond value for x");
end;
perfect_foresight_setup(periods=200);
perfect_foresight_solver(maxit=100);
if ~oo_.deterministic_simulation.status
error('Perfect foresight simulation failed');
end
base_results=load('sim_exo_lead_lag_results.mat');
if max(max(abs(base_results.oo_.endo_simul(1:5,:) - oo_.endo_simul(1:5,:)))) > 1e-8
error('Simulation with leads and lags doesn''t match the one with auxiliary variables')
end
initval_file(series = ds1, first_obs = 3Y, last_obs = 210Y, nobs = 208);
if oo_.initval_series.dates(1) ~= dates('3Y');
error("Wrong initial date in oo_.initval_series");
end;
if oo_.initval_series{'x'}.data(6) ~= 0.9;
error("Wrond value for x");
end;
perfect_foresight_setup(periods=200);
perfect_foresight_solver(maxit=100);
if ~oo_.deterministic_simulation.status
error('Perfect foresight simulation failed');
end
base_results=load('sim_exo_lead_lag_results.mat');
if max(max(abs(base_results.oo_.endo_simul(1:5,:) - oo_.endo_simul(1:5,:)))) > 1e-8
error('Simulation with leads and lags doesn''t match the one with auxiliary variables')
end
initval_file(series = ds1, first_simulation_period = 7);
if oo_.initval_series.dates(1) ~= dates('1Y');
error("Wrong initial date in oo_.initval_series");
end;
if oo_.initval_series{'x'}.data(6) ~= 0.9;
error("Wrond value for x");
end;
perfect_foresight_setup(periods=200);
perfect_foresight_solver(maxit=100);
...
...
@@ -54,3 +109,25 @@ base_results=load('sim_exo_lead_lag_results.mat');
if max(max(abs(base_results.oo_.endo_simul(1:5,:) - oo_.endo_simul(1:5,:)))) > 1e-8
error('Simulation with leads and lags doesn''t match the one with auxiliary variables')
end
initval_file(series = ds1, first_simulation_period = 7Y);
if oo_.initval_series.dates(1) ~= dates('1Y');
error("Wrong initial date in oo_.initval_series");
end;
if oo_.initval_series{'x'}.data(6) ~= 0.9;
error("Wrond value for x");
end;
perfect_foresight_setup(periods=200);
perfect_foresight_solver(maxit=100);
if ~oo_.deterministic_simulation.status
error('Perfect foresight simulation failed');
end
base_results=load('sim_exo_lead_lag_results.mat');
if max(max(abs(base_results.oo_.endo_simul(1:5,:) - oo_.endo_simul(1:5,:)))) > 1e-8
error('Simulation with leads and lags doesn''t match the one with auxiliary variables')
end
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment