From 0efcef8f20c549c1484ce56c8986bc4c24d5292a Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?St=C3=A9phane=20Adjemian=20=28Scylla=29?=
 <stephane.adjemian@univ-lemans.fr>
Date: Mon, 21 Jul 2014 12:45:49 +0200
Subject: [PATCH] Added the possibility to declare non linear prior
 restrictions over estimated parameters.

If a file <MOD_FILE_NAME>_prior_restrictions.m exists in current folder, the value returned by this routine is
substracted to fval (likelihood-lnprior) at the end of dsge_likelihood. The arguments of this routine are: M_,
oo_, options_, dataset_ and dataset_info. Routines for writing <MOD_FILE_NAME>_prior_restrictions.m will be
provided later.
---
 matlab/dsge_likelihood.m        | 6 ++++++
 matlab/dynare_estimation_init.m | 6 ++++++
 matlab/global_initialization.m  | 4 ++++
 3 files changed, 16 insertions(+)

diff --git a/matlab/dsge_likelihood.m b/matlab/dsge_likelihood.m
index 58272ae05..7f32d6a71 100644
--- a/matlab/dsge_likelihood.m
+++ b/matlab/dsge_likelihood.m
@@ -809,6 +809,7 @@ if analytic_derivation
 else
     lnprior = priordens(xparam1,BayesInfo.pshape,BayesInfo.p6,BayesInfo.p7,BayesInfo.p3,BayesInfo.p4);
 end
+
 if DynareOptions.endogenous_prior==1
   if DynareOptions.lik_init==2 || DynareOptions.lik_init==3
     error('Endogenous prior not supported with non-stationary models')
@@ -820,6 +821,11 @@ else
   fval    = (likelihood-lnprior);
 end
 
+if DynareOptions.prior_restrictions.status
+    tmp = feval(DynareOptions.prior_restrictions.routine, Model, DynareResults, DynareOptions, DynareDataset, DatasetInfo);
+    fval = fval - tmp;
+end
+
 if isnan(fval)
     info = 47;
     fval = objective_function_penalty_base + 100;
diff --git a/matlab/dynare_estimation_init.m b/matlab/dynare_estimation_init.m
index 1bdbf0f59..f0a4636c6 100644
--- a/matlab/dynare_estimation_init.m
+++ b/matlab/dynare_estimation_init.m
@@ -130,6 +130,12 @@ if ~isempty(estim_params_)
     [xparam1,estim_params_,bayestopt_,lb,ub,M_] = set_prior(estim_params_,M_,options_);
 end
 
+% Check if a _prior_restrictions.m file exists
+if exist([M_.fname '_prior_restrictions.m'])
+    options_.prior_restrictions.status = 1;
+    options_.prior_restrictions.routine = str2func([M_.fname '_prior_restrictions.m']);
+end
+
 % Check that the provided mode_file is compatible with the current estimation settings.
 if ~isempty(estim_params_) && ~isempty(options_.mode_file) && ~options_.mh_posterior_mode_estimation
     number_of_estimated_parameters = length(xparam1);
diff --git a/matlab/global_initialization.m b/matlab/global_initialization.m
index 53a2d5362..39f9659d1 100644
--- a/matlab/global_initialization.m
+++ b/matlab/global_initialization.m
@@ -394,6 +394,10 @@ options_.MCMC_jumping_covariance='hessian';
 options_.use_calibration_initialization = 0;
 options_.endo_vars_for_moment_computations_in_estimation=[];
 
+% Prior restrictions
+options_.prior_restrictions.status = 0;
+options_.prior_restrictions.routine = [];
+
 options_.mode_compute = 4;
 options_.mode_file = '';
 options_.moments_varendo = 0;
-- 
GitLab