Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
MichelJuillard
dynare
Commits
c6bac390
Commit
c6bac390
authored
Apr 21, 2017
by
Houtan Bastani
Browse files
add exogenous steady state to dynamic function call. #825
parent
8c469213
Changes
25
Hide whitespace changes
Inline
Side-by-side
matlab/discretionary_policy_1.m
View file @
c6bac390
function
[
dr
,
ys
,
info
]
=
discretionary_policy_1
(
oo_
,
Instruments
)
% Copyright (C) 2007-201
6
Dynare Team
% Copyright (C) 2007-201
7
Dynare Team
%
% This file is part of Dynare.
%
...
...
@@ -86,7 +86,8 @@ if exo_nbr == 0
end
[
junk
,
jacobia_
]
=
feval
([
M_
.
fname
'_dynamic'
],
z
,
[
zeros
(
size
(
oo_
.
exo_simul
))
...
oo_
.
exo_det_simul
],
M_
.
params
,
zeros
(
endo_nbr
,
1
),
it_
);
oo_
.
exo_det_simul
],
M_
.
params
,
zeros
(
endo_nbr
,
1
),
...
zeros
(
exo_nbr
,
1
),
it_
);
if
any
(
junk
~=
0
)
error
([
'discretionary_policy: the model must be written in deviation '
...
'form and not have constant terms'
])
...
...
matlab/dyn_risky_steadystate_solver.m
View file @
c6bac390
...
...
@@ -62,7 +62,7 @@ function [dr,info] = dyn_risky_steadystate_solver(ys0,M, ...
%!
@end
deftypefn
%
@eod
:
%
Copyright
(
C
)
2001
-
201
2
Dynare
Team
%
Copyright
(
C
)
2001
-
201
7
Dynare
Team
%
%
This
file
is
part
of
Dynare
.
%
...
...
@@ -162,7 +162,8 @@ function [resid,dr] = risky_residuals(ys,pm,M,dr,options,oo)
z
=
z
(
iyr0
)
;
[
resid1
,
d1
,
d2
]
=
feval
([
M
.
fname
'
_dynamic
'
],
z
,...
[
oo
.
exo_simul
...
oo
.
exo_det_simul
],
M
.
params
,
dr
.
ys
,
2
);
oo
.
exo_det_simul
],
M
.
params
,
dr
.
ys
,
oo
.
exo_steady_state
,
...
2
);
if
~
isreal
(
d1
)
||
~
isreal
(
d2
)
pause
end
...
...
@@ -222,7 +223,8 @@ function [resid,dr] = risky_residuals_ds(x,pm,M,dr,options,oo)
z
=
z
(
iyr0
)
;
[
resid1
,
d1
,
d2
]
=
feval
([
M
.
fname
'
_dynamic
'
],
z
,...
[
oo
.
exo_simul
...
oo
.
exo_det_simul
],
M
.
params
,
dr
.
ys
,
2
);
oo
.
exo_det_simul
],
M
.
params
,
dr
.
ys
,
oo
.
exo_steady_state
,
...
2
);
if
~
isreal
(
d1
)
||
~
isreal
(
d2
)
pause
end
...
...
@@ -255,7 +257,8 @@ function dr_np = first_step_ds(x,pm,M,dr,options,oo)
z
=
z
(
iyr0
)
;
[
resid1
,
d1
,
d2
]
=
feval
([
M
.
fname
'
_dynamic
'
],
z
,...
[
oo
.
exo_simul
...
oo
.
exo_det_simul
],
M
.
params
,
dr
.
ys
,
2
);
oo
.
exo_det_simul
],
M
.
params
,
dr
.
ys
,
oo
.
exo_steady_state
,
...
2
);
if
~
isreal
(
d1
)
||
~
isreal
(
d2
)
pause
end
...
...
@@ -296,7 +299,8 @@ function [resid,dr] = risky_residuals_k_order(ys,pm,M,dr,options,oo)
z
=
z
(
iyr0
)
;
[
resid1
,
d1
,
d2
]
=
feval
([
M
.
fname
'
_dynamic
'
],
z
,...
[
oo
.
exo_simul
...
oo
.
exo_det_simul
],
M
.
params
,
dr
.
ys
,
2
);
oo
.
exo_det_simul
],
M
.
params
,
dr
.
ys
,
oo
.
exo_steady_state
,
...
2
);
if
isfield
(
options
,
'
portfolio
'
)
&&
options
.
portfolio
==
1
eq_np
=
pm
.
eq_np
;
...
...
@@ -331,7 +335,8 @@ function [resid,dr] = risky_residuals_k_order(ys,pm,M,dr,options,oo)
if
nargout
>
1
[
resid1
,
d1
,
d2
,
d3
]
=
feval
([
M
.
fname
'
_dynamic
'
],
z
,...
[
oo
.
exo_simul
...
oo
.
exo_det_simul
],
M
.
params
,
dr
.
ys
,
2
);
oo
.
exo_det_simul
],
M
.
params
,
dr
.
ys
,
oo
.
exo_steady_state
,
...
2
);
[
a
,
b
,
c
]
=
find
(
d2
(
eq_np
,
pm
.
i_d2_np
));
...
...
matlab/evaluate_max_dynamic_residual.m
View file @
c6bac390
function
err
=
evaluate_max_dynamic_residual
(
model_dynamic
,
Y
,
exogenous_variables
,
params
,
steady_state
,
periods
,
ny
,
max_lag
,
lead_lag_incidence
)
function
err
=
evaluate_max_dynamic_residual
(
model_dynamic
,
Y
,
exogenous_variables
,
params
,
steady_state
,
steady_state_x
,
periods
,
ny
,
max_lag
,
lead_lag_incidence
)
% Copyright (C) 2013 Dynare Team
% Copyright (C) 2013
-2017
Dynare Team
%
% This file is part of Dynare.
%
...
...
@@ -23,7 +23,7 @@ i_cols = find(lead_lag_incidence');
err
=
0
;
for
it
=
(
max_lag
+
1
):(
max_lag
+
periods
)
d
=
model_dynamic
(
Y
(
i_cols
),
exogenous_variables
,
params
,
steady_state
,
it
);
d
=
model_dynamic
(
Y
(
i_cols
),
exogenous_variables
,
params
,
steady_state
,
steady_state_x
,
it
);
i_rows
=
i_rows
+
ny
;
i_cols
=
i_cols
+
ny
;
r
=
max
(
abs
(
d
));
...
...
matlab/evaluate_steady_state.m
View file @
c6bac390
...
...
@@ -22,7 +22,7 @@ function [ys,params,info] = evaluate_steady_state(ys_init,M,options,oo,steadysta
% SPECIAL REQUIREMENTS
% none
% Copyright (C) 2001-201
6
Dynare Team
% Copyright (C) 2001-201
7
Dynare Team
%
% This file is part of Dynare.
%
...
...
@@ -313,12 +313,13 @@ function [ys,params,info] = evaluate_steady_state(ys_init,M,options,oo,steadysta
[
chck
,
r
,
junk
]
=
bytecode
(
'dynamic'
,
'evaluate'
,
z
,
zx
,
M
.
params
,
ys
,
1
);
mexErrCheck
(
'bytecode'
,
chck
);
elseif
options
.
block
[
r
,
oo
.
dr
]
=
feval
([
M
.
fname
'_dynamic'
],
z
'
,
zx
,
M
.
params
,
ys
,
M
.
maximum_lag
+
1
,
oo
.
dr
);
[
r
,
oo
.
dr
]
=
feval
([
M
.
fname
'_dynamic'
],
z
'
,
zx
,
M
.
params
,
ys
,
...
M
.
maximum_lag
+
1
,
oo
.
dr
);
else
iyv
=
M
.
lead_lag_incidence
'
;
iyr0
=
find
(
iyv
(:));
xys
=
z
(
iyr0
);
r
=
feval
([
M
.
fname
'_dynamic'
],
z
(
iyr0
),
zx
,
M
.
params
,
ys
,
M
.
maximum_lag
+
1
);
r
=
feval
([
M
.
fname
'_dynamic'
],
z
(
iyr0
),
zx
,
M
.
params
,
ys
,
oo
.
exo_steady_state
,
M
.
maximum_lag
+
1
);
end
% Fail if residual greater than tolerance
...
...
matlab/getH.m
View file @
c6bac390
...
...
@@ -32,7 +32,7 @@ function [H, dA, dOm, Hss, gp, d2A, d2Om, H2ss] = getH(A, B, estim_params_,M_,oo
% H2s: Hessian of steady state with respect to estimated
% structural parameters only (indx)
% Copyright (C) 2010-201
6
Dynare Team
% Copyright (C) 2010-201
7
Dynare Team
%
% This file is part of Dynare.
%
...
...
@@ -125,7 +125,7 @@ end
if
kronflag
==-
2
,
if
nargout
>
5
,
[
residual
,
g1
,
g2
]
=
feval
([
M_
.
fname
,
'_dynamic'
],
yy0
,
oo_
.
exo_steady_state
'
,
...
M_
.
params
,
oo_
.
dr
.
ys
,
1
);
M_
.
params
,
oo_
.
dr
.
ys
,
oo_
.
exo_steady_state
,
1
);
g22
=
hessian_sparse
(
'thet2tau'
,[
M_
.
params
(
indx
)],
options_
.
gstep
,
estim_params_
,
M_
,
oo_
,
indx
,[],
-
1
);
H2ss
=
full
(
g22
(
1
:
M_
.
endo_nbr
,:));
H2ss
=
reshape
(
H2ss
,[
M_
.
endo_nbr
param_nbr
param_nbr
]);
...
...
@@ -145,7 +145,7 @@ if kronflag==-2,
clear
gx22
;
else
[
residual
,
g1
]
=
feval
([
M_
.
fname
,
'_dynamic'
],
yy0
,
oo_
.
exo_steady_state
'
,
...
M_
.
params
,
oo_
.
dr
.
ys
,
1
);
M_
.
params
,
oo_
.
dr
.
ys
,
oo_
.
exo_steady_state
,
1
);
end
gp
=
fjaco
(
'thet2tau'
,[
M_
.
params
(
indx
)],
estim_params_
,
M_
,
oo_
,
indx
,[],
-
1
);
Hss
=
gp
(
1
:
M_
.
endo_nbr
,:);
...
...
@@ -166,7 +166,7 @@ dyssdtheta = -gg1\df;
if
nargout
>
5
,
[
residual
,
gg1
,
gg2
]
=
feval
([
M_
.
fname
,
'_static'
],
oo_
.
dr
.
ys
,
oo_
.
exo_steady_state
'
,
M_
.
params
);
[
residual
,
g1
,
g2
,
g3
]
=
feval
([
M_
.
fname
,
'_dynamic'
],
yy0
,
oo_
.
exo_steady_state
'
,
...
M_
.
params
,
oo_
.
dr
.
ys
,
1
);
M_
.
params
,
oo_
.
dr
.
ys
,
oo_
.
exo_steady_state
,
1
);
[
nr
,
nc
]
=
size
(
gg2
);
[
df
,
gpx
,
d2f
]
=
feval
([
M_
.
fname
,
'_static_params_derivs'
],
oo_
.
dr
.
ys
,
oo_
.
exo_steady_state
'
,
...
...
...
@@ -218,7 +218,7 @@ else
[
df
,
gp
]
=
feval
([
M_
.
fname
,
'_params_derivs'
],
yy0
,
repmat
(
oo_
.
exo_steady_state
'
,[
M_
.
maximum_exo_lag
+
M_
.
maximum_exo_lead
+
1
,
1
]),
...
M_
.
params
,
oo_
.
dr
.
ys
,
1
,
dyssdtheta
,
d2yssdtheta
);
[
residual
,
g1
,
g2
]
=
feval
([
M_
.
fname
,
'_dynamic'
],
yy0
,
repmat
(
oo_
.
exo_steady_state
'
,[
M_
.
maximum_exo_lag
+
M_
.
maximum_exo_lead
+
1
,
1
]),
...
M_
.
params
,
oo_
.
dr
.
ys
,
1
);
M_
.
params
,
oo_
.
dr
.
ys
,
oo_
.
exo_steady_state
,
1
);
end
[
nr
,
nc
]
=
size
(
g2
);
...
...
matlab/identification_analysis.m
View file @
c6bac390
...
...
@@ -28,7 +28,7 @@ function [ide_hess, ide_moments, ide_model, ide_lre, derivatives_info, info, opt
% SPECIAL REQUIREMENTS
% None
% Copyright (C) 2008-201
6
Dynare Team
% Copyright (C) 2008-201
7
Dynare Team
%
% This file is part of Dynare.
%
...
...
@@ -79,7 +79,7 @@ if info(1)==0,
yy0
=
oo_
.
dr
.
ys
(
I
);
[
residual
,
g1
]
=
feval
([
M_
.
fname
,
'_dynamic'
],
yy0
,
...
repmat
(
oo_
.
exo_steady_state
'
,[
M_
.
maximum_exo_lag
+
M_
.
maximum_exo_lead
+
1
]),
M_
.
params
,
...
oo_
.
dr
.
ys
,
1
);
oo_
.
dr
.
ys
,
oo_
.
exo_steady_state
,
1
);
vg1
=
[
oo_
.
dr
.
ys
(
oo_
.
dr
.
order_var
);
vec
(
g1
)];
[
JJ
,
H
,
gam
,
gp
,
dA
,
dOm
,
dYss
]
=
getJJ
(
A
,
B
,
estim_params_
,
M_
,
oo0
,
options_
,
kron_flag
,
indx
,
indexo
,
bayestopt_
.
mf2
,
nlags
,
useautocorr
);
...
...
matlab/model_diagnostics.m
View file @
c6bac390
...
...
@@ -16,7 +16,7 @@ function model_diagnostics(M,options,oo)
% none.
%
% Copyright (C) 1996-201
3
Dynare Team
% Copyright (C) 1996-201
7
Dynare Team
%
% This file is part of Dynare.
%
...
...
@@ -209,7 +209,7 @@ if ~options.block
jacobia_
=
[
loc_dr
.
g1
loc_dr
.
g1_x
loc_dr
.
g1_xd
];
else
[
junk
,
jacobia_
]
=
feval
([
M
.
fname
'_dynamic'
],
z
(
iyr0
),
exo_simul
,
...
M
.
params
,
dr
.
ys
,
it_
);
M
.
params
,
dr
.
ys
,
oo
.
exo_steady_state
,
it_
);
end
;
elseif
options
.
order
>=
2
if
(
options
.
bytecode
)
...
...
@@ -219,7 +219,7 @@ if ~options.block
else
[
junk
,
jacobia_
,
hessian1
]
=
feval
([
M
.
fname
'_dynamic'
],
z
(
iyr0
),
...
exo_simul
,
...
M
.
params
,
dr
.
ys
,
it_
);
M
.
params
,
dr
.
ys
,
oo
.
exo_steady_state
,
it_
);
end
;
if
options
.
use_dll
% In USE_DLL mode, the hessian is in the 3-column sparse representation
...
...
matlab/partial_information/dr1_PI.m
View file @
c6bac390
...
...
@@ -40,7 +40,7 @@ function [dr,info,M_,options_,oo_] = dr1_PI(dr,task,M_,options_,oo_)
% none.
%
% Copyright (C) 1996-201
2
Dynare Team
% Copyright (C) 1996-201
7
Dynare Team
%
% This file is part of Dynare.
%
...
...
@@ -131,7 +131,8 @@ else
end
z
=
z
(
iyr0
)
;
[
junk
,
jacobia_
]
=
feval
([
M_
.
fname
'_dynamic'
],
z
,[
oo_
.
exo_simul
...
oo_
.
exo_det_simul
],
M_
.
params
,
dr
.
ys
,
it_
);
oo_
.
exo_det_simul
],
M_
.
params
,
dr
.
ys
,
oo_
.
exo_steady_state
,
...
it_
);
if
options_
.
ACES_solver
==
1
&&
(
length
(
sim_ruleids
)
>
0
||
length
(
tct_ruleids
)
>
0
)
if
length
(
sim_ruleids
)
>
0
...
...
matlab/perfect-foresight-models/det_cond_forecast.m
View file @
c6bac390
...
...
@@ -12,7 +12,7 @@ function data_set = det_cond_forecast(varargin)
% dataset [dseries] Returns a dseries containing the forecasted endgenous variables and shocks
%
%
% Copyright (C) 2013-201
6
Dynare Team
% Copyright (C) 2013-201
7
Dynare Team
%
% This file is part of Dynare.
%
...
...
@@ -475,7 +475,8 @@ if pf && ~surprise
if
(
options_
.
bytecode
)
[
chck
,
zz
,
data1
]
=
bytecode
(
'dynamic'
,
'evaluate'
,
z
,
zx
,
M_
.
params
,
oo_
.
steady_state
,
k
,
data1
);
else
[
zz
,
g1b
]
=
feval
([
M_
.
fname
'_dynamic'
],
z
'
,
zx
,
M_
.
params
,
oo_
.
steady_state
,
k
);
[
zz
,
g1b
]
=
feval
([
M_
.
fname
'_dynamic'
],
z
'
,
zx
,
M_
.
params
,
...
oo_
.
steady_state
,
oo_
.
exo_steady_state
,
k
);
data1
.
g1_x
=
g1b
(:,
end
-
M_
.
exo_nbr
+
1
:
end
);
data1
.
g1
=
g1b
(:,
1
:
end
-
M_
.
exo_nbr
);
chck
=
0
;
...
...
@@ -747,7 +748,8 @@ else
if
(
options_
.
bytecode
)
[
chck
,
zz
,
data1
]
=
bytecode
(
'dynamic'
,
'evaluate'
,
z
,
zx
,
M_
.
params
,
oo_
.
steady_state
,
k
,
data1
);
else
[
zz
,
g1b
]
=
feval
([
M_
.
fname
'_dynamic'
],
z
'
,
zx
,
M_
.
params
,
oo_
.
steady_state
,
k
);
[
zz
,
g1b
]
=
feval
([
M_
.
fname
'_dynamic'
],
z
'
,
zx
,
...
M_
.
params
,
oo_
.
steady_state
,
oo_
.
exo_steady_state
,
k
);
data1
.
g1_x
=
g1b
(:,
end
-
M_
.
exo_nbr
+
1
:
end
);
data1
.
g1
=
g1b
(:,
1
:
end
-
M_
.
exo_nbr
);
chck
=
0
;
...
...
matlab/perfect-foresight-models/perfect_foresight_mcp_problem.m
View file @
c6bac390
function
[
residuals
,
JJacobian
]
=
perfect_foresight_mcp_problem
(
y
,
dynamic_function
,
Y0
,
YT
,
...
exo_simul
,
params
,
steady_state
,
...
exo_simul
,
params
,
steady_state
,
exo_steady_state
,
...
maximum_lag
,
T
,
ny
,
i_cols
,
...
i_cols_J1
,
i_cols_1
,
i_cols_T
,
...
i_cols_j
,
nnzJ
,
eq_index
)
% function [residuals,JJacobian] = perfect_foresight_mcp_problem(y, dynamic_function, Y0, YT, ...
% exo_simul, params, steady_state, ...
% exo_simul, params, steady_state,
exo_steady_state,
...
% maximum_lag, T, ny, i_cols, ...
% i_cols_J1, i_cols_1, i_cols_T, ...
% i_cols_j,nnzJ,eq_index)
...
...
@@ -20,6 +20,7 @@ function [residuals,JJacobian] = perfect_foresight_mcp_problem(y, dynamic_functi
% for all simulation periods
% params [double] nparams*1 array, parameter values
% steady_state [double] endo_nbr*1 vector of steady state values
% exo_steady_state [double] exo_nbr*1 vector of steady state values
% maximum_lag [scalar] maximum lag present in the model
% T [scalar] number of simulation periods
% ny [scalar] number of endogenous variables
...
...
@@ -45,7 +46,7 @@ function [residuals,JJacobian] = perfect_foresight_mcp_problem(y, dynamic_functi
% SPECIAL REQUIREMENTS
% None.
% Copyright (C) 1996-201
6
Dynare Team
% Copyright (C) 1996-201
7
Dynare Team
%
% This file is part of Dynare.
%
...
...
@@ -77,11 +78,11 @@ i_cols_J = i_cols;
for
it
=
2
:(
T
+
1
)
if
nargout
==
1
res
=
dynamic_function
(
YY
(
i_cols
),
exo_simul
,
params
,
...
steady_state
,
it
);
steady_state
,
exo_steady_state
,
it
);
residuals
(
i_rows
)
=
res
(
eq_index
);
elseif
nargout
==
2
[
res
,
jacobian
]
=
dynamic_function
(
YY
(
i_cols
),
exo_simul
,
params
,
...
steady_state
,
it
);
steady_state
,
exo_steady_state
,
it
);
residuals
(
i_rows
)
=
res
(
eq_index
);
if
it
==
2
[
rows
,
cols
,
vals
]
=
find
(
jacobian
(
eq_index
,
i_cols_1
));
...
...
matlab/perfect-foresight-models/perfect_foresight_problem.m
View file @
c6bac390
function
[
residuals
,
JJacobian
]
=
perfect_foresight_problem
(
y
,
dynamic_function
,
Y0
,
YT
,
...
exo_simul
,
params
,
steady_state
,
...
exo_simul
,
params
,
steady_state
,
exo_steady_state
,
...
maximum_lag
,
T
,
ny
,
i_cols
,
...
i_cols_J1
,
i_cols_1
,
i_cols_T
,
...
i_cols_j
,
nnzJ
)
% function [residuals,JJacobian] = perfect_foresight_problem(y, dynamic_function, Y0, YT, ...
% exo_simul, params, steady_state, ...
% exo_simul, params, steady_state,
exo_steady_state,
...
% maximum_lag, T, ny, i_cols, ...
% i_cols_J1, i_cols_1, i_cols_T, ...
% i_cols_j,nnzJ)
...
...
@@ -19,6 +19,7 @@ function [residuals,JJacobian] = perfect_foresight_problem(y, dynamic_function,
% for all simulation periods
% params [double] nparams*1 array, parameter values
% steady_state [double] endo_nbr*1 vector of steady state values
% exo_steady_state [double] exo_nbr*1 vector of steady state values
% maximum_lag [scalar] maximum lag present in the model
% T [scalar] number of simulation periods
% ny [scalar] number of endogenous variables
...
...
@@ -42,7 +43,7 @@ function [residuals,JJacobian] = perfect_foresight_problem(y, dynamic_function,
% SPECIAL REQUIREMENTS
% None.
% Copyright (C) 1996-201
6
Dynare Team
% Copyright (C) 1996-201
7
Dynare Team
%
% This file is part of Dynare.
%
...
...
@@ -74,10 +75,10 @@ function [residuals,JJacobian] = perfect_foresight_problem(y, dynamic_function,
for
it
=
2
:(
T
+
1
)
if
nargout
==
1
residuals
(
i_rows
)
=
dynamic_function
(
YY
(
i_cols
),
exo_simul
,
params
,
...
steady_state
,
it
);
steady_state
,
exo_steady_state
,
it
);
elseif
nargout
==
2
[
residuals
(
i_rows
),
jacobian
]
=
dynamic_function
(
YY
(
i_cols
),
exo_simul
,
params
,
...
steady_state
,
it
);
steady_state
,
exo_steady_state
,
it
);
if
it
==
2
[
rows
,
cols
,
vals
]
=
find
(
jacobian
(:,
i_cols_1
));
iJacobian
{
1
}
=
[
offset
+
rows
,
i_cols_J1
(
cols
),
vals
];
...
...
matlab/perfect-foresight-models/perfect_foresight_solver_core.m
View file @
c6bac390
...
...
@@ -11,7 +11,7 @@ function [oo_, maxerror] = perfect_foresight_solver_core(M_, options_, oo_)
% - oo_ [struct] contains results
% - maxerror [double] contains the maximum absolute error
% Copyright (C) 2015-201
6
Dynare Team
% Copyright (C) 2015-201
7
Dynare Team
%
% This file is part of Dynare.
%
...
...
@@ -79,36 +79,36 @@ else
else
if
M_
.
maximum_endo_lead
==
0
% Purely backward model
[
oo_
.
endo_simul
,
oo_
.
deterministic_simulation
]
=
...
sim1_purely_backward
(
oo_
.
endo_simul
,
oo_
.
exo_simul
,
oo_
.
steady_state
,
M_
,
options_
);
sim1_purely_backward
(
oo_
.
endo_simul
,
oo_
.
exo_simul
,
oo_
.
steady_state
,
M_
,
options_
,
oo_
);
elseif
M_
.
maximum_endo_lag
==
0
% Purely forward model
[
oo_
.
endo_simul
,
oo_
.
deterministic_simulation
]
=
...
sim1_purely_forward
(
oo_
.
endo_simul
,
oo_
.
exo_simul
,
oo_
.
steady_state
,
M_
,
options_
);
sim1_purely_forward
(
oo_
.
endo_simul
,
oo_
.
exo_simul
,
oo_
.
steady_state
,
M_
,
options_
,
oo_
);
else
% General case
switch
options_
.
stack_solve_algo
case
0
if
options_
.
linear_approximation
[
oo_
.
endo_simul
,
oo_
.
deterministic_simulation
]
=
...
sim1_linear
(
oo_
.
endo_simul
,
oo_
.
exo_simul
,
oo_
.
steady_state
,
oo_
.
exo_steady_state
,
M_
,
options_
);
sim1_linear
(
oo_
.
endo_simul
,
oo_
.
exo_simul
,
oo_
.
steady_state
,
oo_
.
exo_steady_state
,
M_
,
options_
,
oo_
);
else
[
oo_
.
endo_simul
,
oo_
.
deterministic_simulation
]
=
...
sim1
(
oo_
.
endo_simul
,
oo_
.
exo_simul
,
oo_
.
steady_state
,
M_
,
options_
);
sim1
(
oo_
.
endo_simul
,
oo_
.
exo_simul
,
oo_
.
steady_state
,
M_
,
options_
,
oo_
);
end
case
6
if
options_
.
linear_approximation
error
(
'Invalid value of stack_solve_algo option!'
)
end
[
oo_
.
endo_simul
,
oo_
.
deterministic_simulation
]
=
...
sim1_lbj
(
oo_
.
endo_simul
,
oo_
.
exo_simul
,
oo_
.
steady_state
,
M_
,
options_
);
sim1_lbj
(
oo_
.
endo_simul
,
oo_
.
exo_simul
,
oo_
.
steady_state
,
M_
,
options_
,
oo_
);
case
7
if
options_
.
linear_approximation
if
isequal
(
options_
.
solve_algo
,
10
)
warning
(
'It would be more efficient to set option solve_algo equal to 0!'
)
end
[
oo_
.
endo_simul
,
oo_
.
deterministic_simulation
]
=
...
solve_stacked_linear_problem
(
oo_
.
endo_simul
,
oo_
.
exo_simul
,
oo_
.
steady_state
,
oo_
.
exo_steady_state
,
M_
,
options_
);
solve_stacked_linear_problem
(
oo_
.
endo_simul
,
oo_
.
exo_simul
,
oo_
.
steady_state
,
oo_
.
exo_steady_state
,
M_
,
options_
,
oo_
);
else
[
oo_
.
endo_simul
,
oo_
.
deterministic_simulation
]
=
...
solve_stacked_problem
(
oo_
.
endo_simul
,
oo_
.
exo_simul
,
oo_
.
steady_state
,
M_
,
options_
);
solve_stacked_problem
(
oo_
.
endo_simul
,
oo_
.
exo_simul
,
oo_
.
steady_state
,
M_
,
options_
,
oo_
);
end
otherwise
error
(
'Invalid value of stack_solve_algo option!'
)
...
...
@@ -135,7 +135,7 @@ if nargout>1
[
chck
,
residuals
,
junk
]
=
bytecode
(
'dynamic'
,
'evaluate'
,
oo_
.
endo_simul
,
oo_
.
exo_simul
,
M_
.
params
,
oo_
.
steady_state
,
1
);
else
residuals
=
perfect_foresight_problem
(
yy
(:),
str2func
([
M_
.
fname
'_dynamic'
]),
y0
,
yT
,
...
oo_
.
exo_simul
,
M_
.
params
,
oo_
.
steady_state
,
...
oo_
.
exo_simul
,
M_
.
params
,
oo_
.
steady_state
,
oo_
.
exo_steady_state
,
...
M_
.
maximum_lag
,
options_
.
periods
,
M_
.
endo_nbr
,
i_cols
,
...
i_cols_J1
,
i_cols_1
,
i_cols_T
,
i_cols_j
,
...
M_
.
NNZDerivatives
(
1
));
...
...
matlab/perfect-foresight-models/private/simulation_core.m
View file @
c6bac390
function
[
oo_
,
maxerror
]
=
simulation_core
(
options_
,
M_
,
oo_
)
%function [oo_, maxerror] = simulation_core(options_, M_, oo_)
% Copyright (C) 2015 Dynare Team
% Copyright (C) 2015
-2017
Dynare Team
%
% This file is part of Dynare.
%
...
...
@@ -64,29 +64,29 @@ else
else
if
M_
.
maximum_endo_lead
==
0
% Purely backward model
[
oo_
.
endo_simul
,
oo_
.
deterministic_simulation
]
=
...
sim1_purely_backward
(
oo_
.
endo_simul
,
oo_
.
exo_simul
,
oo_
.
steady_state
,
M_
,
options_
);
sim1_purely_backward
(
oo_
.
endo_simul
,
oo_
.
exo_simul
,
oo_
.
steady_state
,
M_
,
options_
,
oo_
);
elseif
M_
.
maximum_endo_lag
==
0
% Purely forward model
[
oo_
.
endo_simul
,
oo_
.
deterministic_simulation
]
=
...
sim1_purely_forward
(
oo_
.
endo_simul
,
oo_
.
exo_simul
,
oo_
.
steady_state
,
M_
,
options_
);
sim1_purely_forward
(
oo_
.
endo_simul
,
oo_
.
exo_simul
,
oo_
.
steady_state
,
M_
,
options_
,
oo_
);
else
% General case
if
options_
.
stack_solve_algo
==
0
if
options_
.
linear_approximation
[
oo_
.
endo_simul
,
oo_
.
deterministic_simulation
]
=
...
sim1_linear
(
oo_
.
endo_simul
,
oo_
.
exo_simul
,
oo_
.
steady_state
,
oo_
.
exo_steady_state
,
M_
,
options_
);
sim1_linear
(
oo_
.
endo_simul
,
oo_
.
exo_simul
,
oo_
.
steady_state
,
oo_
.
exo_steady_state
,
M_
,
options_
,
oo_
);
else
[
oo_
.
endo_simul
,
oo_
.
deterministic_simulation
]
=
...
sim1
(
oo_
.
endo_simul
,
oo_
.
exo_simul
,
oo_
.
steady_state
,
M_
,
options_
);
sim1
(
oo_
.
endo_simul
,
oo_
.
exo_simul
,
oo_
.
steady_state
,
M_
,
options_
,
oo_
);
end
elseif
options_
.
stack_solve_algo
==
6
[
oo_
.
endo_simul
,
oo_
.
deterministic_simulation
]
=
...
sim1_lbj
(
oo_
.
endo_simul
,
oo_
.
exo_simul
,
oo_
.
steady_state
,
M_
,
options_
);
sim1_lbj
(
oo_
.
endo_simul
,
oo_
.
exo_simul
,
oo_
.
steady_state
,
M_
,
options_
,
oo_
);
elseif
options_
.
stack_solve_algo
==
7
if
options_
.
linear_approximation
[
oo_
.
endo_simul
,
oo_
.
deterministic_simulation
]
=
...
solve_stacked_linear_problem
(
oo_
.
endo_simul
,
oo_
.
exo_simul
,
oo_
.
steady_state
,
oo_
.
exo_steady_state
,
M_
,
options_
);
solve_stacked_linear_problem
(
oo_
.
endo_simul
,
oo_
.
exo_simul
,
oo_
.
steady_state
,
oo_
.
exo_steady_state
,
M_
,
options_
,
oo_
);
else
[
oo_
.
endo_simul
,
oo_
.
deterministic_simulation
]
=
...
solve_stacked_problem
(
oo_
.
endo_simul
,
oo_
.
exo_simul
,
oo_
.
steady_state
,
M_
,
options_
);
solve_stacked_problem
(
oo_
.
endo_simul
,
oo_
.
exo_simul
,
oo_
.
steady_state
,
M_
,
options_
,
oo_
);
end
end
end
...
...
matlab/perfect-foresight-models/sim1.m
View file @
c6bac390
function
[
endogenousvariables
,
info
]
=
sim1
(
endogenousvariables
,
exogenousvariables
,
steadystate
,
M
,
options
)
function
[
endogenousvariables
,
info
]
=
sim1
(
endogenousvariables
,
exogenousvariables
,
steadystate
,
M
,
options
,
oo
)
% Performs deterministic simulations with lead or lag on one period. Uses sparse matrices.
%
...
...
@@ -79,7 +79,7 @@ end
model_dynamic
=
str2func
([
M
.
fname
,
'_dynamic'
]);
z
=
Y
(
find
(
lead_lag_incidence
'
));
[
d1
,
jacobian
]
=
model_dynamic
(
z
,
exogenousvariables
,
params
,
steadystate
,
maximum_lag
+
1
);
[
d1
,
jacobian
]
=
model_dynamic
(
z
,
exogenousvariables
,
params
,
steadystate
,
oo
.
exo_steady_state
,
maximum_lag
+
1
);
res
=
zeros
(
periods
*
ny
,
1
);
...
...
@@ -100,7 +100,7 @@ for iter = 1:options.simul.maxit
i_cols
=
i_cols_A
+
(
maximum_lag
-
1
)
*
ny
;
m
=
0
;
for
it
=
(
maximum_lag
+
1
):(
maximum_lag
+
periods
)
[
d1
,
jacobian
]
=
model_dynamic
(
Y
(
i_cols
),
exogenousvariables
,
params
,
steadystate
,
it
);
[
d1
,
jacobian
]
=
model_dynamic
(
Y
(
i_cols
),
exogenousvariables
,
params
,
steadystate
,
oo
.
exo_steady_state
,
it
);
if
it
==
maximum_lag
+
periods
&&
it
==
maximum_lag
+
1
[
r
,
c
,
v
]
=
find
(
jacobian
(:,
i_cols_0
));
iA
((
1
:
length
(
v
))
+
m
,:)
=
[
i_rows
(
r
(:)),
i_cols_A0
(
c
(:)),
v
(:)];
...
...
matlab/perfect-foresight-models/sim1_lbj.m
View file @
c6bac390
function
[
endogenousvariables
,
info
]
=
sim1_lbj
(
endogenousvariables
,
exogenousvariables
,
steadystate
,
M
,
options
)
function
[
endogenousvariables
,
info
]
=
sim1_lbj
(
endogenousvariables
,
exogenousvariables
,
steadystate
,
M
,
options
,
oo
)
% Performs deterministic simulations with lead or lag on one period using the historical LBJ algorithm
%
...
...
@@ -15,7 +15,7 @@ function [endogenousvariables, info] = sim1_lbj(endogenousvariables, exogenousva
% SPECIAL REQUIREMENTS
% None.
% Copyright (C) 1996-201
5
Dynare Team
% Copyright (C) 1996-201
7
Dynare Team
%
% This file is part of Dynare.
%
...
...
@@ -70,14 +70,14 @@ for iter = 1:options.simul.maxit
end
it_
=
it_init
;
z
=
[
endogenousvariables
(
iyp
,
it_
-
1
)
;
endogenousvariables
(:,
it_
)
;
endogenousvariables
(
iyf
,
it_
+
1
)];
[
d1
,
jacobian
]
=
feval
(
dynamicmodel
,
z
,
exogenousvariables
,
M
.
params
,
steadystate
,
it_
);
[
d1
,
jacobian
]
=
feval
(
dynamicmodel
,
z
,
exogenousvariables
,
M
.
params
,
steadystate
,
oo
.
exo_steady_state
,
it_
);
jacobian
=
[
jacobian
(:,
iz
),
-
d1
];
ic
=
[
1
:
ny
];
icp
=
iyp
;
c
(
ic
,:)
=
jacobian
(:,
is
)\
jacobian
(:,
isf1
);
for
it_
=
it_init
+
(
1
:
options
.
periods
-
1
)
z
=
[
endogenousvariables
(
iyp
,
it_
-
1
)
;
endogenousvariables
(:,
it_
)
;
endogenousvariables
(
iyf
,
it_
+
1
)];
[
d1
,
jacobian
]
=
feval
(
dynamicmodel
,
z
,
exogenousvariables
,
M
.
params
,
steadystate
,
it_
);
[
d1
,
jacobian
]
=
feval
(
dynamicmodel
,
z
,
exogenousvariables
,
M
.
params
,
steadystate
,
oo
.
exo_steady_state
,
it_
);
jacobian
=
[
jacobian
(:,
iz
),
-
d1
];
jacobian
(:,[
isf
nrs
])
=
jacobian
(:,[
isf
nrs
])
-
jacobian
(:,
isp
)
*
c
(
icp
,:);
ic
=
ic
+
ny
;
...
...
matlab/perfect-foresight-models/sim1_linear.m
View file @
c6bac390
function
[
endogenousvariables
,
info
]
=
sim1_linear
(
endogenousvariables
,
exogenousvariables
,
steadystate_y
,
steadystate_x
,
M
,
options
)
function
[
endogenousvariables
,
info
]
=
sim1_linear
(
endogenousvariables
,
exogenousvariables
,
steadystate_y
,
steadystate_x
,
M
,
options
,
oo
)
% Solves a linear approximation of a perfect foresight model using sparse matrix.
%
...
...
@@ -38,7 +38,7 @@ function [endogenousvariables, info] = sim1_linear(endogenousvariables, exogenou
% to center the variables around the deterministic steady state to solve the
% perfect foresight model.
% Copyright (C) 2015 Dynare Team
% Copyright (C) 2015
-2017
Dynare Team
%
% This file is part of Dynare.
%
...
...
@@ -111,7 +111,7 @@ dynamicmodel = str2func([M.fname,'_dynamic']);
z
=
steadystate_y
([
ip
;
ic
;
in
]);
% Evaluate the Jacobian of the dynamic model at the deterministic steady state.
[
d1
,
jacobian
]
=
dynamicmodel
(
z
,
transpose
(
steadystate_x
),
params
,
steadystate_y
,
1
);
[
d1
,
jacobian
]
=
dynamicmodel
(
z
,
transpose
(
steadystate_x
),
params
,
steadystate_y
,
oo
.
exo_steady_state
,
1
);
% Check that the dynamic model was evaluated at the steady state.
if
max
(
abs
(
d1
))
>
1e-12
...
...
matlab/perfect-foresight-models/sim1_purely_backward.m
View file @
c6bac390
function
[
endogenousvariables
,
info
]
=
sim1_purely_backward
(
endogenousvariables
,
exogenousvariables
,
steadystate
,
M
,
options
)
function
[
endogenousvariables
,
info
]
=
sim1_purely_backward
(
endogenousvariables
,
exogenousvariables
,
steadystate
,
M
,
options
,
oo
)
% Performs deterministic simulation of a purely backward model
% Copyright (C) 2012-201
5
Dynare Team
% Copyright (C) 2012-201
7
Dynare Team
%
% This file is part of Dynare.
%
...
...
@@ -44,7 +44,7 @@ for it = 2:options.periods+1
[
tmp
,
check
]
=
solve1
(
dynamicmodel
,
[
yb1
;
yb
],
1
:
M
.
endo_nbr
,
nyb
+
1
:
nyb
+
M
.
endo_nbr
,
...
1
,
options
.
gstep
,
options
.
solve_tolf
,
options
.
solve_tolx
,
...
options
.
simul
.
maxit
,
options
.
debug
,
exogenousvariables
,
...
M
.
params
,
steadystate
,
it
+
M
.
maximum_lag
-
1
);
M
.
params
,
steadystate
,
oo
.
exo_steady_state
,
it
+
M
.
maximum_lag
-
1
);
if
check
info
.
status
=
0
;
end
...
...
matlab/perfect-foresight-models/sim1_purely_forward.m
View file @
c6bac390
function
[
endogenousvariables
,
info
]
=
sim1_purely_forward
(
endogenousvariables
,
exogenousvariables
,
steadystate
,
M
,
options
)
function
[
endogenousvariables
,
info
]
=
sim1_purely_forward
(
endogenousvariables
,
exogenousvariables
,
steadystate
,
M
,
options
,
oo
)
% Performs deterministic simulation of a purely forward model
% Copyright (C) 2012-201
5
Dynare Team
% Copyright (C) 2012-201
7
Dynare Team
%
% This file is part of Dynare.
%
...
...
@@ -36,7 +36,7 @@ for it = options.periods:-1:1
1
,
options
.
gstep
,
options
.
solve_tolf
,
...
options
.
solve_tolx
,
options
.
simul
.
maxit
,
...
options
.
debug
,
exogenousvariables
,
M
.
params
,
steadystate
,
...
it
+
M
.
maximum_lag
);
oo
.
exo_steady_state
,
it
+
M
.
maximum_lag
);
if
check
info
.
status
=
0
;
end
...
...
matlab/perfect-foresight-models/solve_stacked_linear_problem.m
View file @
c6bac390