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
Loading items

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
  • ebenetce/dynare
  • chskcau/dynare-doc-fixes
28 results
Select Git revision
Loading items
Show changes
Showing
with 315 additions and 63 deletions
function tf = allCellsAreDates(dcell)
%function tf = allCellsAreDates(dcell)
% Determines if all the elements of dcell are dates objects
%
% INPUTS
% dcell cell of dates objects
%
% OUTPUTS
% tf true if every entry of dcell is a dates object
%
% SPECIAL REQUIREMENTS
% none
% Copyright (C) 2014 Dynare Team
%
% This file is part of Dynare.
%
% Dynare is free software: you can redistribute it and/or modify
% it under the terms of the GNU General Public License as published by
% the Free Software Foundation, either version 3 of the License, or
% (at your option) any later version.
%
% Dynare is distributed in the hope that it will be useful,
% but WITHOUT ANY WARRANTY; without even the implied warranty of
% MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
% GNU General Public License for more details.
%
% You should have received a copy of the GNU General Public License
% along with Dynare. If not, see <http://www.gnu.org/licenses/>.
assert(iscell(dcell));
tf = true;
for i=1:length(dcell)
if ~isa(dcell{i}, 'dates')
tf = false;
return;
end
end
end
\ No newline at end of file
function tf = allCellsAreDatesRange(dcell)
%function tf = allCellsAreDatesRange(dcell)
% Determines if all the elements of dcell are a range of dates
%
% INPUTS
% dcell cell of dates
%
% OUTPUTS
% tf true if every entry of dcell is a range of dates
%
% SPECIAL REQUIREMENTS
% none
% Copyright (C) 2014 Dynare Team
%
% This file is part of Dynare.
%
% Dynare is free software: you can redistribute it and/or modify
% it under the terms of the GNU General Public License as published by
% the Free Software Foundation, either version 3 of the License, or
% (at your option) any later version.
%
% Dynare is distributed in the hope that it will be useful,
% but WITHOUT ANY WARRANTY; without even the implied warranty of
% MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
% GNU General Public License for more details.
%
% You should have received a copy of the GNU General Public License
% along with Dynare. If not, see <http://www.gnu.org/licenses/>.
assert(iscell(dcell));
tf = true;
for i=1:length(dcell)
if ~(isa(dcell{i}, 'dates') && dcell{i}.ndat >= 2)
tf = false;
return;
end
end
end
\ No newline at end of file
......@@ -107,6 +107,30 @@ if info(1)
return
end
if options.loglinear
% Find variables with non positive steady state.
idx = find(dr.ys<1e-9);
if length(idx)
variables_with_non_positive_steady_state = M.endo_names(idx,:);
skipline()
fprintf('You are attempting to simulate/estimate a loglinear approximation of a model, but\n')
fprintf('the steady state level of the following variables is not strictly positive:\n')
for var_iter=1:length(idx)
fprintf(' - %s (%s)\n',deblank(variables_with_non_positive_steady_state(var_iter,:)), num2str(dr.ys(idx(var_iter))))
end
if isestimation()
fprintf('You should check that the priors and/or bounds over the deep parameters are such')
fprintf('the steady state levels of all the variables are strictly positive, or consider')
fprintf('a linearization of the model instead of a log linearization.')
else
fprintf('You should check that the calibration of the deep parameters is such that the')
fprintf('steady state levels of all the variables are strictly positive, or consider')
fprintf('a linearization of the model instead of a log linearization.')
end
error('stoch_simul::resol: The loglinearization of the model cannot be performed because the steady state is not strictly positive!')
end
end
if options.block
[dr,info,M,options,oo] = dr_block(dr,check_flag,M,options,oo);
else
......
function oo_ = shock_decomposition(M_,oo_,options_,varlist)
% function z = shock_decomposition(M_,oo_,options_,varlist)
% Computes shocks contribution to a simulated trajectory
% Computes shocks contribution to a simulated trajectory. The field set is
% oo_.shock_decomposition. It is a n_var by nshock+2 by nperiods array. The
% first nshock columns store the respective shock contributions, column n+1
% stores the role of the initial conditions, while column n+2 stores the
% value of the smoothed variables.
%
% INPUTS
% M_: [structure] Definition of the model
......
......@@ -65,7 +65,7 @@ i_cols_T = nonzeros(lead_lag_incidence(1:2,:)');
i_cols_0 = nonzeros(lead_lag_incidence(2,:)');
i_cols_A0 = find(lead_lag_incidence(2,:)');
i_cols_j = 1:nd;
i_upd = ny+(1:periods*ny);
i_upd = M_.maximum_lag*ny+(1:periods*ny);
Y = endo_simul(:);
......@@ -86,8 +86,8 @@ for iter = 1:options_.simul.maxit
h2 = clock ;
i_rows = 1:ny;
i_cols = find(lead_lag_incidence');
i_cols_A = i_cols;
i_cols_A = find(lead_lag_incidence');
i_cols = i_cols_A+(M_.maximum_lag-1)*ny;
for it = (M_.maximum_lag+1):(M_.maximum_lag+periods)
......@@ -137,7 +137,7 @@ if stop
oo_.deterministic_simulation.status = 0;% NaN or Inf occurred
oo_.deterministic_simulation.error = err;
oo_.deterministic_simulation.iterations = iter;
oo_.endo_simul = reshape(Y,ny,periods+2);
oo_.endo_simul = reshape(Y,ny,periods+M_.maximum_lag+M_.maximum_lead);
skipline();
fprintf('\nSimulation terminated after %d iterations.\n',iter);
fprintf('Total time of simulation : %10.3f\n',etime(clock,h1));
......@@ -150,13 +150,13 @@ if stop
oo_.deterministic_simulation.status = 1;% Convergency obtained.
oo_.deterministic_simulation.error = err;
oo_.deterministic_simulation.iterations = iter;
oo_.endo_simul = reshape(Y,ny,periods+2);
oo_.endo_simul = reshape(Y,ny,periods+M_.maximum_lag+M_.maximum_lead);
end
elseif ~stop
skipline();
fprintf('\nSimulation terminated after %d iterations.\n',iter);
fprintf('Total time of simulation : %10.3f\n',etime(clock,h1));
fprintf('WARNING : maximum number of iterations is reached (modify options_.simul.maxit).\n') ;
warning('Maximum number of iterations is reached (modify option maxit).\n') ;
oo_.deterministic_simulation.status = 0;% more iterations are needed.
oo_.deterministic_simulation.error = err;
%oo_.deterministic_simulation.errors = c/abs(err)
......
......@@ -118,11 +118,11 @@ for iter = 1:options_.simul.maxit
end
if ~stop
fprintf('\n') ;
skipline(2)
disp([' Total time of simulation :' num2str(etime(clock,h1))]) ;
fprintf('\n') ;
disp(['WARNING : maximum number of iterations is reached (modify options_.simul.maxit).']) ;
fprintf('\n') ;
skipline()
warning(['Maximum number of iterations is reached (modify options_.simul.maxit).']) ;
skipline()
oo_.deterministic_simulation.status = 0;% more iterations are needed.
oo_.deterministic_simulation.error = err;
oo_.deterministic_simulation.errors = c/abs(err);
......
function sim1_purely_backward()
% Performs deterministic simulation of a purely backward model
% Copyright (C) 2012-2013 Dynare Team
% Copyright (C) 2012-2014 Dynare Team
%
% This file is part of Dynare.
%
......@@ -36,15 +36,26 @@ function sim1_purely_backward()
model_dynamic = str2func([M_.fname,'_dynamic']);
oo_.deterministic_simulation.status = 1;
for it = 2:options_.periods+1
yb = oo_.endo_simul(:,it-1); % Values at previous period, also used as guess value for current period
yb1 = yb(iyb);
tmp = solve1(model_dynamic, [yb1; yb], 1:M_.endo_nbr, nyb+1:nyb+ ...
[tmp, check] = solve1(model_dynamic, [yb1; yb], 1:M_.endo_nbr, nyb+1:nyb+ ...
M_.endo_nbr, 1, 1, options_.gstep, ...
options_.solve_tolf,options_.solve_tolx, ...
options_.simul.maxit,options_.debug,oo_.exo_simul, ...
M_.params, oo_.steady_state, it);
M_.params, oo_.steady_state, it+M_.maximum_lag-1);
if check
skipline(2);
warning('Simulation terminated after forward recursion of %d periods.\n',it);
oo_.deterministic_simulation.status = 0;% more iterations are needed or model could not be solved.
return
end
oo_.endo_simul(:,it) = tmp(nyb+1:nyb+M_.endo_nbr);
end
\ No newline at end of file
function sim1_purely_forward()
% Performs deterministic simulation of a purely forward model
% Copyright (C) 2012 Dynare Team
% Copyright (C) 2012-2014 Dynare Team
%
% This file is part of Dynare.
%
......@@ -29,15 +29,25 @@ function sim1_purely_forward()
model_dynamic = str2func([M_.fname,'_dynamic']);
oo_.deterministic_simulation.status = 1;
for it = options_.periods:-1:1
yf = oo_.endo_simul(:,it+1); % Values at next period, also used as guess value for current period
yf1 = yf(iyf);
tmp = solve1(model_dynamic, [yf; yf1], 1:M_.endo_nbr, 1:M_.endo_nbr, ...
[tmp, info] = solve1(model_dynamic, [yf; yf1], 1:M_.endo_nbr, 1:M_.endo_nbr, ...
1, 1, options_.gstep, options_.solve_tolf, ...
options_.solve_tolx, options_.simul.maxit, ...
options_.debug,oo_.exo_simul, M_.params, oo_.steady_state, ...
it);
it+M_.maximum_lag);
if info
skipline(2);
warning('Simulation terminated after backward induction of %d periods.\n',it);
oo_.deterministic_simulation.status = 0;% more iterations are needed or model could not be solved.
return
end
oo_.endo_simul(:,it) = tmp(1:M_.endo_nbr);
end
......@@ -45,7 +45,9 @@ number_of_variables = length(x);
% get options.
if isempty(options.maxfcall)
max_func_calls = options.maxfcallfactor*number_of_variables
max_func_calls = options.maxfcallfactor*number_of_variables;
else
max_func_calls=options.maxfcall;
end
% Set tolerance parameter.
......@@ -146,8 +148,8 @@ else
end
% Set delta parameter.
if isfield(options,'delta_parameter')% Size of the simplex
delta = options.delta_parameter;
if isfield(options,'delta_factor')% Size of the simplex
delta = options.delta_factor;
else
delta = 0.05;
end
......
......@@ -57,7 +57,7 @@ end
if size(M_.lead_lag_incidence,2)-nnz(M_.lead_lag_incidence(M_.maximum_endo_lag+1,:)) > 0
mess = ['SIMUL: error in model specification : variable ' M_.endo_names(find(M_.lead_lag_incidence(M_.maximum_lag+1,:)==0),:)];
mess = [mess ' doesn''t appear as current variable.'];
error (mess) ;
error(mess)
end
if options_.periods == 0
......@@ -102,14 +102,19 @@ if(options_.block)
oo_.deterministic_simulation.status = 0;
else
oo_.deterministic_simulation.status = 1;
end;
end
mexErrCheck('bytecode', info);
else
eval([M_.fname '_dynamic']);
end;
end
else
if(options_.bytecode)
[info, oo_.endo_simul]=bytecode('dynamic');
if info == 1
oo_.deterministic_simulation.status = 0;
else
oo_.deterministic_simulation.status = 1;
end;
mexErrCheck('bytecode', info);
else
if M_.maximum_endo_lead == 0 % Purely backward model
......@@ -123,7 +128,7 @@ else
sim1_lbj;
end
end
end;
end;
end
end
dyn2vec;
\ No newline at end of file
function skipline(n,fid)
% Copyright (C) 2013 Dynare Team
% Copyright (C) 2013-2014 Dynare Team
%
% This file is part of Dynare.
%
......@@ -22,7 +22,7 @@ if nargin<2
end
if nargin<1
fid = 1;
n = 1;
end
if ~nargin || isequal(n,1)
......
......@@ -97,7 +97,7 @@ for its = 1:maxit
end
if bad_cond_flag && rcond(fjac) < sqrt(eps)
fjac2=fjac'*fjac;
p=-(fjac2+1e6*sqrt(nn*eps)*max(sum(abs(fjac2)))*eye(nn))\(fjac'*fvec);
p=-(fjac2+sqrt(nn*eps)*max(sum(abs(fjac2)))*eye(nn))\(fjac'*fvec);
else
p = -fjac\fvec ;
end
......
......@@ -38,6 +38,10 @@ elseif options_.order == 3
options_.k_order_solver = 1;
end
% if options_.loglinear == 1 && options_.periods>0
% error('The loglinear option does not work with periods>0.')
% end
if isempty(options_.qz_criterium)
options_.qz_criterium = 1+1e-6;
end
......@@ -77,9 +81,18 @@ elseif options_.discretionary_policy
end
[oo_.dr,ys,info] = discretionary_policy_1(oo_,options_.instruments);
else
if options_.logged_steady_state
oo_.dr.ys=exp(oo_.dr.ys);
oo_.steady_state=exp(oo_.steady_state);
end
[oo_.dr,info,M_,options_,oo_] = resol(0,M_,options_,oo_);
end
if options_.loglinear
oo_.dr.ys=log(oo_.dr.ys);
oo_.steady_state=log(oo_.steady_state);
options_old.logged_steady_state = 1;
end
if info(1)
options_ = options_old;
print_info(info, options_.noprint, options_);
......@@ -127,7 +140,8 @@ end
if options_.periods > 0 && ~PI_PCL_solver
if options_.periods <= options_.drop
disp(['STOCH_SIMUL error: The horizon of simulation is shorter than the number of observations to be dropped'])
fprintf('\nSTOCH_SIMUL error: The horizon of simulation is shorter than the number of observations to be dropped.\n')
fprintf('STOCH_SIMUL error: Either increase options_.periods or decrease options_.drop.\n')
options_ =options_old;
return
end
......@@ -198,7 +212,7 @@ if options_.irf
y(i_var(j),:)');
eval(['oo_.irfs.' deblank(M_.endo_names(i_var(j),:)) '_' ...
deblank(M_.exo_names(i,:)) ' = y(i_var(j),:);']);
if max(y(i_var(j),:)) - min(y(i_var(j),:)) > options_.impulse_responses.plot_threshold
if max(abs(y(i_var(j),:))) > options_.impulse_responses.plot_threshold
irfs = cat(1,irfs,y(i_var(j),:));
if isempty(mylist)
mylist = deblank(var_list(j,:));
......
......@@ -225,9 +225,19 @@ else
dr = dyn_second_order_solver(jacobia_,hessian1,dr,M_,...
options_.threads.kronecker.A_times_B_kronecker_C,...
options_.threads.kronecker.sparse_hessian_times_B_kronecker_C);
% reordering second order derivatives, used for deterministic
% variables below
k1 = nonzeros(M_.lead_lag_incidence(:,order_var)');
kk = [k1; length(k1)+(1:M_.exo_nbr+M_.exo_det_nbr)'];
nk = size(kk,1);
kk1 = reshape([1:nk^2],nk,nk);
kk1 = kk1(kk,kk);
hessian1 = hessian1(:,kk1(:));
end
end
%exogenous deterministic variables
if M_.exo_det_nbr > 0
gx = dr.gx;
......
......@@ -41,7 +41,7 @@ if ~isempty(plist)
end
tmp = dbstack;
message = [message, ' when using ' tmp(2).name '. '];
message = [message, 'If these parameters are not initialized in a steadystate file, Dynare may not be able to solve the model...'];
message = [message, 'If these parameters are not initialized in a steadystate file or a steady_state_model-block, Dynare may not be able to solve the model...'];
message_id = 'Dynare:ParameterCalibration:NaNValues';
warning(message_id,message);
end
\ No newline at end of file
......@@ -2,7 +2,7 @@ function [Gamma_y,stationary_vars] = th_autocovariances(dr,ivar,M_,options_,node
% Computes the theoretical auto-covariances, Gamma_y, for an AR(p) process
% with coefficients dr.ghx and dr.ghu and shock variances Sigma_e_
% for a subset of variables ivar (indices in lgy_)
% Theoretical HPfiltering is available as an option
% Theoretical HP-filtering is available as an option
%
% INPUTS
% dr: [structure] Reduced form solution of the DSGE model (decisions rules)
......@@ -23,8 +23,26 @@ function [Gamma_y,stationary_vars] = th_autocovariances(dr,ivar,M_,options_,node
%
% SPECIAL REQUIREMENTS
%
% Copyright (C) 2001-2012 Dynare Team
% Algorithms
% The means at order=2 are based on the pruned state space as
% in Kim, Kim, Schaumburg, Sims (2008): Calculating and using second-order accurate
% solutions of discrete time dynamic equilibrium models.
% The solution at second order can be written as:
% \[
% \hat x_t = g_x \hat x_{t - 1} + g_u u_t + \frac{1}{2}\left( g_{\sigma\sigma} \sigma^2 + g_{xx}\hat x_t^2 + g_{uu} u_t^2 \right)
% \]
% Taking expectations on both sides requires to compute E(x^2)=Var(x), which
% can be obtained up to second order from the first order solution
% \[
% \hat x_t = g_x \hat x_{t - 1} + g_u u_t
% \]
% by solving the corresponding Lyapunov equation.
% Given Var(x), the above equation can be solved for E(x_t) as
% \[
% E(x_t) = (I - {g_x}\right)^{- 1} 0.5\left( g_{\sigma\sigma} \sigma^2 + g_{xx} Var(\hat x_t) + g_{uu} Var(u_t) \right)
% \]
%
% Copyright (C) 2001-2014 Dynare Team
%
% This file is part of Dynare.
%
......@@ -202,11 +220,15 @@ else% ==> Theoretical HP filter.
IA = eye(size(A,1));
IE = eye(M_.exo_nbr);
for ig = 1:ngrid
if hp1(ig)==0,
f_hp = zeros(length(ivar),length(ivar));
else
f_omega =(1/(2*pi))*( [inv(IA-A*tneg(ig))*ghu1;IE]...
*M_.Sigma_e*[ghu1'*inv(IA-A'*tpos(ig)) ...
IE]); % state variables
g_omega = [aa*tneg(ig) bb]*f_omega*[aa'*tpos(ig); bb']; % selected variables
f_hp = hp1(ig)^2*g_omega; % spectral density of selected filtered series
end
mathp_col = [mathp_col ; (f_hp(:))']; % store as matrix row
% for ifft
end;
......@@ -233,11 +255,15 @@ else% ==> Theoretical HP filter.
IA = eye(size(A,1));
IE = eye(M_.exo_nbr);
for ig = 1:ngrid
if hp1(ig)==0,
f_hp = zeros(length(ivar),length(ivar));
else
f_omega =(1/(2*pi))*( [inv(IA-A*tneg(ig))*b1;IE]...
*SS*[b1'*inv(IA-A'*tpos(ig)) ...
IE]); % state variables
g_omega = [aa*tneg(ig) b2]*f_omega*[aa'*tpos(ig); b2']; % selected variables
f_hp = hp1(ig)^2*g_omega; % spectral density of selected filtered series
end
mathp_col = [mathp_col ; (f_hp(:))']; % store as matrix row
% for ifft
end;
......@@ -247,11 +273,15 @@ else% ==> Theoretical HP filter.
mathp_col = [];
SSi = cs(:,i)*cs(:,i)';
for ig = 1:ngrid
if hp1(ig)==0,
f_hp = zeros(length(ivar),length(ivar));
else
f_omega =(1/(2*pi))*( [inv(IA-A*tneg(ig))*b1;IE]...
*SSi*[b1'*inv(IA-A'*tpos(ig)) ...
IE]); % state variables
g_omega = [aa*tneg(ig) b2]*f_omega*[aa'*tpos(ig); b2']; % selected variables
f_hp = hp1(ig)^2*g_omega; % spectral density of selected filtered series
end
mathp_col = [mathp_col ; (f_hp(:))']; % store as matrix row
% for ifft
end;
......
File moved
function b = isdiagonal(A) % --*-- Unitary tests --*--
% Copyright (C) 2014 Dynare Team
%
% This file is part of Dynare.
%
% Dynare is free software: you can redistribute it and/or modify
% it under the terms of the GNU General Public License as published by
% the Free Software Foundation, either version 3 of the License, or
% (at your option) any later version.
%
% Dynare is distributed in the hope that it will be useful,
% but WITHOUT ANY WARRANTY; without even the implied warranty of
% MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
% GNU General Public License for more details.
%
% You should have received a copy of the GNU General Public License
% along with Dynare. If not, see <http://www.gnu.org/licenses/>.
if isnumeric(A)
if isquare(A)
% Find non zero elements in matrix A...
[ir, ic] = find(A);
% If the non zero elements are on the diagonal, the corresponding elements
% in ir and ic (row and column numbers) should be equal.
b = isequal(ir, ic);
else
error('isdiagonal: Input must be a square matrix!')
end
else
error('isdiagonal: Input must be numeric!')
end
%@test:1
%$ A = zeros(3,3);
%$ t = isdiagonal(A);
%$ T = all(t);
%@eof:1
%@test:2
%$ A = zeros(3,3); A(1,3) = 1;
%$ t = ~isdiagonal(A);
%$ T = all(t);
%@eof:2
%@test:3
%$ A = randn(3,3);
%$ t = ~isdiagonal(A);
%$ T = all(t);
%@eof:3
%@test:4
%$ A = diag(randn(3,1));
%$ t = isdiagonal(A);
%$ T = all(t);
%@eof:4
%@test:5
%$ A = diag(randn(3,1)); A(1,1) = 0;
%$ t = isdiagonal(A);
%$ T = all(t);
%@eof:5