Store deterministic shocks information in M_.
Previously, deterministic shock information was not store in M_, but rather processed on the fly to create oo_.exo_simul and oo_.exo_det_simul. This had several bad consequences, like for example #35. Closes #271time-shift
parent
bb1fd49629
commit
82b3115696
|
@ -37,20 +37,37 @@ end
|
|||
if M_.exo_det_nbr > 1 && isempty(oo_.exo_det_steady_state)
|
||||
oo_.exo_det_steady_state = zeros(M_.exo_det_nbr,1);
|
||||
end
|
||||
if isempty(oo_.exo_simul)
|
||||
if isempty(ex0_)
|
||||
oo_.exo_simul = repmat(oo_.exo_steady_state',M_.maximum_lag+options_.periods+M_.maximum_lead,1);
|
||||
else
|
||||
oo_.exo_simul = [ repmat(ex0_',M_.maximum_lag,1) ; repmat(oo_.exo_steady_state',options_.periods+M_.maximum_lead,1) ];
|
||||
end
|
||||
elseif size(oo_.exo_simul,1) < M_.maximum_lag+M_.maximum_lead+options_.periods
|
||||
oo_.exo_simul = [ oo_.exo_simul ; repmat(oo_.exo_steady_state',M_.maximum_lag+options_.periods+M_.maximum_lead-size(oo_.exo_simul,1),1) ];
|
||||
|
||||
% Initialize oo_.exo_simul
|
||||
if isempty(ex0_)
|
||||
oo_.exo_simul = repmat(oo_.exo_steady_state',M_.maximum_lag+options_.periods+M_.maximum_lead,1);
|
||||
else
|
||||
oo_.exo_simul = [ repmat(ex0_',M_.maximum_lag,1) ; repmat(oo_.exo_steady_state',options_.periods+M_.maximum_lead,1) ];
|
||||
end
|
||||
|
||||
% Initialize oo_.exo_det_simul
|
||||
if M_.exo_det_nbr > 0
|
||||
if isempty(oo_.exo_det_simul)
|
||||
oo_.exo_det_simul = [ones(M_.maximum_lag+options_.periods+M_.maximum_lead,1)*oo_.exo_det_steady_state'];
|
||||
elseif size(oo_.exo_det_simul,1) < M_.maximum_lag+M_.maximum_lead+options_.periods
|
||||
oo_.exo_det_simul = [oo_.exo_det_simul; ones(M_.maximum_lag+options_.periods+M_.maximum_lead-size(oo_.exo_det_simul,1),1)*oo_.exo_det_steady_state'];
|
||||
oo_.exo_det_simul = [ones(M_.maximum_lag+options_.periods+M_.maximum_lead,1)*oo_.exo_det_steady_state'];
|
||||
end
|
||||
|
||||
% Add temporary shocks
|
||||
if isfield(M_, 'det_shocks')
|
||||
for i = 1:length(M_.det_shocks)
|
||||
k = M_.det_shocks(i).periods + M_.maximum_lag;
|
||||
ivar = M_.det_shocks(i).exo_id;
|
||||
v = M_.det_shocks(i).value;
|
||||
if ~M_.det_shocks(i).exo_det
|
||||
if ~M_.det_shocks(i).multiplicative
|
||||
oo_.exo_simul(k,ivar) = v;
|
||||
else
|
||||
oo_.exo_simul(k,ivar) = oo_.exo_simul(k,ivar) * v;
|
||||
end
|
||||
else
|
||||
if ~M_.det_shocks(i).multiplicative
|
||||
oo_.exo_det_simul(k,ivar) = v;
|
||||
else
|
||||
oo_.exo_det_simul(k,ivar) = oo_.exo_det_simul(k,ivar) * v;
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
|
@ -1,67 +0,0 @@
|
|||
function set_shocks(flag,k,ivar,values)
|
||||
|
||||
% function set_shocks(flag,k,ivar,values)
|
||||
% writes a deterministic shock into exo_simul or exo_det_simul
|
||||
%
|
||||
% INPUTS
|
||||
% flag=0: replaces exo_simul
|
||||
% flag=1: multiplicative shock into exo_simul
|
||||
% flag=2: replaces exo_det_simul
|
||||
% flag=3: multipliczative shock into exo_det_simul
|
||||
% k: period
|
||||
% ivar: indice of exogenous variables
|
||||
% values: shock values
|
||||
%
|
||||
% OUTPUTS
|
||||
% none
|
||||
%
|
||||
% SPECIAL REQUIREMENTS
|
||||
% none
|
||||
|
||||
% Copyright (C) 2003-2011 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/>.
|
||||
|
||||
global oo_ M_
|
||||
|
||||
k = k + M_.maximum_lag;
|
||||
n1 = size(oo_.exo_simul,1);
|
||||
n2 = size(oo_.exo_det_simul,1);
|
||||
if k(end) > n1 && flag <= 1
|
||||
oo_.exo_simul = [oo_.exo_simul; repmat(oo_.exo_steady_state',k(end)-n1,1)];
|
||||
elseif k(end) > n2 && flag > 1
|
||||
oo_.exo_det_simul = [oo_.exo_det_simul; repmat(oo_.exo_det_steady_state',k(end)-n2,1)];
|
||||
end
|
||||
|
||||
switch flag
|
||||
case 0
|
||||
if size(values,1) == 1
|
||||
oo_.exo_simul(k,ivar) = repmat(values,length(k),1);
|
||||
else
|
||||
oo_.exo_simul(k,ivar) = values;
|
||||
end
|
||||
case 1
|
||||
oo_.exo_simul(k,ivar) = oo_.exo_simul(k,ivar).*values;
|
||||
case 2
|
||||
if size(values,1) == 1
|
||||
oo_.exo_det_simul(k,ivar) = repmat(values,length(k),1);
|
||||
else
|
||||
oo_.exo_det_simul(k,ivar) = values;
|
||||
end
|
||||
case 3
|
||||
oo_.exo_det_simul(k,ivar) = oo_.exo_det_simul(k,ivar).*values;
|
||||
end
|
||||
|
|
@ -36,13 +36,13 @@ void
|
|||
AbstractShocksStatement::writeDetShocks(ostream &output) const
|
||||
{
|
||||
int exo_det_length = 0;
|
||||
int counter = 1;
|
||||
|
||||
for (det_shocks_t::const_iterator it = det_shocks.begin();
|
||||
it != det_shocks.end(); it++)
|
||||
{
|
||||
int id = symbol_table.getTypeSpecificID(it->first) + 1;
|
||||
bool exo_det = (symbol_table.getType(it->first) == eExogenousDet);
|
||||
int set_shocks_index = ((int) mshocks) + 2 * ((int) exo_det);
|
||||
|
||||
for (size_t i = 0; i < it->second.size(); i++)
|
||||
{
|
||||
|
@ -50,20 +50,19 @@ AbstractShocksStatement::writeDetShocks(ostream &output) const
|
|||
const int &period2 = it->second[i].period2;
|
||||
const expr_t value = it->second[i].value;
|
||||
|
||||
if (period1 == period2)
|
||||
{
|
||||
output << "set_shocks(" << set_shocks_index << "," << period1
|
||||
<< ", " << id << ", ";
|
||||
value->writeOutput(output);
|
||||
output << ");" << endl;
|
||||
}
|
||||
else
|
||||
{
|
||||
output << "set_shocks(" << set_shocks_index << "," << period1
|
||||
<< ":" << period2 << ", " << id << ", ";
|
||||
value->writeOutput(output);
|
||||
output << ");" << endl;
|
||||
}
|
||||
output << "M_.det_shocks(" << counter << ").exo_det=" << (int) exo_det
|
||||
<< ";" << endl
|
||||
<< "M_.det_shocks(" << counter << ").exo_id=" << id
|
||||
<< ";" << endl
|
||||
<< "M_.det_shocks(" << counter << ").multiplicative=" << (int) mshocks
|
||||
<< ";" << endl
|
||||
<< "M_.det_shocks(" << counter << ").periods=" << period1
|
||||
<< ":" << period2 << ";" << endl
|
||||
<< "M_.det_shocks(" << counter << ").value=(";
|
||||
value->writeOutput(output);
|
||||
output << ");" << endl;
|
||||
|
||||
counter++;
|
||||
|
||||
if (exo_det && (period2 > exo_det_length))
|
||||
exo_det_length = period2;
|
||||
|
@ -93,9 +92,6 @@ ShocksStatement::writeOutput(ostream &output, const string &basename) const
|
|||
<< "% SHOCKS instructions" << endl
|
||||
<< "%" << endl;
|
||||
|
||||
// Write instruction that initializes a shock
|
||||
output << "make_ex_;" << endl;
|
||||
|
||||
writeDetShocks(output);
|
||||
writeVarAndStdShocks(output);
|
||||
writeCovarAndCorrShocks(output);
|
||||
|
@ -313,9 +309,6 @@ MShocksStatement::writeOutput(ostream &output, const string &basename) const
|
|||
<< "% MSHOCKS instructions" << endl
|
||||
<< "%" << endl;
|
||||
|
||||
// Write instruction that initializes a shock
|
||||
output << "make_ex_;" << endl;
|
||||
|
||||
writeDetShocks(output);
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue