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
  • chskcau/dynare-doc-fixes
27 results
Select Git revision
Loading items
Show changes
Showing
with 177 additions and 58 deletions
function plan = init_plan(date)
% Creates and initializes a new forecast scenario
%
% INPUTS
% o date [dates] The period of the forecast
%
%
% OUTPUTS
% plan [structure] Returns a structure containing a new forecast scenario
%
%
% Copyright (C) 2013-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/>.
global M_
plan = struct();
plan.date = date;
endo_names_length = size(M_.endo_names,2);
plan.endo_names = deblank(mat2cell(M_.endo_names(1:M_.orig_endo_nbr,:),ones(1,M_.orig_endo_nbr),endo_names_length));
exo_names_length = size(M_.exo_names,2);
plan.exo_names = deblank(mat2cell(M_.exo_names(1:M_.exo_nbr,:),ones(1,M_.exo_nbr),exo_names_length));
plan.constrained_vars_ = [];
plan.constrained_paths_ = [];
plan.constrained_date_ = [];
plan.constrained_perfect_foresight_ = [];
plan.shock_vars_ = [];
plan.shock_paths_ = [];
plan.shock_date_ = [];
plan.shock_perfect_foresight_ = [];
plan.options_cond_fcst_ = struct();
plan.options_cond_fcst_.parameter_set = 'calibration';
plan.options_cond_fcst_.simulation_type = 'deterministic';
plan.options_cond_fcst_.controlled_varexo = [];
......@@ -49,7 +49,7 @@ if isoctave
withvars = L.numlimits(2,1) > L.txtlimits(2,1);
withtime = L.numlimits(1,1) > L.txtlimits(1,1);
else
A = importdata(file);
A = importdata(file, ',');
if ~isstruct(A)
data = A;
T = {};
......
......@@ -76,10 +76,14 @@ if isequal(t1,0) && isequal(t2,0)
% The file contains no informations about the variables and dates.
notime = 1;
noname = 1;
elseif isequal(t2,1) && t1>=t2
% The file contains no informations about the variables.
elseif isequal(t2,1) && t1>=t2 && n2~=t2 %only one column present, but no var name in header text
% The file contains no informations about the dates.
notime = 0;
noname = 1;
elseif isequal(t2,1) && t1>=t2 && n2==t2 %only one column present with var name in header text
% The file contains no informations about the variables.
notime = 1;
noname = 0;
elseif isequal(t1,1) && t2>=t1
% The file contains no informations about the dates.
notime = 1;
......
......@@ -104,9 +104,9 @@ qz_criterium = third_argument;
if method
persistent U T k n
else
if exist('U','var')
clear('U','T','k','n')
end
% if exist('U','var')
% clear('U','T','k','n')
% end
end
u = [];
......
......@@ -12,7 +12,7 @@ function make_y_()
% none
%
% Copyright (C) 1996-2012 Dynare Team
% Copyright (C) 1996-2014 Dynare Team
%
% This file is part of Dynare.
%
......
function forcs = mcforecast3(cL,H,mcValue,shocks,forcs,T,R,mv,mu)
% Copyright (C) 2006-2008 Dynare Team
% forcs = mcforecast3(cL,H,mcValue,shocks,forcs,T,R,mv,mu)
% Computes the shock values for constrained forecasts necessary to keep
% endogenous variables at their constrained paths
%
% INPUTS
% o cL [scalar] number of controlled periods
% o H [scalar] number of forecast periods
% o mcValue [n_controlled_vars by cL double] paths for constrained variables
% o shocks [nexo by H double] shock values draws (with zeros for controlled_varexo)
% o forcs
% o T [n_endovars by n_endovars double] transition matrix of the state equation.
% o R [n_endovars by n_exo double] matrix relating the endogenous variables to the innovations in the state equation.
% o mv [n_controlled_exo by n_endovars boolean] indicator vector selecting constrained endogenous variables
% o mu [n_controlled_vars by nexo boolean] indicator vector
% selecting controlled exogenous variables
%
% Algorithm:
% Relies on state-space form:
% y_t=T*y_{t-1}+R*shocks(:,t)
% Shocks are split up into shocks_uncontrolled and shockscontrolled while
% the endogenous variables are also split up into controlled and
% uncontrolled ones to get:
% y_t(controlled_vars_index)=T*y_{t-1}(controlled_vars_index)+R(controlled_vars_index,uncontrolled_shocks_index)*shocks_uncontrolled_t
% + R(controlled_vars_index,controlled_shocks_index)*shocks_controlled_t
%
% This is then solved to get:
% shocks_controlled_t=(y_t(controlled_vars_index)-(T*y_{t-1}(controlled_vars_index)+R(controlled_vars_index,uncontrolled_shocks_index)*shocks_uncontrolled_t)/R(controlled_vars_index,controlled_shocks_index)
%
% After obtaining the shocks, and for uncontrolled periods, the state-space representation
% y_t=T*y_{t-1}+R*shocks(:,t)
% is used for forecasting
%
% Copyright (C) 2006-2013 Dynare Team
%
% This file is part of Dynare.
%
......
......@@ -243,13 +243,14 @@ elseif options_.load_mh_file && ~options_.mh_recover
LastLineNumber = record.LastLineNumber;
if LastLineNumber < MAX_nruns
NewFile = ones(nblck,1)*LastFileNumber;
fline = ones(nblck,1)*(LastLineNumber+1);
else
NewFile = ones(nblck,1)*(LastFileNumber+1);
fline = ones(nblck,1);
end
ilogpo2 = record.LastLogPost;
ix2 = record.LastParameters;
fblck = 1;
fline = ones(nblck,1)*(LastLineNumber+1);
NumberOfPreviousSimulations = sum(record.MhDraws(:,1),1);
fprintf('Estimation::mcmc: I am writting a new mh-history file... ');
record.MhDraws = [record.MhDraws;zeros(1,3)];
......
......@@ -66,36 +66,48 @@ Q = DynareModel.Sigma_e;
H = DynareModel.H;
% Test if Q is positive definite.
if EstimatedParams.ncx
if ~issquare(Q) || EstimatedParams.ncx || isfield(EstimatedParams,'calibrated_covariances')
% Try to compute the cholesky decomposition of Q (possible iff Q is positive definite)
[CholQ,testQ] = chol(Q);
if testQ
[Q_is_positive_definite, penalty] = ispd(Q);
if ~Q_is_positive_definite
% The variance-covariance matrix of the structural innovations is not definite positive. We have to compute the eigenvalues of this matrix in order to build the endogenous penalty.
a = diag(eig(Q));
k = find(a < 0);
if k > 0
fval = objective_function_penalty_base+sum(-a(k));
fval = objective_function_penalty_base+penalty;
exit_flag = 0;
info = 43;
return
end
if isfield(EstimatedParams,'calibrated_covariances')
correct_flag=check_consistency_covariances(Q);
if ~correct_flag
penalty = sum(Q(EstimatedParams.calibrated_covariances.position).^2);
fval = objective_function_penalty_base+penalty;
exit_flag = 0;
info = 71;
return
end
end
end
% Test if H is positive definite.
if EstimatedParams.ncn
% Try to compute the cholesky decomposition of H (possible iff H is positive definite)
[CholH,testH] = chol(H);
if testH
if ~issquare(H) || EstimatedParams.ncn || isfield(EstimatedParams,'calibrated_covariances_ME')
[H_is_positive_definite, penalty] = ispd(H);
if ~H_is_positive_definite
% The variance-covariance matrix of the measurement errors is not definite positive. We have to compute the eigenvalues of this matrix in order to build the endogenous penalty.
a = diag(eig(H));
k = find(a < 0);
if k > 0
fval = objective_function_penalty_base+sum(-a(k));
fval = objective_function_penalty_base+penalty;
exit_flag = 0;
info = 44;
return
end
if isfield(EstimatedParams,'calibrated_covariances_ME')
correct_flag=check_consistency_covariances(H);
if ~correct_flag
penalty = sum(H(EstimatedParams.calibrated_covariances_ME.position).^2);
fval = objective_function_penalty_base+penalty;
exit_flag = 0;
info = 72;
return
end
end
end
......
......@@ -177,7 +177,7 @@ while notsteady && t<smpl
atilde(:,t) = a(:,t) + PZI*v(di,t);
K(:,di,t) = T*PZI;
L(:,:,t) = T-K(:,di,t)*ZZ;
P(:,:,t+1) = T*P(:,:,t)*T'-T*P(:,:,t)*ZZ'*K(:,di,t)' + QQ;
P(:,:,t+1) = T*P(:,:,t)*L(:,:,t)' + QQ;
end
a(:,t+1) = T*atilde(:,t);
Pf = P(:,:,t);
......
......@@ -75,10 +75,18 @@ for i=1:NumberOfModels
eval(['MarginalLogDensity(i) = mstruct.oo_.MarginalDensity.' type ';'])
catch
if strcmpi(type,'LaplaceApproximation')
if isfield(mstruct.oo_,'mle_mode')
disp(['MODEL_COMPARISON: Model comparison is a Bayesian approach and does not support models estimated with ML'])
else
disp(['MODEL_COMPARISON: I cant''t find the Laplace approximation associated to model ' ModelNames{i}])
end
return
elseif strcmpi(type,'ModifiedHarmonicMean')
if isfield(mstruct.oo_,'mle_mode')
disp(['MODEL_COMPARISON: Model comparison is a Bayesian approach and does not support models estimated with ML'])
else
disp(['MODEL_COMPARISON: I cant''t find the modified harmonic mean estimate associated to model ' ModelNames{i}])
end
return
end
end
......@@ -124,7 +132,7 @@ name = modelname(idx(end)+1:end);
function name = get_model_name_without_extension(modelname)
idx = strfind(modelname,'.mod');
if isempty(idx)
idx = strfind(modelname,'.dyn')
idx = strfind(modelname,'.dyn');
end
if isempty(idx)
name = modelname;
......
......@@ -101,6 +101,7 @@ while i<n
h1(i)=2.1*h1(i);
end
h1(i) = min(h1(i),0.5*hmax(i));
h1(i) = max(h1(i),1.e-10);
xh1(i)=x(i)+h1(i);
try
[fx, ffx]=feval(func,xh1,DynareDataset,DynareOptions,Model,EstimatedParameters,BayesInfo,DynareResults);
......
......@@ -25,18 +25,20 @@ function [final_year,final_subperiod]=check_datafile_years_assigned(options_)
% You should have received a copy of the GNU General Public License
% along with Dynare. If not, see <http://www.gnu.org/licenses/>.
final_year = [];
final_subperiod = [];
final_year = options_.ms.final_year;
final_subperiod = options_.ms.final_subperiod;
if isempty(options_.ms.initial_year)
error('Must set initial_year option');
end
if isempty(options_.ms.final_year)
if isempty(final_year)
n = size(options_.data,1);
freq = options_.ms.freq;
final_subperiod = mod(options_.ms.initial_subperiod+n-2,freq)+1;
final_year = options_.ms.initial_year + floor((n-1)/freq);
elseif isempty(final_subperiod)
final_subperiod = options_.ms.freq;
end
if isempty(options_.datafile)
......
......@@ -11,7 +11,7 @@ function delete_dir_if_exists(dirname)
% SPECIAL REQUIREMENTS
% none
% Copyright (C) 2011 Dynare Team
% Copyright (C) 2011-2014 Dynare Team
%
% This file is part of Dynare.
%
......
......@@ -41,7 +41,7 @@ options_.ms.create_init = 1;
options_.ms.coefficients_prior_hyperparameters = [1.0 1.0 0.1 1.2 1.0 1.0];
options_.ms.freq = 4;
options_.ms.initial_subperiod = 1;
options_.ms.final_subperiod=4;
options_.ms.final_subperiod = '';
options_.ms.nlags = 1;
options_.ms.cross_restrictions = 0;
options_.ms.contemp_reduced_form = 0;
......
......@@ -30,11 +30,7 @@ function ms_sbvar_setup(options_)
options_.data = read_variables(options_.datafile, ...
options_.varobs, [], options_.xls_sheet, options_.xls_range);
[final_year,final_subperiod] = check_datafile_years_assigned(options_);
if ~isempty(final_year)
options_.ms.final_year = final_year;
opions_.ms.final_subperiod = final_subperiod;
end
[options_.ms.final_year,options_.ms.final_subperiod] = check_datafile_years_assigned(options_);
if options_.ms.upper_cholesky
if options_.ms.lower_cholesky
......
......@@ -34,11 +34,7 @@ function sbvar(M, options)
clean_sbvar_files();
options.data = read_variables(options.datafile,options.varobs,[],options.xls_sheet,options.xls_range);
[final_year,final_subperiod] = check_datafile_years_assigned(options);
if ~isempty(final_year)
options.ms.final_year = final_year;
opions.ms.final_subperiod = final_subperiod;
end
[options.ms.final_year,options.ms.final_subperiod] = check_datafile_years_assigned(options);
if options.forecast == 0
options.forecast = 4;
......
......@@ -122,7 +122,7 @@ while norm(gg)>gtol && check==0 && jit<nit
fval=fval1;
x0=x01;
end
if icount==1 || (icount>1 && (fval0(icount-1)-fval0(icount))>1) || ((fval0(icount)-fval)<1.e-2*(gg'*(H*gg))/2 && igibbs),
% if icount==1 || (icount>1 && (fval0(icount-1)-fval0(icount))>1) || ((fval0(icount)-fval)<1.e-2*(gg'*(H*gg))/2 && igibbs),
if length(find(ig))<nx
ggx=ggx*0;
ggx(find(ig))=gg(find(ig));
......@@ -139,7 +139,7 @@ while norm(gg)>gtol && check==0 && jit<nit
nig=[nig ig];
disp('Sequence of univariate steps!!')
fval=fvala;
end
% end
if (fval0(icount)-fval)<ftol && flagit==0
disp('Try diagonal Hessian')
ihh=diag(1./(diag(hhg)));
......
......@@ -133,6 +133,11 @@ ys = [];
trend_coeff = [];
exit_flag = 1;
% Issue an error if loglinear option is used.
if DynareOptions.loglinear
error('non_linear_dsge_likelihood: It is not possible to use a non linear filter with the option loglinear!')
end
% Set the number of observed variables
nvobs = DynareDataset.info.nvobs;
......@@ -212,7 +217,7 @@ end
% Linearize the model around the deterministic sdteadystate and extract the matrices of the state equation (T and R).
[T,R,SteadyState,info,Model,DynareOptions,DynareResults] = dynare_resolve(Model,DynareOptions,DynareResults,'restrict');
if info(1) == 1 || info(1) == 2 || info(1) == 5
if info(1) == 1 || info(1) == 2 || info(1) == 5 || info(1) == 25
fval = objective_function_penalty_base+1;
exit_flag = 0;
return
......@@ -228,13 +233,9 @@ BayesInfo.mf = BayesInfo.mf1;
% Define the deterministic linear trend of the measurement equation.
if DynareOptions.noconstant
constant = zeros(nvobs,1);
else
if DynareOptions.loglinear
constant = log(SteadyState(BayesInfo.mfys));
else
constant = SteadyState(BayesInfo.mfys);
end
end
% Define the deterministic linear trend of the measurement equation.
if BayesInfo.with_trend
......
......@@ -40,7 +40,15 @@ if ~ M_.lead_lag_incidence(M_.maximum_lag+1,:) > 0
end
if M_.maximum_lead == 0
error ('Backward or static model: no point in using OSR') ;
error ('OSR: Backward or static model: no point in using OSR') ;
end
if any(any(isinf(weights)))
error ('OSR: At least one of the optim_weights is infinite.') ;
end
if any(isnan(M_.params(i_params)))
error ('OSR: At least one of the initial parameter values for osr_params is NaN') ;
end
exe =zeros(M_.exo_nbr,1);
......@@ -50,6 +58,8 @@ oo_.dr = set_state_space(oo_.dr,M_,options_);
np = size(i_params,1);
t0 = M_.params(i_params);
inv_order_var = oo_.dr.inv_order_var;
H0 = 1e-4*eye(np);
......@@ -57,6 +67,8 @@ crit=options_.osr.tolf;
nit=options_.osr.maxit;
verbose=options_.osr.verbose;
%extract unique entries of covariance
i_var=unique(i_var);
%% do initial checks
[loss,vx,info,exit_flag]=osr_obj(t0,i_params,inv_order_var(i_var),weights(i_var,i_var));
if info~=0
......@@ -64,12 +76,20 @@ if info~=0
else
fprintf('\nOSR: Initial value of the objective function: %g \n\n',loss);
end
if isinf(loss)
fprintf('\nOSR: The initial value of the objective function is infinite.\n');
fprintf('\nOSR: Check whether the unconditional variance of a target variable is infinite\n');
fprintf('\nOSR: due to the presence of a unit root.\n');
error('OSR: Initial likelihood is infinite')
end
%%do actual optimization
[f,p]=csminwel1('osr_obj',t0,H0,[],crit,nit,options_.gradient_method,options_.gradient_epsilon,i_params,...
inv_order_var(i_var),weights(i_var,i_var));
oo_.osr.objective_function = f;
M_.params(i_params)=p; %make sure optimal parameters are set (and not the last draw used in csminwel)
% options = optimset('fminunc');
% options = optimset('display','iter');
% [p,f]=fminunc(@osr_obj,t0,options,i_params,...
......
......@@ -86,4 +86,4 @@ switch info(1)
end
vx = get_variance_of_endogenous_variables(dr,i_var);
loss = weights(:)'*vx(:);
loss = full(weights(:)'*vx(:));