Commit Graph

1453 Commits (edede274f27e1fcd4d43037e0cebae105c37adbd)

Author SHA1 Message Date
Stéphane Adjemian (Charybdis) 78c36dd0b7 Fixed data files for nonlinear filter's integration test. 2019-12-20 11:31:56 +01:00
Stéphane Adjemian (Charybdis) 53c9d9de69 Use steady_state_model in tests/particles/dsge_base2.mod. 2019-12-20 11:31:56 +01:00
Stéphane Adjemian (Odysseus) 58da5e7120 Added timing for comparing the mex iterating on the nonlinear reduced form model.
local_state_space_iteration_k is significantly slower than old local_state_space_iteration_2...
2019-12-20 11:31:56 +01:00
Sébastien Villemot 996bdd6c64 New local_state_space_iteration_k MEX, for nonlinear filters at k-order
It applies the approximated policy function to a set of particles, using
Dynare++ routines.

There is support for parallelization, using Dynare++ multithreading
model (itself based on C++11 threads; we don’t use OpenMP because it is
incompatible with MKL). For the time being, default to a single thread. This
should be later refined through empirical testing.
2019-12-20 11:31:56 +01:00
Marco Ratto 87963acb3a adapted test function for plot shock decompositions. still needs the new option with_epilogue. 2019-12-19 22:23:28 +01:00
Sébastien Villemot 1ac7344e42
Rollback introduction of +get and +set folders
Under Octave, having namespaces called “get” and “set” overshadows the builtin
functions with the same names, which are needed for graphics manipulation.

Therefore we go back to the initial function naming scheme, but moving all
those functions under an “accessors” subdirectory.

Among other things, this is a revert of
e4134ab59b and
c5e86fcb59.

Ref. !1655, !1686
2019-12-19 17:20:38 +01:00
Sébastien Villemot efa6c6c682
“datafile” option of “perfect_foresight_setup” (and “simul”) now equivalent to “initval_file”
Ref. #1663
2019-12-19 14:58:54 +01:00
Sébastien Villemot 7e07d3e0fc
Testsuite: add further check to verify that “initval_file” works as expected
Ref. #1663
2019-12-19 14:51:59 +01:00
Sébastien Villemot e81c837c51
Testsuite: fix engine for testing M scripts
I’m not sure it has ever worked.

As a consequence, remove the workaround that had apparently been implemented in
tests/initval_file/ramst_initval_file.mod.
2019-12-19 14:51:56 +01:00
Sébastien Villemot 2c9ea629bd Merge branch 'utilsx' into 'master'
Moved get and set utilities to +get and +set

See merge request Dynare/dynare!1686
2019-12-19 09:42:19 +00:00
Sébastien Villemot f720f470bf
Preprocessor update
— “ramsey_policy”: bugfix when no option is passed
— various improvements to “epilogue” (preprocessor#36)
— compatibility with Bison 3.5
— bugfix in search for constant equations
— new “planner_discount_latex_name” option of “ramsey_policy” (Closes: #1686)
2019-12-18 17:46:38 +01:00
Sébastien Villemot cc54fff571
Testsuite: fix typo in m/optimal_policy/Ramsey rule 2019-12-18 17:29:12 +01:00
Sébastien Villemot 6ba10b88f2
Preprocessor: various provisions for improvements to shock decomposition
Accordingly update the MATLAB routines, the testsuite, and the manual.

In particular, “squeeze_shock_decomp” has been renamed to
“squeeze_shock_decomposition” for consistency with other commands.

Ref. #1687, !1655
2019-12-18 11:56:57 +01:00
Marco Ratto e4134ab59b fixed calls to moved utilities 2019-12-17 22:26:38 +01:00
Stéphane Adjemian (Odysseus) 432faa3fae Fixed trailing whitespace warning.
[skip ci]
2019-12-17 21:59:13 +01:00
Sébastien Villemot e2f91abcaf Merge branch 'master' into 'master'
utilities + plot shock decompositions + init condition decompositions

See merge request Dynare/dynare!1655
2019-12-17 18:21:31 +00:00
Willi Mutschler 5a8c206760 Added parameter derivatives of perturbation solution up to 3 order
# Preliminary comments
I finished the identification toolbox at orders two and three using the pruned state space system, but before I merge request this, I decided to first merge the new functionality to compute parameter derivatives of perturbation solution matrices at higher orders. So after this is approved, I merge the identification toolbox.
I guess @rattoma, @sebastien, and @michel are best choices to review this.
I outline the main idea first and then provide some more detailed changes I made to the functions.

***

# Main idea
This merge request is concerned with the *analytical*computation of the parameter derivatives of first, second and third order perturbation solution matrices, i.e. using _closed-form_ expressions to efficiently compute the derivative of  $g_x$ , $g_u$, $g_{xx}$, $g_{xu}$, $g_{uu}$, $g_{\sigma\sigma}$, $g_{xxx}$, $g_{xxu}$, $g_{xuu}$, $g_{uuu}$, $g_{x\sigma\sigma}$, $g_{u\sigma\sigma}$ *with respect to model parameters*  $\theta$.  Note that $\theta$ contains model parameters, stderr and corr parameters of shocks. stderr and corr parameters of measurement errors are not yet supported, (they can easily be included as exogenous shocks). The availability of such derivatives is beneficial in terms of more reliable analysis of model sensitivity and parameter identifiability as well as more efficient estimation methods, in particular for models solved up to third order, as it is well-known that numerical derivatives are a tricky business, especially for large models.

References for my approach are:
* Iskrev (2008, 2010) and Schmitt-Grohé and Uribe (2012, Appendix)  who were the first to compute the parameter derivatives analytically at first order, however, using inefficient (sparse) Kronecker products.
* Mutschler (2015) who provides the expressions for a second-order, but again using inefficient (sparse) Kronecker products.
* Ratto and Iskrev (2012) who show how the first-order system can be solved accurately, fast and efficiently using existing numerical algorithms for generalized Sylvester equations by taking the parameter derivative with respect to each parameter separately.
* Julliard and Kamenik (2004) who provide the perturbation solution equation system in tensor notation at any order k.
* Levintal (2017) who introduces permutation matrices to express the perturbation solution equation system in matrix notation up to fifth order.
Note that @rattoma already implemented the parameter derivatives of $g_x$ and $g_u$ analytically (and numerically), and I rely heavily on his work in `get_first_order_solution_params_derivs.m` (previously `getH.m`). My additions are mainly to this function and thus it is renamed to `get_perturbation_params_derivs.m`.

The basic idea of this merge request is to take the second- and third-order perturbation solution systems in Julliard and Kamenik (2004), unfold these into an equivalent matrix representation using permutation matrices as in Levintal (2017). Then extending Ratto and Iskrev (2012) one takes the derivative with respect to each parameter separately and gets a computational problem that is linear, albeit large, as it involves either solving generalized Sylvester equations or taking inverses of highly sparse matrices. I will now briefly summarize the perturbation solution system at third order and the system that results when taking the derivative with respect to parameters.

## Perturbation Solution
The following systems arise at first, second, and third order:
$(ghx): f_{x} z_{x} = f_{y_{-}^*} + f_{y_0} g_{x} + f_{y_{+}^{**}} g^{**}_{x} g^{*}_{x}= A g_{x} + f_{y_{-}^*}=0$

$(ghu): f_{z} z_{u} = f_{y_0} g_{u} + f_{y_{+}^{**}} g^{**}_{x} g^{*}_{u} + f_{u}= A g_u + f_u = 0$

$(ghxx) : A g_{xx} + B g_{xx} \left(g^{*}_{x} \otimes g^{*}_{x}\right) + f_{zz} \left( z_{x} \otimes z_{x} \right) = 0$

$(ghxu) : A g_{xu} + B g_{xx} \left(g^{*}_{x} \otimes g^{*}_{u}\right) + f_{zz} \left( z_{x} \otimes z_{u} \right) = 0$

$(ghuu) : A g_{uu} + B g_{xx} \left(g^{*}_{u} \otimes g^{*}_{u}\right) + f_{zz} \left( z_{u} \otimes z_{u} \right) = 0$

$(ghs2) : (A+B) g_{\sigma\sigma} +  \left( f_{y^{**}_{+}y^{**}_{+}} \left(g^{**}_{u} \otimes g^{**}_{u}\right) + f_{y^{**}_{+}} g^{**}_{uu}\right)vec(\Sigma) = 0$

$(ghxxx) : A g_{xxx} + B g_{xxx} \left(g^{*}_{x} \otimes g^{*}_{x} \otimes g^{*}_{x}\right) + f_{y_{+}}g^{**}_{xx} \left(g^{*}_x \otimes g^{*}_{xx}\right)P_{x\_xx} + f_{zz} \left( z_{x} \otimes z_{xx} \right)P_{x\_xx} + f_{zzz} \left( z_{x} \otimes z_{x} \otimes z_{x} \right) = 0$

$(ghxxu) : A g_{xxu} + B g_{xxx} \left(g^{*}_{x} \otimes g^{*}_{x} \otimes g^{*}_{u}\right) + f_{zzz} \left( z_{x} \otimes z_{x} \otimes z_{u} \right) + f_{zz} \left( \left( z_{x} \otimes z_{xu} \right)P_{x\_xu} + \left(z_{xx} \otimes z_{u}\right) \right) + f_{y_{+}}g^{**}_{xx} \left( \left(g^{*}_{x} \otimes g^{*}_{xu}\right)P_{x\_xu} + \left(g^{*}_{xx} \otimes g^{*}_{u}\right) \right) = 0$

$(ghxuu) : A g_{xuu} + B g_{xxx} \left(g^{*}_{x} \otimes g^{*}_{u} \otimes g^{*}_{u}\right) + f_{zzz} \left( z_{x} \otimes z_{u} \otimes z_{u} \right)+ f_{zz} \left( \left( z_{xu} \otimes z_{u} \right)P_{xu\_u} + \left(z_{x} \otimes z_{uu}\right) \right) + f_{y_{+}}g^{**}_{xx} \left( \left(g^{*}_{xu} \otimes g^{*}_{u}\right)P_{xu\_u} + \left(g^{*}_{x} \otimes g^{*}_{uu}\right) \right) = 0$

$(ghuuu) : A g_{uuu} + B g_{xxx} \left(g^{*}_{u} \otimes g^{*}_{u} \otimes g^{*}_{u}\right) + f_{zzz} \left( z_{u} \otimes z_{u} \otimes z_{u} \right)+ f_{zz} \left( z_{u} \otimes z_{uu} \right)P_{u\_uu} + f_{y_{+}}g^{**}_{xx} \left(g^{*}_{u} \otimes g^{*}_{uu}\right)P_{u\_uu}  = 0$

$(ghx\sigma\sigma) : A g_{x\sigma\sigma} + B g_{x\sigma\sigma} g^{*}_x + f_{y_{+}} g^{**}_{xx}\left(g^{*}_{x} \otimes g^{*}_{\sigma\sigma}\right) + f_{zz} \left(z_{x} \otimes z_{\sigma\sigma}\right) + F_{xu_{+}u_{+}}\left(I_{n_x} \otimes vec(\Sigma)\right) = 0$
$F_{xu_{+}u_{+}} = f_{y_{+}^{\ast\ast}} g_{xuu}^{\ast\ast} (g_x^{\ast} \otimes I_{n_u^2}) + f_{zz} \left( \left( z_{xu_{+}} \otimes z_{u_{+}} \right)P_{xu\_u} + \left(z_{x} \otimes z_{u_{+}u_{+}}\right) \right) + f_{zzz}\left(z_{x} \otimes z_{u_{+}} \otimes z_{u_{+}}\right)$

$(ghu\sigma\sigma) : A g_{u\sigma\sigma} + B g_{x\sigma\sigma} g^{*}_{u} + f_{y_{+}} g^{**}_{xx}\left(g^{*}_{u} \otimes g^{*}_{\sigma\sigma}\right) + f_{zz} \left(z_{u} \otimes z_{\sigma\sigma}\right) + F_{uu_{+}u_{+}}\left(I_{n_u} \otimes vec(\Sigma_u)\right) = 0$
$F_{uu_{+}u_{+}} = f_{y_{+}^{\ast\ast}} g_{xuu}^{\ast\ast} (g_u^{\ast} \otimes I_{n_u^2})  + f_{zz} \left( \left( z_{uu_{+}} \otimes z_{u_{+}} \right)P_{uu\_u} + \left(z_{u} \otimes z_{u_{+}u_{+}}\right) \right) + f_{zzz}\left(z_{u} \otimes z_{u_{+}} \otimes z_{u_{+}}\right)$

A and B are the common perturbation matrices:

$A = f_{y_0} + \begin{pmatrix} \underbrace{0}_{n\times n_{static}} &\vdots& \underbrace{f_{y^{**}_{+}} \cdot g^{**}_{x}}_{n \times n_{spred}} &\vdots& \underbrace{0}_{n\times n_{frwd}}  \end{pmatrix}$and $B = \begin{pmatrix} \underbrace{0}_{n \times n_{static}}&\vdots & \underbrace{0}_{n \times n_{pred}} & \vdots & \underbrace{f_{y^{**}_{+}}}_{n \times n_{sfwrd}} \end{pmatrix}$

and $z=(y_{-}^{\ast}; y; y_{+}^{\ast\ast}; u)$ denotes the dynamic model variables as in `M_.lead_lag_incidence`, $y^\ast$ denote state variables, $y^{\ast\ast}$ denote forward looking variables, $y_+$ denote the variables with a lead, $y_{-}$ denote variables with a lag, $y_0$ denote variables at period t, $f$ the model equations, and $f_z$ the first-order dynamic model derivatives, $f_{zz}$ the second-order dynamic derivatives, and $f_{zzz}$ the third-order dynamic model derivatives. Then:
$z_{x} = \begin{pmatrix}I\\g_{x}\\g^{**}_{x} g^{*}_{x}\\0\end{pmatrix}$, $z_{u} =\begin{pmatrix}0\\g_{u}\\g^{**}_{x} \cdot g^{*}_{u}\\I\end{pmatrix}$, $z_{u_{+}} =\begin{pmatrix}0\\0\\g^{**}_{u}\\0\end{pmatrix}$
$z_{xx} = \begin{pmatrix} 0\\g_{xx}\\g^{**}_{x} \left( g^{*}_x \otimes g^{*}_{x} \right) + g^{**}_{x} g^{*}_{x}\\0\end{pmatrix}$, $z_{xu} =\begin{pmatrix}0\\g_{xu}\\g^{**}_{xx} \left( g^{*}_x \otimes g^{*}_{u} \right) + g^{**}_{x} g^{*}_{xu}\\0\end{pmatrix}$, $z_{uu} =\begin{pmatrix}0\\g_{uu}\\g^{**}_{xx} \left( g^{*}_u \otimes g^{*}_{u} \right) + g^{**}_{x} g^{*}_{uu}\\0\end{pmatrix}$,
$z_{xu_{+}} =\begin{pmatrix}0\\0\\g^{**}_{xu} \left( g^{*}_x \otimes I \right)\\0\end{pmatrix}$, $z_{uu_{+}} =\begin{pmatrix}0\\0\\g^{**}_{xu} \left( g^{*}_{u} \otimes I \right)\\0\end{pmatrix}$, $z_{u_{+}u_{+}} =\begin{pmatrix}0\\0\\g^{\ast\ast}_{uu}\\0\end{pmatrix}$, $z_{\sigma\sigma} = \begin{pmatrix}0\\ g_{\sigma\sigma}\\ g^{\ast\ast}_{x}g^{\ast}_{\sigma\sigma} + g^{\ast\ast}_{\sigma\sigma}\\0 \end{pmatrix}$

$P$ are permutation matrices that can be computed using Matlab's `ipermute` function.

## Parameter derivatives of perturbation solutions
First, we need the parameter derivatives of first, second, third, and fourth derivatives of the dynamic model (i.e. g1,g2,g3,g4 in dynamic files), I make use of the implicit function theorem: Let $f_{z^k}$ denote the kth derivative (wrt all dynamic variables) of the dynamic model, then let $df_{z^k}$ denote the first-derivative (wrt all model parameters) of $f_{z^k}$ evaluated at the steady state. Note that $f_{z^k}$  is a function of both the model parameters $\theta$  and of the steady state of all dynamic variables $\bar{z}$, which also depend on the parameters. Hence, implicitly $f_{z^k}=f_{z^k}(\theta,\bar{z}(\theta))$  and $df_{z^k}$ consists of two parts:
1. direct derivative wrt to all model parameters given by the preprocessor in the `_params_derivs.m` files
2. contribution of derivative of steady state of dynamic variables (wrt all model parameters): $f_{z^{k+1}} \cdot d\bar{z}$
Note that we already have functionality to compute $d\bar{z}$ analytically.

Having this, the above perturbation systems are basically equations of the following types
$AX +BXC = RHS$ or $AX = RHS$
Now when taking the derivative (wrt to one single parameter $\theta_j$), we get
$A\mathrm{d}\{X\} + B\mathrm{d}\{X\}C = \mathrm{d}\{RHS\} - \mathrm{d}\{A\}X -  \mathrm{d}\{B\}XC - BX\mathrm{d}\{C\}$
or
$A\mathrm{d}\{X\}  = \mathrm{d}\{RHS\} - \mathrm{d}\{A\}X$
The first one is a Sylvester type equation, the second one can be solved by taking the inverse of $A$. The only diffculty and tedious work arrises in computing (the highly sparse) derivatives of $RHS$.

***

# New functions: `
## get_perturbation_params_derivs.m`and `get_perturbation_params_derivs_numerical_objective.m`
* The parameter derivatives up to third order are computed in the new function`get_perturbation_params_derivs.m` both analytically and numerically. For numerical derivatives `get_perturbation_params_derivs_numerical_objective.m` is the objective for `fjaco.m` or `hessian_sparse.m` or `hessian.m`.
* `get_perturbation_params_derivs.m` is basically an extended version of the previous `get_first_order_solution_params_derivs.m` function.
* * `get_perturbation_params_derivs_numerical_objective.m`builds upon `identification_numerical_objective.m`. It is used for numerical derivatives, whenever `analytic_derivation_mode=-1|-2`. It takes from `identification_numerical_objective.m` the parts that compute numerical parameter Jacobians of steady state, dynamic model equations, and perturbation solution matrices. Hence, these parts are removed in `identification_numerical_objective.m` and it only computes numerical parameter Jacobian of moments and spectrum which are needed for identification analysis in `get_identification_jacobians.m`, when `analytic_derivation_mode=-1` only.
* Detailed changes:
      * Most important: notation of this function is now in accordance to the k_order_solver, i.e. we do not compute derivatives of Kalman transition matrices A and B, but rather the solution matrices ghx,ghu,ghxx,ghxu,ghuu,ghs2,ghxxx,ghxxu,ghxuu,ghuuu,ghxss,ghuss in accordance with notation used in `oo_.dr`. As a byproduct at first-order, focusing on ghx and ghu instead of Kalman transition matrices A and B makes the computations slightly faster for large models (e.g. for Quest the computations were faster by a couple of seconds, not much, but okay).
      * Removed use of `kstate`, see also Dynare/dynare#1653 and Dynare/dynare!1656
      * Output arguments are stored in a structure `DERIVS`, there is also a flag `d2flag` that computes parameter hessians needed only in `dsge_likelihood.m`.
      * Removed `kronflag` as input. `options_.analytic_derivation_mode` is now used instead of `kronflag`.
      * Removed `indvar`, an index that was used to selected specific variables in the derivatives. This is not needed, as we always compute the parameter derivatives for all variables first and then select a subset of variables. The selection now takes place in other functions, like `dsge_likelihood.m`.
      * Introduced some checks: (i) deterministic exogenous variables are not supported, (ii) Kronecker method only compatible with first-order approximation so reset to sylvester method, (iii) for purely backward or forward models we need to be careful with the rows in `M_.lead_la	g_incidence`, (iv) if `_params_derivs.m` files are missing an error is thrown.
      * For numerical derivatives, if mod file does not contain an `estimated_params_block`, a temporary one with the most important parameter information is created.
## `unfold_g4.m`
* When evaluating g3 and g4 one needs to take into account that these do not contain symmetric elements, so one needs to use `unfold_g3.m` and the new function `unfold_g4.m`. This returns an unfolded version of the same matrix (i.e. with symmetric elements).

***

# New test models
`.gitignore` and `Makefile.am` are changed accordingly. Also now it is possible to run test suite on analytic_derivatives, i.e. run `make check m/analytic_derivatives`

## `analytic_derivatives/BrockMirman_PertParamsDerivs.mod`
* This is the Brock Mirman model, where we know the exact policy function $g$ for capital and consumption. As this does not imply a nonzero $g_{\sigma\sigma}$, $g_{x\sigma\sigma}$, $g_{u\sigma\sigma}$ I added some artificial equations to get nonzero solution matrices with respect to $\sigma$. The true perturbation solution matrices  $g_x$ , $g_u$, $g_{xx}$, $g_{xu}$, $g_{uu}$, $g_{\sigma\sigma}$, $g_{xxx}$, $g_{xxu}$, $g_{xuu}$, $g_{uuu}$, $g_{x\sigma\sigma}$, $g_{u\sigma\sigma}$ are then computed analytically with Matlab's symbolic toolbox and saved in `nBrockMirmanSYM.mat`. There is a preprocessor flag that recreates these analytical computations if changes are needed (and to check whether I made some errors here ;-) )
* Then solution matrices up to third order and their parameter Jacobians are then compared to the ones computed by Dynare's `k_order_solver` and by `get_perturbation_params_derivs` for all `analytic_derivation_mode`'s. There will be an error if the maximum absolute deviation is too large, i.e. for numerical derivatives (`analytic_derivation_mode=-1|-2`) the tolerance is choosen lower (around 1e-5); for analytical methods we are stricter: around 1e-13 for first-order,  1e-12 for second order, and 1e-11 for third-order.
* As a side note, this mod file also checks Dynare's `k_order_solver` algorithm and throws an error if something is wrong.
* This test model shows that the new functionality works well. And analytical derivatives perform way better and accurate than numerical ones, even for this small model.
## `analytic_derivatives/burnside_3_order_PertParamsDerivs.mod`
* This builds upon `tests/k_order_perturbation/burnside_k_order.mod` and computes the true parameter derivatives analytically by hand.
      * This test model also shows that the new functionality works well.

## `analytic_derivatives/LindeTrabandt2019.mod`
* Shows that the new functionality also works for medium-sized models, i.e. a SW type model solved at third order with 35 variables (11 states). 2 shocks and 20 parameters.
* This mod file can be used to tweak the speed of the computations in the future.
* Compares numerical versus analytical parameter derivatives (for first, second and third order). Note that this model clearly shows that numerical ones are quite different than analytical ones even at first order!
## `identification/LindeTrabandt2019_xfail.mod`
* This model is a check for issue Dynare/dynare#1595, see fjaco.m below, and will fail.
* Removed `analytic_derivatives/ls2003.mod` as this mod file is neither in the testsuite nor does it work.

***

# Detailed changes in other functions
## `get_first_order_solution_params_derivs.m`
* Deleted, or actually, renamed to `get_perturbation_params_derivs.m`, as this function now is able to compute the derivatives up to third order

## `identification_numerical_objective.m`
* `get_perturbation_params_derivs_numerical_objective.m`builds upon `identification_numerical_objective.m`. It takes from `identification_numerical_objective.m` the parts that compute numerical parameter Jacobians of steady state, dynamic model equations, and perturbation solution matrices. Hence, these parts are removed in `identification_numerical_objective.m` and it only computes numerical parameter Jacobian of moments and spectrum which are needed for identification analysis in `get_identification_jacobians.m`, when `analytic_derivation_mode=-1` only.

## `dsge_likelihood.m`
* As `get_first_order_solution_params_derivs.m`is renamed to `get_perturbation_params_derivs.m`, the call is adapted. That is,`get_perturbation_params_derivs` does not compute the derivatives of the Kalman transition `T`matrix anymore, but instead of the dynare solution matrix `ghx`. So we recreate `T` here as this amounts to adding some zeros and focusing on selected variables only.
* Added some checks to make sure the first-order approximation is selected.
* Removed `kron_flag` as input, as `get_perturbation_params_derivs` looks into `options_.analytic_derivation_mode` for `kron_flag`.

## `dynare_identification.m`
* make sure that setting `analytic_derivation_mode` is set both in `options_ident` and `options_`. Note that at the end of the function we restore the `options_` structure, so all changes are local. In a next merge request, I will remove the global variables to make all variables local.

## `get_identification_jacobians.m`
* As `get_first_order_solution_params_derivs.m`is renamed to `get_perturbation_params_derivs.m`, the call is adapted. That is,`get_perturbation_params_derivs` does not compute the derivatives of the Kalman transition `A` and `B` matrix anymore, but instead of the dynare solution matrix `ghx` and `ghu`. So we recreate these matrices here instead of in `get_perturbation_params_derivs.m`.
* Added `str2func` for better function handles in `fjaco.m`.

## `fjaco.m`
* make `tol`an option, which can be adjusted by changing `options_.dynatol.x`for identification and parameter derivatives purposes.
* include a check and an informative error message, if numerical derivatives (two-sided finite difference method) yield errors in `resol.m` for identification and parameter derivatives purposes. This closes issue  Dynare/dynare#1595.
* Changed year of copyright to 2010-2017,2019

***

# Further suggestions and questions
* Ones this is merged, I will merge request an improvement of the identification toolbox, which will work up to third order using the pruned state space. This will also remove some issues and bugs, and also I will remove global variables in this request.
* The third-order derivatives can be further improved by taking sparsity into account and use mex versions for kronecker products etc. I leave this for further testing (and if anybody actually uses this ;-) )
2019-12-17 18:17:09 +00:00
Marco Ratto 199b76c979 also test fo empty list of variables to squeeze 2019-12-15 17:17:10 +01:00
Marco Ratto 6783d51135 added squeeze call in test function 2019-12-15 16:55:02 +01:00
Johannes Pfeifer a4030c3676 testsuite: update ramsey_model to new command sequence using ramsey_model
Related to https://git.dynare.org/Dynare/dynare/issues/1678
2019-12-13 14:18:15 +01:00
Marco Ratto 2edf6d05a3 added testing for flip diff and init2shocks 2019-12-12 16:53:45 +01:00
Houtan Bastani 32872362b3
introduce changes to epilogue block
preprocessor#36
- detrend epilogue statements
- write names of epilogue variables in `M_.epilogue_names`
- output list of endogs used in epilogue equations in `M_.epilogue_var_list_`
- output static and dynamic epilogue files
2019-12-11 16:30:37 +01:00
Houtan Bastani 40e4317ef2
macro processor test file: remove utf-8 character from variable 2019-12-10 16:53:12 +01:00
Houtan Bastani 2017b32f31
fix bug in macro processor with short circuit operators || and &&
#1676
2019-12-10 16:53:12 +01:00
Sébastien Villemot 6a89783b65
Merge remote-tracking branch 'community/master' into enterprise 2019-12-03 15:39:59 +01:00
Dóra Kocsis b9af92eb8a Save conditional forecast output in oo_. Closes: Dynare/dynare#1672 2019-11-29 15:25:05 +01:00
Houtan Bastani 3ef8564279
reporting: add ability to make title page 2019-11-29 11:36:00 +01:00
Johannes Pfeifer 0c01c31491 Remove global variables from user-defined steady state files
M_ and options_ are now passed as an input; params is an output as in the _steadystate2.m files
2019-11-26 17:05:14 +01:00
Johannes Pfeifer fc6c78e5ea testsuite: transform old steady state files to steady_state_model-blocks
Allows for easier maintenance
2019-11-26 17:02:12 +01:00
Sébastien Villemot 8065e9d439
Build system: by default, error out if some dependency is missing
In particular, if either MATLAB or Octave is missing, one needs to pass either
--disable-matlab or --disable-octave.

Moreover, several new configure flags have been introduced for disabling some
components:
--disable-doc
--disable-dynare++
--disable-mex-dynare++
--disable-mex-ms-sbvar
--disable-mex-kalman-steady-state
2019-11-26 13:53:42 +01:00
Houtan Bastani 7a320d2944
fix macro processor bug that resulted in incorrect casts from string to bool 2019-11-26 11:19:15 +01:00
Stéphane Adjemian (Charybdis) 7e7f57d7d1 Encoding fixes. 2019-11-25 11:48:09 +01:00
Michel Juillard cc0f2865a6 use tolf option inside simul() 2019-11-24 09:56:35 +01:00
Dóra Kocsis 75a929051f Update sur and surgibbs function outputs. 2019-11-22 10:59:01 +01:00
Sébastien Villemot 628a8a6ff3
Testsuite: remove obsolete conditionals for testing whether Octave version > 3.4
We now support Octave ≥ 4.2 only.

By the way, in another test, use the isoctave function instead of manual test.
2019-11-19 15:25:59 +01:00
Sébastien Villemot 12d7d8cef2
Testsuite: use XLSX for Octave and MATLAB ≥ R2012a, and XLS for MATLAB < R2012a
In 98bdf76581, all XLSX files were removed in
favour of XLS, for compatibility with MATLAB R2009b.

But this broke the very same tests under Octave, since XLS support is not very
good there.

This commit implements a solution that works everywhere, by using XLSX whenever
possible, and XLS otherwise.
2019-11-19 12:49:01 +01:00
Sébastien Villemot e04ccd9b01
Fix construction of source tarball
Was broken by the previous commit, which renamed some datafile without updating
EXTRA_DIST in tests/Makefile.am.
2019-11-15 22:49:45 +01:00
Sébastien Villemot 98bdf76581
MATLAB R2009b compatibility fixes
— use XLS instead of XLSX in testsuite datafiles
— use optimset instead of optimoptions
— use quadv/quadl/quadgk instead of integral
— fix race condition in load_m_file_data_legacy.m tests
— use fallback implementation for intersect(…, 'stable')
2019-11-15 18:27:37 +01:00
Sébastien Villemot 42f172dec3
perfect_foresight_problem MEX: optimization for linear models
When the model is linear, there is no need to reevaluate the Jacobian for each
time period, since it is invariant.

Closes: #1662
2019-11-14 14:45:10 +01:00
Dóra Kocsis b4cd1c0f57 Add routine printing equations where a searched variable appears in. 2019-11-08 17:33:27 +01:00
Sébastien Villemot 56e7144b91
Merge remote-tracking branch 'community/master' into enterprise 2019-10-23 16:30:29 +02:00
Dóra Kocsis 3648ccb8ff Adjust result output for NLS and Iterative OLS. 2019-10-10 10:10:23 +02:00
Houtan Bastani 43c73a74c8
test for matlab namespace function in steady_state_model block. closes #1639 2019-10-09 16:39:33 +02:00
Houtan Bastani cd83a7790e
add .m files from 4a1b5eccb2 to EXTRA_DIST
[skip ci]
2019-10-09 16:35:32 +02:00
Houtan Bastani 4a1b5eccb2
Support MATLAB namespaces in function calls #1639
shorten test names because adding `_namespace` made some .mod file names too long
2019-10-09 16:22:32 +02:00
Sébastien Villemot 8875ac14d8
Merge remote-tracking branch 'community/master' into enterprise 2019-10-09 12:32:12 +02:00
DoraK 41c66583ac Add linear combination support for growth neutrality in Iiterative OLS. 2019-10-08 23:18:40 +02:00
Sébastien Villemot b3d1e8412b
Add support for mode_compute=1 under Octave
Since version 1.6, the optim Forge package has an implementation of fmincon.
Hence we can now use mode_compute=1 under Octave.

This commit also adds tests/optimizers/fs2000_1.mod to the testsuite. It will
be skipped under MATLAB if the optimization toolbox is not there, or under
Octave if optim ≥ 1.6 is not there.
2019-10-08 18:38:15 +02:00
Sébastien Villemot f91018c319
Fix test broken by 1668d50aaf 2019-10-02 15:06:13 +02:00
Stéphane Adjemian (Charybdis) fb3335f191 Added unitary tests for aggregate routine. 2019-10-02 10:41:32 +02:00
Sébastien Villemot 5d8babb15c
Merge remote-tracking branch 'community/master' into enterprise 2019-10-02 10:36:48 +02:00
Houtan Bastani 32932ce741
preprocessor: submodule update 2019-10-02 10:32:01 +02:00
Sébastien Villemot 9c9e2b443e
Merge remote-tracking branch 'community/master' into enterprise 2019-10-01 14:54:52 +02:00
Stéphane Adjemian (Charybdis) ad73aac0ad Fixed integration test.
Need to increase accuracy (set tolf 1e-9 instead of 1e-6) if some
endogenous variables appear under logs (which is the case for x3).
2019-09-30 14:29:19 +02:00
Houtan Bastani 715ae0ce39
preprocessor: submodule update 2019-09-30 12:28:29 +02:00
Sébastien Villemot e2c57dc5f5
Increase test tolerance 2019-09-26 17:35:24 +02:00
Sébastien Villemot 88c38c9ebc
Fixed some trend_component_model tests
Those tests broke because they were declaring an endogenous (var_allows_…) that
is not used in the model, and this is no longer allowed by the preprocessor.

Those variables were introduced by commit
dccabecee7 (on the old ecb-master branch), at the
same time as a second PAC equation was introduced.

The fix consists in making the second PAC equation different from the first
one, defining a different endogenous.
2019-09-26 17:35:15 +02:00
Sébastien Villemot cbb59fe6f8
Merge remote-tracking branch 'community/master' into enterprise 2019-09-26 16:54:27 +02:00
Sébastien Villemot e9da62eca9
Add missing exceptions to .gitignore 2019-09-26 15:19:26 +02:00
Sébastien Villemot e521dcf081
Drop useless LICENSE file 2019-09-26 15:19:14 +02:00
Sébastien Villemot f665117879
Remove spurious indentation changes
This commits reverts various spurious indentation changes that were on the
ecb-master but not on the master branch.
2019-09-26 15:17:54 +02:00
Sébastien Villemot 42392df3bc
Put binary test datafiles in the git repository
This makes the testsuite robust to network failures.
2019-09-19 14:20:00 +02:00
Houtan Bastani e043c60903
pass M_, options_, oo_ as arguments to stoch_simul, simult_, discretionary_policy. closes dynare#1197 2019-09-12 11:57:01 +02:00
Houtan Bastani 53ce6222c2
remove unused variable in dynare_config 2019-09-05 11:48:19 +02:00
Sébastien Villemot b73f5b7816
Compatibility fix for Octave 5
The sleep() function has been removed in favor of pause().
2019-08-22 17:03:19 +02:00
Houtan Bastani 5994321cd7
preprocessor: submodule update 2019-08-19 16:58:14 +02:00
Houtan Bastani ea06dfbcd5
add tests for casting and range in macro processor 2019-08-07 11:30:16 -04:00
Houtan Bastani f2b61b3e9e
submodule update: preprocessor; doc: introduce comprehensions 2019-06-26 15:09:55 +02:00
Houtan Bastani cb0e84a2c4
submodule update: preprocessor 2019-06-25 10:12:20 +02:00
Houtan Bastani 69229b6b2a
submodule update: preprocessor 2019-06-24 11:16:21 +02:00
Houtan Bastani 42e8b55274
add macro test to file 2019-06-24 11:16:21 +02:00
Houtan Bastani b4d2239da2
submodule update: preprocessor: rework macroprocessor 2019-06-21 17:11:14 +02:00
Stéphane Adjemian (Charybdis) efc174115e Use verbatim block. 2019-06-17 11:33:56 +02:00
Stéphane Adjemian (Charybdis) 75945a62ac Fixed plot_contribution routine. 2019-05-14 22:12:33 +02:00
Houtan Bastani 13547964dc
change graph in reporting test to show how to associate integers with time periods 2019-05-10 11:02:46 +02:00
Sébastien Villemot b0841b4136
Fix test files following change in the preprocessor when there is no parameter or exogenous 2019-04-30 16:42:53 +02:00
Stéphane Adjemian (Charybdis) ea68f849d5 Renamed routine. 2019-04-29 23:49:04 +02:00
Stéphane Adjemian (Charybdis) 92e7010b97 Added integration test. 2019-04-29 23:39:14 +02:00
Sébastien Villemot b2957127ad
k-order DLL: check that simulated time series at order 9 is correct
Ref #217
2019-04-29 15:48:03 +02:00
Sébastien Villemot 7ddf3046b7
Improve description of k-order tests 2019-04-29 15:46:47 +02:00
Stéphane Adjemian (Charybdis) b6a80229a9 Added integration test for cherrypick and agregate routines. 2019-04-27 18:12:53 +02:00
Sébastien Villemot f1b16ced4e
k-order DLL: check computed policy functions at order 9 against Burnside's model
Ref #217
2019-04-26 18:46:04 +02:00
Stéphane Adjemian (Charybdis) 64dc44740b Efficiency change. 2019-04-26 16:20:45 +02:00
Sébastien Villemot c5c1307725
Minor simplification 2019-04-26 14:44:36 +02:00
Stéphane Adjemian ee891948e0 Moved IntegrationAgorithm under options_.ep.stochastic 2019-04-18 18:03:57 +02:00
Stéphane Adjemian 62b0106dde Streamlined extended path examples. 2019-04-18 18:03:57 +02:00
Michel Juillard d6866b2e6b fixed saving of pseudo_data variables 2019-04-18 18:03:57 +02:00
Stéphane Adjemia (Scylla) 66e44dd830
Added missing routine.
Example for agregate routine.
2019-04-10 09:56:30 +02:00
Stéphane Adjemia (Scylla) 8740355407
Rewrote evaluate routine.
- Can handle more than one equation.
 - Can handle identities.
 - Forbids dynamic equations.
 - Can handle following LHS y, diff(y), diff(diff(y)), log(y), diff(log(y)) and
   diff(diff(log(y))), other transformations will result in an error.
 - Added integration tests.

Remark 1. In the integration tests I compare the values returned by the
          evaluate routine with the values computed with the simulation
          routines. Normally the discrepancies should be small, but this is not
          the case when the endogenous variable appear under a log on the
          LHS. My current conclusion is that this has more to do with the
          cumulation of the accuracy errors in the simulation routine (a
          sequence of Newton algorithms) rather than with the evaluate routine.

Remark 2. Currently the only allowed nonlinear transformation on the LHS
          endogenous variable is the log. It is not difficult to generalise, at
          some point I had all the matlab functions allowed by Dynare,
          but this would complicate the code for not much gain.
2019-04-08 11:01:34 +02:00
Stéphane Adjemia (Scylla) 94b20fe7e8
Activate two integration tests. 2019-04-02 22:57:23 +02:00
Sébastien Villemot 774e60f04c
options_.risky_steadystate is an (undocumented) boolean value
By the way, enable the option in example1_korder.mod (it does not work, but no
harm since it’s not in the testsuite).
2019-04-02 19:16:13 +02:00
Stéphane Adjemia (Scylla) aa499671ce
Added the possibility to rename an endogenous variable in equation. 2019-04-02 18:06:47 +02:00
Stéphane Adjemia (Scylla) f39f57b9b5
Added parameter values in cherrypick/agregate routines. 2019-04-02 07:11:32 +02:00
Stéphane Adjemian (Charybdis) bb0660d506
Added integration tests (trend component models). 2019-03-29 17:58:03 +01:00
Stéphane Adjemian (Charybdis) 7b7bca8bda
Generalised trend component model.
Added the possibility to associate more than one trend to an endogenous
variable. The number of error correction equations is longer required to be
equal to the number of trends.
2019-03-29 17:52:46 +01:00
Houtan Bastani d242ed88a2
dyn_ols: add date range option 2019-03-26 15:04:16 +01:00
Houtan Bastani 9ab4c6f80d
ols-style equations: handle additive elements separated by + and -
use same algorithm as in preprocessor to facilitate future changes
2019-03-26 11:06:30 +01:00
Stéphane Adjemian (Charybdis) a77de6ce75
Revert last patch on Makefile.am. 2019-03-25 20:09:14 +01:00
Sébastien Villemot d1df9317ab
Indentation fixes (tabs are meaningful in Makefiles) 2019-03-25 18:47:49 +01:00
Sébastien Villemot e7dfc6ab36
The MATLAB testsuite now works under Windows, so no need to special-case it 2019-03-25 18:47:49 +01:00