diff --git a/.dir-locals.el b/.dir-locals.el
index e17d9ed3b25bccbb5151b480a7dd25e8defa87c3..397b9bd3233a1250f21da2dd589677f2251d987d 100644
--- a/.dir-locals.el
+++ b/.dir-locals.el
@@ -2,6 +2,4 @@
       ((c-file-style . "gnu")
        (indent-tabs-mode . nil)
        (fill-column . 79)))
- (makefile-mode . ((indent-tabs-mode . t)))
- (matlab-mode . ((matlab-indent-level . 4)
-                 (matlab-indent-function-body . nil))))
+ (makefile-mode . ((indent-tabs-mode . t)))
\ No newline at end of file
diff --git a/.gitignore b/.gitignore
index 656a08c2648b8c7d18837344e2798bd870196e7d..41d0985bfff68c2ebca5f53931172b1b28810839 100644
--- a/.gitignore
+++ b/.gitignore
@@ -194,6 +194,8 @@ mex/build/matlab/run_m2html.m
 /contrib/ms-sbvar/*.dat
 /contrib/ms-sbvar/sbvar_commandline
 /contrib/ms-sbvar/sbvar_init_file
+/tests/ms-sbvar/*.tmp
 
 # Reporting
-*synctex.gz
\ No newline at end of file
+*synctex.gz
+tests/reporting/tmpRepDir
diff --git a/.gitmodules b/.gitmodules
index 67e0b82edcab02f0c3949f500672dbba291522bc..3c608c798ab324f069ceb926299dae0ab48b624c 100644
--- a/.gitmodules
+++ b/.gitmodules
@@ -10,3 +10,14 @@
 [submodule "contrib/dmm"]
 	path = contrib/dmm
 	url = http://www.dynare.org/git/dmm.git
+[submodule "matlab/utilities/tests"]
+	path = matlab/utilities/tests
+	url = https://github.com/DynareTeam/m-unit-tests.git
+[submodule "matlab/modules/dates"]
+	path = matlab/modules/dates
+	url = https://github.com/DynareTeam/dates.git
+	branch = old-oop-syntax
+[submodule "matlab/modules/dseries"]
+	path = matlab/modules/dseries
+	url = https://github.com/DynareTeam/dseries.git
+	branch = old-oop-style
diff --git a/NEWS b/NEWS
index b32e24e78ed53df98629e73281ebac7b5ac4470e..500f3e325db118e06b94d3540b9953e475ddff89 100644
--- a/NEWS
+++ b/NEWS
@@ -1,3 +1,84 @@
+Announcement for Dynare 4.4.3 (on 2014-07-31)
+=============================================
+
+We are pleased to announce the release of Dynare 4.4.3.
+
+This is a bugfix release.
+
+The Windows packages are already available for download at:
+
+ http://www.dynare.org/download/dynare-stable
+
+The Mac and GNU/Linux packages (for Debian and Ubuntu LTS) should follow soon.
+
+This release is compatible with MATLAB versions 7.3 (R2006b) to 8.2 (R2013b)
+and with GNU Octave versions 3.6 to 3.8.
+
+Here is a list of the problems identified in version 4.4.2 and that have been
+fixed in version 4.4.3:
+
+ - When loading a dataset in XLS, XLSX or CSV format, the first
+   observation was discarded.
+
+ - Reading data in an Excel-file with only one variable wasz leading
+   to a crash.
+
+ - When using the k_order_perturbation option (which is implicit at
+   3rd order) without the use_dll option, crashes or unexpected
+   behavior could happen if some 2nd or 3rd derivative evaluates to
+   zero (while not being symbolically zero)
+
+ - When using external function, Ramsey policy could crash or return
+   wrong results.
+
+ - For Ramsey policy, the equation numbers associated with the
+   Lagrange multipliers stored in M_.aux_vars were erroneously one too
+   low
+
+ - When updating deep parameters in the steady state file, the changes
+   were not fully taken into account (this was only affecting the
+   Ramsey policy).
+
+ - When using external functions and the bytecode option, wrong
+   results were returned (if second order derivates of the external
+   functions were needed).
+
+ - The confidence level for computations in estimation, conf_sig could
+   not be changed and was fixed at 0.9. The new option mh_conf_sig is
+   now used to set this interval
+
+ - Conditional forecasts with non-diagonal covariance matrix used an
+   incorrect decomposition of the covariance matrix. A Cholesky
+   factorization is used.
+
+ - Option geweke_interval was not effective, Dynare always defaulted
+   to the standard value.
+
+ - The mode_file option lacked backward compatibility with older
+   Dynare versions.
+
+ - Loading an mh_mode file with the mode_file option was broken.
+
+ - Using identification with var_exo_det leaded to crashes (the
+   preprocessor now returns an error if they are used simultaneously)
+
+ - The identification command did not print results if the initial
+   parameter set was invalid and then crashed later on if the MC
+   sample is bigger than 1
+
+ - Inconsistencies between static and dynamic models leaded to crashes
+   instead of error messages (only with block option).
+
+ - The use of external functions crashed the preprocessor when the
+   derivatives of the external function are explicitly called in the
+   model block. The preprocessor now forbids the use of external
+   functions derivates in the model block.
+
+ - Using the block option when a variable does not appear in the
+   current period crashed Dynare instead of providing an error
+   message.
+
+
 Announcement for Dynare 4.4.2 (on 2014-03-04)
 =============================================
 
diff --git a/README.md b/README.md
index 4a0f7b2effbbdca0972a6f6ba42d6d32cee030ef..3c65155fe141290a02db6129c9bb03ca3db1c7d3 100644
--- a/README.md
+++ b/README.md
@@ -49,7 +49,7 @@ A number of tools and libraries are needed in order to recompile everything. You
 
 - A POSIX compliant shell and an implementation of Make (mandatory)
 - The [GNU Compiler Collection](http://gcc.gnu.org/), with gcc, g++ and gfortran (mandatory)
-- [MATLAB](http://www.dynare.org/DynareWiki/BuildingDynareFromSource?action=AttachFile&do=view&target=dynare-mingw64-libs.zip) (if you want to compile MEX for MATLAB)
+- MATLAB (if you want to compile MEX for MATLAB)
 - [GNU Octave](http://www.octave.org), with the development headers (if you want to compile MEX for Octave)
 - [Boost libraries](http://www.boost.org), version 1.36 or later
 - [Bison](http://www.gnu.org/software/bison/), version 2.5 or later (only if you get the source through Git)
@@ -194,8 +194,8 @@ The following instructions are compatible with MATLAB or with Octave/MinGW (as d
     - `mingw64-i686-gcc-core`, `mingw64-i686-gcc-g++`, `mingw64-i686-gcc-fortran` (if you have Octave/MinGW or if you have MATLAB 32-bit)
     - `mingw64-x86_64-gcc-core`, `mingw64-x86_64-gcc-g++`, `mingw64-x86_64-gcc-fortran` (if you have MATLAB 64-bit)
 - Second, install precompiled librairies for BLAS, LAPACK, Boost and GSL:
-    - If you have Octave or MATLAB 32-bit, download [dynare-mingw32-libs.zip](http://www.dynare.org/DynareWiki/BuildingDynareFromSource?action=AttachFile&do=view&target=dynare-mingw32-libs.zip), and uncompress it in `c:\cygwin\usr\local\lib\mingw32`
-    - If you have MATLAB 64-bit, download [dynare-mingw64-libs.zip](http://www.dynare.org/DynareWiki/BuildingDynareFromSource?action=AttachFile&do=view&target=dynare-mingw64-libs.zip), and uncompress it in `c:\cygwin\usr\local\lib\mingw64`
+    - If you have Octave or MATLAB 32-bit, download [dynare-mingw32-libs.zip](http://www.dynare.org/build/dynare-mingw32-libs.zip), and uncompress it in `c:\cygwin\usr\local\lib\mingw32`
+    - If you have MATLAB 64-bit, download [dynare-mingw64-libs.zip](http://www.dynare.org/build/dynare-mingw64-libs.zip), and uncompress it in `c:\cygwin\usr\local\lib\mingw64`
 
 *Remark*: You need to make sure that Cygwin’s git is used and not a potentially installed msysgit. The latter typically happens when one installs msysgit and allows it to set a system path. This will result in wrong line endings and cryptic error messages à la "syntax error near unexpected token `fi'". In that case it might be necessary to uninstall msysgit and reinstall it without setting a system path.
 
@@ -251,35 +251,34 @@ Configure and make:
 
 ## Mac OS X
 
-- Install the Xcode Common Tools:
-    - Install [Xcode](http://developer.apple.com/xcode/) from the App Store
-    - Open Xcode
-    - Go to `Xcode->Preferences...`
-    - In the window that opens, click on the `Downloads` tab
-    - In the tab that appears, click on the `Components` button
-    - Next to `Command Line Tools`, click on `Install`
-- Download [MacOSX10.6.sdk.zip](http://www.jamesgeorge.org/uploads/MacOSX10.6.sdk.zip) and unzip it in `/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs`. Change the owner to be `root` and the group to be `wheel`
-
+- Install the Xcode Command Line Tools:
+    - Download "Command Line Tools (OS X 10.X) for Xcode," where 10.X corresponds to your OS X version, from https://developer.apple.com/downloads/index.action
 - Install [Homebrew](http://mxcl.github.io/homebrew/) by following the instructions on the website
-- Tap [Homebrew Science](https://github.com/Homebrew/homebrew-science) by doing:
+- Tap [Homebrew Science](https://github.com/Homebrew/homebrew-science) by opening Terminal and typing:
     - ```brew tap homebrew/science```
 - Install the following brews:
+    - ```brew install gcc```
     - ```brew install automake```
     - ```brew install gsl```
     - ```brew install bison```
     - ```brew install boost```
-    - ```brew install gfortran```
     - ```brew install libmatio --with-hdf5```
     - ```brew install slicot --with-default-integer-8```
-- **(Optional)** To compile Dynare mex files for use on Octave, first install Octave following the [Simple Installation Instructions](http://wiki.octave.org/Octave_for_MacOS_X#Simple_Installation_Instructions_3). Then, you will probably also want to install graphicsmagick via Homebrew with `brew install graphicsmagick`.
+- Force link ```flex``` and ```bison```
+    - ```brew link --force flex```
+    - ```brew link --force bison```
+- **(Optional)** To compile Dynare mex files for use on Octave:
+    - ```brew install octave```
 - **(Optional)** To compile Dynare's documentation, first install the latest version of [MacTeX](http://www.tug.org/mactex/). Then install `doxygen`, `latex2html` and `texi2html` via Homebrew with the following commands:
     - ```brew install doxygen```
     - ```brew install texinfo```
     - ```brew install latex2html```
     - ```brew install texi2html```
-- **(On OS X 10.7 Only)** Copy [FlexLexer.h](http://www.dynare.org/DynareWiki/BuildingDynareFromSource?action=AttachFile&do=view&target=FlexLexer.h) into the `preprocessor` directory (there was an error in the `FlexLexer.h` file distributed with 10.7)
-- Finally, switch to the root dynare directory. Ensure your path contains `/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/bin:/opt/X11/bin:/usr/texbin:/usr/local/sbin`. Run:
+- **(On OS X 10.7 Only)** Copy [FlexLexer.h](http://www.dynare.org/build/FlexLexer.h) into the `preprocessor` directory (there was an error in the `FlexLexer.h` file distributed with 10.7)
+- Ensure `/usr/local/bin` is at the beginning of your path:
+    - ```PATH=/usr/local/bin:$PATH```
+- Finally, switch to the root dynare directory and compile dynare
     - `autoreconf -si`
-    - `./configure --with-matlab=/Applications/MATLAB_R2013a.app MATLAB_VERSION=8.1 YACC=/usr/local/Cellar/bison/<<BISON VERSION>>/bin/bison`
+    - `./configure --with-matlab=/Applications/MATLAB_R2014b.app MATLAB_VERSION=8.4`
     - `make`
     - `make pdf TEXI2DVI=/usr/local/Cellar/texinfo/5.2/bin/texi2dvi`, where you replace everything after the equal sign with the path to the `texi2dvi` installed by homebrew when you installed `texinfo`.
diff --git a/contrib/ms-sbvar/TZcode b/contrib/ms-sbvar/TZcode
index b642763676536c148ad827a0286862be87c5ae8e..4be470341a73bb22d58bb0d930ff624a5bf1a7f6 160000
--- a/contrib/ms-sbvar/TZcode
+++ b/contrib/ms-sbvar/TZcode
@@ -1 +1 @@
-Subproject commit b642763676536c148ad827a0286862be87c5ae8e
+Subproject commit 4be470341a73bb22d58bb0d930ff624a5bf1a7f6
diff --git a/doc/dynare.texi b/doc/dynare.texi
index 7c9e838ee0944b6649250259614a9a100a0ae35b..6ea52531a8f3567160ff43506d7f01a81737fb97 100644
--- a/doc/dynare.texi
+++ b/doc/dynare.texi
@@ -356,7 +356,7 @@ Adjemian (Université du Maine, Gains and Cepremap), Houtan Bastani
 (Cepremap), Michel Juillard (Banque de France), Frédéric Karamé
 (Université du Maine, Gains and Cepremap), Junior Maih (Norges Bank),
 Ferhat Mihoubi (Université Paris-Est Créteil, Epee and Cepremap), George
-Perendia, Johannes Pfeifer (University of Mannheim), Marco Ratto (JRC)
+Perendia, Johannes Pfeifer (University of Mannheim), Marco Ratto (European Commission, Joint Research Centre - JRC)
 and Sébastien Villemot (Cepremap).
 Increasingly, the developer base is expanding, as tools developed by
 researchers outside of Cepremap are integrated into Dynare. Financial
@@ -515,9 +515,8 @@ Please refer to the
 @uref{http://www.dynare.org/DynareWiki/InstallOnDebianOrUbuntu,Dynare
 Wiki} for detailed instructions.
 
-Dynare will be installed under @file{/usr/share/dynare} and
-@file{/usr/lib/dynare}. Documentation will be under
-@file{/usr/share/doc/dynare}.
+Dynare will be installed under @file{/usr/lib/dynare}. Documentation will be
+under @file{/usr/share/doc/dynare-doc}.
 
 @node On Mac OS X
 @subsection On Mac OS X
@@ -580,7 +579,7 @@ addpath c:\dynare\4.@var{x}.@var{y}\matlab
 Under Debian GNU/Linux or Ubuntu, type:
 
 @example
-addpath /usr/share/dynare/matlab
+addpath /usr/lib/dynare/matlab
 @end example
 
 Under Mac OS X, assuming that you have installed Dynare in the standard
@@ -2067,7 +2066,9 @@ For this last reason, it necessary to provide values for all the
 endogenous variables in an @code{initval} block (even though,
 theoretically, initial conditions are only necessary for lagged
 variables). If some variables, endogenous or exogenous, are not mentioned in the
-@code{initval} block, a zero value is assumed.
+@code{initval} block, a zero value is assumed. It is particularly important to keep 
+this in mind when specifying exogenous variables using @code{varexo} that are not allowed 
+to take on the value of zero, like e.g. TFP. 
 
 Note that if the @code{initval} block is immediately followed by a
 @code{steady} command, its semantics is changed. The @code{steady}
@@ -2730,11 +2731,7 @@ add new variables one by one.
 
 @item maxit = @var{INTEGER}
 Determines the maximum number of iterations used in the non-linear solver. The
-default value of @code{maxit} is 10. The @code{maxit} option is shared with the
-@code{perfect_foresight_solver} and @code{simul} commands. So a change in
-@code{maxit} in a @code{steady} command will also be considered in the
-following @code{perfect_foresight_solver} and @code{simul} commands.
-
+default value of @code{maxit} is 50. 
 
 @item solve_algo = @var{INTEGER}
 @anchor{solve_algo}
@@ -3362,10 +3359,7 @@ order to setup the environment for the simulation.
 
 @item maxit = @var{INTEGER}
 Determines the maximum number of iterations used in the non-linear solver. The
-default value of @code{maxit} is 10. The @code{maxit} option is shared with the
-@code{steady} command. So a change in @code{maxit} in a
-@code{perfect_foresight_solver} command will also be considered in the
-following @code{steady} commands.
+default value of @code{maxit} is 50. 
 
 @item stack_solve_algo = @var{INTEGER}
 Algorithm used for computing the solution. Possible values are:
@@ -3605,6 +3599,9 @@ Threshold size for plotting IRFs. All IRFs for a particular variable with a maxi
 @item nocorr
 Don't print the correlation matrix (printing them is the default).
 
+@item nodecomposition
+Don't compute (and don't print) unconditional variance decomposition.
+
 @item nofunctions
 Don't print the coefficients of the approximated solution (printing
 them is the default).
@@ -3713,7 +3710,7 @@ period(s). The periods must be strictly positive. Conditional variances are give
 decomposition provides the decomposition of the effects of shocks upon
 impact. The results are stored in
 @code{oo_.conditional_variance_decomposition}
-(@pxref{oo_.conditional_variance_decomposition}). The variance decomposition is only conducted, if theoretical moments are requested, i.e. using the @code{periods=0}-option. In case of @code{order=2}, Dynare provides a second-order accurate approximation to the true second moments based on the linear terms of the second-order solution (see @cite{Kim, Kim, Schaumburg and Sims (2008)}). Note that the unconditional variance decomposition (i.e. at horizon infinity) is automatically conducted if theoretical moments are requested (@pxref{oo_.variance_decomposition})
+(@pxref{oo_.conditional_variance_decomposition}). The variance decomposition is only conducted, if theoretical moments are requested, i.e. using the @code{periods=0}-option. In case of @code{order=2}, Dynare provides a second-order accurate approximation to the true second moments based on the linear terms of the second-order solution (see @cite{Kim, Kim, Schaumburg and Sims (2008)}). Note that the unconditional variance decomposition (i.e. at horizon infinity) is automatically conducted if theoretical moments are requested and if @code{nodecomposition} is not set (@pxref{oo_.variance_decomposition})
 
 @item pruning
 Discard higher order terms when iteratively computing simulations of
@@ -4354,10 +4351,20 @@ Specifies a starting value for the posterior mode optimizer or the
 maximum likelihood estimation. If unset, defaults to the prior mean.
 
 @item @var{LOWER_BOUND}
-Specifies a lower bound for the parameter value in maximum likelihood estimation
+@anchor{lower_bound} Specifies a lower bound for the parameter value in maximum
+likelihood estimation. In a Bayesian estimation context, sets a lower bound
+only effective while maximizing the posterior kernel. This lower bound does not
+modify the shape of the prior density, and is only aimed at helping the
+optimizer in identifying the posterior mode (no consequences for the MCMC). For
+some prior densities (namely inverse gamma, gamma, uniform or beta) it is
+possible to shift the support of the prior distributions to the left or the right using
+@ref{prior_3rd_parameter}. In this case the prior density is effectively
+modified (note that the truncated Gaussian density is not implemented in
+Dynare). If unset, defaults to minus infinity (ML) or the natural lower bound
+of the prior (Bayesian estimation).
 
 @item @var{UPPER_BOUND}
-Specifies an upper bound for the parameter value in maximum likelihood estimation
+Same as @ref{lower_bound}, but specifying an upper bound instead.
 
 @item @var{PRIOR_SHAPE}
 A keyword specifying the shape of the prior density.
@@ -4369,16 +4376,18 @@ that @code{inv_gamma_pdf} is equivalent to
 @code{inv_gamma1_pdf}
 
 @item @var{PRIOR_MEAN}
-The mean of the prior distribution
+@anchor{prior_mean} The mean of the prior distribution
 
 @item @var{PRIOR_STANDARD_ERROR}
-The standard error of the prior distribution
+@anchor{prior_standard_error} The standard error of the prior distribution
 
 @item @var{PRIOR_3RD_PARAMETER}
+@anchor{prior_3rd_parameter}
 A third parameter of the prior used for generalized beta distribution,
 generalized gamma and for the uniform distribution. Default: @code{0}
 
 @item @var{PRIOR_4TH_PARAMETER}
+@anchor{prior_4th_parameter}
 A fourth parameter of the prior used for generalized beta distribution
 and for the uniform distribution. Default: @code{1}
 
@@ -4593,15 +4602,15 @@ univariate convergence diagnostic.
 @table @code
 
 @item datafile = @var{FILENAME}
-@anchor{datafile}
-The datafile: a @file{.m} file, a @file{.mat} file, a @file{.csv}
-file, or a @file{.xls}/@file{.xlsx} file (under Octave, the
-@uref{http://octave.sourceforge.net/io/,io} from Octave-Forge is
-required for the @file{.csv}, @file{.xls} and @file{.xlsx} formats; in
-addition, for the @file{.xls} and @file{.xlsx} formats, the
-@uref{http://octave.sourceforge.net/java/,java} package is required,
-along with a @uref{http://www.java.com/download,Java Runtime
-Environment})
+@anchor{datafile} The datafile: a @file{.m} file, a @file{.mat} file, a
+@file{.csv} file, or a @file{.xls}/@file{.xlsx} file (under Octave, the
+@uref{http://octave.sourceforge.net/io/,io} from Octave-Forge is required for
+the @file{.csv}, @file{.xls} and @file{.xlsx} formats; in addition, for the
+@file{.xls} and @file{.xlsx} formats, the
+@uref{http://octave.sourceforge.net/java/,java} package is required, along with
+a @uref{http://www.java.com/download,Java Runtime Environment}). Note that the
+base name (ie without extension) of the datafile has to be different from the
+base name of the model file.
 
 @item xls_sheet = @var{NAME}
 @anchor{xls_sheet}
@@ -4609,7 +4618,7 @@ The name of the sheet with the data in an Excel file
 
 @item xls_range = @var{RANGE}
 @anchor{xls_range}
-The range with the data in an Excel file
+The range with the data in an Excel file. For example, @code{xls_range=B2:D200}
 
 @item nobs = @var{INTEGER}
 @anchor{nobs}
@@ -5133,7 +5142,11 @@ Use the Univariate Diffuse Kalman Filter
 @end table
 @noindent
 Default value is @code{0}. In case of missing observations of single or all series, Dynare treats those missing values as unobserved states and uses the Kalman filter to infer their value (see e.g. @cite{Durbin and Koopman (2012), Ch. 4.10})
-
+This procedure has the advantage of being capable of dealing with observations where the forecast error variance matrix becomes singular for some variable(s).
+If this happens, the respective observation enters with a weight of zero in the log-likelihood, i.e. this observation for the respective variable(s) is dropped
+from the likelihood computations (for details see @cite{Durbin and Koopman (2012), Ch. 6.4 and 7.2.5}). If the use of a multivariate Kalman filter is specified and a
+singularity is encountered, Dynare by default automatically switches to the univariate Kalman filter for this parameter draw. This behavior can be changed via the
+@ref{use_univariate_filters_if_singularity_is_detected} option.
 
 @item kalman_tol = @var{DOUBLE}
 @anchor{kalman_tol} Numerical tolerance for determining the singularity of the covariance matrix of the prediction errors during the Kalman filter (minimum allowed reciprocal of the matrix condition number). Default value is @code{1e-10}
@@ -5148,13 +5161,14 @@ See below.
 
 @item filter_step_ahead = [@var{INTEGER1} @var{INTEGER2}  @dots{}]
 @anchor{filter_step_ahead}
-Triggers the computation k-step ahead filtered values. Stores results in
+Triggers the computation k-step ahead filtered values, i.e. @math{E_{t}{y_{t+k}}}. Stores results in
 @code{oo_.FilteredVariablesKStepAhead} and
 @code{oo_.FilteredVariablesKStepAheadVariances}.
 
 @item filter_decomposition
 @anchor{filter_decomposition} Triggers the computation of the shock
-decomposition of the above k-step ahead filtered values.
+decomposition of the above k-step ahead filtered values. Stores results in @code{oo_.FilteredVariablesShockDecomposition}.
+
 
 @item diffuse_filter
 Uses the diffuse Kalman filter (as described in
@@ -5173,8 +5187,9 @@ any value of  @math{\bar a} of @math{a} is a  deterministic steady state for pro
 Note that the nonstationary variables in the model must be integrated processes (their first difference or k-difference must be stationary).
 
 @item selected_variables_only
+@anchor{selected_variables_only}
 Only run the smoother on the variables listed just after the
-@code{estimation} command. Default: run the smoother on all the
+@code{estimation} command. This options is incompatible with requesting classical frequentist forecasts and will be overridden in this case. Default: run the smoother on all the
 declared endogenous variables.
 
 @item cova_compute = @var{INTEGER}
@@ -5267,6 +5282,7 @@ Use endogenous priors as in @cite{Christiano, Trabandt and Walentin
 (2011)}.
 
 @item use_univariate_filters_if_singularity_is_detected = @var{INTEGER}
+@anchor{use_univariate_filters_if_singularity_is_detected}
 Decide whether Dynare should automatically switch to univariate filter
 if a singularity is encountered in the likelihood computation (this is
 the behaviour if the option is equal to @code{1}). Alternatively, if
@@ -5301,8 +5317,70 @@ filtered variables and forecasts (when requested) on all the observed
 variables. This is equivalent to manually listing all the observed
 variables after the @code{estimation} command.
 
+@item number_of_particles = @var{INTEGER}
+@anchor{number_of_particles}
+Number of particles used when evaluating the likelihood of a non linear state space model. Default: @code{1000}.
+
+@item resampling = @var{OPTION}
+@anchor{resampling}
+Determines if resampling of the particles is done. Possible values for @var{OPTION} are:
+
+@table @code
+
+@item none
+No resampling.
+
+@item systematic
+Resampling at each iteration, this is the default value.
+
+@item generic
+Resampling if and only if the effective sample size is below a certain level defined by @ref{resampling_threshold}*@ref{number_of_particles}.
+
 @end table
 
+@item resampling_threshold = @var{DOUBLE}
+@anchor{resampling_threshold}
+A real number between zero and one. The resampling step is triggered as soon as the effective number of particles is less than this number times the total number of particles (as set by @ref{number_of_particles}). This option is effective if and only if option @ref{resampling} has value @code{generic}.
+
+@item resampling_method = @var{OPTION}
+@anchor{resampling_method}
+Sets the resampling method. Possible values for @var{OPTION} are: @code{kitagawa}, @code{stratified} and @code{smooth}.
+
+@item filter_algorithm = @var{OPTION}
+@anchor{filter_algorithm}
+Sets the particle filter algorithm. Possible values for @var{OPTION} are:
+
+@table @code
+
+@item sis
+Sequential importance sampling algorithm, this is the default value.
+
+@item apf
+Auxiliary particle filter.
+
+@item gf
+Gaussian filter.
+
+@item gmf
+Gaussian mixture filter.
+
+@item cpf
+Conditional particle filter.
+
+@end table
+
+@item proposal_approximation = @var{OPTION}
+@anchor{proposal_approximation}
+Sets the method for approximating the proposal distribution. Possible values for @var{OPTION} are: @code{cubature}, @code{montecarlo} and @code{unscented}. Default value is @code{cubature}.
+
+@item distribution_approximation = @var{OPTION}
+@anchor{distribution_approximation}
+Sets the method for approximating the particle distribution. Possible values for @var{OPTION} are: @code{cubature}, @code{montecarlo} and @code{unscented}. Default value is @code{unscented}.
+
+
+@end table
+
+
 @customhead{Note}
 
 If no @code{mh_jscale} parameter is used in estimated_params, the
@@ -5410,6 +5488,7 @@ After an estimation without Metropolis, fields are of the form:
 @code{oo_.FilteredVariables.@var{VARIABLE_NAME}}
 @end example
 
+
 After an estimation with Metropolis, fields are of the form:
 @example
 @code{oo_.FilteredVariables.@var{MOMENT_NAME}.@var{VARIABLE_NAME}}
@@ -5418,12 +5497,23 @@ After an estimation with Metropolis, fields are of the form:
 
 @defvr {MATLAB/Octave variable} oo_.FilteredVariablesKStepAhead
 Variable set by the @code{estimation} command, if it is used with the
-@code{filter_step_ahead} option. The k-steps are stored along the rows while the columns indicate the respective variables. The third dimension of the array provides the observation for which the forecast has been made. For example, if @code{filter_step_ahead=[1 2 4]} and @code{nobs=200}, the element (3,5,204) stores the four period ahead filtered value of variable 5 computed at time t=200 for time t=204. The periods at the beginning and end of the sample for which no forecasts can be made, e.g. entries (1,5,1) and (1,5,204) in the example, are set to zero.
+@code{filter_step_ahead} option. The k-steps are stored along the rows while the columns 
+indicate the respective variables. The third dimension of the array provides the
+observation for which the forecast has been made. For example, if @code{filter_step_ahead=[1 2 4]} 
+and @code{nobs=200}, the element (3,5,204) stores the four period ahead filtered 
+value of variable 5 computed at time t=200 for time t=204. The periods at the beginning 
+and end of the sample for which no forecasts can be made, e.g. entries (1,5,1) and 
+(1,5,204) in the example, are set to zero. Note that in case of Bayesian estimation 
+the variables will be ordered in the order of declaration after the estimation 
+command (or in general declaration order if no variables are specified here). In case 
+of running the classical smoother, the variables will always be ordered in general 
+declaration order. If the @xref{selected_variables_only} option is specified with the classical smoother, 
+non-requested variables will be simply left out in this order.
 @end defvr
 
 @defvr {MATLAB/Octave variable} oo_.FilteredVariablesKStepAheadVariances
 Variable set by the @code{estimation} command, if it is used with the
-@code{filter_step_ahead} option.
+@code{filter_step_ahead} option. It is a 4 dimensional array where the k-steps are stored along the first dimension, while the fourth dimension of the array provides the observation for which the forecast has been made. The second and third dimension provide the respective variables. For example, if @code{filter_step_ahead=[1 2 4]} and @code{nobs=200}, the element (3,4,5,204) stores the four period ahead forecast error covariance between variable 4 and variable 5, computed at time t=200 for time t=204. Padding with zeros is analogous to @code{oo_.FilteredVariablesKStepAhead}. 
 @end defvr
 
 @defvr {MATLAB/Octave variable} oo_.Filtered_Variables_X_step_ahead
@@ -5670,16 +5760,29 @@ estimates using a higher tapering are usually more reliable.
 
 @deffn Command model_comparison @var{FILENAME}[(@var{DOUBLE})]@dots{};
 @deffnx Command model_comparison (marginal_density = laplace | modifiedharmonicmean) @var{FILENAME}[(@var{DOUBLE})]@dots{};
-
+@anchor{model_comparison}
 @descriptionhead
 
-This command computes odds ratios and estimate a posterior density
-over a collection of models 
-(see e.g. @cite{Koop (2003), Ch. 1}). The priors over models can be specified
-as the @var{DOUBLE} values, otherwise a uniform prior over all models is assumed. 
-In contrast to frequentist econometrics, the models to be compared do not need to be nested. 
-However, as the computation of posterior odds ratios is a Bayesian technique, 
-the comparison of models estimated with maximum likelihood is not supported.
+This command computes odds ratios and estimate a posterior density over a
+collection of models (see e.g. @cite{Koop (2003), Ch. 1}). The priors over
+models can be specified as the @var{DOUBLE} values, otherwise a uniform prior
+over all models is assumed.  In contrast to frequentist econometrics, the
+models to be compared do not need to be nested.  However, as the computation of
+posterior odds ratios is a Bayesian technique, the comparison of models
+estimated with maximum likelihood is not supported.
+
+It is important to keep in mind that model comparison of this type is only
+valid with proper priors.  If the prior does not integrate to one for all
+compared models, the comparison is not valid. This may be the case if part of
+the prior mass is implicitly truncated because Blanchard and Kahn conditions
+(instability or indeterminacy of the model) are not fulfilled, or because for
+some regions of the parameters space the deterministic steady state is
+undefined (or Dynare is unable to find it). The compared marginal densities
+should be renormalized by the effective prior mass, but this not done by
+Dynare: it is the user's responsibility to make sure that model comparison is
+based on proper priors. Note that, for obvious reasons, this is not an issue if
+the compared marginal densities are based on Laplace approximations.
+
 
 @examplehead
 
@@ -6316,7 +6419,7 @@ parameters in the @code{params}-command and be entered in the
 
 @item
 @math{e} are the exogenous stochastic shocks, specified in the
-@code{var_exo}-command;
+@code{varexo}-command;
 
 @item
 @math{W} is the weighting matrix;
@@ -7051,7 +7154,7 @@ The threshold @math{pvalue} for significant Kolmogorov-Smirnov test (@i{i.e.} pl
 
 @item pvalue_corr = @var{DOUBLE}
 The threshold @math{pvalue} for significant correlation in filtered samples
-(@i{i.e.} plot bivariate samples when @math{pvalue<} @code{pvalue_corr}). Default: @code{0.001}
+(@i{i.e.} plot bivariate samples when @math{pvalue<} @code{pvalue_corr}). Default: @code{1e-5}
 
 @end table
 @customhead{Reduced Form Mapping Options}
@@ -7080,7 +7183,7 @@ are filtered. Default: @code{0.1}
 
 @item alpha2_redform = @var{DOUBLE}
 Critical value for correlations @math{\rho}  when reduced form entries
-are filtered. Default: @code{0.3}
+are filtered. Default: @code{1e-5}
 
 @item namendo = (@var{VARIABLE_NAME}@dots{})
 List of endogenous variables. `@code{:}' indicates all endogenous variables.
@@ -7127,7 +7230,7 @@ Critical value for Smirnov statistics @math{d}: plot parameters with
 
 @item alpha2_rmse = @var{DOUBLE}
 Critical value for correlation @math{\rho}: plot couples of parmaters with
-@math{\left|\rho\right|=} @code{alpha2_rmse}. Default: @code{1.0}
+@math{\left|\rho\right|=} @code{alpha2_rmse}. Default: @code{1e-5}
 
 @item datafile = @var{FILENAME}
 @xref{datafile}.
@@ -10150,6 +10253,31 @@ Overloads the Matlab/Octave @code{exp} function for @dseries objects.
 
 @sp 1
 
+@deftypefn{dseries} {@var{l} =} exist (@var{A}, @var{varname})
+
+Tests if @var{variable} exists in @dseries object @var{A}. Returns 1 (true) iff @var{variable} exists in @var{A}.
+
+@exampleshead
+
+@example
+>> ts = dseries(randn(100,1));
+>> ts.exist('Variable_1')
+
+ans =
+
+     1
+
+>> ts.exist('Variable_2')
+
+ans =
+
+     0
+@end example
+
+@end deftypefn
+
+@sp 1
+
 @deftypefn{dseries} {@var{C} =} extract (@var{A}, @var{B}[, ...])
 
 Extracts some variables from a @dseries object @var{A} and returns a @dseries object @var{C}. The input arguments following @var{A} are strings representing the variables to be selected in the new @dseries object @var{C}. To simplify the creation of sub-objects, the @dseries class overloads the curly braces (@code{D = extract (A, B, C)} is equivalent to @code{D = A@{B,C@}}) and allows implicit loops (defined between a pair of @@ symbol, see examples below) or Matlab/Octave's regular expressions (introduced by square brackets).
@@ -11322,7 +11450,7 @@ command. Default: @code{`!'}
 @end defmethod
 
 @anchor{addGraph}
-@defmethod Report addGraph axisShape, data, graphDirName, graphName, graphSize, height, showGrid, showLegend, showLegendBox, legendLocation, legendOrientation, legendFontSize, miscTikzAxisOptions, miscTikzPictureOptions, seriesToUse, shade, shadeColor, shadeOpacity, tickFontSize, title, titleFontSize, titleFormat, width, xlabel, ylabel, xAxisTight, xrange, xTicks, xTickLabels, xTickLabelAnchor, xTickLabelRotation, yAxisTight, yTickLabelFixed, yTickLabelPrecision, yTickLabelScaled, yTickLabelZeroFill, yrange, showZeroline, zeroLineColor
+@defmethod Report addGraph axisShape, data, graphDirName, graphName, graphSize, height, showGrid, showLegend, showLegendBox, legendLocation, legendOrientation, legendFontSize, miscTikzAxisOptions, miscTikzPictureOptions, seriesToUse, shade, shadeColor, shadeOpacity, tickFontSize, title, titleFontSize, titleFormat, width, writeCSV, xlabel, ylabel, xAxisTight, xrange, xTicks, xTickLabels, xTickLabelAnchor, xTickLabelRotation, yAxisTight, yTickLabelFixed, yTickLabelPrecision, yTickLabelScaled, yTickLabelZeroFill, yrange, showZeroline, zeroLineColor
 Adds a @code{Graph} to a @code{Section}.
 @optionshead
 @table @code
@@ -11337,10 +11465,12 @@ to the left, right, bottom, and top of the graphed line(s). @code{`L'} means
 that there is an axis to the left and bottom of the graphed line(s). Default:
 @code{`box'}
 
+@anchor{graphDirName}
 @item graphDirName, @code{STRING}
 The name of the folder in which to store this figure. Default:
 @code{tmpRepDir}
 
+@anchor{graphName}
 @item graphName, @code{STRING}
 The name to use when saving this figure. Default: something of the
 form @code{graph_pg1_sec2_row1_col3.tex}
@@ -11426,6 +11556,12 @@ the title and subtitles. Default: @code{TikZ default}
 @item width, @code{DOUBLE}
 The width of the graph, in inches. Default: @code{6.0}
 
+@item writeCSV, @code{BOOLEAN}
+Whether or not to write a CSV file with only the plotted data. The file will be
+saved in the directory specified by @ref{graphDirName} with the same base name
+as specified by @ref{graphName} with the ending @code{.csv}. Default:
+@code{false}
+
 @item xlabel, @code{STRING}
 The x-axis label. Default: @code{none}
 
@@ -11495,7 +11631,7 @@ reports. Default: @code{`black'}
 @end table
 @end defmethod
 
-@defmethod Report addTable data, showHlines, precision, range, seriesToUse, tableDirName, tableName, title, titleFormat, vlineAfter, vlineAfterEndOfPeriod, showVlines
+@defmethod Report addTable data, highlightRows, showHlines, precision, range, seriesToUse, tableDirName, tableName, title, titleFormat, vlineAfter, vlineAfterEndOfPeriod, showVlines, writeCSV
 Adds a @code{Table} to a @code{Section}.
 @optionshead
 @table @code
@@ -11503,6 +11639,12 @@ Adds a @code{Table} to a @code{Section}.
 @item data, @code{dseries}
 @xref{data}.
 
+@item highlightRows, @code{CELL_ARRAY_STRINGS}
+A cell array containing the colors to use for row highlighting. See
+@ref{shadeColor} for how to use colors with reports. Highlighting for a
+specific row can be overridden by using the @ref{tableRowColor} option to
+@ref{addSeries}. Default: @code{empty}
+
 @item showHlines, @code{BOOLEAN}
 Whether or not to show horizontal lines separating the rows. Default: @code{false}
 
@@ -11515,10 +11657,12 @@ The date range of the data to be displayed. Default: @code{all}
 @item seriesToUse, @code{CELL_ARRAY_STRINGS}
 @xref{seriesToUse}.
 
+@anchor{tableDirName}
 @item tableDirName, @code{STRING}
 The name of the folder in which to store this table. Default:
 @code{tmpRepDir}
 
+@anchor{tableName}
 @item tableName, @code{STRING}
 The name to use when saving this table. Default: something of the
 form @code{table_pg1_sec2_row1_col3.tex}
@@ -11539,6 +11683,13 @@ every year, after the fourth quarter, etc.). Default: @code{false}
 
 @item showVlines, @code{BOOLEAN}
 Whether or not to show vertical lines separating the columns. Default: @code{false}
+
+@item writeCSV, @code{BOOLEAN}
+Whether or not to write a CSV file containing the data displayed in the
+table. The file will be saved in the directory specified by @ref{tableDirName}
+with the same base name as specified by @ref{tableName} with the ending
+@code{.csv}. Default: @code{false}
+
 @end table
 @end defmethod
 
@@ -11610,6 +11761,7 @@ quarterly @code{tableDataRhs} could point to the yearly averages of
 the quarterly series. This would cause quarterly data to be displayed
 followed by annual data. Default: @code{empty}
 
+@anchor{tableRowColor}
 @item tableRowColor, @code{STRING}
 The color that you want the row to be. Predefined values include
 @code{LightCyan} and @code{Gray}. Default: @code{white}.
diff --git a/license.txt b/license.txt
index 64f84a2d671869c19398249724b6fedf783b6586..27122feb62a644eb287fd64444356008477e6cd0 100644
--- a/license.txt
+++ b/license.txt
@@ -80,15 +80,17 @@ Copyright: 1995-2007 Kurt Hornik
            2008-2009 Dynare Team
 License: GPL-3+
 
-Files: matlab/missing/bicgstab/bicgstab.m
-Copyright: 2008 Radek Salac
-License: GPL-3+
-
 Files: matlab/missing/strjoin/strjoin.m
 Copyright: 2007 Muthiah Annamalai <muthiah.annamalai@uta.edu>
            2013 Dynare Team
 License: GPL-3+
 
+Files: matlab/missing/corrcoef/corrcoef.m matlab/missing/corrcoef/sumskipnan.m
+ matlab/missing/corrcoef/flag_implicit_skip_nan.m matlab/missing/corrcoef/tcdf.m
+Copyright: 2000-2005,2008,2009,2011 by Alois Schloegl <alois.schloegl@gmail.com>
+           2014 Dynare Team
+License: GPL-3+
+
 Files: matlab/lmmcp/catstruct.m
 Copyright: 2005 Jos van der Geest <jos@jasen.nl>
            2013 Christophe Gouel
diff --git a/m4/ax_blas.m4 b/m4/ax_blas.m4
index 821459d85791faa0eecd51c6577f6e0fc1e5e507..1b5887d607bb86fd0b1b0ed00c7cf79c05f2eb42 100644
--- a/m4/ax_blas.m4
+++ b/m4/ax_blas.m4
@@ -170,11 +170,11 @@ if test $ax_blas_ok = no; then
 	AC_CHECK_LIB(mkl, $sgemm, [ax_blas_ok=yes;BLAS_LIBS="-lmkl -lguide -lpthread"],,[-lguide -lpthread])
 fi
 
-# BLAS in Apple vecLib library?
+# BLAS in Apple Accelerate library?
 if test $ax_blas_ok = no; then
-	save_LIBS="$LIBS"; LIBS="-framework vecLib $LIBS"
-	AC_MSG_CHECKING([for $sgemm in -framework vecLib])
-	AC_TRY_LINK_FUNC($sgemm, [ax_blas_ok=yes;BLAS_LIBS="-framework vecLib"])
+	save_LIBS="$LIBS"; LIBS="-framework Accelerate $LIBS"
+	AC_MSG_CHECKING([for $sgemm in -framework Accelerate])
+	AC_TRY_LINK_FUNC($sgemm, [ax_blas_ok=yes;BLAS_LIBS="-framework Accelerate"])
 	AC_MSG_RESULT($ax_blas_ok)
 	LIBS="$save_LIBS"
 fi
diff --git a/m4/ax_matlab_version.m4 b/m4/ax_matlab_version.m4
index 440af100ee6facb891c82fd42b8cad1390ee3e5e..c7a1d5f3ea3ed92d5d2fcad812abec3945b74691 100644
--- a/m4/ax_matlab_version.m4
+++ b/m4/ax_matlab_version.m4
@@ -22,6 +22,9 @@ AC_REQUIRE([AX_MATLAB])
 AC_MSG_CHECKING([for MATLAB version])
 if test "x$MATLAB_VERSION" != "x"; then
   case $MATLAB_VERSION in
+    *2014b | *2014B)
+      MATLAB_VERSION="8.4"
+      ;;
     *2014a | *2014A)
       MATLAB_VERSION="8.3"
       ;;
diff --git a/matlab/@dates/append.m b/matlab/@dates/append.m
deleted file mode 100644
index c818294ed6cb5e99d3b7041863f404d39d68f386..0000000000000000000000000000000000000000
--- a/matlab/@dates/append.m
+++ /dev/null
@@ -1,102 +0,0 @@
-function B = append(A,a) % --*-- Unitary tests --*--
-
-% append method for dates class.
-%
-% INPUTS 
-%  o A    dates object.
-%  o a    dates object with one element or string that can be interpreted as a date.
-%
-% OUTPUTS 
-%  o B    dates object containing dates defined in A and a.
-%
-% EXAMPLE 1 
-%  If A is a dates object with quarterly frequency, then B = A.append(dates('1950Q2')) and 
-%  B = A.append('1950Q2') are equivalent syntaxes.
-
-% Copyright (C) 2012-2013 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 isa(a,'dates')
-    if ~isequal(length(a),1)
-        error(['dates::append: Input argument ' inputname(2) ' has to be a dates object with one element.'])
-    end
-    if isempty(a)
-        B = A;
-        return
-    end
-elseif isdate(a)
-    a = dates(a);
-end
-
-if ~isequal(A.freq, a.freq)
-    error(['dates::append: A and a must have common frequency!'])
-end
-
-B = dates();
-B.ndat = A.ndat+1;
-B.freq = A.freq;
-B.time = NaN(B.ndat,2);
-B.time(1:A.ndat,:) = A.time;
-B.time(A.ndat+1,:) = a.time; 
-
-%@test:1
-%$ % Define some dates
-%$ B1 = '1953Q4';
-%$ B2 = '1950Q2';
-%$ B3 = '1950Q1';
-%$ B4 = '1945Q3';
-%$ B5 = '2009Q2';
-%$
-%$ % Define expected results.
-%$ e.time = [1945 3; 1950 1; 1950 2; 1953 4; 2009 2];
-%$ e.freq = 4;
-%$ e.ndat = 5;
-%$
-%$ % Call the tested routine.
-%$ d = dates(B4,B3,B2,B1);
-%$ d = d.append(dates(B5));
-%$
-%$ % Check the results.
-%$ t(1) = dyn_assert(d.time,e.time);
-%$ t(2) = dyn_assert(d.freq,e.freq);
-%$ t(3) = dyn_assert(d.ndat,e.ndat);
-%$ T = all(t);
-%@eof:1
-
-%@test:2
-%$ % Define some dates
-%$ B1 = '1953Q4';
-%$ B2 = '1950Q2';
-%$ B3 = '1950Q1';
-%$ B4 = '1945Q3';
-%$ B5 = '2009q2';
-%$
-%$ % Define expected results.
-%$ e.time = [1945 3; 1950 1; 1950 2; 1953 4; 2009 2];
-%$ e.freq = 4;
-%$ e.ndat = 5;
-%$
-%$ % Call the tested routine.
-%$ d = dates(B4,B3,B2,B1);
-%$ d = d.append(B5);
-%$
-%$ % Check the results.
-%$ t(1) = dyn_assert(d.time,e.time);
-%$ t(2) = dyn_assert(d.freq,e.freq);
-%$ t(3) = dyn_assert(d.ndat,e.ndat);
-%$ T = all(t);
-%@eof:2
\ No newline at end of file
diff --git a/matlab/@dates/char.m b/matlab/@dates/char.m
deleted file mode 100644
index bdde032dc39e4353ee21c3e48c99bbdc07fcafe9..0000000000000000000000000000000000000000
--- a/matlab/@dates/char.m
+++ /dev/null
@@ -1,35 +0,0 @@
-function s = char(dd)
-
-% Given a one element dates object, returns a string with the formatted date.
-%
-% INPUTS 
-%   o dd   dates object with one element
-%
-% OUTPUTS
-%   o s    a string
-%
-% 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/>.
-
-if length(dd)>1
-    error('The input argument must be a singleton dates object!')
-end
-
-s = date2string(dd.time, dd.freq);
\ No newline at end of file
diff --git a/matlab/@dates/colon.m b/matlab/@dates/colon.m
deleted file mode 100644
index a68b82519b8fcf3e06b7161161765702d457f034..0000000000000000000000000000000000000000
--- a/matlab/@dates/colon.m
+++ /dev/null
@@ -1,192 +0,0 @@
-function C = colon(varargin) % --*-- Unitary tests --*--
-
-% Overloads the colon operator (:). This method can be used to create ranges of dates.
-%
-% INPUTS 
-%  o A    dates object with one element.
-%  o d    integer scalar, number of periods between each date (default value, if nargin==2, is one)
-%  o B    dates object with one element.
-%
-% OUTPUTS 
-%  o C    dates object with length(B-A) elements (if d==1).
-%
-% REMARKS 
-%  B must be greater than A if d>0.
-
-% Copyright (C) 2013 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 isequal(nargin,2)
-    A = varargin{1};
-    B = varargin{2};
-    d = 1;
-    if ~(isa(A,'dates') && isa(B,'dates') && isequal(length(A),1) && isequal(length(B),1))
-        error('dates::colon: In an expression like A:B, A and B must be dates objects!')
-    end
-elseif isequal(nargin,3)
-    A = varargin{1};
-    B = varargin{3};
-    d = varargin{2};
-    if ~(isa(A,'dates') && isa(B,'dates') && isequal(length(A),1) && isequal(length(B),1))
-        error('dates::colon: In an expression like A:d:B, A and B must be dates objects and d a scalar integer (number of periods)!')
-    end
-    if ~(isscalar(d) && isint(d))
-        error('dates::colon: In an expression like A:d:B, A and B must be dates objects and d a scalar integer (number of periods)!')
-    end
-    if isequal(d,0)
-        error('dates::colon: In an expression like A:d:B, d (the incremental number of periods) must nonzero!')
-    end
-else
-    error('dates::colon: Wrong calling sequence! See the manual for the colon (:) operator and dates objects.')
-end
-
-if ~isequal(A.freq,B.freq)
-    error(['dates::colon: Input arguments ' inputname(1) 'and ' inputname(2) ' must have common frequency!'])
-end
-
-if A>B && d>0
-    error(['dates::colon: ' inputname(1) ' must precede ' inputname(2) '!' ])
-end
-
-if B>A && d<0
-    error(['dates::colon: ' inputname(2) ' must precede ' inputname(1) '!' ])
-end
-
-C = dates();
-n = (B-A)+1;
-m = n;
-if d>1
-    m = length(1:d:n);
-end
-C.freq = A.freq;
-
-if isequal(C.freq,1)
-    C.ndat = m;
-    C.time = NaN(m,2);
-    C.time(:,1) = A.time(1)+transpose(0:d:n-1);
-    C.time(:,2) = 1;
-else
-    C.time = NaN(n,2);
-    initperiods = min(C.freq-A.time(2)+1,n);
-    C.time(1:initperiods,1) = A.time(1);
-    C.time(1:initperiods,2) = transpose(A.time(2)-1+(1:initperiods));
-    if n>initperiods
-        p = n-initperiods;
-        if p<=C.freq
-            C.time(initperiods+(1:p),1) = A.time(1)+1;
-            C.time(initperiods+(1:p),2) = transpose(1:p);
-        else
-            q = fix(p/C.freq);
-            r = rem(p,C.freq);
-            C.time(initperiods+(1:C.freq*q),2) = repmat(transpose(1:C.freq),q,1);
-            C.time(initperiods+(1:C.freq*q),1) = kron(A.time(1)+transpose(1:q),ones(C.freq,1));
-            if r>0
-                C.time(initperiods+C.freq*q+(1:r),1) = C.time(initperiods+C.freq*q,1)+1;
-                C.time(initperiods+C.freq*q+(1:r),2) = transpose(1:r);
-            end
-        end
-    end
-    if d>1
-        C.time = C.time(1:d:n,:);
-        C.ndat = m;
-    else
-        C.ndat = n;
-    end
-end
-
-%@test:1
-%$ % Define two dates
-%$ date_1 = '1950Q2';
-%$ date_2 = '1951Q4';
-%$
-%$ % Define expected results.
-%$ e.freq = 4;
-%$ e.time = [1950 2; 1950 3; 1950 4; 1951 1; 1951 2; 1951 3; 1951 4];
-%$
-%$ % Call the tested routine.
-%$ d1 = dates(date_1);
-%$ d2 = dates(date_2);
-%$ d3 = d1:d2;
-%$
-%$ % Check the results.
-%$ t(1) = dyn_assert(d3.time,e.time);
-%$ t(2) = dyn_assert(d3.freq,e.freq);
-%$ T = all(t);
-%@eof:1
-
-%@test:2
-%$ % Define expected results.
-%$ e.freq = 4;
-%$ e.time = [1950 2; 1950 3; 1950 4; 1951 1; 1951 2; 1951 3; 1951 4];
-%$
-%$ % Call the tested routine.
-%$ d = dates('1950Q2'):dates('1951Q4');
-%$
-%$ % Check the results.
-%$ t(1) = dyn_assert(d.time,e.time);
-%$ t(2) = dyn_assert(d.freq,e.freq);
-%$ T = all(t);
-%@eof:2
-
-%@test:3
-%$ % Define expected results.
-%$ e.freq = 4;
-%$ e.time = [1950 2; 1950 4; 1951 2; 1951 4];
-%$
-%$ % Call the tested routine.
-%$ d = dates('1950Q2'):2:dates('1951Q4');
-%$
-%$ % Check the results.
-%$ t(1) = dyn_assert(d.time,e.time);
-%$ t(2) = dyn_assert(d.freq,e.freq);
-%$ T = all(t);
-%@eof:3
-
-
-%$ @test:3
-%$ % Create an empty dates object for quaterly data
-%$ qq = dates('Q');
-%$
-%$ % Define expected results.
-%$ e.freq = 4;
-%$ e.time = [1950 2; 1950 3; 1950 4; 1951 1; 1951 2; 1951 3; 1951 4];
-%$
-%$ % Call the tested routine.
-%$ d = qq(1950,2):qq(1951,4);
-%$
-%$ % Check the results.
-%$ t(1) = dyn_assert(d.time,e.time);
-%$ t(2) = dyn_assert(d.freq,e.freq);
-%$ T = all(t);
-%$ @eof:3
-
-%$ @test:4
-%$ % Create an empty dates object for quaterly data
-%$ qq = dates('Q');
-%$
-%$ % Define expected results.
-%$ e.freq = 4;
-%$ e.time = [1950 1; 1950 2; 1950 3];
-%$
-%$ % Call the tested routine.
-%$ d = qq(1950,1):qq(1950,3);
-%$
-%$ % Check the results.
-%$ t(1) = dyn_assert(d.time,e.time);
-%$ t(2) = dyn_assert(d.freq,e.freq);
-%$ T = all(t);
-%$ @eof:4
\ No newline at end of file
diff --git a/matlab/@dates/dates.m b/matlab/@dates/dates.m
deleted file mode 100644
index ecc55ef511b2dacd4bfd29d7ac357637319b0b5d..0000000000000000000000000000000000000000
--- a/matlab/@dates/dates.m
+++ /dev/null
@@ -1,311 +0,0 @@
-function dd = dates(varargin) % --*-- Unitary tests --*--
-
-%@info:
-%! @deftypefn {Function File} {@var{dd} =} dates (@var{a},@var{b},...)
-%! @anchor{dates}
-%! @sp 1
-%! Constructor for the Dynare dates class (unordered sequence of dates).
-%! @sp 2
-%! @strong{Inputs}
-%! @sp 1
-%! @table @ @var
-%! @item a
-%! String, date.
-%! @item b
-%! @end table
-%! @sp 2
-%! @strong{Outputs}
-%! @sp 1
-%! @table @ @var
-%! @item dd
-%! Dynare dates object.
-%! @end table
-%! @sp 1
-%! @strong{Properties}
-%! @sp 1
-%! The constructor defines the following properties:
-%! @sp 1
-%! @table @ @var
-%! @item ndate
-%! Scalar integer, the number of dates.
-%! @item freq
-%! Scalar integer, the frequency of the time series. @var{freq} is equal to 1 if data are on a yearly basis or if
-%! frequency is unspecified. @var{freq} is equal to 4 if data are on a quaterly basis. @var{freq} is equal to
-%! 12 if data are on a monthly basis. @var{freq} is equal to 52 if data are on a weekly basis.
-%! @item time
-%! Array of integers (nobs*2). The first column defines the years associated to each date. The second column,
-%! depending on the frequency, indicates the week, month or quarter numbers. For yearly data or unspecified frequency
-%! the second column is filled by ones.
-%! @end table
-%! @sp 2
-%! @strong{This function is called by:}
-%! @sp 2
-%! @strong{This function calls:}
-%!
-%! @end deftypefn
-%@eod:
-
-% Copyright (C) 2011-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/>.
-
-% Initialization.
-if nargin>0 && ischar(varargin{1}) && isequal(varargin{1},'initialize')
-    dd = struct('ndat', 0, 'freq', NaN(0), 'time', NaN(0,2));
-    dd = class(dd,'dates');
-    assignin('base','emptydatesobject',dd);
-    return
-end
-
-dd = evalin('base','emptydatesobject');
-
-if isequal(nargin, 0)
-    % Return an empty dates obect
-    return
-end
-
-if all(cellfun(@isdates, varargin))
-    % Concatenates dates in a dates object.
-    dd = horzcat(varargin{:});
-    return
-end
-
-if all(cellfun(@isstringdate,varargin))
-    % Concatenates dates in a dates object.
-    tmp = cellfun(@string2date,varargin);
-    if all([tmp.freq]-tmp(1).freq==0)
-        dd.freq = tmp(1).freq;
-    else
-        error('dates::dates: Wrong calling sequence of the constructor! All dates must have common frequency.')
-    end
-    dd.ndat = length(tmp);
-    dd.time = transpose(reshape([tmp.time],2,dd.ndat));
-    return
-end
-
-if isequal(nargin,1) && isfreq(varargin{1})
-    % Instantiate an empty dates object (only set frequency)
-    if ischar(varargin{1})
-        dd.freq = string2freq(varargin{1});
-    else
-        dd.freq = varargin{1};
-    end
-    return
-end
-
-if isequal(nargin,3) && isfreq(varargin{1})
-    if ischar(varargin{1})
-        dd.freq = string2freq(varargin{1});
-    else
-        dd.freq = varargin{1};
-    end
-    if (isnumeric(varargin{2}) && isvector(varargin{2}) && all(isint(varargin{2})))
-        if isnumeric(varargin{3}) && isvector(varargin{3}) && all(isint(varargin{3}))
-            if all(varargin{3}>=1) && all(varargin{3}<=dd.freq)
-                dd.time = [varargin{2}(:), varargin{3}(:)];
-                dd.ndat = size(dd.time,1);
-            else
-                error(sprintf('dates::dates: Wrong calling sequence of the constructor! Third input must contain integers between 1 and %i.',dd.freq))
-            end
-        else
-            error('dates::dates: Wrong calling sequence of the constructor! Third input must be a vector of integers.')
-        end
-    else
-        error('dates::dates: Wrong calling sequence of the constructor! Second input must be a vector of integers.')
-    end
-    return
-end
-
-if isequal(nargin,2) && isfreq(varargin{1})
-    if ischar(varargin{1})
-        dd.freq = string2freq(varargin{1});
-    else
-        dd.freq = varargin{1};
-    end
-    if isequal(dd.freq, 1)
-        if (isnumeric(varargin{2}) && isvector(varargin{2}) && isint(varargin{2}))
-            dd.time = [varargin{2}, ones(length(varargin{2}),1)];
-            dd.ndat = size(dd.time,1);
-            return
-        else
-            error('dates::dates: Wrong calling sequence of the constructor! Second input must be a vector of integers.')
-        end
-    else
-        if isequal(size(varargin{2},2), 2)
-            if all(isint(varargin{2}(:,1))) && all(isint(varargin{2}(:,1)))
-                if all(varargin{2}(:,2)>=1) && all(varargin{2}(:,2)<=dd.freq)
-                    dd.time = [varargin{2}(:,1), varargin{2}(:,2)];
-                    dd.ndat = size(dd.time,1);
-                else
-                    error(sprintf('dates::dates: Wrong calling sequence of the constructor! Second column of the last input must contain integers between 1 and %i.',dd.freq))
-                end
-            else
-                error('dates::dates: Wrong calling sequence! Second input argument must be an array of integers.')
-            end
-        else
-            error('dates::dates: Wrong calling sequence!')
-        end
-    end
-    return
-end
-
-error('dates::dates: Wrong calling sequence!')
-
-%@test:1
-%$ % Define some dates
-%$ B1 = '1945Q3';
-%$ B2 = '1950Q2';
-%$ B3 = '1950q1';
-%$ B4 = '1953Q4';
-%$
-%$ % Define expected results.
-%$ e.time = [1945 3; 1950 2; 1950 1; 1953 4];
-%$ e.freq = 4;
-%$ e.ndat = 4;
-%$
-%$ % Call the tested routine.
-%$ d = dates(B1,B2,B3,B4);
-%$
-%$ % Check the results.
-%$ t(1) = dyn_assert(d.time,e.time);
-%$ t(2) = dyn_assert(d.freq,e.freq);
-%$ t(3) = dyn_assert(d.ndat,e.ndat);
-%$ T = all(t);
-%@eof:1
-
-%@test:2
-%$ % Define some dates
-%$ B1 = '1945M3';
-%$ B2 = '1950M2';
-%$ B3 = '1950M10';
-%$ B4 = '1953M12';
-%$
-%$ % Define expected results.
-%$ e.time = [1945 3; 1950 2; 1950 10; 1953 12];
-%$ e.freq = 12;
-%$ e.ndat = 4;
-%$
-%$ % Call the tested routine.
-%$ d = dates(B1,B2,B3,B4);
-%$
-%$ % Check the results.
-%$ t(1) = dyn_assert(d.time,e.time);
-%$ t(2) = dyn_assert(d.freq,e.freq);
-%$ t(3) = dyn_assert(d.ndat,e.ndat);
-%$ T = all(t);
-%@eof:2
-
-%@test:3
-%$ % Define some dates
-%$ B1 = '1945y';
-%$ B2 = '1950Y';
-%$ B3 = '1950a';
-%$ B4 = '1953A';
-%$
-%$ % Define expected results.
-%$ e.time = [1945 1; 1950 1; 1950 1; 1953 1];
-%$ e.freq = 1;
-%$ e.ndat = 4;
-%$
-%$ % Call the tested routine.
-%$ d = dates(B1,B2,B3,B4);
-%$
-%$ % Check the results.
-%$ t(1) = dyn_assert(d.time,e.time);
-%$ t(2) = dyn_assert(d.freq,e.freq);
-%$ t(3) = dyn_assert(d.ndat,e.ndat);
-%$ T = all(t);
-%@eof:3
-
-%@test:4
-%$ % Define a dates object
-%$ B = dates('1950Q1'):dates('1960Q3');
-%$
-%$
-%$ % Call the tested routine.
-%$ d = B(2);
-%$ if isa(d,'dates')
-%$     t(1) = 1;
-%$ else
-%$     t(1) = 0;
-%$ end
-%$
-%$ if t(1)
-%$     t(2) = dyn_assert(d.freq,B.freq);
-%$     t(3) = dyn_assert(d.time,[1950 2]);
-%$ end
-%$ T = all(t);
-%@eof:4
-
-%@test:5
-%$ % Define a dates object
-%$ B = dates(4,1950,1):dates(4,1960,3);
-%$
-%$ % Call the tested routine.
-%$ d = B(2);
-%$ if isa(d,'dates')
-%$     t(1) = 1;
-%$ else
-%$     t(1) = 0;
-%$ end
-%$
-%$ if t(1)
-%$     t(2) = dyn_assert(d.freq,B.freq);
-%$     t(3) = dyn_assert(d.time,[1950 2]);
-%$ end
-%$ T = all(t);
-%@eof:5
-
-%@test:6
-%$ % Define a dates object
-%$ B = dates(4,[1950 1]):dates(4,[1960 3]);
-%$
-%$ % Call the tested routine.
-%$ d = B(2);
-%$ if isa(d,'dates')
-%$     t(1) = 1;
-%$ else
-%$     t(1) = 0;
-%$ end
-%$
-%$ if t(1)
-%$     t(2) = dyn_assert(d.freq,B.freq);
-%$     t(3) = dyn_assert(d.time,[1950 2]);
-%$ end
-%$ T = all(t);
-%@eof:6
-
-%@test:7
-%$ try
-%$   B = dates(4,[1950; 1950], [1; 2]);
-%$   t = 1;
-%$ catch
-%$   t = 0;
-%$ end
-%$
-%$ T = all(t);
-%@eof:7
-
-%@test:8
-%$ try
-%$   B = dates(4,[1950, 1950], [1, 2]);
-%$   t = 1;
-%$ catch
-%$   t = 0;
-%$ end
-%$
-%$ T = all(t);
-%@eof:8
\ No newline at end of file
diff --git a/matlab/@dates/disp.m b/matlab/@dates/disp.m
deleted file mode 100644
index 9c012fea451cf02dd3ccd9234cb116fba74d43d8..0000000000000000000000000000000000000000
--- a/matlab/@dates/disp.m
+++ /dev/null
@@ -1,49 +0,0 @@
-function disp(dd)
-
-% Copyright (C) 2013 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 isempty(dd)
-    fprintf('Empty dates object.\n');
-    return
-end
-    
-max_displayed = 5;
-first_displayed = 2;
-    
-fprintf('<dates: ');
-    
-if dd.ndat<=max_displayed
-    for i=1:dd.ndat
-        fprintf(date2string(dd.time(i,:),dd.freq))
-        if i<dd.ndat
-            fprintf(', ')
-        else
-            fprintf('>\n')
-        end
-    end
-else
-    for i=1:first_displayed
-        fprintf(date2string(dd.time(i,:),dd.freq))
-        fprintf(', ')
-    end
-    fprintf(' ..., ')
-    fprintf(date2string(dd.time(dd.ndat-1,:),dd.freq))
-    fprintf(', ')
-    fprintf(date2string(dd.time(dd.ndat,:),dd.freq))
-    fprintf('>\n')
-end
diff --git a/matlab/@dates/display.m b/matlab/@dates/display.m
deleted file mode 100644
index 2d230dc8510fd4e828228f4b102b287699e81f52..0000000000000000000000000000000000000000
--- a/matlab/@dates/display.m
+++ /dev/null
@@ -1,49 +0,0 @@
-function display(dd)
-
-% Copyright (C) 2013 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 isempty(dd)
-    fprintf('%s is an empty dates object.\n', inputname(1));
-    return
-end
-
-max_displayed = 5;
-first_displayed = 2;
-    
-fprintf('%s = <dates: ', inputname(1));
-
-if dd.ndat<=max_displayed
-    for i=1:dd.ndat
-        fprintf(date2string(dd.time(i,:),dd.freq))
-        if i<dd.ndat
-            fprintf(', ')
-        else
-            fprintf('>\n')
-        end
-    end
-else
-    for i=1:first_displayed
-        fprintf(date2string(dd.time(i,:),dd.freq))
-        fprintf(', ')
-    end
-    fprintf(' ..., ')
-    fprintf(date2string(dd.time(dd.ndat-1,:),dd.freq))
-    fprintf(', ')
-    fprintf(date2string(dd.time(dd.ndat,:),dd.freq))
-    fprintf('>\n')
-end
\ No newline at end of file
diff --git a/matlab/@dates/double.m b/matlab/@dates/double.m
deleted file mode 100644
index 4306199b5a1f85546e61487c30700e6e7f5ce687..0000000000000000000000000000000000000000
--- a/matlab/@dates/double.m
+++ /dev/null
@@ -1,81 +0,0 @@
-function [B, C]  = double(A) % --*-- Unitary tests --*--
-
-% Returns a vector of doubles with the fractional part corresponding
-% to the subperiod. Used for plots and to store dates in a matrix.
-%
-% INPUTS 
-%  o A     dates object.
-%
-% OUTPUTS  
-%  o B     A.ndat*1 vector of doubles.
-%  o C     integer scalar, the frequency (1, 4, 12 or 52).
-%
-% REMARKS 
-%  Obviously the frequency is lost during the conversion.
-    
-% Copyright (C) 2013 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/>.
-
-B = A.time(:,1)+(A.time(:,2)-1)/A.freq;
-if nargout>1
-    C = A.freq;
-end
-
-%@test:1
-%$ % Define a dates object
-%$ qq = dates('Q');
-%$ B = qq(1950,1):qq(1951,1);
-%$
-%$ % Call the tested routine.
-%$ try
-%$     C = double(B);
-%$     t(1) = 1;
-%$ catch
-%$     t(1) = 0;
-%$ end
-%$
-%$ % Define expected results.
-%$ E = [ones(4,1)*1950; 1951];
-%$ E = E + [(transpose(1:4)-1)/4; 0];
-%$ if t(1)
-%$     t(2) = dyn_assert(isequal(C,E),1);
-%$ end
-%$ T = all(t);
-%@eof:1
-
-%@test:2
-%$ % Define a dates object
-%$ qq = dates('Q');
-%$
-%$ % Call the tested routine.
-%$ try
-%$     C = NaN(2,1);
-%$     C(1) = double(qq(1950,1));
-%$     C(2) = double(qq(1950,2));
-%$     t(1) = 1;
-%$ catch
-%$     t(1) = 0;
-%$ end
-%$
-%$ % Define expected results.
-%$ E = ones(2,1)*1950;
-%$ E = E + [0; .25];
-%$ if t(1)
-%$     t(2) = dyn_assert(isequal(C,E),1);
-%$ end
-%$ T = all(t);
-%@eof:2
\ No newline at end of file
diff --git a/matlab/@dates/end.m b/matlab/@dates/end.m
deleted file mode 100644
index d1f04449f98c07d3ac7987dcea8fd91f071a9cf1..0000000000000000000000000000000000000000
--- a/matlab/@dates/end.m
+++ /dev/null
@@ -1,34 +0,0 @@
-function lastIndex = end(o, k, n)
-
-% Overloads end keyword.
-%
-% INPUTS
-%   o              [dates] dates object
-%   k              [integer]  index where end appears
-%   n              [integer]  number of indices
-%
-% OUTPUTS
-%   lastIndex      [integer] last dates index
-%
-% SPECIAL REQUIREMENTS
-%   none
-
-% Copyright (C) 2013 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(k==1 && n==1, 'dates::end: dates only has one dimension');
-lastIndex = o.ndat;
\ No newline at end of file
diff --git a/matlab/@dates/eq.m b/matlab/@dates/eq.m
deleted file mode 100644
index 16983d184badf4ca7ab1897c91874428792d376b..0000000000000000000000000000000000000000
--- a/matlab/@dates/eq.m
+++ /dev/null
@@ -1,102 +0,0 @@
-function C = eq(A,B) % --*-- Unitary tests --*--
-
-% Overloads == operator for dates objects.
-%
-% INPUTS 
-%  o A    dates object with n or 1 elements.
-%  o B    dates object with n or 1 elements.
-%
-% OUTPUTS 
-%  o C    column vector of max(n,1) elements (zeros or ones).
-
-% Copyright (C) 2013 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 ~isequal(nargin,2)
-    error('dates::eq: I need exactly two input arguments!')
-end
-
-if ~isa(A,'dates') || ~isa(B,'dates')
-    error(['dates::eq: Input arguments ''' inputname(1) ''' and ''' inputname(2) ''' have to be a dates objects!'])
-end
-
-if ~isequal(A.freq,B.freq)
-    C = 0;
-    return
-end
-
-if isequal(A.ndat, B.ndat)
-    C = transpose(all(transpose(eq(A.time,B.time))));
-else
-    if isequal(A.ndat,1) || isequal(B.ndat,1)
-        C = transpose(all(transpose(bsxfun(@eq,A.time,B.time))));
-    else
-        C = 0;
-    end
-end
-
-%@test:1
-%$ % Define some dates objects
-%$ d1 = dates('1950Q1','1950Q2','1950Q3','1950Q4') ;
-%$ d2 = dates('1960Q1','1960Q2','1960Q3','1960Q4') ;
-%$ d3 = dates('1950Q1','1960Q2','1950Q3','1960Q4') ;
-%$
-%$ % Call the tested routine.
-%$ t1 = d1==d1;
-%$ t2 = d1==d2;
-%$ t3 = d1==d3;
-%$
-%$ % Check the results.
-%$ t(1) = dyn_assert(t1,ones(4,1));
-%$ t(2) = dyn_assert(t2,zeros(4,1));
-%$ t(2) = dyn_assert(t3,[1; 0; 1; 0]);
-%$ T = all(t);
-%@eof:1
-
-%@test:2
-%$ % Define some dates objects
-%$ d1 = dates('1950Q1') ;
-%$ d2 = dates('1960Q1') ;
-%$ d3 = dates('1960Q1') ;
-%$
-%$ % Call the tested routine.
-%$ t1 = d1==d1;
-%$ t2 = d1==d2;
-%$ t3 = d1==d3;
-%$
-%$ % Check the results.
-%$ t(1) = dyn_assert(t1,1);
-%$ t(2) = dyn_assert(t2,0);
-%$ t(2) = dyn_assert(t3,0);
-%$ T = all(t);
-%@eof:2
-
-%@test:3
-%$ % Define some dates objects
-%$ d1 = dates('1950Q1','1950Q2','1950Q3','1950Q4') ;
-%$ d2 = dates('1950Q2') ;
-%$ d3 = dates('1970Q1') ;
-%$
-%$ % Call the tested routine.
-%$ t1 = d1==d2;
-%$ t2 = d1==d3;
-%$
-%$ % Check the results.
-%$ t(1) = dyn_assert(t1,[0; 1; 0; 0]);
-%$ t(2) = dyn_assert(t2,zeros(4,1));
-%$ T = all(t);
-%@eof:3
diff --git a/matlab/@dates/ge.m b/matlab/@dates/ge.m
deleted file mode 100644
index 625f1bbdf2edc98c77b4771cfbef0afa6d36345c..0000000000000000000000000000000000000000
--- a/matlab/@dates/ge.m
+++ /dev/null
@@ -1,127 +0,0 @@
-function C = ge(A,B)  % --*-- Unitary tests --*--
-
-% Overloads the >= operator for dates objects.
-%
-% INPUTS 
-%  o A    dates object with n or 1 elements.
-%  o B    dates object with n or 1 elements.
-%
-% OUTPUTS 
-%  o C    column vector of max(n,1) elements (zeros or ones).
-
-% Copyright (C) 2013 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 ~isequal(nargin,2)
-    error('dates::ge: I need exactly two input arguments!')
-end
-
-if ~isa(A,'dates') || ~isa(B,'dates')
-    error(['dates::ge: Input arguments ''' inputname(1) ''' and ''' inputname(2) ''' have to be a dates objects!'])
-end
-
-if ~isequal(A.freq,B.freq)
-    C = 0;
-    return
-end
-
-if isequal(A.ndat, B.ndat)
-    C = (A==B);
-    idx = find(C==0);
-    for i=1:length(idx)
-        C(idx(i)) = greaterorequal(A.time(idx(i),:), B.time(idx(i),:));
-    end
-else
-    if isequal(A.ndat,1)
-        C = NaN(B.ndat,1);
-        for i=1:B.ndat
-            C(i) = greaterorequal(A.time, B.time(i,:));
-        end
-    elseif isequal(B.ndat,1)
-        C = NaN(A.ndat,1);
-        for i=1:A.ndat
-            C(i) = greaterorequal(A.time(i,:), B.time);
-        end
-    else
-        C = 0;
-    end
-end
-
-
-function c = greaterorequal(a,b)
-    if a(1)>b(1)
-        c = 1;
-    else
-        if a(1)<b(1)
-            c = 0;
-        else
-            if a(2)>=b(2)
-                c = 1;
-            else
-                c = 0;
-            end
-        end
-    end
-
-
-%@test:1
-%$ % Define some dates
-%$ date_2 = '1950Q2';
-%$ date_3 = '1950Q3';
-%$ date_4 = '1950Q1';
-%$ date_5 = '1949Q2';
-%$
-%$ % Call the tested routine.
-%$ d2 = dates(date_2);
-%$ d3 = dates(date_3);
-%$ d4 = dates(date_4);
-%$ d5 = dates(date_5);
-%$ i1 = (d2>=d3);
-%$ i2 = (d3>=d4);
-%$ i3 = (d4>=d2);
-%$ i4 = (d5>=d4);
-%$ i5 = (d5>=d5); 
-%$
-%$ % Check the results.
-%$ t(1) = dyn_assert(i1,0);
-%$ t(2) = dyn_assert(i2,1);
-%$ t(3) = dyn_assert(i3,0);
-%$ t(4) = dyn_assert(i4,0);
-%$ t(5) = dyn_assert(i5,1);
-%$ T = all(t);
-%@eof:1
-
-%@test:2
-%$ % Define some dates
-%$ B1 = '1945Q1';
-%$ B2 = '1945Q2';
-%$ B3 = '1945Q3';
-%$ B4 = '1945Q4';
-%$ B5 = '1950Q1';
-%$
-%$ % Create dates objects.
-%$ dd = dates(B1,B2,B3,B4);
-%$
-%$ % Check the results.
-%$ t(1) = dyn_assert(dates(B1)>=dates(B2),0);
-%$ t(2) = dyn_assert(dates(B2)>=dates(B1),1);
-%$ t(3) = dyn_assert(dates(B2)>=dates(B2),1);
-%$ t(4) = dyn_assert(dd>=dates(B5),zeros(4,1));
-%$ t(5) = dyn_assert(dates(B5)>=dd,ones(4,1));
-%$ t(6) = dyn_assert(dates(B1)>=dd,[1; zeros(3,1)]);
-%$ T = all(t);
-%@eof:2
\ No newline at end of file
diff --git a/matlab/@dates/gt.m b/matlab/@dates/gt.m
deleted file mode 100644
index 7960388850c099835cb9de72dbe7ea5ef78285ae..0000000000000000000000000000000000000000
--- a/matlab/@dates/gt.m
+++ /dev/null
@@ -1,123 +0,0 @@
-function C = gt(A,B)  % --*-- Unitary tests --*--
-
-% Overloads the > operator for dates objects.
-%
-% INPUTS 
-%  o A    dates object with n or 1 elements.
-%  o B    dates object with n or 1 elements.
-%
-% OUTPUTS 
-%  o C    column vector of max(n,1) elements (zeros or ones).
-
-% Copyright (C) 2013 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 ~isequal(nargin,2)
-    error('dates::gt: I need exactly two input arguments!')
-end
-
-if ~isa(A,'dates') || ~isa(B,'dates')
-    error(['dates::gt: Input arguments ''' inputname(1) ''' and ''' inputname(2) ''' have to be a dates objects!'])
-end
-
-if ~isequal(A.freq,B.freq)
-    C = 0;
-    return
-end
-
-if isequal(A.ndat, B.ndat)
-    C = NaN(A.ndat,1);
-    for i=1:A.ndat
-        C(i) = greaterthan(A.time(i,:), B.time(i,:));
-    end
-else
-    if isequal(A.ndat,1)
-        C = NaN(B.ndat,1);
-        for i=1:B.ndat
-            C(i) = greaterthan(A.time, B.time(i,:));
-        end
-    elseif isequal(B.ndat,1)
-        C = NaN(A.ndat,1);
-        for i=1:A.ndat
-            C(i) = greaterthan(A.time(i,:), B.time);
-        end
-    else
-        C = 0;
-    end
-end
-
-
-function c = greaterthan(a,b)
-    if a(1)>b(1)
-        c = 1;
-    else
-        if a(1)<b(1)
-            c = 0;
-        else
-            if a(2)>b(2)
-                c = 1;
-            else
-                c = 0;
-            end
-        end
-    end
-
-%@test:1
-%$ % Define some dates
-%$ date_2 = '1950Q2';
-%$ date_3 = '1950Q3';
-%$ date_4 = '1950Q1';
-%$ date_5 = '1949Q2';
-%$
-%$ % Call the tested routine.
-%$ d2 = dates(date_2);
-%$ d3 = dates(date_3);
-%$ d4 = dates(date_4);
-%$ d5 = dates(date_5);
-%$ i1 = (d2>d3);
-%$ i2 = (d3>d4);
-%$ i3 = (d4>d2);
-%$ i4 = (d5>d4);
-%$
-%$ % Check the results.
-%$ t(1) = dyn_assert(i1,0);
-%$ t(2) = dyn_assert(i2,1);
-%$ t(3) = dyn_assert(i3,0);
-%$ t(4) = dyn_assert(i4,0);
-%$ T = all(t);
-%@eof:1
-
-%@test:2
-%$ % Define some dates
-%$ B1 = '1945Q1';
-%$ B2 = '1945Q2';
-%$ B3 = '1945Q3';
-%$ B4 = '1945Q4';
-%$ B5 = '1950Q1';
-%$
-%$ % Create dates objects.
-%$ dd = dates(B1,B2,B3,B4);
-%$
-%$ % Check the results.
-%$ t(1) = dyn_assert(dates(B1)>dates(B2),0);
-%$ t(2) = dyn_assert(dates(B2)>dates(B1),1);
-%$ t(3) = dyn_assert(dates(B5)>dates(B1),1);
-%$ t(4) = dyn_assert(dd>dates(B5),zeros(4,1));
-%$ t(5) = dyn_assert(dates(B5)>dd,ones(4,1));
-%$ t(6) = dyn_assert(dates(B1)>dd,[0; zeros(3,1)]);
-%$ T = all(t);
-%@eof:2
\ No newline at end of file
diff --git a/matlab/@dates/horzcat.m b/matlab/@dates/horzcat.m
deleted file mode 100644
index 8bc1eddd33c5a824b7f9eefeaeccaa551ba17400..0000000000000000000000000000000000000000
--- a/matlab/@dates/horzcat.m
+++ /dev/null
@@ -1,152 +0,0 @@
-function B = horzcat(varargin) % --*-- Unitary tests --*--
-
-% Overloads the horzcat method for dates objects.
-%
-% INPUTS 
-%  o A1    dates object.
-%  o A2    dates object.
-%  o ...
-%
-% OUTPUTS 
-%  o B    dates object containing dates defined in A1, A2, ...
-%
-% EXAMPLE 1 
-%  If A, B and C are dates objects the following syntax:
-%    
-%    D = [A, B, C] ;
-%
-%  Defines a dates object D containing the dates appearing in A, B and C.
-    
-% Copyright (C) 2013 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 ~all(cellfun(@isdates,varargin))
-    error('dates::horzcat: All input arguments must be dates objects.')
-end
-
-n = nargin;
-B = varargin{1};
-
-if isequal(n,1), return, end
-
-for i=2:n
-    C = varargin{i};
-    if isequal(B.freq,C.freq)
-        if ~isempty(C)
-            B.ndat = B.ndat + C.ndat;
-            B.time = [B.time; C.time];
-        end
-    else
-        error('dates::horzcat: All input arguments must have the same frequency!')
-    end
-end
-
-%@test:1
-%$ % Define some dates
-%$ B1 = '1953Q4';
-%$ B2 = '1950Q2';
-%$ B3 = '1950Q1';
-%$ B4 = '1945Q3';
-%$ B5 = '2009Q2';
-%$
-%$ % Define expected results.
-%$ e.time = [1945 3; 1950 1; 1950 2; 1953 4; 2009 2];
-%$ e.freq = 4;
-%$ e.ndat = 5;
-%$
-%$ % Call the tested routine.
-%$ d = dates(B4,B3,B2,B1);
-%$ d = [d, dates(B5)];
-%$
-%$ % Check the results.
-%$ t(1) = dyn_assert(d.time,e.time);
-%$ t(2) = dyn_assert(d.freq,e.freq);
-%$ t(3) = dyn_assert(d.ndat,e.ndat);
-%$ T = all(t);
-%@eof:1
-
-%@test:2
-%$ % Define some dates
-%$ B1 = '1953Q4';
-%$ B2 = '1950Q2';
-%$ B3 = '1950Q1';
-%$ B4 = '1945Q3';
-%$ B5 = '2009Q2';
-%$
-%$ % Define expected results.
-%$ e.time = [1945 3; 1950 1; 1950 2; 1953 4; 2009 2];
-%$ e.freq = 4;
-%$ e.ndat = 5;
-%$
-%$ % Call the tested routine.
-%$ d = dates(B4,B3,B2);
-%$ d = [d, dates(B1), dates(B5)];
-%$
-%$ % Check the results.
-%$ t(1) = dyn_assert(d.time,e.time);
-%$ t(2) = dyn_assert(d.freq,e.freq);
-%$ t(3) = dyn_assert(d.ndat,e.ndat);
-%$ T = all(t);
-%@eof:2
-
-%@test:3
-%$ % Define some dates
-%$ B1 = '1953Q4';
-%$ B2 = '1950Q2';
-%$ B3 = '1950Q1';
-%$ B4 = '1945Q3';
-%$ B5 = '2009Q2';
-%$
-%$ % Define expected results.
-%$ e.time = [1945 3; 1950 1; 1950 2; 1953 4; 2009 2];
-%$ e.freq = 4;
-%$ e.ndat = 5;
-%$
-%$ % Call the tested routine.
-%$ d = dates(B4,B3,B2);
-%$ d = [d, dates(B1,B5)];
-%$
-%$ % Check the results.
-%$ t(1) = dyn_assert(d.time,e.time);
-%$ t(2) = dyn_assert(d.freq,e.freq);
-%$ t(3) = dyn_assert(d.ndat,e.ndat);
-%$ T = all(t);
-%@eof:3
-
-%@test:4
-%$ % Define some dates
-%$ B1 = '1953Q4';
-%$ B2 = '1950Q2';
-%$ B3 = '1950Q1';
-%$ B4 = '1945Q3';
-%$ B5 = '2009Q2';
-%$
-%$ % Define expected results.
-%$ e.time = [1945 3; 1950 1; 1950 2; 1953 4; 2009 2];
-%$ e.freq = 4;
-%$ e.ndat = 5;
-%$
-%$ % Call the tested routine.
-%$ d = dates(B4,B3,B2);
-%$ d = [d, [dates(B1), dates(B5)]];
-%$
-%$ % Check the results.
-%$ t(1) = dyn_assert(d.time,e.time);
-%$ t(2) = dyn_assert(d.freq,e.freq);
-%$ t(3) = dyn_assert(d.ndat,e.ndat);
-%$ T = all(t);
-%@eof:4
\ No newline at end of file
diff --git a/matlab/@dates/intersect.m b/matlab/@dates/intersect.m
deleted file mode 100644
index cd427918c572cf521509740d4ed5d2cffe4e3222..0000000000000000000000000000000000000000
--- a/matlab/@dates/intersect.m
+++ /dev/null
@@ -1,88 +0,0 @@
-function C = intersect(A,B) % --*-- Unitary tests --*--
-
-%@info:
-%! @deftypefn {Function File} {@var{C} =} intersect (@var{A},@var{B})
-%! @anchor{@dates/intersect}
-%! @sp 1
-%! C of B and A.
-%! if A and B are not disjoints.
-%! @sp 2
-%! @strong{Inputs}
-%! @sp 1
-%! @table @ @var
-%! @item A
-%! @ref{dates} object.
-%! @item B
-%! @ref{dates} object.
-%! @end table
-%! @sp 2
-%! @strong{Outputs}
-%! @sp 1
-%! @table @ @var
-%! @item C
-%! @ref{dates} object.
-%! @end table
-%! @end deftypefn
-%@eod:
-
-% Copyright (C) 2013 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 ~isa(A,'dates') || ~isa(B,'dates')
-    error(['dates::plus: Input arguments ''' inputname(1) ''' and ''' inputname(2) ''' must be dates objects!'])
-end
-
-if eq(A,B)
-    C = A;
-    return
-end
-
-if ~isequal(A.freq,B.freq)
-    C = dates();
-    return
-end
-
-if isoctave || matlab_ver_less_than('8.1.0')
-    time = intersect(A.time,B.time,'rows');
-else
-    time = intersect(A.time,B.time,'rows','legacy');
-end
-
-C = dates();
-if isempty(time)
-    return
-end
-
-C.freq = A.freq;
-C.time = time;
-C.ndat = rows(time); 
-
-%@test:1
-%$ % Define some dates objects
-%$ d1 = dates('1950Q1'):dates('1969Q4') ;
-%$ d2 = dates('1960Q1'):dates('1969Q4') ;
-%$ d3 = dates('1970Q1'):dates('1979Q4') ;
-%$
-%$ % Call the tested routine.
-%$ c1 = intersect(d1,d2);
-%$ c2 = intersect(d1,d3);
-%$
-%$ % Check the results.
-%$ t(1) = dyn_assert(isequal(c1,d2),1);
-%$ t(2) = dyn_assert(isempty(c2),1);
-%$ T = all(t);
-%@eof:1
\ No newline at end of file
diff --git a/matlab/@dates/isempty.m b/matlab/@dates/isempty.m
deleted file mode 100644
index 859f7a785ed3e8a364d9a8e07e2b175a3cf6422b..0000000000000000000000000000000000000000
--- a/matlab/@dates/isempty.m
+++ /dev/null
@@ -1,50 +0,0 @@
-function B = isempty(A) % --*-- Unitary tests --*--
-
-%@info:
-%! @deftypefn {Function File} {@var{B} =} isempty (@var{A})
-%! @anchor{@dates/isempty}
-%! @sp 1
-%! Overloads the isempty function for the @ref{dates} class.
-%! @sp 2
-%! @strong{Inputs}
-%! @sp 1
-%! @table @ @var
-%! @item A
-%! @ref{dates} object.
-%! @end table
-%! @sp 1
-%! @strong{Outputs}
-%! @sp 1
-%! @table @ @var
-%! @item b
-%! Integer scalar (equal to zero if @var{A} is not empty).
-%! @end table
-%! @end deftypefn
-%@eod:
-
-% Copyright (C) 2013 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/>.
-    
-B = isequal(A.ndat,0);
-
-%@test:1
-%$ % Instantiate an empty dates object
-%$ d = dates();
-%$ % Test if this object is empty
-%$ t(1) = isempty(d);
-%$ T = all(t);
-%@eof:1
\ No newline at end of file
diff --git a/matlab/@dates/isequal.m b/matlab/@dates/isequal.m
deleted file mode 100644
index 1e436b96901356f1656cb720d1ce1ed9d4c6c7df..0000000000000000000000000000000000000000
--- a/matlab/@dates/isequal.m
+++ /dev/null
@@ -1,36 +0,0 @@
-function C = isequal(A,B)
-
-% Overloads isequal function for dates objects.
-    
-% Copyright (C) 2013 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 ~isa(A,'dates') || ~isa(B,'dates')
-    error('dates::isequal: Both inputs must be dates objects!')
-end
-
-if ~isequal(A.freq, B.freq)
-    C = 0;
-    return
-end
-
-if ~isequal(A.ndat, B.ndat)
-    C = 0;
-    return
-end
-
-C = isequal(A.time,B.time);
\ No newline at end of file
diff --git a/matlab/@dates/le.m b/matlab/@dates/le.m
deleted file mode 100644
index 3056785fe7f630b4e48aafb7d6b32b3c7353ffd1..0000000000000000000000000000000000000000
--- a/matlab/@dates/le.m
+++ /dev/null
@@ -1,127 +0,0 @@
-function C = le(A,B)  % --*-- Unitary tests --*--
-
-% Overloads the <= operator for dates objects.
-%
-% INPUTS 
-%  o A    dates object with n or 1 elements.
-%  o B    dates object with n or 1 elements.
-%
-% OUTPUTS 
-%  o C    column vector of max(n,1) elements (zeros or ones).
-
-% Copyright (C) 2013 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 ~isequal(nargin,2)
-    error('dates::le: I need exactly two input arguments!')
-end
-
-if ~isa(A,'dates') || ~isa(B,'dates')
-    error(['dates::le: Input arguments ''' inputname(1) ''' and ''' inputname(2) ''' have to be a dates objects!'])
-end
-
-if ~isequal(A.freq,B.freq)
-    C = 0;
-    return
-end
-
-if isequal(A.ndat, B.ndat)
-    C = (A==B);
-    idx = find(C==0);
-    for i=1:length(idx)
-        C(idx(i)) = lessorequal(A.time(idx(i),:), B.time(idx(i),:));
-    end
-else
-    if isequal(A.ndat,1)
-        C = NaN(B.ndat,1);
-        for i=1:B.ndat
-            C(i) = lessorequal(A.time, B.time(i,:));
-        end
-    elseif isequal(B.ndat,1)
-        C = NaN(A.ndat,1);
-        for i=1:A.ndat
-            C(i) = lessorequal(A.time(i,:), B.time);
-        end
-    else
-        C = 0;
-    end
-end
-
-
-function c = lessorequal(a, b)
-    if a(1)<b(1)
-        c = 1;
-    else
-        if a(1)>b(1)
-            c = 0;
-        else
-            if a(2)<=b(2)
-                c = 1;
-            else
-                c = 0;
-            end
-        end
-    end
-
-
-%@test:1
-%$ % Define some dates
-%$ date_2 = '1950Q2';
-%$ date_3 = '1950Q3';
-%$ date_4 = '1950Q1';
-%$ date_5 = '1949Q2';
-%$
-%$ % Call the tested routine.
-%$ d2 = dates(date_2);
-%$ d3 = dates(date_3);
-%$ d4 = dates(date_4);
-%$ d5 = dates(date_5);
-%$ i1 = (d2<=d3);
-%$ i2 = (d3<=d4);
-%$ i3 = (d4<=d2);
-%$ i4 = (d5<=d4);
-%$ i5 = (d5<=d5);
-%$
-%$ % Check the results.
-%$ t(1) = dyn_assert(i1,1);
-%$ t(2) = dyn_assert(i2,0);
-%$ t(3) = dyn_assert(i3,1);
-%$ t(4) = dyn_assert(i4,1);
-%$ t(5) = dyn_assert(i5,1);
-%$ T = all(t);
-%@eof:1
-
-%@test:2
-%$ % Define some dates
-%$ B1 = '1945Q1';
-%$ B2 = '1945Q2';
-%$ B3 = '1945Q3';
-%$ B4 = '1945Q4';
-%$ B5 = '1950Q1';
-%$
-%$ % Create dates objects.
-%$ dd = dates(B1,B2,B3,B4);
-%$
-%$ % Check the results.
-%$ t(1) = dyn_assert(dates(B1)<=dates(B2),1);
-%$ t(2) = dyn_assert(dates(B2)<=dates(B1),0);
-%$ t(3) = dyn_assert(dates(B2)<=dates(B2),1);
-%$ t(4) = dyn_assert(dd<=dates(B5),ones(4,1));
-%$ t(5) = dyn_assert(dates(B5)<=dd,zeros(4,1));
-%$ t(6) = dyn_assert(dates(B1)<=dd,ones(4,1));
-%$ T = all(t);
-%@eof:2
\ No newline at end of file
diff --git a/matlab/@dates/length.m b/matlab/@dates/length.m
deleted file mode 100644
index 26c24d13affcfdbdccf3812eeadd413c564fe43c..0000000000000000000000000000000000000000
--- a/matlab/@dates/length.m
+++ /dev/null
@@ -1,22 +0,0 @@
-function n = length(A)
-
-% Returns the number of elements in a dates object.
-
-% Copyright (C) 2013 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/>.
-
-n = A.ndat;
\ No newline at end of file
diff --git a/matlab/@dates/lt.m b/matlab/@dates/lt.m
deleted file mode 100644
index 97bddcff8aec921db81cc243dcc36a217e361734..0000000000000000000000000000000000000000
--- a/matlab/@dates/lt.m
+++ /dev/null
@@ -1,122 +0,0 @@
-function C = lt(A,B)  % --*-- Unitary tests --*--
-
-% Overloads the < operator for dates objects.
-%
-% INPUTS 
-%  o A    dates object with n or 1 elements.
-%  o B    dates object with n or 1 elements.
-%
-% OUTPUTS 
-%  o C    column vector of max(n,1) elements (zeros or ones).
-
-% Copyright (C) 2013 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 ~isequal(nargin,2)
-    error('dates::lt: I need exactly two input arguments!')
-end
-
-if ~isa(A,'dates') || ~isa(B,'dates')
-    error(['dates::lt: Input arguments ''' inputname(1) ''' and ''' inputname(2) ''' have to be a dates objects!'])
-end
-
-if ~isequal(A.freq,B.freq)
-    C = 0;
-    return
-end
-
-if isequal(A.ndat, B.ndat)
-    C = NaN(A.ndat,1);
-    for i=1:A.ndat
-        C(i) = lessthan(A.time(i,:),B.time(i,:));
-    end
-else
-    if isequal(A.ndat,1)
-        C = NaN(B.ndat,1);
-        for i=1:B.ndat
-            C(i) = lessthan(A.time,B.time(i,:));
-        end
-    elseif isequal(B.ndat,1)
-        C = NaN(A.ndat,1);
-        for i=1:A.ndat
-            C(i) =  lessthan(A.time(i,:),B.time);
-        end
-    else
-        C = 0;
-    end
-end
-
-function c = lessthan(a,b)
-    if a(1)<b(1)
-        c = 1;
-    else
-        if a(1)>b(1)
-            c = 0;
-        else
-            if a(2)<b(2)
-                c = 1;
-            else
-                c = 0;
-            end
-        end
-    end
-
-%@test:1
-%$ % Define some dates
-%$ date_2 = '1950Q2';
-%$ date_3 = '1950Q3';
-%$ date_4 = '1950Q1';
-%$ date_5 = '1949Q2';
-%$
-%$ % Call the tested routine.
-%$ d2 = dates(date_2);
-%$ d3 = dates(date_3);
-%$ d4 = dates(date_4);
-%$ d5 = dates(date_5);
-%$ i1 = (d2<d3);
-%$ i2 = (d3<d4);
-%$ i3 = (d4<d2);
-%$ i4 = (d5<d4);
-%$
-%$ % Check the results.
-%$ t(1) = dyn_assert(i1,1);
-%$ t(2) = dyn_assert(i2,0);
-%$ t(3) = dyn_assert(i3,1);
-%$ t(4) = dyn_assert(i4,1);
-%$ T = all(t);
-%@eof:1
-
-%@test:2
-%$ % Define some dates
-%$ B1 = '1945Q1';
-%$ B2 = '1945Q2';
-%$ B3 = '1945Q3';
-%$ B4 = '1945Q4';
-%$ B5 = '1950Q1';
-%$
-%$ % Create dates objects.
-%$ dd = dates(B1,B2,B3,B4);
-%$
-%$ % Check the results.
-%$ t(1) = dyn_assert(dates(B1)<dates(B2),1);
-%$ t(2) = dyn_assert(dates(B2)<dates(B1),0);
-%$ t(3) = dyn_assert(dates(B2)<dates(B1),0);
-%$ t(4) = dyn_assert(dd<dates(B5),ones(4,1));
-%$ t(5) = dyn_assert(dates(B5)<dd,zeros(4,1));
-%$ t(6) = dyn_assert(dates(B1)<dd,[0; ones(3,1)]);
-%$ T = all(t);
-%@eof:2
diff --git a/matlab/@dates/max.m b/matlab/@dates/max.m
deleted file mode 100644
index e7af8c4b81cfa22b5aaeecac77b135d5f6076ee6..0000000000000000000000000000000000000000
--- a/matlab/@dates/max.m
+++ /dev/null
@@ -1,86 +0,0 @@
-function C = max(varargin)
-    
-% Overloads the max function for dates objects.
-    
-% Copyright (C) 2013 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/>.
-
-switch nargin
-  case 1
-    switch length(varargin{1})
-      case 0
-        C= dates();
-      case 1
-        C = varargin{1};
-      otherwise
-        tmp = sortrows(varargin{1}.time);
-        C = dates();
-        C.freq = varargin{1}.freq;
-        C.ndat = 1;
-        C.time = tmp(varargin{1}.ndat,:);
-    end
-  otherwise
-    C = max(horzcat(varargin{:}));
-end
-
-%@test:1
-%$ % Define some dates
-%$ d3 = dates('1950q2');
-%$ d4 = dates('1950Q3');
-%$ d5 = dates('1950m1');
-%$ d6 = dates('1948M6');
-%$ m2 = max(d3,d4);
-%$ i2 = (m2==d4);
-%$ m3 = max(d5,d6);
-%$ i3 = (m3==d5);
-%$
-%$ % Check the results.
-%$ t(1) = dyn_assert(i2,1);
-%$ t(2) = dyn_assert(i3,1);
-%$ T = all(t);
-%@eof:1
-
-%@test:2
-%$ % Define some dates
-%$ d = dates('1950Q2','1951Q3','1949Q1','1950Q4');
-%$ m = max(d);
-%$ i = (m==dates('1951Q3'));
-%$
-%$ % Check the results.
-%$ t(1) = dyn_assert(i,1);
-%$ T = all(t);
-%@eof:2
-
-%@test:3
-%$ % Define some dates
-%$ m = max(dates('1950Q2','1951Q3'),dates('1949Q1'),dates('1950Q4'));
-%$ i = (m==dates('1951Q3'));
-%$
-%$ % Check the results.
-%$ t(1) = dyn_assert(i,1);
-%$ T = all(t);
-%@eof:3
-
-%@test:4
-%$ % Define some dates
-%$ m = max(dates('1950Q2'),dates('1951Q3'),dates('1949Q1'),dates('1950Q4'));
-%$ i = (m==dates('1951Q3'));
-%$
-%$ % Check the results.
-%$ t(1) = dyn_assert(i,1);
-%$ T = all(t);
-%@eof:4
\ No newline at end of file
diff --git a/matlab/@dates/min.m b/matlab/@dates/min.m
deleted file mode 100644
index 1bdfe3c57fe25f8d6e77faf7d1859035513bad05..0000000000000000000000000000000000000000
--- a/matlab/@dates/min.m
+++ /dev/null
@@ -1,86 +0,0 @@
-function C = min(varargin)
-    
-% Overloads the min function for dates objects.
-    
-% Copyright (C) 2013 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/>.
-
-switch nargin
-  case 1
-    switch length(varargin{1})
-      case 0
-        C= dates();
-      case 1
-        C = varargin{1};
-      otherwise
-        tmp = sortrows(varargin{1}.time);
-        C = dates();
-        C.freq = varargin{1}.freq;
-        C.ndat = 1;
-        C.time = tmp(1,:);
-    end
-  otherwise
-    C = min(horzcat(varargin{:}));
-end
-
-%@test:1
-%$ % Define some dates
-%$ d3 = dates('1950q2');
-%$ d4 = dates('1950Q3');
-%$ d5 = dates('1950m1');
-%$ d6 = dates('1948M6');
-%$ m2 = min(d3,d4);
-%$ i2 = (m2==d3);
-%$ m3 = min(d5,d6);
-%$ i3 = (m3==d6);
-%$
-%$ % Check the results.
-%$ t(1) = dyn_assert(i2,1);
-%$ t(2) = dyn_assert(i3,1);
-%$ T = all(t);
-%@eof:1
-
-%@test:2
-%$ % Define some dates
-%$ d = dates('1950Q2','1951Q3','1949Q1','1950Q4');
-%$ m = min(d);
-%$ i = (m==dates('1949Q1'));
-%$
-%$ % Check the results.
-%$ t(1) = dyn_assert(i,1);
-%$ T = all(t);
-%@eof:2
-
-%@test:3
-%$ % Define some dates
-%$ m = min(dates('1950Q2','1951Q3'),dates('1949Q1'),dates('1950Q4'));
-%$ i = (m==dates('1949Q1'));
-%$
-%$ % Check the results.
-%$ t(1) = dyn_assert(i,1);
-%$ T = all(t);
-%@eof:3
-
-%@test:4
-%$ % Define some dates
-%$ m = min(dates('1950Q2'),dates('1951Q3'),dates('1949Q1'),dates('1950Q4'));
-%$ i = (m==dates('1949Q1'));
-%$
-%$ % Check the results.
-%$ t(1) = dyn_assert(i,1);
-%$ T = all(t);
-%@eof:4
\ No newline at end of file
diff --git a/matlab/@dates/minus.m b/matlab/@dates/minus.m
deleted file mode 100644
index 4c90ff566af0f1762e6ccc1d6203308e93859112..0000000000000000000000000000000000000000
--- a/matlab/@dates/minus.m
+++ /dev/null
@@ -1,154 +0,0 @@
-function C = minus(A,B) % --*-- Unitary tests --*--
-
-% Overloads the minus operator (-). If A and B are dates objects, the method returns the number of periods between A and B (so that A+C=B). If 
-% one of the inputs is an integer or a vector of integers, the method shifts the dates object by X (the interger input) periods backward.
-
-% Copyright (C) 2013 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 isa(B,'dates')
-    if ~isequal(A.freq,B.freq)
-        error(['dates::minus: Input arguments ''' inputname(1) ''' and ''' inputname(2) ''' must have common frequencies!'])
-    end
-    if isempty(A) || isempty(B)
-        error(['dates::minus: Input arguments ''' inputname(1) ''' and ''' inputname(2) ''' must not be empty!'])
-    end
-    if ~isequal(length(A),length(B))
-        if length(A)==1
-            A.time = repmat(A.time,B.ndat,1);
-            A.ndat = B.ndat;
-        elseif length(B)==1
-            B.time = repmat(B.time,A.ndat,1);
-            B.ndat = A.ndat;
-        else
-            error(['dates::minus: Input arguments ''' inputname(1) ''' and ''' inputname(2) ''' lengths are not consistent!'])
-        end
-    end
-    C = zeros(length(A),1);
-    id = find(~(A==B));
-    if isempty(id)
-        return
-    end
-    C(id) = A.time(id,2)-B.time(id,2) + (A.time(id,1)-B.time(id,1))*A.freq;
-elseif (isvector(B) && isequal(length(B),A.ndat) && all(isint(B))) || isscalar(B) && isint(B) || isequal(length(A),1) && isvector(B) && all(isint(B))
-    C = dates();
-    C.freq = A.freq;
-    C.time = add_periods_to_array_of_dates(A.time, A.freq, -B);
-    C.ndat = rows(C.time);
-else
-    error('dates::plus: I don''t understand what you want to do! Check the manual.')
-end
-
-%@test:1
-%$ % Define some dates objects
-%$ d1 = dates('1950Q1','1950Q2','1960Q1');
-%$ d2 = dates('1950Q3','1950Q4','1960Q1');
-%$ d3 = dates('2000Q1');
-%$ d4 = dates('2002Q2');
-%$ % Call the tested routine.
-%$ try
-%$   e1 = d2-d1;
-%$   e2 = d4-d3;
-%$   t(1) = 1;
-%$ catch
-%$   t(1) = 0;
-%$ end
-%$
-%$ if t(1)
-%$   t(2) = dyn_assert(e1,[2; 2; 0]);
-%$   t(3) = dyn_assert(e2,9);
-%$ end
-%$ T = all(t);
-%@eof:1
-
-%@test:2
-%$ % Define some dates objects
-%$ d1 = dates('1950Y','1951Y','1953Y');
-%$ d2 = dates('1951Y','1952Y','1953Y');
-%$ d3 = dates('2000Y');
-%$ d4 = dates('1999Y');
-%$ % Call the tested routine.
-%$ try
-%$   e1 = d2-d1;
-%$   e2 = d4-d3;
-%$   t(1) = 1;
-%$ catch
-%$   t(1) = 0;
-%$ end
-%$
-%$ if t(1)
-%$   t(2) = dyn_assert(e1,[1; 1; 0]);
-%$   t(3) = dyn_assert(e2,-1);
-%$ end
-%$ T = all(t);
-%@eof:2
-
-%@test:3
-%$ % Define some dates objects
-%$ d1 = dates('2000Y');
-%$ d2 = dates('1999Y');
-%$ % Call the tested routine.
-%$ try
-%$   e1 = d1-1;
-%$   e2 = d2-(-1);
-%$   t(1) = 1;
-%$ catch
-%$   t(1) = 0;
-%$ end
-%$
-%$ if t(1)
-%$   t(2) = dyn_assert(isequal(e1,d2),1);
-%$   t(3) = dyn_assert(isequal(e2,d1),1);
-%$ end
-%$ T = all(t);
-%@eof:3
-
-%@test:4
-%$ % Define some dates objects
-%$ d1 = dates('2000Q1');
-%$ e1 = dates('1999Q4','1999Q3','1999Q2','1999Q1','1998Q4');
-%$ % Call the tested routine.
-%$ try
-%$   f1 = d1-transpose(1:5);
-%$   t(1) = 1;
-%$ catch
-%$   t(1) = 0;
-%$ end
-%$
-%$ if t(1)
-%$   t(2) = dyn_assert(isequal(e1,f1),1);
-%$ end
-%$ T = all(t);
-%@eof:4
-
-%@test:5
-%$ % Define some dates objects
-%$ d1 = dates('1999Q4','1999Q3','1999Q2','1999Q1','1998Q4');
-%$ e1 = dates('2000Q1')*5;
-%$ % Call the tested routine.
-%$ try
-%$   f1 = d1-(-transpose(1:5));
-%$   t(1) = 1;
-%$ catch
-%$   t(1) = 0;
-%$ end
-%$
-%$ if t(1)
-%$   t(2) = dyn_assert(isequal(e1,f1),1);
-%$ end
-%$ T = all(t);
-%@eof:5
\ No newline at end of file
diff --git a/matlab/@dates/mtimes.m b/matlab/@dates/mtimes.m
deleted file mode 100644
index 513915b3283f7210ce25f53063de36a56709c75f..0000000000000000000000000000000000000000
--- a/matlab/@dates/mtimes.m
+++ /dev/null
@@ -1,39 +0,0 @@
-function B = mtimes(A,n)
-
-% Overloads the times operator (*). Returns dates object A replicated n times.
-%
-% INPUTS 
-%  o A    dates object with m elements.
-%
-% OUTPUTS 
-%  o B    dates object with m*n elements.
-%
-% EXAMPLE 1
-%  If A = dates('2000Q1'), then B=A*3 is a dates object equal to dates('2000Q1','2000Q1','2000Q1')  
-%
-% EXAMPLE 2
-%  If A = dates('2003Q1','2009Q2'), then B=A*2 is a dates object equal to dates('2003Q1','2009Q2','2003Q1','2009Q2')
-
-% Copyright (C) 2013 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 ~(isscalar(n) && isint(n))
-    error('dates::m: First and second input arguments have to be a dates object and a scalar integer!')
-end
-B = A;
-B.time = repmat(A.time,n,1);
-B.ndat = A.ndat*n;
\ No newline at end of file
diff --git a/matlab/@dates/ne.m b/matlab/@dates/ne.m
deleted file mode 100644
index a5bab143b67cbe3b761f25a9bcd1b26adb4f2111..0000000000000000000000000000000000000000
--- a/matlab/@dates/ne.m
+++ /dev/null
@@ -1,102 +0,0 @@
-function C = ne(A,B) % --*-- Unitary tests --*--
-
-% Overloads ~= operator for dates objects.
-%
-% INPUTS 
-%  o A    dates object with n or 1 elements.
-%  o B    dates object with n or 1 elements.
-%
-% OUTPUTS 
-%  o C    column vector of max(n,1) elements (zeros or ones).
-
-% Copyright (C) 2013 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 ~isequal(nargin,2)
-    error('dates::ne: I need exactly two input arguments!')
-end
-
-if ~isdates(A) || ~isdates(B)
-    error(['dates::ne: Input arguments ''' inputname(1) ''' and ''' inputname(2) ''' have to be dates objects!'])
-end
-
-if ~isequal(A.freq,B.freq)
-    C = 0;
-    return
-end
-
-if isequal(A.ndat, B.ndat)
-    C = transpose(any(transpose(ne(A.time,B.time))));
-else
-    if isequal(A.ndat,1) || isequal(B.ndat,1)
-        C = transpose(any(transpose(bsxfun(@ne,A.time,B.time))));
-    else
-        C = 0;
-    end
-end
-
-%@test:1
-%$ % Define some dates objects
-%$ d1 = dates('1950Q1','1950Q2','1950Q3','1950Q4') ;
-%$ d2 = dates('1960Q1','1960Q2','1960Q3','1960Q4') ;
-%$ d3 = dates('1950Q1','1960Q2','1950Q3','1960Q4') ;
-%$
-%$ % Call the tested routine.
-%$ t1 = d1~=d1;
-%$ t2 = d1~=d2;
-%$ t3 = d1~=d3;
-%$
-%$ % Check the results.
-%$ t(1) = dyn_assert(t1,zeros(4,1));
-%$ t(2) = dyn_assert(t2,ones(4,1));
-%$ t(3) = dyn_assert(t3,[0; 1; 0; 1]);
-%$ T = all(t);
-%@eof:1
-
-%@test:2
-%$ % Define some dates objects
-%$ d1 = dates('1950Q1') ;
-%$ d2 = dates('1960Q1') ;
-%$ d3 = dates('1960Q1') ;
-%$
-%$ % Call the tested routine.
-%$ t1 = d1~=d1;
-%$ t2 = d1~=d2;
-%$ t3 = d1~=d3;
-%$
-%$ % Check the results.
-%$ t(1) = dyn_assert(t1,0);
-%$ t(2) = dyn_assert(t2,1);
-%$ t(3) = dyn_assert(t3,1);
-%$ T = all(t);
-%@eof:2
-
-%@test:3
-%$ % Define some dates objects
-%$ d1 = dates('1950Q1','1950Q2','1950Q3','1950Q4') ;
-%$ d2 = dates('1950Q2') ;
-%$ d3 = dates('1970Q1') ;
-%$
-%$ % Call the tested routine.
-%$ t1 = d1~=d2;
-%$ t2 = d1~=d3;
-%$
-%$ % Check the results.
-%$ t(1) = dyn_assert(t1,[1; 0; 1; 1]);
-%$ t(2) = dyn_assert(t2,ones(4,1));
-%$ T = all(t);
-%@eof:3
diff --git a/matlab/@dates/plus.m b/matlab/@dates/plus.m
deleted file mode 100644
index 4f1e222ed39bc298679f830f0290fd8fb324159d..0000000000000000000000000000000000000000
--- a/matlab/@dates/plus.m
+++ /dev/null
@@ -1,132 +0,0 @@
-function C = plus(A,B) % --*-- Unitary tests --*--
-
-% Overloads the plus operator. If A and B are dates objects the method combines A and B without removing repetitions. If
-% one of the inputs is an integer or a vector of integers, the method shifts the dates object by X (the interger input)
-% periods forward.
-
-% Copyright (C) 2013 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 isa(B,'dates')
-    % Concatenate dates objects without removing repetitions if A and B are not disjoint sets of dates.
-    if ~isequal(A.freq,B.freq) && A.ndat>0 && B.ndat>0
-        error(['dates::plus: Input arguments ''' inputname(1) ''' and ''' inputname(2) ''' must have common frequencies!'])
-    end
-    if isempty(B)
-        C = A;
-        return
-    end
-    if isempty(A)
-        C = B;
-        return
-    end
-    C = dates();
-    C.freq = A.freq;
-    C.time = [A.time; B.time];
-    C.ndat = A.ndat+B.ndat;
-elseif (isvector(B) && isequal(length(B),A.ndat) && all(isint(B))) || isscalar(B) && isint(B) || isequal(length(A),1) && isvector(B) && all(isint(B))
-    C = dates();
-    C.freq = A.freq;
-    C.time = add_periods_to_array_of_dates(A.time, A.freq, B);
-    C.ndat = rows(C.time);
-else
-    error('dates::plus: I don''t understand what you want to do! Check the manual.')
-end
-
-%@test:1
-%$ % Define some dates objects
-%$ d1 = dates('1950Q1','1950Q2') ;
-%$ d2 = dates('1950Q3','1950Q4') ;
-%$ d3 = dates('1950Q1','1950Q2','1950Q3','1950Q4') ;
-%$
-%$ % Call the tested routine.
-%$ try
-%$   e1 = d1+d2;
-%$   e2 = d1+d2+d3;
-%$   t(1) = 1;
-%$ catch
-%$   t(1) = 0;
-%$ end
-%$
-%$ if t(1) 
-%$   t(2) = dyn_assert(isequal(e1,d3),1);
-%$   t(3) = dyn_assert(isequal(e2,dates('1950Q1','1950Q2','1950Q3','1950Q4','1950Q1','1950Q2','1950Q3','1950Q4')),1);
-%$ end
-%$ T = all(t);
-%@eof:1
-
-%@test:2
-%$ % Define some dates objects
-%$ d1 = dates('1950Q1');
-%$ e1 = dates('1950Q2');
-%$ e2 = dates('1950Q3');
-%$ e3 = dates('1950Q4');
-%$ e4 = dates('1951Q1');
-%$ e5 = dates('1950Q2','1950Q3','1950Q4','1951Q1');
-%$
-%$ % Call the tested routine.
-%$ try
-%$   f1 = d1+1;
-%$   f2 = d1+2;
-%$   f3 = d1+3;
-%$   f4 = d1+4;
-%$   f5 = d1+transpose(1:4);
-%$   t(1) = 1;
-%$ catch
-%$   t(1) = 0;
-%$ end
-%$
-%$ if t(1)
-%$   t(2) = dyn_assert(isequal(e1,f1),1);
-%$   t(3) = dyn_assert(isequal(e2,f2),1);
-%$   t(4) = dyn_assert(isequal(e3,f3),1);
-%$   t(5) = dyn_assert(isequal(e4,f4),1);
-%$   t(6) = dyn_assert(isequal(e5,f5),1);
-%$ end
-%$ T = all(t);
-%@eof:2
-
-%@test:3
-%$ % Define some dates objects
-%$ d1 = dates('1950Q1');
-%$ e1 = dates('1949Q4');
-%$ e2 = dates('1949Q3');
-%$ e3 = dates('1949Q2');
-%$ e4 = dates('1949Q1');
-%$ e5 = dates('1948Q4');
-%$
-%$ % Call the tested routine.
-%$ try
-%$   f1 = d1+(-1);
-%$   f2 = d1+(-2);
-%$   f3 = d1+(-3);
-%$   f4 = d1+(-4);
-%$   f5 = d1+(-5);
-%$   t(1) = 1;
-%$ catch
-%$   t(1) = 0;
-%$ end
-%$
-%$ if t(1)
-%$   t(2) = dyn_assert(isequal(e1,f1),1);
-%$   t(3) = dyn_assert(isequal(e2,f2),1);
-%$   t(4) = dyn_assert(isequal(e3,f3),1);
-%$   t(5) = dyn_assert(isequal(e4,f4),1);
-%$   t(6) = dyn_assert(isequal(e5,f5),1);
-%$ end
-%$ T = all(t);
-%@eof:3
\ No newline at end of file
diff --git a/matlab/@dates/pop.m b/matlab/@dates/pop.m
deleted file mode 100644
index 2aec07a405adae82d3731f6d111f93ec8464669a..0000000000000000000000000000000000000000
--- a/matlab/@dates/pop.m
+++ /dev/null
@@ -1,119 +0,0 @@
-function B = pop(A,a) % --*-- Unitary tests --*--
-
-% pop method for dates class (removes a date).
-%
-% INPUTS 
-%  o A     dates object.
-%  o a     dates object with one element, string which can be interpreted as a date or integer scalar.
-%
-% OUTPUTS 
-%  o B     dates object (with B.ndat==A.ndat-1).
-%
-% REMARKS 
-%  If a is a date appearing more than once in A, then only the last occurence is removed. If one wants to
-%  remove all the occurences of a in A, the setdiff function should be used instead.
-
-% Copyright (C) 2012-2013 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 nargin<2
-    % Remove last date
-    B = dates();
-    B.ndat = A.ndat-1;
-    B.freq = A.freq;
-    B.time = NaN(B.ndat,2);
-    B.time = A.time(1:end-1,:);
-    return
-end
-
-if ~( isdates(a) || isdate(a) || (isscalar(a) && isint(a)) )
-    error(['dates::pop: Input argument ' inputname(2) ' has to be a dates object with a single element, a string (which can be interpreted as a date) or an integer.'])
-end
-
-if ischar(a)
-    a = dates(a);
-end
-
-B = dates();
-B.ndat = A.ndat-1;
-B.freq = A.freq;
-B.time = NaN(B.ndat,2);
-
-if isscalar(a) && isint(a)
-    idx = find(transpose(1:A.ndat)~=a);
-    B.time = A.time(idx,:);
-else
-    if ~isequal(A.freq,a.freq)
-        error('dates::pop: Inputs must have common frequency!')
-    end
-    idx = find(A==a);
-    jdx = find(transpose(1:A.ndat)~=idx(end));
-    B.time = A.time(jdx,:);
-end
-
-%@test:1
-%$ % Define some dates
-%$ B1 = '1953Q4';
-%$ B2 = '1950Q2';
-%$ B3 = '1950Q1';
-%$ B4 = '1945Q3';
-%$ B5 = '2009Q2';
-%$
-%$ % Define expected results
-%$ e.time = [1945 3; 1950 1; 1950 2; 1953 4; 2009 2];
-%$ e.freq = 4;
-%$ e.ndat = 5;
-%$
-%$ % Call the tested routine
-%$ d = dates(B4,B3,B2,B1);
-%$ d = d.append(dates(B5));
-%$ f = d.pop();
-%$ t(1) = dyn_assert(f.time,e.time(1:end-1,:));
-%$ t(2) = dyn_assert(f.freq,e.freq);
-%$ t(3) = dyn_assert(f.ndat,e.ndat-1);
-%$ f = d.pop(B1);
-%$ t(4) = dyn_assert(f.time,[1945 3; 1950 1; 1950 2; 2009 2]);
-%$ t(5) = dyn_assert(f.freq,e.freq);
-%$ t(6) = dyn_assert(f.ndat,e.ndat-1);
-%$ f = d.pop(dates(B1));
-%$ t(7) = dyn_assert(f.time,[1945 3; 1950 1; 1950 2; 2009 2]);
-%$ t(8) = dyn_assert(f.freq,e.freq);
-%$ t(9) = dyn_assert(f.ndat,e.ndat-1);
-%$
-%$ % Check the results.
-%$ T = all(t);
-%@eof:1
-
-%@test:2
-%$ % Define some dates
-%$ B1 = '1950Q1';
-%$ B2 = '1950Q2';
-%$ B3 = '1950Q1';
-%$ B4 = '1945Q3';
-%$ B5 = '2009Q2';
-%$
-%$ % Call the tested routine
-%$ d = dates(B1,B2,B3,B4);
-%$ d = d.append(dates(B5));
-%$ f = d.pop();
-%$ t(1) = dyn_assert(isequal(f,dates(B1,B2,B3,B4)),1);
-%$ f = d.pop(B1);
-%$ t(2) = dyn_assert(isequal(f,dates(B1,B2,B4,B5)),1);
-%$ g = f.pop(1);
-%$ t(3) = dyn_assert(isequal(g,dates(B2,B4,B5)),1);
-%$ T = all(t);
-%@eof:2
\ No newline at end of file
diff --git a/matlab/@dates/setdiff.m b/matlab/@dates/setdiff.m
deleted file mode 100644
index fb0228c0e8983afabb7a89f07739f8302ca1d420..0000000000000000000000000000000000000000
--- a/matlab/@dates/setdiff.m
+++ /dev/null
@@ -1,88 +0,0 @@
-function C = setdiff(A,B) % --*-- Unitary tests --*--
-
-%@info:
-%! @deftypefn {Function File} {@var{C} =} setdiff (@var{A},@var{B})
-%! @anchor{@dates/intersect}
-%! @sp 1
-%! C of B and A.
-%! if A and B are not disjoints.
-%! @sp 2
-%! @strong{Inputs}
-%! @sp 1
-%! @table @ @var
-%! @item A
-%! @ref{dates} object.
-%! @item B
-%! @ref{dates} object.
-%! @end table
-%! @sp 2
-%! @strong{Outputs}
-%! @sp 1
-%! @table @ @var
-%! @item C
-%! @ref{dates} object.
-%! @end table
-%! @end deftypefn
-%@eod:
-
-% Copyright (C) 2013 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 ~isa(A,'dates') || ~isa(B,'dates')
-    error(['dates::plus: Input arguments ''' inputname(1) ''' and ''' inputname(2) ''' must be dates objects!'])
-end
-
-if eq(A,B)
-    C = A;
-    return
-end
-
-if ~isequal(A.freq,B.freq)
-    C = dates();
-    return
-end
-
-if isoctave || matlab_ver_less_than('8.1.0')
-    time = setdiff(A.time,B.time,'rows');
-else
-    time = setdiff(A.time,B.time,'rows','legacy');
-end
-
-C = dates();
-if isempty(time)
-    return
-end
-
-C.freq = A.freq;
-C.time = time;
-C.ndat = rows(time); 
-
-%@test:1
-%$ % Define some dates objects
-%$ d1 = dates('1950Q1'):dates('1969Q4') ;
-%$ d2 = dates('1960Q1'):dates('1969Q4') ;
-%$ d3 = dates('1970Q1'):dates('1979Q4') ;
-%$
-%$ % Call the tested routine.
-%$ c1 = intersect(d1,d2);
-%$ c2 = intersect(d1,d3);
-%$
-%$ % Check the results.
-%$ t(1) = dyn_assert(isequal(c1,d2),1);
-%$ t(2) = dyn_assert(isempty(c2),1);
-%$ T = all(t);
-%@eof:1
\ No newline at end of file
diff --git a/matlab/@dates/size.m b/matlab/@dates/size.m
deleted file mode 100644
index 02df260705529d3dc2e8b039c16bec6d580d6385..0000000000000000000000000000000000000000
--- a/matlab/@dates/size.m
+++ /dev/null
@@ -1,35 +0,0 @@
-function varargout = size(o)
-
-% 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/>.
-
-switch nargout
-  case 0
-    if isempty(o)
-        size([])
-    else
-        size(o.time)
-    end
-  case 1
-    if isempty(o)
-        varargout{1} = size([]);
-    else
-        varargout{1} = size(o.time);
-    end
-  otherwise
-    error('dates::size: Wrong calling sequence! Cannot return more than one argument.')
-end
\ No newline at end of file
diff --git a/matlab/@dates/sort.m b/matlab/@dates/sort.m
deleted file mode 100644
index d86c73901d530f1f089eb03f4947662fd05a0006..0000000000000000000000000000000000000000
--- a/matlab/@dates/sort.m
+++ /dev/null
@@ -1,78 +0,0 @@
-function dd = sort(dd) % --*-- Unitary tests --*--
-
-% Sort method for dates class.
-%
-% INPUTS 
-%  o dd    dates object.
-%
-% OUTPUTS 
-%  o dd    dates object (with dates sorted by increasing order).
-
-% Copyright (C) 2011-2013 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 isequal(dd.ndat,1)
-    return
-end
-
-dd.time = sortrows(dd.time,[1,2]);
-
-%@test:1
-%$ % Define some dates
-%$ B1 = '1953Q4';
-%$ B2 = '1950Q2';
-%$ B3 = '1950Q1';
-%$ B4 = '1945Q3';
-%$
-%$ % Define expected results.
-%$ e.time = [1945 3; 1950 1; 1950 2; 1953 4];
-%$ e.freq = 4;
-%$ e.ndat = 4;
-%$
-%$ % Call the tested routine.
-%$ d = dates(B1,B2,B3,B4);
-%$ d = d.sort;
-%$ 
-%$ % Check the results.
-%$ t(1) = dyn_assert(d.time,e.time);
-%$ t(2) = dyn_assert(d.freq,e.freq);
-%$ t(3) = dyn_assert(d.ndat,e.ndat);
-%$ T = all(t);
-%@eof:1
-
-%@test:1
-%$ % Define some dates
-%$ B1 = '1953Q4';
-%$ B2 = '1950Q2';
-%$ B3 = '1950Q1';
-%$ B4 = '1945Q3';
-%$
-%$ % Define expected results.
-%$ e.time = [1945 3; 1950 1; 1950 2; 1953 4];
-%$ e.freq = 4;
-%$ e.ndat = 4;
-%$
-%$ % Call the tested routine.
-%$ d = dates(B1,B2,B3,B4);
-%$ d = d.sort();
-%$
-%$ % Check the results.
-%$ t(1) = dyn_assert(d.time,e.time);
-%$ t(2) = dyn_assert(d.freq,e.freq);
-%$ t(3) = dyn_assert(d.ndat,e.ndat);
-%$ T = all(t);
-%@eof:1
\ No newline at end of file
diff --git a/matlab/@dates/strings.m b/matlab/@dates/strings.m
deleted file mode 100644
index 94ccefa1129fe12e64bc4588ca2b4f1f9a0b10ec..0000000000000000000000000000000000000000
--- a/matlab/@dates/strings.m
+++ /dev/null
@@ -1,35 +0,0 @@
-function m = strings(dd)
-
-% Returns a cell array of strings containing the dates
-%
-% INPUTS 
-%   o dd   dates object
-%
-% OUTPUTS
-%   o m    cell array of strings
-%
-% SPECIAL REQUIREMENTS
-%   none
-
-% Copyright (C) 2013 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/>.
-
-m = cell(1,dd.ndat);
-
-for i = 1:dd.ndat
-    m(i) = { date2string(dd.time(i,:), dd.freq) };
-end
\ No newline at end of file
diff --git a/matlab/@dates/subsasgn.m b/matlab/@dates/subsasgn.m
deleted file mode 100644
index 4b910070496d3443e50d27abc1ac70e811219f03..0000000000000000000000000000000000000000
--- a/matlab/@dates/subsasgn.m
+++ /dev/null
@@ -1,20 +0,0 @@
-function val = subsasgn(val, idx, rhs)
-
-% Copyright (C) 2013 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/>.
-
-error('dates::subsasgn: Members of dates class are private')
\ No newline at end of file
diff --git a/matlab/@dates/subsref.m b/matlab/@dates/subsref.m
deleted file mode 100644
index e966fc1e958e65bbe3ae23fe937453a3002cb3f9..0000000000000000000000000000000000000000
--- a/matlab/@dates/subsref.m
+++ /dev/null
@@ -1,333 +0,0 @@
-function B = subsref(A,S) % --*-- Unitary tests --*--
-
-% Overload the subsref method for dates objects.
-%
-% INPUTS 
-%  o A     dates object.
-%  o S     matlab's structure.
-%
-% OUTPUTS 
-%  o B     dates object.
-%
-% REMARKS 
-%  See the matlab's documentation about the subsref method.
-
-% Copyright (C) 2011-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/>.
-
-switch S(1).type
-  case '.'
-    switch S(1).subs
-      case {'time','freq','ndat'}% Access public members.
-        if length(S)>1 && isequal(S(2).type,'()') && isempty(S(2).subs)
-            error(['dates::subsref: ' S(1).subs ' is not a method but a member!'])
-        end
-        B = builtin('subsref', A, S(1));
-      case {'sort','unique','double','isempty','length','char'}% Public methods (without input arguments)
-        B = feval(S(1).subs,A);
-        if length(S)>1 && isequal(S(2).type,'()') && isempty(S(2).subs)
-           S = shiftS(S,1);
-        end
-      case {'append','pop'}% Public methods (with arguments).
-        if isequal(S(2).type,'()')
-            B = feval(S(1).subs,A,S(2).subs{:});
-            S = shiftS(S,1);
-        else
-            error('dates::subsref: Something is wrong in your syntax!')
-        end
-      case {'disp'}
-        feval(S(1).subs,A);
-        return
-      otherwise
-        error('dates::subsref: Unknown public member or method!')
-    end
-  case '()'
-    if isempty(A)
-        if isempty(A.freq)
-            % Populate an empty dates object with time member (freq is not specified). Needs two or three inputs. First input is an integer
-            % scalar specifying the frequency. Second input is either the time member (a n*2 array of integers) or a column vector with n
-            % elements (the first column of the time member --> years). If the the second input is a row vector and if A.freq~=1 a third input
-            % is necessary. The third input is n*1 vector of integers between 1 and A.freq (second column of the time member --> subperiods).
-            B = dates();
-            % First input is the frequency.
-            if isfreq(S(1).subs{1})
-                if ischar(S(1).subs{1})
-                    B.freq = string2freq(S(1).subs{1});
-                else
-                    B.freq = S(1).subs{1};
-                end
-            else
-                error('dates::subsref: First input must be a frequency!')
-            end
-            if isequal(length(S(1).subs),2)
-                % If two inputs are provided, the second input must be a n*2 array except if frequency is annual.
-                [n, m] = size(S(1).subs{2});
-                if m>2
-                    error('dates::subsref: Second input argument array cannot have more than two columns!')
-                end
-                if ~isequal(m,2) && ~isequal(B.freq,1)
-                    error('dates::subsref: Second argument has to be a n*2 array for non annual frequency!')
-                end
-                if ~all(all(S(1).subs{2}))
-                    error('dates::subsref: Second argument has be an array of intergers!')
-                end
-                if m>1 && ~issubperiod(S(1).subs{2}(:,2),B.freq)
-                    error(['dates::subsref: Elements in the second column of the first input argument are not legal subperiods (should be integers betwwen 1 and ' num2str(B.freq) ')!'])
-                end
-                if isequal(m,2)
-                    B.time = S(1).subs{2};
-                elseif isequal(m,1)
-                    B.time = [S(1).subs{2}, ones(n,1)];
-                else
-                    error('dates::subsref: This is a bug!')
-                end
-                B.ndat = rows(B.time);
-            elseif isequal(length(S(1).subs),3)
-                % If three inputs are provided, the second and third inputs are column verctors of integers (years and subperiods).
-                if ~iscolumn(S(1).subs{2}) && ~all(isint(S(1).subs{2}))
-                    error('dates::subsref: Second input argument must be a column vector of integers!')
-                end
-                n1 = size(S(1).subs{2},1);
-                if ~iscolumn(S(1).subs{3}) && ~issubperiod(S(1).subs{3}, B.freq)
-                    error(['dates::subsref: Third input argument must be a column vector of subperiods (integers between 1 and ' num2str(B.freq) ')!'])
-                end
-                n2 = size(S(1).subs{3},1);
-                if ~isequal(n1,n2)
-                    error('dates::subsref: Second and third input arguments must have the same number of elements!')
-                end
-                B.time = [S(1).subs{2}, S(1).subs{3}];
-                B.ndat = rows(B.time);
-            else
-                error('dates::subsref: Wrong calling sequence!')
-            end
-        else
-            % Populate an empty dates object with time member (freq is already specified).
-            % Needs one (time) or two (first and second columns of time for years and subperiods) inputs.
-            B = A;
-            if isequal(length(S(1).subs),2)
-                if ~iscolumn(S(1).subs{1}) && ~all(isint(S(1).subs{1}))
-                    error('dates::subsref: First argument has to be a column vector of integers!')
-                end
-                n1 = size(S(1).subs{1},1);
-                if ~iscolumn(S(1).subs{2}) && ~issubperiod(S(1).subs{2}, B.freq)
-                    error(['dates::subsref: Second argument has to be a column vector of subperiods (integers between 1 and ' num2str(B.freq) ')!'])
-                end
-                n2 = size(S(1).subs{2},1);
-                if ~isequal(n2,n1)
-                    error('dates::subsref: First and second argument must have the same number of rows!')
-                end
-                B.time = [S(1).subs{1}, S(1).subs{2}];
-                B.ndat = rows(B.time);
-            elseif isequal(length(S(1).subs),1)
-                [n, m] = size(S(1).subs{1});
-                if ~isequal(m,2) && ~isequal(B.freq,1)
-                    error('dates::subsref: First argument has to be a n*2 array!')
-                end
-                if ~all(isint(S(1).subs{1}(:,1)))
-                    error('dates::subsref: First column of the first argument has to be a column vector of integers!')
-                end
-                if m>1 && issubperiod(S(1).subs{1}(:,1), B.freq)
-                    error(['dates::subsref: The second column of the first input argument has to be a column  vector of subperiods (integers between 1 and ' num2str(B.freq) ')!'])
-                end
-                if isequal(m,2)
-                    B.time = S(1).subs{1};
-                elseif isequal(m,1) && isequal(B.freq,1)
-                    B.time = [S(1).subs{1}, ones(n,1)];
-                else
-                    error('dates::subsref: This is a bug!')
-                end
-                B.ndat = rows(B.time);
-            else
-                error('dates::subsref: Wrong number of inputs!')
-            end
-        end
-    else
-        % dates object A is not empty. We extract some dates
-        if isvector(S(1).subs{1}) && all(isint(S(1).subs{1})) && all(S(1).subs{1}>0) && all(S(1).subs{1}<=A.ndat)
-            B = dates();
-            B.freq = A.freq;
-            B.time = A.time(S(1).subs{1},:);
-            B.ndat = rows(B.time);
-        else
-            error(['dates::subsref: indices has to be a vector of positive integers less than or equal to ' int2str(A.ndat) '!'])
-        end
-    end
-  otherwise
-    error('dates::subsref: Something is wrong in your syntax!')
-end
-
-S = shiftS(S,1);
-if ~isempty(S)
-    B = subsref(B, S);
-end
-
-%@test:1
-%$ % Define a dates object
-%$ B = dates('1950Q1','1950Q2','1950Q3','1950Q4','1951Q1');
-%$
-%$ % Try to extract a sub-dates object.
-%$ d = B(2:3);
-%$
-%$ if isa(d,'dates')
-%$     t(1) = 1;
-%$ else
-%$     t(1) = 0;
-%$ end
-%$
-%$ if t(1)
-%$     t(2) = dyn_assert(d.freq,B.freq);
-%$     t(3) = dyn_assert(d.time,[1950 2; 1950 3]);
-%$     t(4) = dyn_assert(d.ndat,2);
-%$ end
-%$ T = all(t);
-%@eof:1
-
-%@test:2
-%$ % Define a dates object
-%$ B = dates('1950Q1'):dates('1960Q3');
-%$
-%$ % Try to extract a sub-dates object and apply a method
-%$ 
-%$ d = B(2:3).sort ;
-%$
-%$ if isa(d,'dates')
-%$     t(1) = 1;
-%$ else
-%$     t(1) = 0;
-%$ end
-%$
-%$ if t(1)
-%$     t(2) = dyn_assert(d.freq,B.freq);
-%$     t(3) = dyn_assert(d.time,[1950 2; 1950 3]);
-%$     t(4) = dyn_assert(d.ndat,2);
-%$ end
-%$ T = all(t);
-%@eof:2
-
-%@test:3
-%$ % Define a dates object
-%$ B = dates('1950Q1'):dates('1960Q3');
-%$
-%$ % Try to extract a sub-dates object and apply a method
-%$
-%$ d = B(2:3).sort() ;
-%$
-%$ if isa(d,'dates')
-%$     t(1) = 1;
-%$ else
-%$     t(1) = 0;
-%$ end
-%$
-%$ if t(1)
-%$     t(2) = dyn_assert(d.freq,B.freq);
-%$     t(3) = dyn_assert(d.time,[1950 2; 1950 3]);
-%$     t(4) = dyn_assert(d.ndat,2);
-%$ end
-%$ T = all(t);
-%@eof:3
-
-%@test:4
-%$ % Define a dates object
-%$ B = dates('1950Q1','1950Q2','1950Q3','1950Q4','1951Q1');
-%$
-%$ % Try to extract a sub-dates object.
-%$ d = B(2);
-%$
-%$ if isa(d,'dates')
-%$     t(1) = 1;
-%$ else
-%$     t(1) = 0;
-%$ end
-%$
-%$ if t(1)
-%$     t(2) = dyn_assert(d.freq,B.freq);
-%$     t(3) = dyn_assert(d.time,[1950 2]);
-%$     t(4) = dyn_assert(d.ndat,1);
-%$ end
-%$ T = all(t);
-%@eof:4
-
-%@test:5
-%$ % Define an empty dates object with quaterly frequency.
-%$ qq = dates('Q');
-%$
-%$ % Define a ranges of dates using qq.
-%$ try
-%$     r1 = qq(1950,1):qq(1950,3);%qq([1950, 3]);
-%$     t(1) = 1;
-%$ catch
-%$     t(1) = 0;
-%$ end
-%$ if t(1)
-%$     try
-%$         r2 = qq([1950, 1; 1950, 2; 1950, 3]);
-%$         t(2) = 1;
-%$     catch
-%$         t(2) = 0;
-%$     end
-%$ end
-%$ if t(1) && t(2)
-%$     try
-%$         r3 = qq(1950*ones(3,1), transpose(1:3));
-%$         t(3) = 1;
-%$     catch
-%$         t(3) = 0;
-%$     end
-%$ end
-%$
-%$ if t(1) && t(2) && t(3)
-%$     t(4) = dyn_assert(isequal(r1,r2),1);
-%$     t(5) = dyn_assert(isequal(r1,r3),1);
-%$ end
-%$ T = all(t);
-%@eof:5
-
-%@test:6
-%$ % Define an empty dates object with quaterly frequency.
-%$ date = dates();
-%$
-%$ % Define a ranges of dates using qq.
-%$ try
-%$     r1 = date(4,1950,1):date(4,[1950, 3]);
-%$     t(1) = 1;
-%$ catch
-%$     t(1) = 0;
-%$ end
-%$ if t(1)
-%$     try
-%$         r2 = date(4,[1950, 1; 1950, 2; 1950, 3]);
-%$         t(2) = 1;
-%$     catch
-%$         t(2) = 0;
-%$     end
-%$ end
-%$ if t(1) && t(2)
-%$     try
-%$         r3 = date(4,1950*ones(3,1), transpose(1:3));
-%$         t(3) = 1;
-%$     catch
-%$         t(3) = 0;
-%$     end
-%$ end
-%$
-%$ if t(1) && t(2) && t(3)
-%$     t(4) = dyn_assert(isequal(r1,r2),1);
-%$     t(5) = dyn_assert(isequal(r1,r3),1);
-%$ end
-%$ T = all(t);
-%@eof:6
-
diff --git a/matlab/@dates/uminus.m b/matlab/@dates/uminus.m
deleted file mode 100644
index fd3a79c1806065eead5e62169ea91919f016b309..0000000000000000000000000000000000000000
--- a/matlab/@dates/uminus.m
+++ /dev/null
@@ -1,78 +0,0 @@
-function B = uminus(A)  % --*-- Unitary tests --*--
-
-% Overloads the unary minus operator for dates objects. Shifts all the elements by one period.
-%
-% INPUTS 
-%  o A    dates object with n elements.
-%
-% OUTPUTS 
-%  o B    dates object with n elements.
-
-% Copyright (C) 2013 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/>.
-
-B = dates(A);
-B.time(:,2) = B.time(:,2)-1;
-idx = find(B.time(:,2)==0);
-B.time(idx,1) = B.time(idx,1)-1;
-B.time(idx,2) = B.freq;
-
-%@test:1
-%$ % Define some dates
-%$ date_1 = '1950Y';
-%$ date_2 = '1950Q2';
-%$ date_3 = '1950Q1';
-%$ date_4 = '1950M2';
-%$ date_5 = '1950M1';
-%$
-%$ % Call the tested routine.
-%$ d1 = dates(date_1); d1 = -d1;
-%$ d2 = dates(date_2); d2 = -d2;
-%$ d3 = dates(date_3); d3 = -d3;
-%$ d4 = dates(date_4); d4 = -d4;
-%$ d5 = dates(date_5); d5 = -d5;
-%$ i1 = (d1==dates('1949Y'));
-%$ i2 = (d2==dates('1950Q1'));
-%$ i3 = (d3==dates('1949Q4'));
-%$ i4 = (d4==dates('1950M1'));
-%$ i5 = (d5==dates('1949M12'));
-%$
-%$ % Check the results.
-%$ t(1) = dyn_assert(i1,1);
-%$ t(2) = dyn_assert(i2,1);
-%$ t(3) = dyn_assert(i3,1);
-%$ t(4) = dyn_assert(i4,1);
-%$ t(5) = dyn_assert(i5,1);
-%$ T = all(t);
-%@eof:1
-
-%@test:2
-%$ d1 = dates('1950Q1','1950Q2','1950Q3','1950Q4','1951Q1');
-%$ d2 = dates('1949Q4','1950Q1','1950Q2','1950Q3','1950Q4');
-%$ try
-%$   d3 = -d1;
-%$   t(1) = 1;
-%$ catch
-%$   t(1) = 0;
-%$ end
-%$
-%$ if t(1)
-%$   t(2) = dyn_assert(all(d2==d3),1);
-%$ end
-%$
-%$ T = all(t);
-%@eof:2
\ No newline at end of file
diff --git a/matlab/@dates/union.m b/matlab/@dates/union.m
deleted file mode 100644
index ab3d393abb2c3728af1a41fa3edae1d5274a7c3d..0000000000000000000000000000000000000000
--- a/matlab/@dates/union.m
+++ /dev/null
@@ -1,58 +0,0 @@
-function D = union(varargin) % --*-- Unitary tests --*--
-
-% Overloads union function for dates objects (removes repetitions if any).
-%
-% INPUTS 
-%  o A    dates object.
-%  o B    dates object.
-%  o C    dates object.
-%  o ...
-%
-% OUPUTS 
-%  o D    dates object (elements are sorted by increasing order).
-
-% Copyright (C) 2013 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 isequal(nargin,1)
-    D = sort(unique(varargin{1}));
-    return;
-end
-
-D = sort(unique(horzcat(varargin{:})));
-
-%@test:1
-%$ % Define some dates objects
-%$ d1 = dates('1950Q1'):dates('1959Q4') ;
-%$ d2 = dates('1960Q1'):dates('1969Q4') ;
-%$ d3 = dates('1970Q1'):dates('1979Q4') ;
-%$
-%$ % Call the tested routine.
-%$ e1 = union(d1);
-%$ e2 = union(d1,d2);
-%$ e3 = union(d1,d2,d3);
-%$ e4 = union(d1,d2,d3,d2+d3);
-%$ e5 = union(d1,d2,d3,d2);
-%$
-%$ % Check the results.
-%$ t(1) = dyn_assert(isequal(e1,d1),1);
-%$ t(2) = dyn_assert(isequal(e2,d1+d2),1);
-%$ t(3) = dyn_assert(isequal(e3,d1+d2+d3),1);
-%$ t(4) = dyn_assert(isequal(e4,d1+d2+d3),1);
-%$ t(5) = dyn_assert(isequal(e5,d1+d2+d3),1);
-%$ T = all(t);
-%@eof:1
\ No newline at end of file
diff --git a/matlab/@dates/unique.m b/matlab/@dates/unique.m
deleted file mode 100644
index 66ee5d067cb4a1de572059962550f782395a7049..0000000000000000000000000000000000000000
--- a/matlab/@dates/unique.m
+++ /dev/null
@@ -1,65 +0,0 @@
-function B = unique(A) % --*-- Unitary tests --*--
-
-% Overloads the unique function for dates objects.
-%
-% INPUTS 
-%  o A    dates object.
-%
-% OUTPUTS 
-%  o B    dates object (a copy of A without repetitions, only the last occurence of a date is kept).
-
-% Copyright (C) 2012-2013 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 isequal(A.ndat,1)
-    return
-end
-
-B = A;
-
-if isoctave || matlab_ver_less_than('8.1.0')
-    [tmp, id, jd] = unique(A.time,'rows');
-else
-    [tmp, id, jd] = unique(A.time,'rows','legacy');
-end
-
-B.time = A.time(sort(id),:);
-B.ndat = size(B.time,1);
-
-%@test:1
-%$ % Define some dates
-%$ B1 = '1953Q4';
-%$ B2 = '1950Q2';
-%$ B3 = '1950q1';
-%$ B4 = '1945Q3';
-%$ B5 = '1950Q2'; 
-%$
-%$ % Define expected results.
-%$ e.time = [1953 4; 1950 1; 1945 3; 1950 2];
-%$ e.freq = 4;
-%$ e.ndat = 4;
-%$
-%$ % Call the tested routine.
-%$ d = dates(B1,B2,B3,B4,B5);
-%$ d = d.unique();
-%$ 
-%$ % Check the results.
-%$ t(1) = dyn_assert(d.time,e.time);
-%$ t(2) = dyn_assert(d.freq,e.freq);
-%$ t(3) = dyn_assert(d.ndat,e.ndat);
-%$ T = all(t);
-%@eof:1
\ No newline at end of file
diff --git a/matlab/@dates/uplus.m b/matlab/@dates/uplus.m
deleted file mode 100644
index 33bf6ff2be94db41505ece985c687c88d07eed6e..0000000000000000000000000000000000000000
--- a/matlab/@dates/uplus.m
+++ /dev/null
@@ -1,78 +0,0 @@
-function B = uplus(A)  % --*-- Unitary tests --*--
-
-% Overloads the unary plus operator for dates objects. Shifts all the elements by one period.
-%
-% INPUTS 
-%  o A    dates object with n elements.
-%
-% OUTPUTS 
-%  o B    dates object with n elements.
-
-% Copyright (C) 2013 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/>.
-
-B = dates(A);
-B.time(:,2) = B.time(:,2)+1;
-idx = find(B.time(:,2)>B.freq); % Happy new year!
-B.time(idx,1) = B.time(idx,1)+1;
-B.time(idx,2) = 1;
-
-%@test:1
-%$ % Define some dates
-%$ date_1 = '1950Y';
-%$ date_2 = '1950Q2';
-%$ date_3 = '1950Q4';
-%$ date_4 = '1950M2';
-%$ date_5 = '1950M12';
-%$
-%$ % Call the tested routine.
-%$ d1 = dates(date_1); d1 = +d1;
-%$ d2 = dates(date_2); d2 = +d2;
-%$ d3 = dates(date_3); d3 = +d3;
-%$ d4 = dates(date_4); d4 = +d4;
-%$ d5 = dates(date_5); d5 = +d5;
-%$ i1 = (d1==dates('1951Y'));
-%$ i2 = (d2==dates('1950Q3'));
-%$ i3 = (d3==dates('1951Q1'));
-%$ i4 = (d4==dates('1950M3'));
-%$ i5 = (d5==dates('1951M1'));
-%$
-%$ % Check the results.
-%$ t(1) = dyn_assert(i1,1);
-%$ t(2) = dyn_assert(i2,1);
-%$ t(3) = dyn_assert(i3,1);
-%$ t(4) = dyn_assert(i4,1);
-%$ t(5) = dyn_assert(i5,1);
-%$ T = all(t);
-%@eof:1
-
-%@test:2
-%$ d1 = dates('1950Q1','1950Q2','1950Q3','1950Q4','1951Q1');
-%$ d2 = dates('1950Q2','1950Q3','1950Q4','1951Q1','1951Q2');
-%$ try
-%$   d3 = +d1;
-%$   t(1) = 1;
-%$ catch
-%$   t(1) = 0;
-%$ end
-%$
-%$ if t(1)
-%$   t(2) = dyn_assert(all(d2==d3),1);
-%$ end
-%$
-%$ T = all(t);
-%@eof:2
\ No newline at end of file
diff --git a/matlab/@dates/vertcat.m b/matlab/@dates/vertcat.m
deleted file mode 100644
index 6cf21743dd5dd027f0b5c7fbfa634b15b716f08b..0000000000000000000000000000000000000000
--- a/matlab/@dates/vertcat.m
+++ /dev/null
@@ -1,37 +0,0 @@
-function B = vertcat(varargin)
-    
-% Overloads the vertcat method for dates objects.
-%
-% INPUTS 
-%  o A1    dates object.
-%  o A2    dates object.
-%  o ...
-%
-% OUTPUTS 
-%  o B    dates object containing dates defined in A1, A2, ...
-%
-% EXAMPLE 1 
-%  If A, B and C are dates object the following syntax:
-%    
-%    D = [A; B; C] ;
-%
-%  Defines a dates object D containing the dates appearing in A, B and C.
-    
-% Copyright (C) 2013 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/>.
-
-B = horzcat(varargin{:});
\ No newline at end of file
diff --git a/matlab/@dseries/abs.m b/matlab/@dseries/abs.m
deleted file mode 100644
index ba4da3faba03f57f264ab76525020259b29e9373..0000000000000000000000000000000000000000
--- a/matlab/@dseries/abs.m
+++ /dev/null
@@ -1,107 +0,0 @@
-function A = abs(B) % --*-- Unitary tests --*--
-
-%@info:
-%! @deftypefn {Function File} {@var{A} =} abs (@var{B})
-%! @anchor{@dseries/uminus}
-%! @sp 1
-%! Overloads the abs method for the Dynare time series class (@ref{dseries}).
-%! @sp 2
-%! @strong{Inputs}
-%! @sp 1
-%! @table @ @var
-%! @item B
-%! Dynare time series object instantiated by @ref{dseries}.
-%! @end table
-%! @sp 1
-%! @strong{Outputs}
-%! @sp 1
-%! @table @ @var
-%! @item A
-%! Dynare time series object.
-%! @end deftypefn
-%@eod:
-
-% Copyright (C) 2013 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/>.
-
-A = dseries();
-
-A.data = abs(B.data);
-A.dates = B.dates;
-
-A.name = cell(vobs(A), 1);
-A.tex = cell(vobs(A), 1);
-for i = 1:vobs(A)
-    A.name(i) = {[ 'abs(' B.name{i} ')']};
-    A.tex(i) = {[ '|' B.tex{i} '|']};
-end
-
-%@test:1
-%$ % Define a datasets.
-%$ A = randn(10,2);
-%$
-%$ % Define names
-%$ A_name = {'A1';'A2'};
-%$ A_tex = {'A_1';'A_2'};
-%$ t = zeros(6,1);
-%$
-%$ % Instantiate a time series object and compute the absolute value.
-%$ try
-%$    ts1 = dseries(A,[],A_name,A_tex);
-%$    ts2 = abs(ts1);
-%$    t(1) = 1;
-%$ catch
-%$    t = 0;
-%$ end
-%$
-%$ if t(1)
-%$    t(2) = dyn_assert(ts2.vobs,2);
-%$    t(3) = dyn_assert(ts2.nobs,10);
-%$    t(4) = dyn_assert(ts2.data,abs(A),1e-15);
-%$    t(5) = dyn_assert(ts2.name,{'abs(A1)';'abs(A2)'});
-%$    t(6) = dyn_assert(ts2.tex,{'|A_1|';'|A_2|'});
-%$ end
-%$ T = all(t);
-%@eof:1
-
-%@test:2
-%$ % Define a datasets.
-%$ A = randn(10,2);
-%$
-%$ % Define names
-%$ A_name = {'A1';'A2'};
-%$ A_tex = {'A_1';'A_2'};
-%$ t = zeros(6,1);
-%$
-%$ % Instantiate a time series object and compute the absolute value.
-%$ try
-%$    ts1 = dseries(A,[],A_name,A_tex);
-%$    ts2 = ts1.abs();
-%$    t(1) = 1;
-%$ catch
-%$    t = 0;
-%$ end
-%$
-%$ if t(1)
-%$    t(2) = dyn_assert(ts2.vobs,2);
-%$    t(3) = dyn_assert(ts2.nobs,10);
-%$    t(4) = dyn_assert(ts2.data,abs(A),1e-15);
-%$    t(5) = dyn_assert(ts2.name,{'abs(A1)';'abs(A2)'});
-%$    t(6) = dyn_assert(ts2.tex,{'|A_1|';'|A_2|'});
-%$ end
-%$ T = all(t);
-%@eof:2
\ No newline at end of file
diff --git a/matlab/@dseries/align.m b/matlab/@dseries/align.m
deleted file mode 100644
index 32878127ec1631bb97778a330544bc569086d3e0..0000000000000000000000000000000000000000
--- a/matlab/@dseries/align.m
+++ /dev/null
@@ -1,182 +0,0 @@
-function [a,b] = align(a, b) % --*-- Unitary tests --*--
-    
-%@info:
-%! @deftypefn {Function File} {[@var{a}, @var{b}] =} align (@var{a}, @var{b})
-%! @anchor{dseries/align}
-%! @sp 1
-%! If dseries objects @var{a} and @var{b} are defined on different time ranges, extend @var{a} and/or
-%! @var{b} with NaNs so that they are defined on the same time range.
-%! @sp 2
-%! @strong{Inputs}
-%! @sp 1
-%! @table @ @var
-%! @item a
-%! Object instantiated by @ref{dseries}.
-%! @item b
-%! Object instantiated by @ref{dseries}.
-%! @end table
-%! @sp 2
-%! @strong{Outputs}
-%! @sp 1
-%! @table @ @var
-%! @item a
-%! Object instantiated by @ref{dseries}.
-%! @item b
-%! Object instantiated by @ref{dseries}.
-%! @end table
-%! @end deftypefn
-%@eod:
-
-% Copyright (C) 2013 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 ~isequal(frequency(a),frequency(b))
-    error(['dseries::align: ''' inputname(1) ''' and ''' inputname(2) ''' dseries objects must have common frequencies!'])
-end
-
-init = min(firstdate(a),firstdate(b));
-last = max(lastdate(a),lastdate(b));
-
-if isempty(intersect(a.dates,b.dates))
-    error(['dseries::align: ''' inputname(1) ''' and ''' inputname(2) ''' dseries object must have at least one common date!'])
-end
-
-a_init = init;
-b_init = init;
-a_last = last;
-b_last = last;
-
-if firstdate(b)>init
-    n = firstdate(b)-init;
-    b.data = [NaN(n, vobs(b)); b.data];
-    b_init = init;
-end
-
-if firstdate(a)>init
-    n = firstdate(a)-init;
-    a.data = [NaN(n, vobs(a)); a.data];
-    a_init = init;
-end
-
-if lastdate(b)<last
-    n = last-lastdate(b);
-    b.data = [b.data; NaN(n, vobs(b))];
-end
-
-if lastdate(a)<last
-    n = last-lastdate(a);
-    a.data = [a.data; NaN(n, vobs(a))];
-end
-
-a.dates = a_init:a_init+(nobs(a)-1);
-b.dates = b_init:b_init+(nobs(b)-1);
-
-%@test:1
-%$ % Define a datasets.
-%$ A = rand(8,3); B = rand(7,2);
-%$
-%$ % Define names
-%$ A_name = {'A1';'A2';'A3'};
-%$ B_name = {'B1';'B2'};
-%$
-%$ % Define initial dates
-%$ A_init = '1990Q1';
-%$ B_init = '1989Q2';
-%$
-%$ % Instantiate two dseries objects
-%$ ts1 = dseries(A,A_init,A_name);
-%$ ts2 = dseries(B,B_init,B_name);
-%$
-%$ try
-%$   [ts1, ts2] = align(ts1, ts2);
-%$   t(1) = 1;
-%$ catch
-%$   t(1) = 0;
-%$ end
-%$
-%$ if t(1)
-%$   t(2) = dyn_assert(ts1.nobs,ts2.nobs);
-%$   t(3) = dyn_assert(isequal(ts1.init,ts2.init),1);
-%$   t(4) = dyn_assert(ts1.data,[NaN(3,3); A], 1e-15);
-%$   t(5) = dyn_assert(ts2.data,[B; NaN(4,2)], 1e-15);
-%$ end
-%$ T = all(t);
-%@eof:1
-
-%@test:2
-%$ % Define a datasets.
-%$ A = rand(8,3); B = rand(7,2);
-%$
-%$ % Define names
-%$ A_name = {'A1';'A2';'A3'};
-%$ B_name = {'B1';'B2'};
-%$
-%$ % Define initial dates
-%$ A_init = '1990Q1';
-%$ B_init = '1990Q1';
-%$
-%$ % Instantiate two dseries objects
-%$ ts1 = dseries(A,A_init,A_name);
-%$ ts2 = dseries(B,B_init,B_name);
-%$
-%$ try
-%$   [ts1, ts2] = align(ts1, ts2);
-%$   t(1) = 1;
-%$ catch
-%$   t(1) = 0;
-%$ end
-%$
-%$ if t(1)
-%$   t(2) = dyn_assert(ts1.nobs,ts2.nobs);
-%$   t(3) = dyn_assert(isequal(ts1.init,ts2.init),1);
-%$   t(4) = dyn_assert(ts1.data,A, 1e-15);
-%$   t(5) = dyn_assert(ts2.data,[B; NaN(1,2)], 1e-15);
-%$ end
-%$ T = all(t);
-%@eof:2
-
-%@test:3
-%$ % Define a datasets.
-%$ A = rand(8,3); B = rand(7,2);
-%$
-%$ % Define names
-%$ A_name = {'A1';'A2';'A3'};
-%$ B_name = {'B1';'B2'};
-%$
-%$ % Define initial dates
-%$ A_init = '1990Q1';
-%$ B_init = '1990Q1';
-%$
-%$ % Instantiate two dseries objects
-%$ ts1 = dseries(A,A_init,A_name);
-%$ ts2 = dseries(B,B_init,B_name);
-%$
-%$ try
-%$   [ts2, ts1] = align(ts2, ts1);
-%$   t(1) = 1;
-%$ catch
-%$   t(1) = 0;
-%$ end
-%$
-%$ if t(1)
-%$   t(2) = dyn_assert(ts1.nobs,ts2.nobs);
-%$   t(3) = dyn_assert(isequal(ts1.init,ts2.init),1);
-%$   t(4) = dyn_assert(ts1.data,A, 1e-15);
-%$   t(5) = dyn_assert(ts2.data,[B; NaN(1,2)], 1e-15);
-%$ end
-%$ T = all(t);
-%@eof:3
\ No newline at end of file
diff --git a/matlab/@dseries/baxter_king_filter.m b/matlab/@dseries/baxter_king_filter.m
deleted file mode 100644
index 1943668310ea1f8f89bab4ed1bc0151828db8376..0000000000000000000000000000000000000000
--- a/matlab/@dseries/baxter_king_filter.m
+++ /dev/null
@@ -1,148 +0,0 @@
-function ts = baxter_king_filter(ts, high_frequency, low_frequency, K) % --*-- Unitary tests --*--
-
-% ts = baxter_king_filter(ts, high_frequency, low_frequency, K)
-%
-% Implementation of Baxter and King (1999) band pass filter for dseries objects. The code is adapted from
-% the one provided by Baxter and King. This filter isolates business cycle fluctuations with a period of length 
-% ranging between high_frequency to low_frequency (quarters).
-%
-% INPUTS 
-%  o ts                 dseries object.
-%  o high_frequency     positive scalar, period length (default value is 6).
-%  o low_frequency      positive scalar, period length (default value is 32).
-%  o K                  positive scalar integer, truncation parameter (default value is 12).
-%
-% OUTPUTS 
-%  o ts                 dseries object.
-%
-% REMARKS 
-% This filter use a (symmetric) moving average smoother, so that K observations at the beginning and at the end of the 
-% sample are lost in the computation of the filter.
-
-% Copyright (C) 2013 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 nargin<4 || isempty(truncature)
-    K = 12;
-    if nargin<3 || isempty(low_frequency)
-        % Set default number of periods corresponding to the lowest frequency.
-        low_frequency = 32;
-        if nargin<2 || isempty(high_frequency)
-            % Set default number of periods corresponding to the highest frequency.
-            high_frequency = 6;
-            if nargin<1
-                error('dseries::baxter_king_filter: I need at least one argument')
-            end
-        else
-            if high_frequency<2
-                error('dseries::baxter_king_filter: Second argument must be greater than 2!')
-            end
-            if high_frequency>low_frequency
-                error('dseries::baxter_king_filter: Second argument must be smaller than the third argument!')
-            end
-        end
-    end
-end
-       
-% translate periods into frequencies.
-hf=2.0*pi/high_frequency;
-lf=2.0*pi/low_frequency;
-
-% Set weights for the band-pass filter's lag polynomial.
-weights = zeros(K+1,1); lpowers = transpose(1:K);
-weights(2:K+1) = (sin(lpowers*hf)-sin(lpowers*lf))./(lpowers*pi);
-weights(1) = (hf-lf)/pi;
-
-% Set the constraint on the sum of weights.
-if low_frequency>1000
-    % => low pass filter.
-    sum_of_weights_constraint = 1.0;
-else
-    sum_of_weights_constraint = 0.0;
-end
-
-% Compute the sum of weights.
-sum_of_weights = weights(1) + 2*sum(weights(2:K+1));
-
-% Correct the weights.
-weights = weights + (sum_of_weights_constraint - sum_of_weights)/(2*K+1);
-
-% Weights are symmetric!
-weights = [flipud(weights(2:K+1)); weights];
-
-tmp = zeros(size(ts.data));
-
-% Filtering step.
-for t = K+1:nobs(ts)-K
-    tmp(t,:)  = weights'*ts.data(t-K:t+K,:);    
-end
-
-% Update dseries object.
-ts.data = tmp(K+1:end-K,:);
-init = firstdate(ts)+K;
-ts.dates = init:init+(nobs(ts)-1);
-
-%@test:1
-%$ plot_flag = 0;
-%$
-%$ % Create a dataset.
-%$ e = .2*randn(200,1);
-%$ u = randn(200,1);
-%$ stochastic_trend = cumsum(e); 
-%$ deterministic_trend = .1*transpose(1:200);
-%$ x = zeros(200,1);
-%$ for i=2:200
-%$    x(i) = .75*x(i-1) + e(i);
-%$ end
-%$ y = x + stochastic_trend + deterministic_trend;
-%$
-%$ % Test the routine.
-%$ try
-%$     ts = dseries(y,'1950Q1');
-%$     ts = ts.baxter_king_filter();
-%$     xx = dseries(x,'1950Q1');
-%$     t(1) = 1;
-%$ catch
-%$     t(1) = 0;
-%$ end
-%$
-%$ if t(1)
-%$     t(2) = dyn_assert(ts.freq,4);
-%$     t(3) = dyn_assert(ts.init.freq,4);
-%$     t(4) = dyn_assert(ts.init.time,[1953, 1]);
-%$     t(5) = dyn_assert(ts.vobs,1);
-%$     t(6) = dyn_assert(ts.nobs,176);
-%$ end
-%$
-%$ % Show results
-%$ if plot_flag
-%$     plot(xx(ts.dates).data,'-k');
-%$     hold on
-%$     plot(ts.data,'--r');
-%$     hold off
-%$     axis tight
-%$     id = get(gca,'XTick');
-%$     set(gca,'XTickLabel',strings(ts.dates(id)));
-%$     legend({'Stationary component of y', 'Filtered y'})
-%$     print('-depsc2','../doc/dynare.plots/BaxterKingFilter.eps')
-%$     system('convert -density 300 ../doc/dynare.plots/BaxterKingFilter.eps ../doc/dynare.plots/BaxterKingFilter.png');
-%$     system('convert -density 300 ../doc/dynare.plots/BaxterKingFilter.eps ../doc/dynare.plots/BaxterKingFilter.pdf');
-%$     system('convert -density 300 ../doc/dynare.plots/BaxterKingFilter.eps ../doc/dynare.plots/BaxterKingFilter.jpg');
-%$ end
-%$
-%$ T = all(t);
-%@eof:1
\ No newline at end of file
diff --git a/matlab/@dseries/chain.m b/matlab/@dseries/chain.m
deleted file mode 100644
index fae59f0523d92f84feb1bdbe1749d39150f9d41c..0000000000000000000000000000000000000000
--- a/matlab/@dseries/chain.m
+++ /dev/null
@@ -1,61 +0,0 @@
-function vs = chain(ts,us)  % --*-- 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 vobs(ts)-vobs(us)
-    error(['dseries::chain: dseries objects ' inputname(1) ' and ' inputname(2) ' must have the same number of variables!'])
-end
-
-if frequency(ts)-frequency(us)
-    error(['dseries::chain: dseries objects ' inputname(1) ' and ' inputname(2) ' must have common frequencies!'])
-end
-
-if lastdate(ts)<firstdate(us)
-    error(['dseries::chain: The last date in ' inputname(1) ' (' date2string(ts.dates(end)) ') must not preceed the first date in ' inputname(2) ' (' date2string(us.dates(1)) ')!'])
-end
-
-tdx = find(sum(bsxfun(@eq,us.dates.time,ts.dates.time(end,:)),2)==2);
-GrowthFactor = us.data(tdx+1:end,:)./us.data(tdx:end-1,:);
-CumulatedGrowthFactors = cumprod(GrowthFactor);
-
-vs = ts;
-vs.data = [vs.data; bsxfun(@times,CumulatedGrowthFactors,vs.data(end,:))];
-
-vs.dates = firstdate(vs):firstdate(vs)+nobs(vs);
-
-%@test:1
-%$ try
-%$     ts = dseries([1; 2; 3; 4],dates('1950Q1')) ;
-%$     us = dseries([3; 4; 5; 6],dates('1950Q3')) ;
-%$     vs = chain(ts,us);
-%$     t(1) = 1;
-%$ catch
-%$     t(1) = 0;
-%$ end
-%$
-%$ if t(1)
-%$     t(2) = dyn_assert(vs.freq,4);
-%$     t(3) = dyn_assert(vs.init.freq,4);
-%$     t(4) = dyn_assert(vs.init.time,[1950, 1]);
-%$     t(5) = dyn_assert(ts.vobs,1);
-%$     t(6) = dyn_assert(vs.nobs,6);
-%$     t(7) = isequal(vs.data,transpose(1:6));
-%$ end
-%$
-%$ T = all(t);
-%@eof:1
\ No newline at end of file
diff --git a/matlab/@dseries/check.m b/matlab/@dseries/check.m
deleted file mode 100644
index c4bfce37a40008176eaed90794a31e953cfa01f6..0000000000000000000000000000000000000000
--- a/matlab/@dseries/check.m
+++ /dev/null
@@ -1,86 +0,0 @@
-function [error_flag,message] = check(A)
-
-% Copyright (C) 2013 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/>.
-
-error_flag = 0;
-
-[n,m] = size(A.data);
-
-if ~isequal(m, vobs(A));
-    error_flag = 1;
-    if nargout>1
-        message = ['dseries: Wrong number of variables in dseries object ''' inputname(1) '''!'];
-    end
-    return
-end
-
-if ~isequal(n,nobs(A));
-    error_flag = 1;
-    if nargout>1
-        message = ['dseries: Wrong number of observations in dseries object ''' inputname(1) '''!'];
-    end
-    return
-end
-
-if ~isequal(m,numel(A.name));
-    error_flag = 1;
-    if nargout>1
-        message = ['dseries: Wrong number of variable names in dseries object ''' inputname(1) '''!'];
-    end
-    return
-end
-
-if ~isequal(m,numel(A.tex));
-    error_flag = 1;
-    if nargout>1
-        message = ['dseries: Wrong number of variable tex names in dseries object ''' inputname(1) '''!'];
-    end
-    return
-end
-
-if ~isequal(numel(A.name),numel(A.tex));
-    error_flag = 1;
-    if nargout>1
-        message = ['dseries: The number of variable tex names has to be equal to the number of variable names in dseries object ''' inputname(1) '''!'];
-    end
-    return
-end
-
-if ~isequal(numel(unique(A.name)),numel(A.name));
-    error_flag = 1;
-    if nargout>1
-        message = ['dseries: The variable names in dseries object ''' inputname(1) ''' are not unique!'];
-    end
-    return
-end
-
-if ~isequal(numel(unique(A.tex)),numel(A.tex));
-    error_flag = 1;
-    if nargout>1
-        message = ['dseries: The variable tex names in dseries object ''' inputname(1) ''' are not unique!'];
-    end
-    return
-end
-
-if ~isequal(A.dates,firstdate(A):firstdate(A)+nobs(A))
-    error_flag = 1;
-    if nargout>1
-        message = ['dseries: Wrong definition of the dates member in dseries object ''' inputname(1) '''!'];
-    end
-    return
-end
\ No newline at end of file
diff --git a/matlab/@dseries/cumprod.m b/matlab/@dseries/cumprod.m
deleted file mode 100644
index 4e98d38b1ad3ca6177e80cfa19baa3d5a263b515..0000000000000000000000000000000000000000
--- a/matlab/@dseries/cumprod.m
+++ /dev/null
@@ -1,234 +0,0 @@
-function B = cumprod(varargin) % --*-- Unitary tests --*--
-
-% Overloads matlab's cumprod function for dseries objects.
-%
-% INPUTS
-%  o A     dseries object [mandatory].
-%  o d     dates object [optional]
-%  o v     dseries object with one observation [optional]
-%
-% OUTPUTS
-%  o B     dseries object.
-
-% 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/>.
-
-% Get indices of the columns without NaNs
-idx = find(~any(isnan(varargin{1}.data)));
-
-if isempty(idx)
-    error('dseries::cumprod: All the variables have NaNs. The cumulated product cannot be computed!')
-end
-
-if ~isequal(idx(:),transpose(1:vobs(varargin{1})))
-    warning('dseries::cumprod: The cumulated product is not computed for some variables because they have NaNs!')
-end
-
-switch nargin
-    case 1
-      % Initialize the output.
-      B = varargin{1};
-      % Perform the cumulated sum
-      B.data(:,idx) = cumprod(B.data(:,idx));
-      % Change the name of the variables
-      for i=1:vobs(B)
-          B.name(i) = {['cumprod(' B.name{i} ')']};
-          B.tex(i) = {['\prod_t ' B.tex{i}]};
-      end
-  case 2
-    if isdseries(varargin{2})
-        if ~isequal(vobs(varargin{1}), vobs(varargin{2}))
-            error('dseries::cumprod: First and second input arguments must be dseries objects with the same number of variables!')
-        end
-        if ~isequal(varargin{1}.name, varargin{2}.name)
-            warning('dseries::cumprod: First and second input arguments must be dseries objects do not have the same variables!')
-        end
-        if ~isequal(nobs(varargin{2}),1)
-            error('dseries::cumprod: Second input argument must be a dseries object with only one observation!')
-        end
-        B = cumprod(varargin{1});
-        B.data = bsxfun(@rdivide,B.data,B.data(1,:));
-        B.data = bsxfun(@times,B.data,varargin{2}.data);
-    elseif isdates(varargin{2})
-        B = cumprod(varargin{1});
-        t = find(B.dates==varargin{2});
-        if isempty(t)
-            if varargin{2}==(firstdate(B)-1)
-                return
-            else
-                error(['dseries::cumprod: date ' date2string(varargin{2}) ' is not in the sample!'])
-            end
-        end
-        B.data = bsxfun(@rdivide,B.data,B.data(t,:));
-    else
-        error('dseries::cumprod: Second input argument must be a dseries object or a dates object!')
-    end
-  case 3
-    if ~isdates(varargin{2})
-        error('dseries::cumprod: Second input argument must be a dates object!')
-    end
-    if ~isdseries(varargin{3})
-        error('dseries::cumprod: Third input argument must be a dseries object!')
-    end
-    if ~isequal(vobs(varargin{1}), vobs(varargin{3}))
-        error('dseries::cumprod: First and third input arguments must be dseries objects with the same number of variables!')
-    end
-    if ~isequal(varargin{1}.name, varargin{3}.name)
-        warning('dseries::cumprod: First and third input arguments must be dseries objects do not have the same variables!')
-    end
-    if ~isequal(nobs(varargin{3}),1)
-        error('dseries::cumprod: Third input argument must be a dseries object with only one observation!')
-    end
-    B = cumprod(varargin{1});
-    t = find(B.dates==varargin{2});
-    if isempty(t)
-        if varargin{2}==(firstdate(B)-1)
-            B.data = bsxfun(@times,B.data,varargin{3}.data);
-            return
-        else
-            error(['dseries::cumprod: date ' date2string(varargin{2}) ' is not in the sample!'])
-        end
-    end
-    B.data = bsxfun(@rdivide, B.data, B.data(t,:));
-    B.data = bsxfun(@times, B.data, varargin{3}.data);
-  otherwise
-    error('dseries::cumprod: Wrong number of input arguments!')
-end
-
-%@test:1
-%$ % Define a data set.
-%$ A = 2*ones(4,1);
-%$
-%$ % Define names
-%$ A_name = {'A1'};
-%$
-%$ % Instantiate a time series object.
-%$ ts = dseries(A,[],A_name,[]);
-%$
-%$ % Call the tested method.
-%$ try
-%$     ts = cumprod(ts);
-%$     t(1) = 1;
-%$ catch
-%$     t(1) = 0;
-%$ end
-%$
-%$ if t(1)
-%$     t(2) = isequal(ts.data,cumprod(A));
-%$     t(3) = isequal(ts.name{1},'cumprod(A1)');
-%$ end
-%$
-%$ T = all(t);
-%@eof:1
-
-%@test:2
-%$ % Define a data set.
-%$ A = 2*ones(4,1);
-%$
-%$ % Define names
-%$ A_name = {'A1'};
-%$
-%$ % Instantiate a time series object.
-%$ ts = dseries(A,[],A_name,[]);
-%$
-%$ % Call the tested method.
-%$ try
-%$     ts = ts.cumprod();
-%$     t(1) = 1;
-%$ catch
-%$     t(1) = 0;
-%$ end
-%$
-%$ if t(1)
-%$     t(2) = isequal(ts.data,cumprod(A));
-%$     t(3) = isequal(ts.name{1},'cumprod(A1)');
-%$ end
-%$
-%$ T = all(t);
-%@eof:2
-
-
-%@test:3
-%$ % Define a data set.
-%$ A = 2*ones(7,1);
-%$
-%$ % Define names
-%$ A_name = {'A1'};
-%$
-%$ % Instantiate a time series object.
-%$ ts = dseries(A,[],A_name,[]);
-%$
-%$ % Call the tested method.
-%$ ts = cumprod(ts,dates('3Y'));
-%$
-%$ % Expected results.
-%$ ds = dseries([.25; .5; 1; 2; 4; 8; 16], [], A_name, []);
-%$
-%$ % Check the results.
-%$ warning off, % Because the names of the variables are not the same...
-%$ t(1) = dyn_assert(isequal(ts,ts),1);
-%$ warning_config
-%$ T = all(t);
-%@eof:3
-
-%@test:4
-%$ % Define a data set.
-%$ A = 2*ones(7,1);
-%$
-%$ % Define names
-%$ A_name = {'A1'};
-%$
-%$ % Instantiate a time series object.
-%$ ts1 = dseries(A,[],A_name,[]);
-%$ ts2 = dseries(pi, [], A_name, []);
-%$
-%$ % Call the tested method.
-%$ ts3 = cumprod(ts1,dates('3Y'),ts2);
-%$
-%$ % Expected results.
-%$ ts4 = dseries([.25; .5; 1; 2; 4; 8; 16]*pi, [], A_name, []);
-%$
-%$ % Check the results.
-%$ warning off, % Because the names of the variables are not the same...
-%$ t(1) = dyn_assert(isequal(ts3,ts4),1);
-%$ warning_config
-%$ T = all(t);
-%@eof:4
-
-%@test:5
-%$ % Define a data set.
-%$ A = 2*ones(7,1);
-%$
-%$ % Define names
-%$ A_name = {'A1'};
-%$
-%$ % Instantiate a time series object.
-%$ ts1 = dseries(A,[],A_name,[]);
-%$ ts2 = dseries(pi, [], A_name, []);
-%$
-%$ % Call the tested method.
-%$ ts3 = ts1.cumprod(dates('3Y'),ts2);
-%$
-%$ % Expected results.
-%$ ts4 = dseries([.25; .5; 1; 2; 4; 8; 16]*pi, [], A_name, []);
-%$
-%$ % Check the results.
-%$ warning off, % Because the names of the variables are not the same...
-%$ t(1) = dyn_assert(isequal(ts3,ts4),1);
-%$ warning_config
-%$ T = all(t);
-%@eof:5
\ No newline at end of file
diff --git a/matlab/@dseries/cumsum.m b/matlab/@dseries/cumsum.m
deleted file mode 100644
index 6dfb73c284dfd166d59b91cb08e2f375dc306b42..0000000000000000000000000000000000000000
--- a/matlab/@dseries/cumsum.m
+++ /dev/null
@@ -1,225 +0,0 @@
-function B = cumsum(varargin) % --*-- Unitary tests --*--
-
-% Overloads matlab's cumsum function for dseries objects.
-%
-% INPUTS 
-%  o A     dseries object [mandatory].
-%  o d     dates object [optional]
-%  o v     dseries object with one observation [optional]
-%
-% OUTPUTS 
-%  o B     dseries object.
-
-% Copyright (C) 2013 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/>.
-
-% Get indices of the columns without NaNs
-idx = find(~any(isnan(varargin{1}.data)));
-
-if isempty(idx)
-    error('dseries::cumsum: All the variables have NaNs. The cumulated sum cannot be computed!')
-end
-
-if ~isequal(idx(:),transpose(1:vobs(varargin{1})))
-    warning('dseries::cumsum: The cumulated sum is not computed for some variables because they have NaNs!')
-end
-
-switch nargin
-    case 1
-      % Initialize the output.
-      B = varargin{1};
-      % Perform the cumulated sum
-      B.data(:,idx) = cumsum(B.data(:,idx));
-      % Change the name of the variables
-      for i=1:vobs(B)
-          B.name(i) = {['cumsum(' B.name{i} ')']};
-          B.tex(i) = {['\sum_t ' B.tex{i}]};
-      end
-  case 2
-    if isdseries(varargin{2})
-        if ~isequal(vobs(varargin{1}), vobs(varargin{2}))
-            error('dseries::cumsum: First and second input arguments must be dseries objects with the same number of variables!')
-        end
-        if ~isequal(varargin{1}.name, varargin{2}.name)
-            warning('dseries::cumsum: First and second input arguments must be dseries objects do not have the same variables!')
-        end
-        if ~isequal(nobs(varargin{2}),1)
-            error('dseries::cumsum: Second input argument must be a dseries object with only one observation!')
-        end
-        B = cumsum(varargin{1});
-        B.data = bsxfun(@plus,B.data,varargin{2}.data);
-    elseif isdates(varargin{2})
-        B = cumsum(varargin{1});
-        t = find(B.dates==varargin{2});
-        if isempty(t)
-            if varargin{2}==(firstdate(B)-1)
-                return
-            else
-                error(['dseries::cumsum: date ' date2string(varargin{2}) ' is not in the sample!'])
-            end
-        end
-        B.data = bsxfun(@minus,B.data,B.data(t,:));
-    else
-        error('dseries::cumsum: Second input argument must be a dseries object or a dates object!')
-    end
-  case 3
-    if ~isdates(varargin{2})
-        error('dseries::cumsum: Second input argument must be a dates object!')
-    end
-    if ~isdseries(varargin{3})
-        error('dseries::cumsum: Third input argument must be a dseries object!')
-    end
-    if ~isequal(vobs(varargin{1}), vobs(varargin{3}))
-        error('dseries::cumsum: First and third input arguments must be dseries objects with the same number of variables!')
-    end
-    if ~isequal(varargin{1}.name, varargin{3}.name)
-        warning('dseries::cumsum: First and third input arguments must be dseries objects do not have the same variables!')
-    end
-    if ~isequal(nobs(varargin{3}),1)
-        error('dseries::cumsum: Third input argument must be a dseries object with only one observation!')
-    end
-    B = cumsum(varargin{1});
-    t = find(B.dates==varargin{2});
-    if isempty(t)
-        if varargin{2}==(firstdate(B)-1)
-            B.data = bsxfun(@plus,B.data,varargin{3}.data);
-            return
-        else
-            error(['dseries::cumsum: date ' date2string(varargin{2}) ' is not in the sample!'])
-        end
-    end
-    B.data = bsxfun(@plus,B.data,varargin{3}.data-B.data(t,:));
-  otherwise
-    error('dseries::cumsum: Wrong number of input arguments!')
-end
-
-%@test:1
-%$ % Define a data set.
-%$ A = ones(10,1);
-%$
-%$ % Define names
-%$ A_name = {'A1'};
-%$
-%$ % Instantiate a time series object.
-%$ ts1 = dseries(A,[],A_name,[]);
-%$
-%$ % Call the tested method.
-%$ ts1 = cumsum(ts1);
-%$
-%$ % Expected results.
-%$ ts2 = dseries(transpose(1:10), [], A_name, []);
-%$
-%$ % Check the results.
-%$ warning off, % Because the names of the variables are not the same...
-%$ t(1) = dyn_assert(isequal(ts1,ts2),1);
-%$ warning_config
-%$ T = all(t);
-%@eof:1
-
-%@test:2
-%$ % Define a data set.
-%$ A = ones(10,1);
-%$
-%$ % Define names
-%$ A_name = {'A1'};
-%$
-%$ % Instantiate a time series object.
-%$ ts1 = dseries(A,[],A_name,[]);
-%$
-%$ % Call the tested method.
-%$ ts1 = ts1.cumsum();
-%$
-%$ % Expected results.
-%$ ts2 = dseries(transpose(1:10), [], A_name, []);
-%$
-%$ % Check the results.
-%$ warning off, % Because the names of the variables are not the same...
-%$ t(1) = dyn_assert(isequal(ts1,ts2),1);
-%$ warning_config
-%$ T = all(t);
-%@eof:2
-
-%@test:3
-%$ % Define a data set.
-%$ A = ones(10,1);
-%$
-%$ % Define names
-%$ A_name = {'A1'};
-%$
-%$ % Instantiate a time series object.
-%$ ts1 = dseries(A,[],A_name,[]);
-%$ 
-%$ % Call the tested method.
-%$ ts1 = cumsum(ts1,dates('3Y'));
-%$
-%$ % Expected results.
-%$ ts2 = dseries([-2; -1; 0; 1; 2; 3; 4; 5; 6; 7], [], A_name, []);
-%$
-%$ % Check the results.
-%$ warning off, % Because the names of the variables are not the same...
-%$ t(1) = dyn_assert(isequal(ts1,ts2),1);
-%$ warning_config
-%$ T = all(t);
-%@eof:3
-
-%@test:4
-%$ % Define a data set.
-%$ A = ones(10,1);
-%$
-%$ % Define names
-%$ A_name = {'A1'};
-%$
-%$ % Instantiate a time series object.
-%$ ts1 = dseries(A,[],A_name,[]);
-%$ ts2 = dseries(pi, [], A_name, []);
-%$
-%$ % Call the tested method.
-%$ ts3 = cumsum(ts1,dates('3Y'),ts2);
-%$
-%$ % Expected results.
-%$ ts4 = dseries([-2; -1; 0; 1; 2; 3; 4; 5; 6; 7]+pi, [], A_name, []);
-%$
-%$ % Check the results.
-%$ warning off, % Because the names of the variables are not the same...
-%$ t(1) = dyn_assert(isequal(ts3,ts4),1);
-%$ warning_config
-%$ T = all(t);
-%@eof:4
-
-%@test:5
-%$ % Define a data set.
-%$ A = ones(10,1);
-%$
-%$ % Define names
-%$ A_name = {'A1'};
-%$
-%$ % Instantiate a time series object.
-%$ ts1 = dseries(A,[],A_name,[]);
-%$ ts2 = dseries(pi, [], A_name, []);
-%$
-%$ % Call the tested method.
-%$ ts3 = ts1.cumsum(dates('3Y'),ts2);
-%$
-%$ % Expected results.
-%$ ts4 = dseries([-2; -1; 0; 1; 2; 3; 4; 5; 6; 7]+pi, [], A_name, []);
-%$
-%$ % Check the results.
-%$ warning off, % Because the names of the variables are not the same...
-%$ t(1) = dyn_assert(isequal(ts3,ts4),1);
-%$ warning_config
-%$ T = all(t);
-%@eof:5
\ No newline at end of file
diff --git a/matlab/@dseries/detrend.m b/matlab/@dseries/detrend.m
deleted file mode 100644
index fa6a193f102c93a7593cfb475f663b58483fa063..0000000000000000000000000000000000000000
--- a/matlab/@dseries/detrend.m
+++ /dev/null
@@ -1,110 +0,0 @@
-function o = detrend(o, model) % --*-- 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/>.
-
-% Set default for the order of the polynomial trend (constant).
-if nargin<2
-    model = 0;
-end
-
-data = o.data;
-
-if isnumeric(model)
-    if isscalar(model) && isint(model)
-        switch model
-          case 0
-            data = demean(data);
-          otherwise
-            x = NaN(nobs(o), model+1);
-            x(:,1) = ones(nobs(o), 1);
-            x(:,2) = transpose(1:nobs(o));
-            for c=3:model+1
-                x(:,c) = x(:,c-1).*x(:,2);
-            end
-            data = data - x*(x\data);
-        end
-    else
-        error('dseries::detrend: Second argument must be a positive integer scalar!')
-    end
-else
-    error('dseries::detrend: Second argument must be a positive integer scalar!')
-end
-
-o = dseries(data, o.dates, o.name, o.tex);
-
-%@test:1
-%$ % Define a dataset.
-%$ a = dseries(randn(1000,3));
-%$
-%$ % detrend (default).
-%$ try
-%$    b1 = a.detrend();
-%$    t(1) = 1;
-%$ catch
-%$    t = 0;
-%$ end
-%$
-%$ % detrend (constant).
-%$ if t(1)
-%$    try
-%$       b2 = a.detrend(0);
-%$       t(2) = 1;
-%$    catch
-%$       t(2) = 0;
-%$    end
-%$ end
-%$
-%$ % detrend (linear).
-%$ if t(2)
-%$    try
-%$       b3 = a.detrend(1);
-%$       t(3) = 1;
-%$    catch
-%$       t(3) = 0;
-%$    end
-%$ end
-%$
-%$ % detrend (quadratic).
-%$ if t(3)
-%$    try
-%$       b4 = a.detrend(2);
-%$       t(4) = 1;
-%$    catch
-%$       t(4) = 0;
-%$    end
-%$ end
-%$
-%$ % detrend (cubic).
-%$ if t(4)
-%$    try
-%$       b5 = a.detrend(3);
-%$       t(5) = 1;
-%$    catch
-%$       t(5) = 0;
-%$    end
-%$ end
-%$
-%$ if t(5)
-%$    t(6) = dyn_assert(max(mean(b1.data)),0,1e-12);
-%$    t(7) = dyn_assert(max(mean(b2.data)),0,1e-12);
-%$    t(8) = dyn_assert(max(mean(b3.data)),0,1e-12);
-%$    t(9) = dyn_assert(max(mean(b4.data)),0,1e-12);
-%$    t(10) = dyn_assert(max(mean(b5.data)),0,1e-12);
-%$ end
-%$ T = all(t);
-%@eof:1
diff --git a/matlab/@dseries/disp.m b/matlab/@dseries/disp.m
deleted file mode 100644
index 5bd38f464e997b25ec3fdc661bff2a2900096b19..0000000000000000000000000000000000000000
--- a/matlab/@dseries/disp.m
+++ /dev/null
@@ -1,40 +0,0 @@
-function disp(A)
-
-%@info:
-%! @deftypefn {Function File} disp (@var{A})
-%! @anchor{@dseries/disp}
-%! @sp 1
-%! Overloads the disp method for the Dynare time series class (@ref{dseries}).
-%! @sp 2
-%! @strong{Inputs}
-%! @sp 1
-%! @table @ @var
-%! @item A
-%! Dynare time series object instantiated by @ref{dseries}.
-%! @end table
-%! @sp 1
-%! @strong{Outputs}
-%! @sp 1
-%! None
-%! @end deftypefn
-%@eod:
-
-separator = repmat(' | ', nobs(A)+1,1);
-vspace = ' ';
-TABLE = ' ';
-for t=1:nobs(A)
-    TABLE = char(TABLE, date2string(A.dates(t)));
-end
-for i = 1:vobs(A)
-    TABLE = horzcat(TABLE,separator);
-    tmp = A.name{i};
-    for t=1:nobs(A)
-        tmp = char(tmp,num2str(A.data(t,i)));
-    end
-    TABLE = horzcat(TABLE, tmp);
-end
-disp(vspace)
-disp([inputname(1) ' is a dseries object:'])
-disp(vspace);
-disp(TABLE);
-disp(vspace);
\ No newline at end of file
diff --git a/matlab/@dseries/display.m b/matlab/@dseries/display.m
deleted file mode 100644
index d6826a801354b943a64438e15e15982629873f37..0000000000000000000000000000000000000000
--- a/matlab/@dseries/display.m
+++ /dev/null
@@ -1,128 +0,0 @@
-function display(A)
-%@info:
-%! @deftypefn {Function File} display (@var{A})
-%! @anchor{@dseries/display}
-%! @sp 1
-%! Overloads the disp method for the Dynare time series class (@ref{dseries}).
-%! @sp 2
-%! @strong{Inputs}
-%! @sp 1
-%! @table @ @var
-%! @item A
-%! Dynare time series object instantiated by @ref{dseries}.
-%! @end table
-%! @sp 1
-%! @strong{Outputs}
-%! @sp 1
-%! None
-%! @end deftypefn
-%@eod:
-
-vspace = ' ';
-TABLE = ' ';
-
-if vobs(A)<=10
-    if nobs(A)<=40
-        separator = repmat(' | ', nobs(A)+1,1);
-        for t=1:nobs(A)
-            TABLE = char(TABLE, date2string(A.dates(t)));
-        end
-        for i = 1:vobs(A)
-            TABLE = horzcat(TABLE,separator);
-            tmp = A.name{i};
-            for t=1:nobs(A)
-                tmp = char(tmp,num2str(A.data(t,i)));
-            end
-            TABLE = horzcat(TABLE, tmp);
-        end
-    else
-        n = 10;
-        separator = repmat(' | ',2*n+3,1);
-        for t=1:n
-            TABLE = char(TABLE, date2string(A.dates(t)));
-        end
-        TABLE = char(TABLE,vspace);
-        for t = nobs(A)-n:nobs(A)
-            TABLE = char(TABLE, date2string(A.dates(t)));
-        end
-        for i=1:vobs(A)
-            TABLE = horzcat(TABLE,separator);
-            tmp = A.name{i};
-            for t=1:10
-                tmp = char(tmp,num2str(A.data(t,i)));
-            end
-            tmp = char(tmp,vspace);
-            for t=nobs(A)-10:nobs(A)
-                tmp = char(tmp,num2str(A.data(t,i)));
-            end
-            TABLE = horzcat(TABLE, tmp);
-        end
-    end
-else
-    m = 4;
-    if nobs(A)<=40
-        separator = repmat(' | ', nobs(A)+1,1);
-        for t=1:nobs(A)
-            TABLE = char(TABLE, date2string(A.dates(t)));
-        end
-        for i = 1:m
-            TABLE = horzcat(TABLE,separator);
-            tmp = A.name{i};
-            for t=1:nobs(A)
-                tmp = char(tmp,num2str(A.data(t,i)));
-            end
-            TABLE = horzcat(TABLE, tmp);
-        end
-        TABLE = horzcat(TABLE, separator, repmat(' ... ', nobs(A)+1,1));
-        for i = vobs(A)-m+1:vobs(A)
-            TABLE = horzcat(TABLE,separator);
-            tmp = A.name{i};
-            for t=1:nobs(A)
-                tmp = char(tmp,num2str(A.data(t,i)));
-            end
-            TABLE = horzcat(TABLE, tmp);
-        end
-    else
-        n = 10;
-        separator = repmat(' | ',2*n+3,1);
-        for t=1:n
-            TABLE = char(TABLE, date2string(A.dates(t)));
-        end
-        TABLE = char(TABLE,vspace);
-        for t = nobs(A)-n:nobs(A)
-            TABLE = char(TABLE, date2string(A.dates(t)));
-        end
-        for i=1:m
-            TABLE = horzcat(TABLE,separator);
-            tmp = A.name{i};
-            for t=1:10
-                tmp = char(tmp,num2str(A.data(t,i)));
-            end
-            tmp = char(tmp,vspace);
-            for t=nobs(A)-10:nobs(A)
-                tmp = char(tmp,num2str(A.data(t,i)));
-            end
-            TABLE = horzcat(TABLE, tmp);
-        end
-        TABLE = horzcat(TABLE, separator, repmat(' ... ', 2*n+3,1));
-        for i=vobs(A)-m+1:vobs(A)
-            TABLE = horzcat(TABLE,separator);
-            tmp = A.name{i};
-            for t=1:10
-                tmp = char(tmp,num2str(A.data(t,i)));
-            end
-            tmp = char(tmp,vspace);
-            for t=nobs(A)-10:nobs(A)
-                tmp = char(tmp,num2str(A.data(t,i)));
-            end
-            TABLE = horzcat(TABLE, tmp);
-        end
-    end
-end
-disp(vspace)
-disp([inputname(1) ' is a dseries object:'])
-disp(vspace);
-if ~isempty(strtrim(TABLE))
-    disp(TABLE);
-    disp(vspace);
-end
diff --git a/matlab/@dseries/dseries.m b/matlab/@dseries/dseries.m
deleted file mode 100644
index 7fadb4c4332c3081772579b5239330a8daf64b48..0000000000000000000000000000000000000000
--- a/matlab/@dseries/dseries.m
+++ /dev/null
@@ -1,546 +0,0 @@
-function ts = dseries(varargin) % --*-- Unitary tests --*--
-
-%@info:
-%! @deftypefn {Function File} {@var{ts} =} dseries (@var{a},@var{b},@var{c},@var{d})
-%! @anchor{dseries}
-%! @sp 1
-%! Constructor for the Dynare time series class.
-%! @sp 2
-%! @strong{Inputs}
-%! @sp 2
-%! If @code{nargin==0} then an empty dseries object is created. The object can be populated with data subsequently using the overloaded subsref method.
-%! @sp 2
-%! If @code{nargin==1} and if the input argument is a @ref{dates} object, then a dseries object without data is created. This object can be populated with the overload subsref method.
-%! @sp 2
-%! If @code{nargin==1} and if the input argument is a string for the name of a csv, m or mat file containing data, then a dseries object is created from these data.
-%! @sp 2
-%! If @code{nargin>1}:
-%! @sp 1
-%! @table @ @var
-%! @item a
-%! T*1 vector or T*N matrix of data.
-%! @item b
-%! Initial date. For Quaterly, Monthly or Weekly data, b must be a string. For yearly data or if the frequence is not defined b must be an integer.
-%! @item c
-%! N*1 cell array of strings or N*q array of strings. Names of the N time series.
-%! @item d
-%! N*1 cell array of strings or N*p array of characters. TeX names of the N time series.
-%! @end table
-%! @sp 2
-%! @strong{Outputs}
-%! @sp 1
-%! @table @ @var
-%! @item ts
-%! Dynare time series object.
-%! @end table
-%! @sp 2
-%! @strong{Properties}
-%! @sp 1
-%! The constructor defines the following properties:
-%! @sp 1
-%! @table @ @var
-%! @item data
-%! Array of doubles (nobs*vobs).
-%! @item nobs
-%! Scalar integer, the number of observations.
-%! @item vobs
-%! Scalar integer, the number of variables.
-%! @item name
-%! Cell array of strings, names of the variables.
-%! @item tex
-%! Cell array of strings, tex names of the variables.
-%! @item freq
-%! Scalar integer, the frequency of the time series. @var{freq} is equal to 1 if data are on a yearly basis or if
-%! frequency is unspecified. @var{freq} is equal to 4 if data are on a quaterly basis. @var{freq} is equal to
-%! 12 if data are on a monthly basis. @var{freq} is equal to 52 if data are on a weekly basis.
-%! @item init
-%! @ref{dates} object, initial date of the dataset.
-%! @end table
-%! @end deftypefn
-%@eod:
-
-% Copyright (C) 2011-2013 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 nargin>0 && ischar(varargin{1}) && isequal(varargin{1},'initialize')
-    ts = struct;
-    ts.data  = [];
-    ts.name  = {};
-    ts.tex   = {};
-    ts.dates = dates();
-    ts = class(ts,'dseries');
-    assignin('base','emptydseriesobject',ts);
-    return
-end
-
-ts = evalin('base','emptydseriesobject');
-
-switch nargin
-  case 0
-    %  Create an empty dseries object.
-    return
-  case 1
-    if isdates(varargin{1})
-        switch length(varargin{1})
-          case 0
-            error(['dseries::dseries: Input ' inputname(1) ' (identified as a dates object) must be non empty!'])
-          case 1
-            % Create an empty dseries object with an initial date.
-            ts.dates = varargin{1};
-          otherwise
-            % A range of dates is passed to the constructor
-            ts.dates = varargin{1};
-        end
-        return
-    elseif ischar(varargin{1})
-        % Create a dseries object loading data in a file (*.csv, *.m, *.mat).
-        if isempty(varargin{1})
-            error('dseries:: Wrong calling sequence! Input argument cannot be an empty string.')
-        elseif check_file_extension(varargin{1},'m')
-            [freq,init,data,varlist,tex] = load_m_file_data(varargin{1});
-        elseif check_file_extension(varargin{1},'mat')
-            [freq,init,data,varlist,tex] = load_mat_file_data(varargin{1});
-        elseif check_file_extension(varargin{1},'csv')
-            [freq,init,data,varlist] = load_csv_file_data(varargin{1});
-            tex = [];
-        elseif check_file_extension(varargin{1},'xls') || check_file_extension(varargin{1},'xlsx')
-            if isglobalinbase('options_')
-                % Check that the object is instantiated within a dynare session so that options_ global structure exists.
-                % Should provide latter a mechanism to pass range and sheet to dseries constructor...
-                range = evalin('base','options_.xls_range');
-                sheet = evalin('base','options_.xls_sheet');
-            else
-                % By default only the (whole) first sheet is loaded.
-                range = [];
-                sheet = [];
-            end
-            [freq,init,data,varlist] = load_xls_file_data(varargin{1}, sheet, range);
-            tex = [];
-        else
-            error(['dseries:: I''m not able to load data from ' inputname(1) '!'])
-        end
-        ts.data = data;
-        ts.name = varlist;
-        ts.dates = init:init+(nobs(ts)-1);
-        if isempty(tex)
-            ts.tex = name2tex(varlist);
-        else
-            ts.tex = tex;
-        end
-    elseif isnumeric(varargin{1}) && isequal(ndims(varargin{1}),2)
-        ts.data = varargin{1};
-        ts.name = default_name(vobs(ts));
-        ts.tex = name2tex(ts.name);
-        ts.dates = dates(1,1):dates(1,1)+(nobs(ts)-1);
-    end
-  case {2,3,4}
-    if isequal(nargin,2) && ischar(varargin{1}) && isdates(varargin{2})
-        % Instantiate dseries object with a data file and force the initial date to be as given by the second input argument.
-        ds = dseries(varargin{1});
-        ts = dseries(ds.data, varargin{2}, ds.name, ds.tex);
-        return
-    end
-    if isequal(nargin,2) && ischar(varargin{1}) && ischar(varargin{2}) && isdate(varargin{2})
-        % Instantiate dseries object with a data file and force the initial date to be as given by the second input argument.
-        ds = dseries(varargin{1});
-        ts = dseries(ds.data, dates(varargin{2}), ds.name, ds.tex);
-        return
-    end
-    a = varargin{1};
-    b = varargin{2};
-    if nargin<4
-        d = {};
-    else
-        d = varargin{4};
-        if ~iscell(d) && ~isempty(d)
-            d = cellstr(d);
-        end
-    end
-    if nargin<3
-        c = {};
-    else
-        c = varargin{3};
-        if ~iscell(c) && ~isempty(c)
-            c = cellstr(c);
-        end
-    end
-    % Get data, number of observations and number of variables.
-    ts.data = a;
-    % Get the first date and set the frequency.
-    if isempty(b)
-        init = dates(1,1);
-    elseif (isdates(b) && isequal(length(b),1))
-        init = b;
-    elseif ischar(b) && isdate(b)% Weekly, Monthly, Quaterly or Annual data (string).
-        init = dates(b);
-    elseif (isnumeric(b) && isscalar(b) && isint(b)) % Yearly data.
-        init = dates([num2str(b) 'Y']);
-    elseif isdates(b) % Range of dates
-        init = b(1);
-        if nobs(ts)>1 && ~isequal(b.ndat,nobs(ts))
-            message =   'dseries::dseries: If second input is a range, its number of elements must match ';
-            message = char(message, '                  the number of rows in the first input, unless the first input');
-            message = char(message, '                  has only one row.');
-            skipline()
-            disp(message);
-            error(' ');
-        elseif isequal(nobs(ts), 1)
-            ts.data = repmat(ts.data,b.ndat,1);
-        end
-        ts.dates = b;
-    elseif (isnumeric(b) && isint(b)) % Range of yearly dates.
-        message = 'dseries::dseries: Not implemented! If you need to define a range of years';
-        message = char(message, '                  you have to pass a dates object as the second input argument.');
-        disp(message)
-        error(' ')
-    else
-        error('dseries::dseries: Wrong calling sequence!');
-    end
-    % Get the names of the variables.
-    if ~isempty(c)
-        if vobs(ts)==length(c)
-            for i=1:vobs(ts)
-                ts.name = vertcat(ts.name, c(i));
-            end
-        else
-            error('dseries::dseries: The number of declared names does not match the number of variables!')
-        end
-    else
-        ts.name = default_name(vobs(ts));
-    end
-    if ~isempty(d)
-        if vobs(ts)==length(d)
-            for i=1:vobs(ts)
-                ts.tex = vertcat(ts.tex, d(i));
-            end
-        else
-            error('dseries::dseries: The number of declared tex names does not match the number of variables!')
-        end
-    else
-        ts.tex = name2tex(ts.name);
-    end
-  otherwise
-    error('dseries::dseries: Can''t instantiate the class, wrong calling sequence!')
-end
-
-if isempty(ts.dates)
-    ts.dates = init:init+(nobs(ts)-1);
-end
-
-%@test:1
-%$ % Test if we can instantiate an empty dseries object.
-%$ try
-%$     ts = dseries();
-%$     t(1) = 1;
-%$ catch
-%$     t(1) = 0;
-%$ end
-%$
-%$ T = all(t);
-%@eof:1
-
-%@test:2
-%$ t = zeros(4,1);
-%$
-%$ try
-%$     aa = dates('1938M11');
-%$     ts = dseries(aa);
-%$     t(1) = 1;
-%$ catch
-%$     t = 0;
-%$ end
-%$
-%$ if length(t)>1
-%$     t(2) = dyn_assert(ts.freq,12);
-%$     t(3) = dyn_assert(ts.init.freq,12);
-%$     t(4) = dyn_assert(ts.init.time,[1938, 11]);
-%$ end
-%$
-%$ T = all(t);
-%@eof:2
-
-%@test:3
-%$ t = zeros(6,1);
-%$
-%$ try
-%$     ts = dseries('dynseries_test_data.m');
-%$     t(1) = 1;
-%$ catch
-%$     t = 0;
-%$ end
-%$
-%$ if length(t)>1
-%$     t(2) = dyn_assert(ts.freq,4);
-%$     t(3) = dyn_assert(ts.init.freq,4);
-%$     t(4) = dyn_assert(ts.init.time,[1994, 3]);
-%$     t(5) = dyn_assert(ts.vobs,2);
-%$     t(6) = dyn_assert(ts.nobs,100);
-%$ end
-%$
-%$ T = all(t);
-%@eof:3
-
-%@test:4
-%$ t = zeros(6,1);
-%$
-%$ try
-%$     ts = dseries('dynseries_test_data.mat');
-%$     t(1) = 1;
-%$ catch
-%$     t = 0;
-%$ end
-%$
-%$ if length(t)>1
-%$     t(2) = dyn_assert(ts.freq,4);
-%$     t(3) = dyn_assert(ts.init.freq,4);
-%$     t(4) = dyn_assert(ts.init.time,[1994, 3]);
-%$     t(5) = dyn_assert(ts.vobs,2);
-%$     t(6) = dyn_assert(ts.nobs,100);
-%$ end
-%$
-%$ T = all(t);
-%@eof:4
-
-%@test:5
-%$ t = zeros(8,1);
-%$
-%$ try
-%$     ts = dseries('dynseries_test_data.csv');
-%$     t(1) = 1;
-%$ catch
-%$     t = 0;
-%$ end
-%$
-%$ if length(t)>1
-%$     t(2) = dyn_assert(ts.freq,4);
-%$     t(3) = dyn_assert(ts.init.freq,4);
-%$     t(4) = dyn_assert(ts.init.time,[1990, 1]);
-%$     t(5) = dyn_assert(ts.vobs,4);
-%$     t(6) = dyn_assert(ts.nobs,4);
-%$     t(7) = dyn_assert(ts.name,{'azert';'yuiop';'qsdfg';'jklm'});
-%$     t(8) = dyn_assert(ts.tex,{'azert';'yuiop';'qsdfg';'jklm'});
-%$ end
-%$
-%$ T = all(t);
-%@eof:5
-
-%@test:6
-%$ t = zeros(8,1);
-%$
-%$ try
-%$     ts = dseries(transpose(1:5),[]);
-%$     t(1) = 1;
-%$ catch
-%$     t = 0;
-%$ end
-%$
-%$ if length(t)>1
-%$     t(2) = dyn_assert(ts.freq,1);
-%$     t(3) = dyn_assert(ts.init.freq,1);
-%$     t(4) = dyn_assert(ts.init.time,[1, 1]);
-%$     t(5) = dyn_assert(ts.vobs,1);
-%$     t(6) = dyn_assert(ts.nobs,5);
-%$     t(7) = dyn_assert(ts.name,{'Variable_1'});
-%$     t(8) = dyn_assert(ts.tex,{'Variable\\_1'});
-%$ end
-%$
-%$ T = all(t);
-%@eof:6
-
-%@test:7
-%$ t = zeros(8,1);
-%$
-%$ try
-%$     ts = dseries(transpose(1:5),'1950Q1');
-%$     t(1) = 1;
-%$ catch
-%$     t = 0;
-%$ end
-%$
-%$ if length(t)>1
-%$     t(2) = dyn_assert(ts.freq,4);
-%$     t(3) = dyn_assert(ts.init.freq,4);
-%$     t(4) = dyn_assert(ts.init.time,[1950, 1]);
-%$     t(5) = dyn_assert(ts.vobs,1);
-%$     t(6) = dyn_assert(ts.nobs,5);
-%$     t(7) = dyn_assert(ts.name,{'Variable_1'});
-%$     t(8) = dyn_assert(ts.tex,{'Variable\\_1'});
-%$ end
-%$
-%$ T = all(t);
-%@eof:7
-
-%@test:8
-%$ t = zeros(8,1);
-%$
-%$ try
-%$     ts = dseries([transpose(1:5), transpose(6:10)],'1950q1',{'Output'; 'Consumption'}, {'Y_t'; 'C_t'});
-%$     t(1) = 1;
-%$ catch
-%$     t = 0;
-%$ end
-%$
-%$ if length(t)>1
-%$     t(2) = dyn_assert(ts.freq,4);
-%$     t(3) = dyn_assert(ts.init.freq,4);
-%$     t(4) = dyn_assert(ts.init.time,[1950, 1]);
-%$     t(5) = dyn_assert(ts.vobs,2);
-%$     t(6) = dyn_assert(ts.nobs,5);
-%$     t(7) = dyn_assert(ts.name,{'Output'; 'Consumption'});
-%$     t(8) = dyn_assert(ts.tex,{'Y_t'; 'C_t'});
-%$ end
-%$
-%$ T = all(t);
-%@eof:8
-
-%@test:9
-%$ try
-%$     ts = dseries('dynseries_test_data-1.xls');
-%$     t(1) = 1;
-%$ catch
-%$     t(1) = 0;
-%$ end
-%$
-%$ if t(1)
-%$     t(2) = dyn_assert(ts.freq,4);
-%$     t(3) = dyn_assert(ts.init.freq,4);
-%$     t(4) = dyn_assert(ts.init.time,[1990, 1]);
-%$     t(5) = dyn_assert(ts.vobs,3);
-%$     t(6) = dyn_assert(ts.nobs,5);
-%$     t(7) = dyn_assert(ts.name,{'GDP';'Consumption';'CPI'});
-%$     t(8) = dyn_assert(ts.tex,{'GDP';'Consumption';'CPI'});
-%$ end
-%$
-%$ T = all(t);
-%@eof:9
-
-%@test:10
-%$ try
-%$     ts = dseries('dynseries_test_data-2.xls');
-%$     t(1) = 1;
-%$ catch
-%$     t(1) = 0;
-%$ end
-%$
-%$ if t(1)
-%$     t(2) = dyn_assert(ts.freq,4);
-%$     t(3) = dyn_assert(ts.init.freq,4);
-%$     t(4) = dyn_assert(ts.init.time,[1990, 1]);
-%$     t(5) = dyn_assert(ts.vobs,3);
-%$     t(6) = dyn_assert(ts.nobs,5);
-%$     t(7) = dyn_assert(ts.name,{'Variable_1';'Variable_2';'Variable_3'});
-%$     t(8) = dyn_assert(ts.tex,{'Variable\\_1';'Variable\\_2';'Variable\\_3'});
-%$ end
-%$
-%$ T = all(t);
-%@eof:10
-
-%@test:11
-%$ try
-%$     ts = dseries('dynseries_test_data-3.xls');
-%$     t(1) = 1;
-%$ catch
-%$     t(1) = 0;
-%$ end
-%$
-%$ if t(1)
-%$     t(2) = dyn_assert(ts.freq,1);
-%$     t(3) = dyn_assert(ts.init.freq,1);
-%$     t(4) = dyn_assert(ts.init.time,[1, 1]);
-%$     t(5) = dyn_assert(ts.vobs,3);
-%$     t(6) = dyn_assert(ts.nobs,5);
-%$     t(7) = dyn_assert(ts.name,{'Variable_1';'Variable_2';'Variable_3'});
-%$     t(8) = dyn_assert(ts.tex,{'Variable\\_1';'Variable\\_2';'Variable\\_3'});
-%$ end
-%$
-%$ T = all(t);
-%@eof:11
-
-%@test:12
-%$ try
-%$     ts = dseries('dynseries_test_data-4.xls');
-%$     t(1) = 1;
-%$ catch
-%$     t(1) = 0;
-%$ end
-%$
-%$ if t(1)
-%$     t(2) = dyn_assert(ts.freq,1);
-%$     t(3) = dyn_assert(ts.init.freq,1);
-%$     t(4) = dyn_assert(ts.init.time,[1, 1]);
-%$     t(5) = dyn_assert(ts.vobs,3);
-%$     t(6) = dyn_assert(ts.nobs,5);
-%$     t(7) = dyn_assert(ts.name,{'GDP';'Consumption';'CPI'});
-%$     t(8) = dyn_assert(ts.tex,{'GDP';'Consumption';'CPI'});
-%$ end
-%$
-%$ T = all(t);
-%@eof:12
-
-%@test:13
-%$ t = zeros(6,1);
-%$
-%$ try
-%$     ts = dseries(transpose(1:4),dates('1990Q1'):dates('1990Q4'));
-%$     t(1) = 1;
-%$ catch
-%$     t = 0;
-%$ end
-%$
-%$ if length(t)>1
-%$     t(2) = dyn_assert(ts.freq,4);
-%$     t(3) = dyn_assert(ts.init.freq,4);
-%$     t(4) = dyn_assert(ts.init.time,[1990, 1]);
-%$     t(5) = dyn_assert(ts.vobs,1);
-%$     t(6) = dyn_assert(ts.nobs,4);
-%$ end
-%$
-%$ T = all(t);
-%@eof:13
-
-%@test:14
-%$ t = zeros(7,1);
-%$
-%$ try
-%$     ts = dseries([1, 2],dates('1990Q1'):dates('1990Q4'));
-%$     t(1) = 1;
-%$ catch
-%$     t = 0;
-%$ end
-%$
-%$ if length(t)>1
-%$     t(2) = dyn_assert(ts.freq,4);
-%$     t(3) = dyn_assert(ts.init.freq,4);
-%$     t(4) = dyn_assert(ts.init.time,[1990, 1]);
-%$     t(5) = dyn_assert(ts.vobs,2);
-%$     t(6) = dyn_assert(ts.nobs,4);
-%$     t(7) = dyn_assert(ts.data, [ones(4,1), 2*ones(4,1)]);
-%$ end
-%$
-%$ T = all(t);
-%@eof:14
-
-%@test:15
-%$ try
-%$     ts = dseries([1; 2],dates('1990Q1'):dates('1990Q4'));
-%$     t = 0;
-%$ catch
-%$     t = 1;
-%$ end
-%$
-%$ T = all(t);
-%@eof:15
diff --git a/matlab/@dseries/end.m b/matlab/@dseries/end.m
deleted file mode 100644
index 8f60971367a15c179134630fbabde65724df11c6..0000000000000000000000000000000000000000
--- a/matlab/@dseries/end.m
+++ /dev/null
@@ -1,21 +0,0 @@
-function lastIndex = end(o, k, n)
-
-% 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(k==1 && n==1, 'dseries::end: Wrong indexing!');
-lastIndex = vobs(o);
\ No newline at end of file
diff --git a/matlab/@dseries/eq.m b/matlab/@dseries/eq.m
deleted file mode 100644
index 7664cb094a2bbb221c10d1ce09e8ac01a81f65d0..0000000000000000000000000000000000000000
--- a/matlab/@dseries/eq.m
+++ /dev/null
@@ -1,89 +0,0 @@
-function C = eq(A,B) % --*-- Unitary tests --*--
-
-% Overloads eq (==) operator.
-%
-% INPUTS 
-%  o A      dseries object (T periods, N variables).
-%  o B      dseries object (T periods, N variables).
-%
-% OUTPUTS 
-%  o C      T*N matrix of zeros and ones. Element C(t,n) is nonzero iff observation t of variable n in A and B are equal.  
-%
-% REMARKS 
-%  If the number of variables, the number of observations or the frequencies are different in A and B, the function returns a zero scalar. 
-
-% Copyright (C) 2013 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 nargin~=2
-    error('dseries::eq: I need exactly two input arguments!')
-end
-
-if ~(isdseries(A) && isdseries(B))
-    error('dseries::eq: Both input arguments must be dseries objects!')
-end
-
-if ~isequal(nobs(A), nobs(B))
-    warning('dseries::eq: Both input arguments should have the same number of observations!')
-    C = 0;
-    return
-end
-
-if ~isequal(vobs(A), vobs(B))
-    warning('dseries::eq: Both input arguments should have the same number of observations!')
-    C = 0;
-    return
-end
-
-if ~isequal(frequency(A),frequency(B))
-    warning('dseries::eq: Both input arguments should have the same frequencies!')
-    C = 0;
-    return
-end
-
-if ~isequal(firstdate(A),firstdate(B))
-    warning('dseries::eq: Both input arguments should have the same initial period!')
-    C = 0;
-    return
-end
-
-C = eq(A.data, B.data);
-
-%@test:1
-%$ % Define a datasets.
-%$ A = rand(10,3);
-%$
-%$ % Define names
-%$ A_name = {'A1';'A2';'A3'};
-%$
-%$ t = zeros(2,1);
-%$
-%$ % Instantiate a time series object.
-%$ try
-%$    ts1 = dseries(A,[],A_name,[]);
-%$    ts2 = ts1;
-%$    a = eq(ts1,ts2);
-%$    t(1) = 1;
-%$ catch
-%$    t = 0;
-%$ end
-%$
-%$ if length(t)>1
-%$    t(2) = dyn_assert(a,ones(10,3));
-%$ end
-%$ T = all(t);
-%@eof:1
\ No newline at end of file
diff --git a/matlab/@dseries/exp.m b/matlab/@dseries/exp.m
deleted file mode 100644
index 06ed6a1f03291cb11d51ea5fcd35855c87987cab..0000000000000000000000000000000000000000
--- a/matlab/@dseries/exp.m
+++ /dev/null
@@ -1,52 +0,0 @@
-function ts = exp(ts)
-% Apply the exponential function to a Dynare time series object.
-
-%@info:
-%! @deftypefn {Function File} {@var{ts} =} log(@var{ts})
-%! @anchor{exp}
-%! Apply the exponential function to a Dynare time series object.
-%!
-%! @strong{Inputs}
-%! @table @var
-%! @item ts
-%! Dynare time series object, instantiated by @ref{dseries}
-%! @end table
-%!
-%! @strong{Outputs}
-%! @table @var
-%! @item ts
-%! Dynare time series object with transformed data field.
-%! @end table
-%!
-%! @strong{This function is called by:}
-%! None.
-%!
-%! @strong{This function calls:}
-%! None.
-%!
-%! @end deftypefn
-%@eod:
-
-% Copyright (C) 2011-2013 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/>.
-
-ts.data = exp(ts.data);
-
-for i=1:vobs(ts)
-    ts.name(i) = {['exp(' ts.name{i} ')']};
-    ts.tex(i) = {['\exp(' ts.tex{i} ')']};
-end
\ No newline at end of file
diff --git a/matlab/@dseries/extract.m b/matlab/@dseries/extract.m
deleted file mode 100644
index c280115ee4f4e515f62a21ce189251816468cfa8..0000000000000000000000000000000000000000
--- a/matlab/@dseries/extract.m
+++ /dev/null
@@ -1,230 +0,0 @@
-function A = extract(B,varargin) % --*-- Unitary tests --*--
-
-% Extract some variables from a database.
-    
-% Copyright (C) 2012-2013 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/>.
-
-A = dseries();
-
-% Get the names of the variables to be extracted from dseries object B.
-VariableName_ = {};
-for i=1:nargin-1
-    VariableName = varargin{i};
-    idArobase = strfind(VariableName,'@');
-    if mod(length(idArobase),2)
-        error('dseries::extract: (Implicit loops) The number of @ symbols must be even!')
-    end
-    idBracket.open = strfind(VariableName,'[');
-    idBracket.close = strfind(VariableName,']');
-    if ~isequal(length(idBracket.open),length(idBracket.open))
-        error('dseries::extract: (Matlab/Octave''s regular expressions) Check opening and closing square brackets!')
-    end
-    if length(idArobase)
-        NumberOfImplicitLoops = .5*length(idArobase);
-        idComma = cell(NumberOfImplicitLoops,1);
-        expressions = cell(NumberOfImplicitLoops,1);
-        for i=0:NumberOfImplicitLoops-1
-            idComma(i+1) = { strfind(VariableName(idArobase(2*i+1)+1:idArobase(2*i+2)-1),',') };
-            expressions(i+1) = { VariableName(idArobase(2*i+1)+1:idArobase(2*i+2)-1) };
-        end
-        if any(cellfun(@isempty,idComma))
-            error('dseries::extract: (Implicit loops) Wrong syntax!')
-        end
-        switch NumberOfImplicitLoops
-          case 1
-            expression = expressions{1};
-            idVariables_ = [];
-            while ~isempty(expression)
-                [token, expression] = strtok(expression,',');             
-                candidate = [VariableName(1:idArobase(1)-1), token, VariableName(idArobase(2)+1:end)];
-                id = find(strcmp(candidate,B.name));
-                if isempty(id)
-                    error(['dseries::extract: (Implicit loops) Variable ''' candidate ''' does not exist in dseries object ''' inputname(1) '''!'])
-                else
-                    idVariables_ = [idVariables_; id];
-                end
-            end
-            VariableName = B.name(idVariables_);
-          case 2
-            idVariables_ = [];
-            expression_1 = expressions{1};
-            while ~isempty(expression_1)
-                [token_1, expression_1] = strtok(expression_1,',');
-                expression_2 = expressions{2};
-                while ~isempty(expression_2)
-                    [token_2, expression_2] = strtok(expression_2,',');
-                    candidate = [VariableName(1:idArobase(1)-1), token_1, VariableName(idArobase(2)+1:idArobase(3)-1),  token_2, VariableName(idArobase(4)+1:end)];
-                    id = find(strcmp(candidate,B.name));
-                    if isempty(id)
-                        error(['dseries::extract: (Implicit loops) Variable ''' candidate ''' does not exist in dseries object ''' inputname(1) '''!'])
-                    else
-                        idVariables_ = [idVariables_; id];
-                    end
-                end
-            end
-            VariableName = B.name(idVariables_);
-          otherwise
-            error('dseries::extract: (Implicit loops) Cannot unroll more than two implicit loops!')
-        end
-        VariableName_ = vertcat(VariableName_,VariableName);
-    elseif length(idBracket.open)
-        % Matlab/Octave's regular expressions.
-        first_block_id = 0;
-        last_block_id = 0;
-        idVariables = find(isnotempty_cell(regexp(B.name,VariableName,'match')));
-        if isempty(idVariables)
-            error(['dseries::extract: Can''t find any variable matching ' VariableName ' pattern!'])
-        end
-        idVariables_ = [];
-        for j = 1:length(idVariables)
-            first_block_flag = 0;
-            if (first_block_id && strcmp(B.name{idVariables(j)}(1:first_block_id),VariableName(1:first_block_id))) || ~first_block_id
-                first_block_flag = 1;
-            end
-            last_block_flag = 0;
-            if (last_block_id && strcmp(B.name{idVariables(j)}(end-last_block_id:end),VariableName(end-last_block_id:end))) || ~last_block_id
-                last_block_flag = 1;
-            end
-            if first_block_flag && last_block_flag
-                idVariables_ = [idVariables_; idVariables(j)];
-            end
-        end
-        VariableName = B.name(idVariables_);
-        VariableName_ = vertcat(VariableName_,VariableName);
-    else
-        VariableName_ = varargin(:);
-    end
-end
-
-% Remove trailing white spaces if any
-VariableName_ = strtrim(VariableName_);
-
-% Get indices of the selected variables
-idVariableName = NaN(length(VariableName_),1);
-for i = 1:length(idVariableName)
-    idx = find(strcmp(VariableName_{i},B.name));
-    if isempty(idx)
-        error(['dseries::extract: Variable ' VariableName_{i} ' is not a member of ' inputname(1) '!'])
-    end
-    idVariableName(i) = idx;
-end
-
-A.data = B.data(:,idVariableName);
-A.dates = B.dates;
-A.name = B.name(idVariableName);
-A.tex = B.tex(idVariableName);
-
-function b = isnotempty_cell(CellArray)
-    CellArrayDimension = size(CellArray);
-    b = NaN(CellArrayDimension);
-    for i=1:CellArrayDimension(1)
-        for j = 1:CellArrayDimension(2)
-            b(i,j) = ~isempty(CellArray{i,j});
-        end
-    end
-    
-    
-%@test:1
-%$ % Define a data set.
-%$ A = rand(10,24);
-%$
-%$ % Define names
-%$ A_name = {'GDP_1';'GDP_2';'GDP_3'; 'GDP_4'; 'GDP_5'; 'GDP_6'; 'GDP_7'; 'GDP_8'; 'GDP_9'; 'GDP_10'; 'GDP_11'; 'GDP_12'; 'HICP_1';'HICP_2';'HICP_3'; 'HICP_4'; 'HICP_5'; 'HICP_6'; 'HICP_7'; 'HICP_8'; 'HICP_9'; 'HICP_10'; 'HICP_11'; 'HICP_12';};
-%$
-%$ % Instantiate a time series object.
-%$ ts1 = dseries(A,[],A_name,[]);
-%$
-%$ % Call the tested method.
-%$ a = ts1{'GDP_@1,2,3,4,5@'};
-%$ b = ts1{'@GDP,HICP@_1'};
-%$
-%$ % Expected results.
-%$ e1.data = A(:,1:5);
-%$ e1.nobs = 10;
-%$ e1.vobs = 5;
-%$ e1.name = {'GDP_1';'GDP_2';'GDP_3'; 'GDP_4'; 'GDP_5'};
-%$ e1.freq = 1;
-%$ e1.init = dates(1,1);
-%$ e2.data = A(:,[1, 13]);
-%$ e2.nobs = 10;
-%$ e2.vobs = 2;
-%$ e2.name = {'GDP_1';'HICP_1'};
-%$ e2.freq = 1;
-%$ e2.init = dates(1,1);
-%$
-%$ % Check results.
-%$ t(1) = dyn_assert(e1.data,a.data);
-%$ t(2) = dyn_assert(e1.nobs,a.nobs);
-%$ t(3) = dyn_assert(e1.vobs,a.vobs);
-%$ t(4) = dyn_assert(e1.name,a.name);
-%$ t(5) = dyn_assert(isequal(e1.init,a.init),1);
-%$ t(6) = dyn_assert(e2.data,b.data);
-%$ t(7) = dyn_assert(e2.nobs,b.nobs);
-%$ t(8) = dyn_assert(e2.vobs,b.vobs);
-%$ t(9) = dyn_assert(e2.name,b.name);
-%$ t(10) = dyn_assert(isequal(e2.init,b.init),1);
-%$ T = all(t);
-%@eof:1
-
-
-%@test:2
-%$ % Define a data set.
-%$ A = rand(10,24);
-%$
-%$ % Define names
-%$ A_name = {'GDP_1';'GDP_2';'GDP_3'; 'GDP_4'; 'GDP_5'; 'GDP_6'; 'GDP_7'; 'GDP_8'; 'GDP_9'; 'GDP_10'; 'GDP_11'; 'GDP_12'; 'HICP_1';'HICP_2';'HICP_3'; 'HICP_4'; 'HICP_5'; 'HICP_6'; 'HICP_7'; 'HICP_8'; 'HICP_9'; 'HICP_10'; 'HICP_11'; 'HICP_12';};
-%$
-%$ % Instantiate a time series object.
-%$ ts1 = dseries(A,[],A_name,[]);
-%$
-%$ % Call the tested method.
-%$ try
-%$   a = ts1{'GDP_@1,2,3,4,55@'};
-%$   t = 0;
-%$ catch
-%$   t = 1;
-%$ end
-%$
-%$ T = all(t);
-%@eof:2
-
-
-%@test:3
-%$ % Define a data set.
-%$ A = rand(10,24);
-%$
-%$ % Define names
-%$ A_name = {'GDP_1';'GDP_2';'GDP_3'; 'GDP_4'; 'GDP_5'; 'GDP_6'; 'GDP_7'; 'GDP_8'; 'GDP_9'; 'GDP_10'; 'GDP_11'; 'GDP_12'; 'HICP_1';'HICP_2';'HICP_3'; 'HICP_4'; 'HICP_5'; 'HICP_6'; 'HICP_7'; 'HICP_8'; 'HICP_9'; 'HICP_10'; 'HICP_11'; 'HICP_12';};
-%$
-%$ % Instantiate a time series object.
-%$ ts1 = dseries(A,[],A_name,[]);
-%$
-%$ % Call the tested method.
-%$ try
-%$   a = ts1{'@GDP,HICP@_@1,2,3,4,5@'};
-%$   t = 1;
-%$ catch
-%$   t = 0;
-%$ end
-%$
-%$ if t(1)
-%$   t(2) = dyn_assert(a.name,{'GDP_1';'GDP_2';'GDP_3';'GDP_4';'GDP_5';'HICP_1';'HICP_2';'HICP_3';'HICP_4';'HICP_5'});
-%$ end
-%$
-%$ T = all(t);
-%@eof:3
diff --git a/matlab/@dseries/firstdate.m b/matlab/@dseries/firstdate.m
deleted file mode 100644
index 9a7db50ea427161d35e0a58e8a83900a07d14349..0000000000000000000000000000000000000000
--- a/matlab/@dseries/firstdate.m
+++ /dev/null
@@ -1,20 +0,0 @@
-function f = firstdate(o)
-
-% 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/>.
-
-f = o.dates(1);
\ No newline at end of file
diff --git a/matlab/@dseries/frequency.m b/matlab/@dseries/frequency.m
deleted file mode 100644
index c2befb5477059cc992cc9f2fb4d0efd95f9fb892..0000000000000000000000000000000000000000
--- a/matlab/@dseries/frequency.m
+++ /dev/null
@@ -1,20 +0,0 @@
-function f = frequency(o)
-
-% 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/>.
-
-f = o.dates.freq;
\ No newline at end of file
diff --git a/matlab/@dseries/horzcat.m b/matlab/@dseries/horzcat.m
deleted file mode 100644
index e4d9cbee7b7dc51235cbc23c074745e5f3dcac6b..0000000000000000000000000000000000000000
--- a/matlab/@dseries/horzcat.m
+++ /dev/null
@@ -1,317 +0,0 @@
-function B = horzcat(varargin) % --*-- Unitary tests --*--
-
-% Overloads horzcat method for dseries objects.
-%
-% INPUTS 
-%  o A1    dseries object.
-%  o A2    dseries object.
-%  o ...
-%
-% OUTPUTS 
-%  o B     dseries object.
-%
-% EXAMPLE 1 
-%  If A, B and C are dseries objects the following syntax:
-%    
-%    D = [A, B, C] ;
-%
-%  Defines a dseries object D containing the variables appearing in A, B and C.
-%
-% REMARKS 
-%  o A1, A2, ... must not have common variables.
-    
-% Copyright (C) 2011-2013 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/>.
-
-switch nargin
-  case 0
-    B = dseries();
-  case 1
-    B = varargin{1};
-  otherwise
-    B = concatenate(varargin{1}, varargin{2});
-    if nargin>2
-        B = horzcat(B, varargin{3:end});
-    end
-end
-
-function a = concatenate(b,c)
-    [n,message] = common_strings_in_cell_arrays(b.name,c.name);
-    if isempty(b)
-        a = c;
-        return
-    end
-    if isempty(c)
-        a = b;
-        return
-    end
-    if n
-        error(['dseries::horzcat: I cannot concatenate dseries objects with common variable names (' message ')!'])
-    end
-    if ~isequal(frequency(b),frequency(c))
-        error('dseries::horzcat: All time series objects must have common frequency!')
-    else
-        a = dseries();
-    end
-    d_nobs_flag = 0;
-    if ~isequal(nobs(b),nobs(c))
-        d_nobs_flag = 1;
-    end
-    d_init_flag = 0;
-    if ~isequal(firstdate(b),firstdate(c))
-        d_init_flag = 1;
-    end
-    a.name = vertcat(b.name,c.name);
-    a.tex  = vertcat(b.tex,c.tex);
-    if ~( d_nobs_flag(1) || d_init_flag(1) )
-        a.data = [b.data,c.data];
-        a.dates = b.dates;
-    else
-        nobs_b = nobs(b);
-        nobs_c = nobs(c);
-        if firstdate(b)<=firstdate(c)
-            if firstdate(b)<firstdate(c)
-                c.data = [NaN(firstdate(c)-firstdate(b), vobs(c)); c.data];
-            end
-        else
-            b.data = [NaN(firstdate(b)-firstdate(c), vobs(b)); b.data];
-        end
-        b_last_date = firstdate(b)+nobs_b;
-        c_last_date = firstdate(c)+nobs_c;
-        if b_last_date<c_last_date
-            b.data = [b.data; NaN(c_last_date-b_last_date, vobs(b))];
-        elseif b_last_date>c_last_date
-            c.data = [c.data; NaN(b_last_date-c_last_date, vobs(c))];
-        end
-        a.data = [b.data, c.data];
-        a.dates = unique([b.dates, c.dates]);
-    end
-
-%@test:1
-%$ % Define a data set.
-%$ A = [transpose(1:10),2*transpose(1:10)];
-%$ B = [transpose(1:10),2*transpose(1:10)];
-%$
-%$ % Define names
-%$ A_name = {'A1';'A2'};
-%$ B_name = {'B1';'B2'};
-%$
-%$ % Define expected results.
-%$ e.init = dates(1,1);
-%$ e.freq = 1;
-%$ e.name = {'A1';'A2';'B1';'B2'};
-%$ e.data = [A,B];
-%$
-%$ % Instantiate two time series objects.
-%$ ts1 = dseries(A,[],A_name,[]);
-%$ ts2 = dseries(B,[],B_name,[]);
-%$
-%$ % Call the tested method.
-%$ ts3 = [ts1,ts2];
-%$
-%$ % Check the results.
-%$
-%$ t(1) = dyn_assert(isequal(ts3.init,e.init),1);
-%$ t(2) = dyn_assert(ts3.freq,e.freq);
-%$ t(3) = dyn_assert(ts3.data,e.data);
-%$ t(4) = dyn_assert(ts3.name,e.name);
-%$ T = all(t);
-%@eof:1
-
-%@test:2
-%$ % Define a data set.
-%$ A = [transpose(1:10),2*transpose(1:10)];
-%$ B = [transpose(5:12),2*transpose(5:12)];
-%$
-%$ % Define names
-%$ A_name = {'A1';'A2'};
-%$ B_name = {'B1';'B2'};
-%$
-%$ % Define initial date
-%$ A_init = 2001;
-%$ B_init = 2005;
-%$
-%$ % Define expected results.
-%$ e.init = dates('2001Y');
-%$ e.freq = 1;
-%$ e.name = {'A1';'A2';'B1';'B2'};
-%$ e.data = [ [A; NaN(2,2)], [NaN(4,2); B]];
-%$
-%$ % Instantiate two time series objects.
-%$ ts1 = dseries(A,A_init,A_name,[]);
-%$ ts2 = dseries(B,B_init,B_name,[]);
-%$
-%$ % Call the tested method.
-%$ ts3 = [ts1,ts2];
-%$
-%$ % Check the results.
-%$ t(1) = dyn_assert(isequal(ts3.init,e.init),1);
-%$ t(2) = dyn_assert(ts3.freq,e.freq);
-%$ t(3) = dyn_assert(ts3.data,e.data);
-%$ t(4) = dyn_assert(ts3.name,e.name);
-%$ T = all(t);
-%@eof:2
-
-%@test:3
-%$ % Define a data set.
-%$ A = [transpose(1:7),2*transpose(1:7)];
-%$ B = [transpose(5:11),2*transpose(5:11)];
-%$
-%$ % Define names
-%$ A_name = {'A1';'A2'};
-%$ B_name = {'B1';'B2'};
-%$
-%$ % Define initial date
-%$ A_init = '1950Q1';
-%$ B_init = '1950Q3';
-%$
-%$ % Define expected results.
-%$ e.freq = 4;
-%$ e.init = dates('1950Q1');
-%$ e.name = {'A1';'A2';'B1';'B2'};
-%$ e.data = [ [A; NaN(2,2)], [NaN(2,2); B]];
-%$
-%$ % Instantiate two time series objects.
-%$ ts1 = dseries(A,A_init,A_name,[]);
-%$ ts2 = dseries(B,B_init,B_name,[]);
-%$
-%$ % Call the tested method.
-%$ ts3 = [ts1,ts2];
-%$
-%$ % Check the results.
-%$ t(1) = dyn_assert(isequal(ts3.init,e.init),1);
-%$ t(2) = dyn_assert(ts3.freq,e.freq);
-%$ t(3) = dyn_assert(ts3.data,e.data);
-%$ t(4) = dyn_assert(ts3.name,e.name);
-%$ T = all(t);
-%@eof:3
-
-%@test:4
-%$ % Define a data set.
-%$ A = [transpose(1:7),2*transpose(1:7)];
-%$ B = [transpose(5:9),2*transpose(5:9)];
-%$
-%$ % Define names
-%$ A_name = {'A1';'A2'};
-%$ B_name = {'B1';'B2'};
-%$
-%$ % Define initial date
-%$ A_init = '1950Q1';
-%$ B_init = '1950Q3';
-%$
-%$ % Define expected results.
-%$ e.init = dates(A_init);
-%$ e.freq = 4;
-%$ e.name = {'A1';'A2';'B1';'B2'};
-%$ e.data = [ A, [NaN(2,2); B]];
-%$
-%$ % Instantiate two time series objects.
-%$ ts1 = dseries(A,A_init,A_name,[]);
-%$ ts2 = dseries(B,B_init,B_name,[]);
-%$
-%$ % Call the tested method.
-%$ ts3 = [ts1,ts2];
-%$
-%$ % Check the results.
-%$ t(1) = dyn_assert(isequal(ts3.init,e.init),1);
-%$ t(2) = dyn_assert(ts3.freq,e.freq);
-%$ t(3) = dyn_assert(ts3.data,e.data);
-%$ t(4) = dyn_assert(ts3.name,e.name);
-%$ T = all(t);
-%@eof:4
-
-%@test:5
-%$ % Define a data set.
-%$ A = [transpose(1:10),2*transpose(1:10)];
-%$ B = [transpose(1:10),3*transpose(1:10)];
-%$ C = [transpose(1:10),4*transpose(1:10)];
-%$
-%$ % Define names
-%$ A_name = {'A1';'A2'};
-%$ B_name = {'B1';'B2'};
-%$ C_name = {'C1';'C2'};
-%$
-%$ % Define expected results.
-%$ e.init = dates(1,1);
-%$ e.freq = 1;
-%$ e.name = {'A1';'A2';'B1';'B2';'C1';'C2'};
-%$ e.data = [A,B,C];
-%$
-%$ % Instantiate two time series objects.
-%$ ts1 = dseries(A,[],A_name,[]);
-%$ ts2 = dseries(B,[],B_name,[]);
-%$ ts3 = dseries(C,[],C_name,[]);
-%$
-%$ % Call the tested method.
-%$ ts4 = [ts1,ts2,ts3];
-%$
-%$ % Check the results.
-%$ t(1) = dyn_assert(isequal(ts4.init,e.init),1);
-%$ t(2) = dyn_assert(ts4.freq,e.freq);
-%$ t(3) = dyn_assert(ts4.data,e.data);
-%$ t(4) = dyn_assert(ts4.name,e.name);
-%$ T = all(t);
-%@eof:5
-
-%@test:6
-%$ % Define a data set.
-%$ A = [transpose(1:10),2*transpose(1:10)];
-%$ B = [transpose(1:10),2*transpose(1:10)];
-%$
-%$ % Define names
-%$ A_name = {'A1';'A2'};
-%$ B_name = {'B1';'A2'};
-%$
-%$ % Instantiate two time series objects.
-%$ ts1 = dseries(A,[],A_name,[]);
-%$ ts2 = dseries(B,[],B_name,[]);
-%$
-%$ % Call the tested method.
-%$ try
-%$   ts3 = [ts1,ts2];
-%$   t = 0;
-%$ catch
-%$   t = 1;
-%$ end
-%$
-%$ T = t;
-%@eof:6
-
-%@test:7
-%$ % Define X
-%$ X = randn(30,2);
-%$
-%$ % Instantiate two time series objects.
-%$ ts1 = dseries();
-%$ ts2 = dseries(randn(30,2),'1950Q2');
-%$
-%$ % Call the tested method.
-%$ try
-%$   ts3 = [ts1,ts2];
-%$   t = 1;
-%$ catch
-%$   t = 0;
-%$ end
-%$
-%$ if t(1)
-%$   t(2) = dyn_assert(ts3.freq,4);
-%$   t(3) = dyn_assert(ts3.data,X);
-%$   t(4) = dyn_assert(isequal(ts3.dates(1),dates('1950Q2')),1);
-%$ end
-%$
-%$ T = t;
-%@eof:7
diff --git a/matlab/@dseries/hpcycle.m b/matlab/@dseries/hpcycle.m
deleted file mode 100644
index ad1ec56fa389003b32d40d98e4336877d24781d6..0000000000000000000000000000000000000000
--- a/matlab/@dseries/hpcycle.m
+++ /dev/null
@@ -1,96 +0,0 @@
-function ts = hpcycle(ts, lambda) % --*-- Unitary tests --*--
-
-% ts = hpcycle(ts, lambda)
-%
-% Extracts the cycle component from a dseries object using Hodrick Prescott filter.
-%
-% INPUTS 
-%  o ts         dseries object.
-%  o lambda     positive scalar, trend smoothness parameter.
-%
-% OUTPUTS 
-%  o ts         dseries object, with time series replaced by the cyclical component of the original time series.
-
-% Copyright (C) 2013 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 nargin>1 
-    if lambda<=0
-        error(['dseries::hpcycle: Lambda must be a positive integer!'])
-    end
-else
-    lambda = [];
-end 
-
-for i=1:vobs(ts)
-    ts.name(i) = {['hpcycle(' ts.name{i} ')']};
-    ts.tex(i) = {['\text{hpcycle}(' ts.tex{i} ')']};
-end
-
-[junk, data] = sample_hp_filter(ts.data,lambda);
-ts.data = data;
-
-%@test:1
-%$ plot_flag = 0;
-%$
-%$ % Create a dataset.
-%$ e = .2*randn(200,1);
-%$ u = randn(200,1);
-%$ stochastic_trend = cumsum(e); 
-%$ deterministic_trend = .1*transpose(1:200);
-%$ x = zeros(200,1);
-%$ for i=2:200
-%$    x(i) = .9*x(i-1) + e(i);
-%$ end
-%$ y = x + stochastic_trend + deterministic_trend;
-%$
-%$ % Test the routine.
-%$ try
-%$     ts0 = dseries(y,'1950Q1');
-%$     ts1 = dseries(x,'1950Q1');
-%$     ts2 = ts0.hpcycle();
-%$     t(1) = 1;
-%$ catch
-%$     t(1) = 0;
-%$ end
-%$
-%$ if t(1)
-%$     t(2) = dyn_assert(ts2.freq,4);
-%$     t(3) = dyn_assert(ts2.init.freq,4);
-%$     t(4) = dyn_assert(ts2.init.time,[1950, 1]);
-%$     t(5) = dyn_assert(ts2.vobs,1);
-%$     t(6) = dyn_assert(ts2.nobs,200);
-%$ end
-%$
-%$ % Show results
-%$ if plot_flag
-%$     plot(ts1.data,'-k'); % Plot of the stationary component.
-%$     hold on
-%$     plot(ts2.data,'--r');          % Plot of the filtered y.
-%$     hold off
-%$     axis tight
-%$     id = get(gca,'XTick');
-%$     set(gca,'XTickLabel',strings(ts1.dates(id)));
-%$     legend({'Stationary component of y', 'Filtered y'})
-%$     print('-depsc2','../doc/dynare.plots/HPCycle.eps')
-%$     system('convert -density 300 ../doc/dynare.plots/HPCycle.eps ../doc/dynare.plots/HPCycle.png');
-%$     system('convert -density 300 ../doc/dynare.plots/HPCycle.eps ../doc/dynare.plots/HPCycle.pdf');
-%$     system('convert -density 300 ../doc/dynare.plots/HPCycle.eps ../doc/dynare.plots/HPCycle.jpg');
-%$ end
-%$
-%$ T = all(t);
-%@eof:1
\ No newline at end of file
diff --git a/matlab/@dseries/hptrend.m b/matlab/@dseries/hptrend.m
deleted file mode 100644
index 754b3212a430b2961ab04328d07900300ef1688f..0000000000000000000000000000000000000000
--- a/matlab/@dseries/hptrend.m
+++ /dev/null
@@ -1,94 +0,0 @@
-function ts = hptrend(ts, lambda) % --*-- Unitary tests --*--
-
-% ts = hptrend(ts, lambda)
-%
-% Extracts the trend component from a dseries object using Hodrick Prescott filter.
-%
-% INPUTS 
-%  o ts         dseries object.
-%  o lambda     positive scalar, trend smoothness parameter.
-%
-% OUTPUTS 
-%  o ts         dseries object, with time series replaced by the trend component of the original time series.
-
-% Copyright (C) 2013 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 nargin>1 
-    if lambda<=0
-        error(['dseries::hptrend: Lambda must be a positive integer!'])
-    end
-else
-    lambda = [];
-end
-
-for i=1:vobs(ts)
-    ts.name(i) = {['hptrend(' ts.name{i} ')']};
-    ts.tex(i) = {['\text{hptrend}(' ts.tex{i} ')']};
-end
-
-ts.data = sample_hp_filter(ts.data,lambda);
-
-%@test:1
-%$ plot_flag = 0; 
-%$
-%$ % Create a dataset.
-%$ e = .2*randn(200,1);
-%$ u = randn(200,1);
-%$ stochastic_trend = cumsum(e); 
-%$ deterministic_trend = .1*transpose(1:200);
-%$ x = zeros(200,1);
-%$ for i=2:200
-%$    x(i) = .75*x(i-1) + e(i);
-%$ end
-%$ y = x + stochastic_trend + deterministic_trend;
-%$
-%$ % Test the routine.
-%$ try
-%$     ts0 = dseries(y,'1950Q1');
-%$     ts1 = dseries(stochastic_trend+deterministic_trend,'1950Q1');
-%$     ts2 = ts0.hptrend(1600);
-%$     t(1) = 1;
-%$ catch
-%$     t(1) = 0;
-%$ end
-%$
-%$ if t(1)
-%$     t(2) = dyn_assert(ts2.freq,4);
-%$     t(3) = dyn_assert(ts2.init.freq,4);
-%$     t(4) = dyn_assert(ts2.init.time,[1950, 1]);
-%$     t(5) = dyn_assert(ts2.vobs,1);
-%$     t(6) = dyn_assert(ts2.nobs,200);
-%$ end
-%$
-%$ % Show results
-%$ if plot_flag
-%$     plot(ts1.data,'-k'); % Plot of the stationary component.
-%$     hold on
-%$     plot(ts2.data,'--r');          % Plot of the filtered y.
-%$     hold off
-%$     axis tight
-%$     id = get(gca,'XTick');
-%$     set(gca,'XTickLabel',strings(ts1.dates(id)));
-%$     legend({'Nonstationary component of y', 'Estimated trend of y'})
-%$     print('-depsc2','../doc/dynare.plots/HPTrend.eps')
-%$     system('convert -density 300 ../doc/dynare.plots/HPTrend.eps ../doc/dynare.plots/HPTrend.png');
-%$     system('convert -density 300 ../doc/dynare.plots/HPTrend.eps ../doc/dynare.plots/HPTrend.pdf');
-%$     system('convert -density 300 ../doc/dynare.plots/HPTrend.eps ../doc/dynare.plots/HPTrend.jpg');
-%$ end
-%$ T = all(t);
-%@eof:1
\ No newline at end of file
diff --git a/matlab/@dseries/insert.m b/matlab/@dseries/insert.m
deleted file mode 100644
index e1550861413540b531fe78123329f95e06a77008..0000000000000000000000000000000000000000
--- a/matlab/@dseries/insert.m
+++ /dev/null
@@ -1,107 +0,0 @@
-function ts = insert(ts,us,id) % --*-- Unitary tests --*--
-
-% Add a variable in a dseries object.
-
-%@info:
-%! @deftypefn {Function File} {@var{ts} =} insert (@var{ts}, @var{us}, @var{id})
-%! @anchor{dseries/insert}
-%! @sp 1
-%! Insert method for the dseries class. Insert new variables (@var{us}) in a dseries object (@var{ts}) at
-%! positions @var{id}.
-%! @sp 2
-%! @strong{Inputs}
-%! @sp 1
-%! @table @ @var
-%! @item ts
-%! Object instantiated by @ref{dseries}.
-%! @item us
-%! Object instantiated by @ref{dseries}.
-%! @item id
-%! vector of integers.
-%! @end table
-%! @sp 2
-%! @strong{Outputs}
-%! @sp 1
-%! @table @ @var
-%! @item ts
-%! Object instantiated by @ref{dseries}, without variable (@var{a}).
-%! @end table
-%! @end deftypefn
-%@eod:
-
-% Copyright (C) 2013 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/>.
-
-[n,message] = common_strings_in_cell_arrays(ts.name,us.name);
-
-if n
-    error(['dseries::insert: Variable(s) ' message ' already exist in ''' inputname(1) '''!'])
-end
-
-if ~isequal(frequency(ts),frequency(us))
-    error(['dseries::insert: ''' inputname(1) ''' and ''' inputname(2) ''' dseries objects must have common frequencies!'])
-end
-
-[ts,us] = align(ts, us);
-
-n = length(id);
-
-if n>1
-   [id, jd] = sort(id);
-   us.data = us.data(:,jd);
-   us.name = us.name(jd);
-   us.tex = us.tex(jd);
-end
-
-for i=1:n
-    ts.data = insert_column_vector_in_a_matrix(ts.data,us.data(:,i),id(i));
-    ts.name = insert_object_in_a_one_dimensional_cell_array(ts.name,us.name{i},id(i));
-    ts.tex = insert_object_in_a_one_dimensional_cell_array(ts.tex,us.tex{i},id(i));
-    id = id+1;
-end
-
-%@test:1
-%$ % Define a datasets.
-%$ A = rand(10,3); B = rand(5,2);
-%$
-%$ % Define names.
-%$ A_name = {'A1'; 'A2';'A3'};
-%$ B_name = {'B1'; 'B2'};
-%$
-%$ % Define initial dates.
-%$ A_init = '1950Q1';
-%$ B_init = '1950Q3';
-%$
-%$ % Instantiate two dseries objects.
-%$ ts1 = dseries(A, A_init, A_name,[]);
-%$ ts2 = dseries(B, B_init, B_name,[]);
-%$
-%$ try
-%$    ts1 = insert(ts1,ts2,[1,2]);
-%$    t(1) = 1;
-%$ catch
-%$    t = 0;
-%$ end
-%$
-%$ if length(t)>1
-%$    t(2) = dyn_assert(ts1.vobs,{'B1';'A1';'B2';'A3'});
-%$    t(3) = dyn_assert(ts1.nobs,10);
-%$    eB = [NaN(2,2); B; NaN(3,2)];
-%$    t(4) = dyn_assert(ts1.data,[eB(:,1), A(:,1), eB(:,2), A(:,2:3)], 1e-15);
-%$ end
-%$ T = all(t);
-%@eof:1
\ No newline at end of file
diff --git a/matlab/@dseries/isempty.m b/matlab/@dseries/isempty.m
deleted file mode 100644
index 5df634e46ee8ab8a70499adf1b3d79950c281f98..0000000000000000000000000000000000000000
--- a/matlab/@dseries/isempty.m
+++ /dev/null
@@ -1,40 +0,0 @@
-function b = isempty(A)
-%@info:
-%! @deftypefn {Function File} {@var{b} =} isempty (@var{A})
-%! @anchor{@dseries/isempty}
-%! @sp 1
-%! Overloads the isempty function for the Dynare time series class (@ref{dseries}).
-%! @sp 2
-%! @strong{Inputs}
-%! @sp 1
-%! @table @ @var
-%! @item 1
-%! Dynare time series object instantiated by @ref{dseries}.
-%! @end table
-%! @sp 1
-%! @strong{Outputs}
-%! @sp 1
-%! @table @ @var
-%! @item b
-%! Scalar integer (0 or 1).
-%! @end deftypefn
-%@eod:
-
-% Copyright (C) 2011-2012 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/>.
-
-b = isempty(A.data);
\ No newline at end of file
diff --git a/matlab/@dseries/isequal.m b/matlab/@dseries/isequal.m
deleted file mode 100644
index d57150551ee819bb3931c83fbd62b311c01ed4f8..0000000000000000000000000000000000000000
--- a/matlab/@dseries/isequal.m
+++ /dev/null
@@ -1,65 +0,0 @@
-function C = isequal(A,B)
-
-% Overloads the isequal Matlab/Octave's function.
-%
-% INPUTS 
-%  o A      dseries object (T periods, N variables).
-%  o B      dseries object (T periods, N variables).
-%
-% OUTPUTS 
-%  o C      Integer scalar equal to zero or one.
-
-% Copyright (C) 2013 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 nargin~=2
-    error('dseries::isequal: I need exactly two input arguments!')
-end
-
-if ~isdseries(B)
-    error('dseries::isequal: Both input arguments must be dseries objects!')
-end
-
-if ~isequal(nobs(A), nobs(B))
-    C = 0;
-    return
-end
-
-if ~isequal(vobs(A), vobs(B))
-    C = 0;
-    return
-end
-
-if ~isequal(frequency(A),frequency(B))
-    C = 0;
-    return
-end
-
-if ~isequal(A.dates,B.dates)
-    C = 0;
-    return
-end
-
-if ~isequal(A.name,B.name)
-    warning('dseries::isequal: Both input arguments do not have the same variables!')
-end
-
-if ~isequal(A.tex,B.tex)
-    warning('dseries::isequal: Both input arguments do not have the same tex names!')
-end
-
-C = isequal(A.data, B.data);
\ No newline at end of file
diff --git a/matlab/@dseries/lag.m b/matlab/@dseries/lag.m
deleted file mode 100644
index 4a2069599b543033c096a8a2eb3ad11072e34396..0000000000000000000000000000000000000000
--- a/matlab/@dseries/lag.m
+++ /dev/null
@@ -1,85 +0,0 @@
-function us = lag(ts,p) % --*-- Unitary tests --*--
-
-%@info:
-%! @deftypefn {Function File} {@var{us} =} lag (@var{ts})
-%! @anchor{lag}
-%! @sp 1
-%! Computes lagged time series.
-%! @sp 2
-%! @strong{Inputs}
-%! @sp 1
-%! @table @var
-%! @item ts
-%! Dynare time series object, instantiated by @ref{dseries}
-%! @end table
-%! @sp 2
-%! @strong{Outputs}
-%! @sp 1
-%! @table @var
-%! @item us
-%! Dynare time series object with transformed data field.
-%! @end table
-%! @end deftypefn
-%@eod:
-
-% Copyright (C) 2013 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/>.
-
-% Set default number of lags
-if nargin<2
-    p = 1;
-end
-
-if p<=0
-    error('dseries::lag: Second input argument must be strictly positive! Use lead method instead.')
-end
-
-% Copy of ts dseries object
-us = ts;
-
-% Update data member
-us.data = [NaN(p, vobs(ts));  ts.data(1:end-p,:)];
-
-for i=1:vobs(ts)
-    us.name(i) = {[ 'lag(' ts.name{i} ',' int2str(p) ')']};
-    us.tex(i) = {[ ts.tex{i} '_{-' int2str(p) '}']};
-end
-
-%@test:1
-%$ t = zeros(4,1);
-%$
-%$ try
-%$     data = transpose(0:1:50);
-%$     ts = dseries(data,'1950Q1');
-%$     a = ts.lag;
-%$     b = ts.lag.lag;
-%$     c = lag(ts,2);
-%$     t(1) = 1;
-%$ catch
-%$     t = 0;
-%$ end
-%$
-%$ if length(t)>1
-%$     DATA = [NaN(1,ts.vobs); transpose(0:1:49)];
-%$     t(2) = dyn_assert(a.data,DATA,1e-15);
-%$     DATA = [NaN(2,ts.vobs); transpose(0:1:48)];
-%$     t(3) = dyn_assert(b.data,DATA,1e-15);
-%$     t(4) = dyn_assert(b.data,c.data,1e-15);
-%$ end
-%$
-%$ T = all(t);
-%@eof:1
\ No newline at end of file
diff --git a/matlab/@dseries/lastdate.m b/matlab/@dseries/lastdate.m
deleted file mode 100644
index 972a70e1899f3ea255d10db1522466c0da7e21d3..0000000000000000000000000000000000000000
--- a/matlab/@dseries/lastdate.m
+++ /dev/null
@@ -1,20 +0,0 @@
-function l = lastdate(o)
-
-% 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/>.
-
-l = o.dates(end);
\ No newline at end of file
diff --git a/matlab/@dseries/lead.m b/matlab/@dseries/lead.m
deleted file mode 100644
index c4eba7a230226d87007943f673c4c8c93d790890..0000000000000000000000000000000000000000
--- a/matlab/@dseries/lead.m
+++ /dev/null
@@ -1,85 +0,0 @@
-function us = lead(ts,p) % --*-- Unitary tests --*--
-
-%@info:
-%! @deftypefn {Function File} {@var{us} =} lead (@var{ts})
-%! @anchor{lag}
-%! @sp 1
-%! Computes leaded time series.
-%! @sp 2
-%! @strong{Inputs}
-%! @sp 1
-%! @table @var
-%! @item ts
-%! Dynare time series object, instantiated by @ref{dseries}
-%! @end table
-%! @sp 2
-%! @strong{Outputs}
-%! @sp 1
-%! @table @var
-%! @item us
-%! Dynare time series object with transformed data field.
-%! @end table
-%! @end deftypefn
-%@eod:
-
-% Copyright (C) 2013 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/>.
-
-% Set default number of leads
-if nargin<2
-    p = 1;
-end
-
-if p<=0
-    error('dseries::lead: Second input argument must be strictly positive! Use lag method instead.')
-end
-
-% Copy of ts dseries object
-us = ts;
-
-% Update data member
-us.data = [  ts.data(p+1:end,:); NaN(p, vobs(ts));];
-
-for i=1:vobs(ts)
-    us.name(i) = {[ 'lead(' ts.name{i} ',' int2str(p) ')']};
-    us.tex(i) = {[ ts.tex{i} '_{+' int2str(p) '}']};
-end
-
-%@test:1
-%$ t = zeros(4,1);
-%$
-%$ try
-%$     data = transpose(0:1:50);
-%$     ts = dseries(data,'1950Q1');
-%$     a = ts.lead;
-%$     b = ts.lead.lead;
-%$     c = lead(ts,2);
-%$     t(1) = 1;
-%$ catch
-%$     t = 0;
-%$ end
-%$
-%$ if length(t)>1
-%$     DATA = [transpose(1:50); NaN(1,ts.vobs)];
-%$     t(2) = dyn_assert(a.data,DATA,1e-15);
-%$     DATA = [transpose(2:50); NaN(2,ts.vobs)];
-%$     t(3) = dyn_assert(b.data,DATA,1e-15);
-%$     t(4) = dyn_assert(b.data,c.data,1e-15);
-%$ end
-%$
-%$ T = all(t);
-%@eof:1
\ No newline at end of file
diff --git a/matlab/@dseries/log.m b/matlab/@dseries/log.m
deleted file mode 100644
index 2ff8e6488572bc1bf7497ca771f996beb34a4962..0000000000000000000000000000000000000000
--- a/matlab/@dseries/log.m
+++ /dev/null
@@ -1,55 +0,0 @@
-function ts = log(ts)
-
-%@info:
-%! @deftypefn {Function File} {@var{ts} =} log(@var{ts})
-%! @anchor{log}
-%! Apply the logarithm function to a Dynare time series object.
-%!
-%! @strong{Inputs}
-%! @table @var
-%! @item ts
-%! Dynare time series object, instantiated by @ref{dseries}
-%! @end table
-%!
-%! @strong{Outputs}
-%! @table @var
-%! @item ts
-%! Dynare time series object with transformed data field.
-%! @end table
-%!
-%! @strong{This function is called by:}
-%! None.
-%!
-%! @strong{This function calls:}
-%! None.
-%!
-%! @end deftypefn
-%@eod:
-
-% Copyright (C) 2011-2013 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 any(ts.data<eps)
-    error('dseries::log: Input argument has to be strictly positive!')
-end
-
-for i=1:vobs(ts)
-    ts.name(i) = {['log(' ts.name{i} ')']};
-    ts.tex(i) = {['\log(' ts.tex{i} ')']};
-end
-
-ts.data = log(ts.data);
\ No newline at end of file
diff --git a/matlab/@dseries/merge.m b/matlab/@dseries/merge.m
deleted file mode 100644
index 1ab70b389299c6f5bd9daf114c0e26f58468f305..0000000000000000000000000000000000000000
--- a/matlab/@dseries/merge.m
+++ /dev/null
@@ -1,146 +0,0 @@
-function A = merge(B,C) % --*-- Unitary tests --*--
-
-%@info:
-%! @deftypefn {Function File} {@var{A} =} merge (@var{B},@var{C})
-%! @anchor{@dseries/plus}
-%! @sp 1
-%! Overloads the merge method for the Dynare time series class (@ref{dseries}).
-%! @sp 2
-%! @strong{Inputs}
-%! @sp 1
-%! @table @ @var
-%! @item B
-%! Dynare time series object instantiated by @ref{dseries}.
-%! @item C
-%! Dynare time series object instantiated by @ref{dseries}.
-%! @end table
-%! @sp 1
-%! @strong{Outputs}
-%! @sp 1
-%! @table @ @var
-%! @item A
-%! Dynare time series object.
-%! @end deftypefn
-%@eod:
-
-% Copyright (C) 2013 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 ~isdseries(C)
-    error('dseries::merge: Both inputs must be dseries objects!')
-end
-
-if ~isequal(frequency(B),frequency(C))
-    error(['dseries::merge: Cannot merge ' inputname(1) ' and ' inputname(2) ' (frequencies are different)!'])
-end
-
-A = dseries();
-[A.name, IBC, junk] = unique([B.name; C.name], 'last');
-tex = [B.tex; C.tex];
-A.tex = tex(IBC);
-
-if nobs(B) == 0
-    A = C;
-elseif nobs(C) == 0
-    A = B;
-elseif firstdate(B) >= firstdate(C)
-    diff = firstdate(B) - firstdate(C);
-    A_nobs = max(nobs(B) + diff, nobs(C));
-    A.data = NaN(A_nobs, vobs(A));
-    Z1 = [NaN(diff, vobs(B));B.data];
-    if nobs(A) > nobs(B) + diff
-        Z1 = [Z1; NaN(nobs(A)-(nobs(B) + diff), vobs(B))];
-    end;
-    Z2 = C.data;
-    if nobs(A) > nobs(C)
-        Z2 = [Z2; NaN(nobs(A) - nobs(C), vobs(C))];
-    end;
-    Z = [Z1 Z2];
-    A.data = Z(:,IBC);
-    A_init = firstdate(C);
-else
-    diff = firstdate(C) - firstdate(B);
-    A_nobs = max(nobs(C) + diff, nobs(B));
-    A.data = NaN(A_nobs, vobs(A));
-    Z1 = [NaN(diff, vobs(C)); C.data];
-    if nobs(A) > nobs(C) + diff
-        Z1 = [Z1; NaN(nobs(A)-(nobs(C) + diff), vobs(C))];
-    end
-    Z2 = B.data;
-    if nobs(A) > nobs(B)
-        Z2 = [Z2; NaN(nobs(A) - nobs(B), vobs(B))];
-    end;
-    Z = [Z2 Z1];
-    A.data = Z(:,IBC);
-    A_init = B.init;
-end
-
-A.dates = A_init:A_init+(nobs(A)-1);
-
-%@test:1
-%$ % Define a datasets.
-%$ A = rand(10,2); B = randn(10,1);
-%$
-%$ % Define names
-%$ A_name = {'A1';'A2'}; B_name = {'A1'};
-%$
-%$ t = zeros(4,1);
-%$
-%$ % Instantiate a time series object.
-%$ try
-%$    ts1 = dseries(A,[],A_name,[]);
-%$    ts2 = dseries(B,[],B_name,[]);
-%$    ts3 = merge(ts1,ts2);
-%$    t(1) = 1;
-%$ catch
-%$    t = 0;
-%$ end
-%$
-%$ if length(t)>1
-%$    t(2) = dyn_assert(ts3.vobs,2);
-%$    t(3) = dyn_assert(ts3.nobs,10);
-%$    t(4) = dyn_assert(ts3.data,[B, A(:,2)],1e-15);
-%$ end
-%$ T = all(t);
-%@eof:1
-
-%@test:2
-%$ % Define a datasets.
-%$ A = rand(10,2); B = randn(10,1);
-%$
-%$ % Define names
-%$ A_name = {'A1';'A2'}; B_name = {'B1'};
-%$
-%$ t = zeros(4,1);
-%$
-%$ % Instantiate a time series object.
-%$ try
-%$    ts1 = dseries(A,[],A_name,[]);
-%$    ts2 = dseries(B,[],B_name,[]);
-%$    ts3 = merge(ts1,ts2);
-%$    t(1) = 1;
-%$ catch
-%$    t = 0;
-%$ end
-%$
-%$ if length(t)>1
-%$    t(2) = dyn_assert(ts3.vobs,3);
-%$    t(3) = dyn_assert(ts3.nobs,10);
-%$    t(4) = dyn_assert(ts3.data,[A, B],1e-15);
-%$ end
-%$ T = all(t);
-%@eof:2
\ No newline at end of file
diff --git a/matlab/@dseries/minus.m b/matlab/@dseries/minus.m
deleted file mode 100644
index a6b6f91e477285da4c5da9c7164cb9e38f86e8af..0000000000000000000000000000000000000000
--- a/matlab/@dseries/minus.m
+++ /dev/null
@@ -1,196 +0,0 @@
-function A = minus(B,C) % --*-- Unitary tests --*--
-
-%@info:
-%! @deftypefn {Function File} {@var{A} =} minus (@var{B},@var{C})
-%! @anchor{@dseries/minus}
-%! @sp 1
-%! Overloads the minus method for the Dynare time series class (@ref{dseries}).
-%! @sp 2
-%! @strong{Inputs}
-%! @sp 1
-%! @table @ @var
-%! @item B
-%! Dynare time series object instantiated by @ref{dseries}.
-%! @item C
-%! Dynare time series object instantiated by @ref{dseries}.
-%! @end table
-%! @sp 1
-%! @strong{Outputs}
-%! @sp 1
-%! @table @ @var
-%! @item A
-%! Dynare time series object.
-%! @end deftypefn
-%@eod:
-
-% Copyright (C) 2012-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(B) && (isscalar(B) ||  isvector(B))
-    if ~isdseries(C)
-        error('dseries::minus: Second input argument must be a dseries object!')
-    end
-    A = C;
-    A.data = bsxfun(@minus,B,C.data);
-    return;
-end
-
-if isnumeric(C) && (isscalar(C) || isvector(C))
-    if ~isdseries(B)
-        error('dseries::minus: First input argument must be a dseries object!')
-    end
-    A = B;
-    A.data = bsxfun(@minus,B.data,C);
-    return
-end
-
-if ~isequal(vobs(B), vobs(C)) && ~(isequal(vobs(B),1) || isequal(vobs(C),1))
-    error(['dseries::minus: Cannot substract ' inputname(1) ' and ' inputname(2) ' (wrong number of variables)!'])
-else
-    if vobs(B)>vobs(C)
-        idB = 1:vobs(B);
-        idC = ones(1:vobs(B));
-    elseif vobs(B)<vobs(C)
-        idB = ones(1,vobs(C));
-        idC = 1:vobs(C);
-    else
-        idB = 1:vobs(B);
-        idC = 1:vobs(C);
-    end
-end
-
-if ~isequal(frequency(B),frequency(C))
-    error(['dseries::plus: Cannot substract ' inputname(1) ' and ' inputname(2) ' (frequencies are different)!'])
-end
-
-if ~isequal(nobs(B), nobs(C)) || ~isequal(firstdate(B),firstdate(C))
-    [B, C] = align(B, C);
-end
-
-if isempty(B)
-    A = -C;
-    return
-end
-
-if isempty(C)
-    A = B;
-    return
-end
-
-A = dseries();
-
-A.dates = B.dates;
-A_vobs = max(vobs(B), vobs(C));
-A.name = cell(A_vobs,1);
-A.tex = cell(A_vobs,1);
-for i=1:A_vobs
-    A.name(i) = {['minus(' B.name{idB(i)} ',' C.name{idC(i)} ')']};
-    A.tex(i) = {['(' B.tex{idB(i)} '-' C.tex{idC(i)} ')']};
-end
-A.data = bsxfun(@minus,B.data,C.data);
-
-%@test:1
-%$ % Define a datasets.
-%$ A = rand(10,2); B = randn(10,1);
-%$
-%$ % Define names
-%$ A_name = {'A1';'A2'}; B_name = {'B1'};
-%$
-%$ t = zeros(5,1);
-%$
-%$ % Instantiate a time series object.
-%$ try
-%$    ts1 = dseries(A,[],A_name,[]);
-%$    ts2 = dseries(B,[],B_name,[]);
-%$    ts3 = ts1-ts2;
-%$    t(1) = 1;
-%$ catch
-%$    t = 0;
-%$ end
-%$
-%$ if length(t)>1
-%$    t(2) = dyn_assert(ts3.vobs,2);
-%$    t(3) = dyn_assert(ts3.nobs,10);
-%$    t(4) = dyn_assert(ts3.data,[A(:,1)-B, A(:,2)-B],1e-15);
-%$    t(5) = dyn_assert(ts3.name,{'minus(A1,B1)';'minus(A2,B1)'});
-%$ end
-%$ T = all(t);
-%@eof:1
-
-%@test:3
-%$ % Define a datasets.
-%$ A = rand(10,2); B = randn(5,1);
-%$
-%$ % Define names
-%$ A_name = {'A1';'A2'}; B_name = {'B1'};
-%$
-%$ t = zeros(5,1);
-%$
-%$ % Instantiate a time series object.
-%$ try
-%$    ts1 = dseries(A,[],A_name,[]);
-%$    ts2 = dseries(B,[],B_name,[]);
-%$    ts3 = ts1-ts2;
-%$    t(1) = 1;
-%$ catch
-%$    t = 0;
-%$ end
-%$
-%$ if length(t)>1
-%$    t(2) = dyn_assert(ts3.vobs,2);
-%$    t(3) = dyn_assert(ts3.nobs,10);
-%$    t(4) = dyn_assert(ts3.data,[A(1:5,1)-B(1:5), A(1:5,2)-B(1:5) ; NaN(5,2)],1e-15);
-%$    t(5) = dyn_assert(ts3.name,{'minus(A1,B1)';'minus(A2,B1)'});
-%$ end
-%$ T = all(t);
-%@eof:3
-
-%@test:4
-%$ ts1 = dseries(ones(3,1));
-%$ ts2 = ts1-1;
-%$ ts3 = 2-ts1;
-%$ t(1) = isequal(ts2.data, zeros(3,1));
-%$ t(2) = isequal(ts3.data, ts1.data);
-%$ T = all(t);
-%@eof:4
-
-%@test:5
-%$ ts1 = dseries(ones(3,2));
-%$ ts2 = ts1-1;
-%$ ts3 = 2-ts1;
-%$ t(1) = isequal(ts2.data, zeros(3,2));
-%$ t(2) = isequal(ts3.data, ts1.data);
-%$ T = all(t);
-%@eof:5
-
-%@test:6
-%$ ts1 = dseries(ones(3,2));
-%$ ts2 = ts1-ones(3,1);
-%$ ts3 = 2*ones(3,1)-ts1;
-%$ t(1) = isequal(ts2.data, zeros(3,2));
-%$ t(2) = isequal(ts3.data, ts1.data);
-%$ T = all(t);
-%@eof:6
-
-%@test:7
-%$ ts1 = dseries(ones(3,2));
-%$ ts2 = ts1-ones(1,2);
-%$ ts3 = 2*ones(1,2)-ts1;
-%$ t(1) = isequal(ts2.data, zeros(3,2));
-%$ t(2) = isequal(ts3.data, ts1.data);
-%$ T = all(t);
-%@eof:7
diff --git a/matlab/@dseries/mpower.m b/matlab/@dseries/mpower.m
deleted file mode 100644
index ef6dc2d9f7f5969fc6aef1a20caac39c5fa8930f..0000000000000000000000000000000000000000
--- a/matlab/@dseries/mpower.m
+++ /dev/null
@@ -1,168 +0,0 @@
-function A = mpower(B,C) % --*-- Unitary tests --*--
-
-%@info:
-%! @deftypefn {Function File} {@var{A} =} mpower (@var{B},@var{C})
-%! @anchor{@dseries/mpower}
-%! @sp 1
-%! Overloads the mpower method for the Dynare time series class (@ref{dseries}).
-%! @sp 2
-%! @strong{Inputs}
-%! @sp 1
-%! @table @ @var
-%! @item B
-%! Dynare time series object instantiated by @ref{dseries}, with T observations and N variables.
-%! @item C
-%! Real scalar or a dseries object with T observations and N variables.
-%! @end table
-%! @sp 1
-%! @strong{Outputs}
-%! @sp 1
-%! @table @ @var
-%! @item A
-%! dseries object with T observations and N variables.
-%! @end deftypefn
-%@eod:
-
-% Copyright (C) 2013 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(B) && isvector(B) && length(B)>1
-    if ~isdseries(C)
-        error('dseries::mpower: Second input argument must be a dseries object!')
-    end
-    A = C;
-    A.data = bsxfun(@power,C.data,B);
-    return;
-end
-
-if isnumeric(C) && isvector(C) && length(C)>1
-    if ~isdseries(B)
-        error('dseries::mpower: First input argument must be a dseries object!')
-    end
-    A = B;
-    A.data = bsxfun(@power,B.data,C);
-    return
-end
-
-if isdseries(B) && isnumeric(C) && isreal(C) &&  isscalar(C)
-    A = dseries();
-    A.dates = B.dates;
-    A.data = B.data.^C;
-    A.name = cell(vobs(A),1);
-    A.tex = cell(vobs(A),1);
-    for i=1:vobs(A)
-        A.name(i) = {['power(' B.name{i} ',' num2str(C) ')']};
-        A.tex(i) = {[B.tex{i} '^' num2str(C) ]};
-    end
-    return
-end
-
-if isdseries(B) && isdseries(C)
-    if isequal(nobs(B),nobs(C)) && isequal(vobs(B), vobs(C)) && isequal(frequency(B),frequency(C))
-        A = dseries();
-        A.data = B.data.^C.data;
-        A.dates = B.dates;
-        A.name = cell(vobs(A),1);
-        A.tex = cell(vobs(A),1);
-        for i=1:vobs(A)
-            A.name(i) = {['power(' B.name{i} ',' C.name{i} ')']};
-            A.tex(i) = {[B.tex{i} '^{' C.tex{i} '}']};
-        end
-    else
-        error('dseries::mpower: If both input arguments are dseries objects, they must have the same numbers of variables and observations and common frequency!')
-    end
-    return
-end
-
-error(['dseries::mpower: Wrong calling sequence!'])
-
-%@test:1
-%$ % Define a datasets.
-%$ A = rand(10,2); B = randn(10,2);
-%$
-%$ % Define names
-%$ A_name = {'A1';'A2'}; B_name = {'B1';'B2'};
-%$
-%$
-%$ % Instantiate a time series object.
-%$ try
-%$    ts1 = dseries(A,[],A_name,[]);
-%$    ts2 = dseries(B,[],B_name,[]);
-%$    ts3 = ts1^ts2;
-%$    t = 1;
-%$ catch
-%$    t = 0;
-%$ end
-%$
-%$ if t(1)
-%$    t(2) = dyn_assert(ts3.vobs,2);
-%$    t(3) = dyn_assert(ts3.nobs,10);
-%$    t(4) = dyn_assert(ts3.data,A.^B,1e-15);
-%$    t(5) = dyn_assert(ts3.name,{'power(A1,B1)';'power(A2,B2)'});
-%$    t(6) = dyn_assert(ts3.tex,{'A1^{B1}';'A2^{B2}'});
-%$ end
-%$ T = all(t);
-%@eof:1
-
-%@test:2
-%$ % Define a datasets.
-%$ A = rand(10,2);
-%$
-%$ % Define names
-%$ A_name = {'A1';'A2'};
-%$
-%$
-%$ % Instantiate a time series object.
-%$ try
-%$    ts1 = dseries(A,[],A_name,[]);
-%$    ts3 = ts1^2;
-%$    t = 1;
-%$ catch
-%$    t = 0;
-%$ end
-%$
-%$ if t(1)
-%$    t(2) = dyn_assert(ts3.vobs,2);
-%$    t(3) = dyn_assert(ts3.nobs,10);
-%$    t(4) = dyn_assert(ts3.data,A.^2,1e-15);
-%$    t(5) = dyn_assert(ts3.name,{'power(A1,2)';'power(A2,2)'});
-%$    t(6) = dyn_assert(ts3.tex,{'A1^2';'A2^2'});
-%$ end
-%$ T = all(t);
-%@eof:2
-
-%@test:3
-%$ % Define a dseries object
-%$ ts1=dseries([1 1;2 2;3 3], '1999y', {'MyVar1','MyVar2'});
-%$
-%$ % Use the power
-%$ try
-%$    ts2 = ts1^transpose(1:3);
-%$    t = 1;
-%$ catch
-%$    t = 0;
-%$ end
-%$
-%$ if t(1)
-%$    t(2) = dyn_assert(ts2.vobs,2);
-%$    t(3) = dyn_assert(ts2.nobs,3);
-%$    t(4) = dyn_assert(ts2.data,bsxfun(@power,ts1.data,transpose(1:3)),1e-15);
-%$    t(5) = dyn_assert(ts2.name,{'MyVar1';'MyVar2'});
-%$    t(6) = dyn_assert(ts2.tex,{'MyVar1';'MyVar2'});
-%$ end
-%$ T = all(t);
-%@eof:3
\ No newline at end of file
diff --git a/matlab/@dseries/mrdivide.m b/matlab/@dseries/mrdivide.m
deleted file mode 100644
index 606cc3b212f30d340b605f9111458b9672c7e514..0000000000000000000000000000000000000000
--- a/matlab/@dseries/mrdivide.m
+++ /dev/null
@@ -1,174 +0,0 @@
-function A = mrdivide(B,C) % --*-- Unitary tests --*--
-
-%@info:
-%! @deftypefn {Function File} {@var{A} =} mrdivide (@var{B},@var{C})
-%! @anchor{@dseries/mrdivide}
-%! @sp 1
-%! Overloads the mrdivide method for the Dynare time series class (@ref{dseries}).
-%! @sp 2
-%! @strong{Inputs}
-%! @sp 1
-%! @table @ @var
-%! @item B
-%! Dynare time series object instantiated by @ref{dseries}.
-%! @item C
-%! Dynare time series object instantiated by @ref{dseries}.
-%! @end table
-%! @sp 1
-%! @strong{Outputs}
-%! @sp 1
-%! @table @ @var
-%! @item A
-%! Dynare time series object.
-%! @end deftypefn
-%@eod:
-
-% Copyright (C) 2012-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(B) && (isscalar(B) ||  isvector(B))
-    if ~isdseries(C)
-        error('dseries::mrdivide: Second input argument must be a dseries object!')
-    end
-    A = C;
-    A.data = bsxfun(@rdivide,B,C.data);
-    return;
-end
-
-if isnumeric(C) && (isscalar(C) || isvector(C))
-    if ~isdseries(B)
-        error('dseries::mrdivide: First input argument must be a dseries object!')
-    end
-    A = B;
-    A.data = bsxfun(@rdivide,B.data,C);
-    return
-end    
-
-if isdseries(B) && isdseries(C)
-    % Element by element divisions of two dseries object
-    if ~isequal(vobs(B), vobs(C)) && ~(isequal(vobs(B),1) || isequal(vobs(C),1))
-        error(['dseries::times: Cannot divide ' inputname(1) ' and ' inputname(2) ' (wrong number of variables)!'])
-    else
-        if vobs(B)>vobs(C)
-            idB = 1:vobs(B);
-            idC = ones(1:vobs(B));
-        elseif vobs(B)<vobs(C)
-            idB = ones(1,vobs(C));
-            idC = 1:vobs(C);
-        else
-            idB = 1:vobs(B);
-            idC = 1:vobs(C);
-        end
-    end
-    if ~isequal(frequency(B),frequency(C))
-        error(['dseries::times: Cannot divide ' inputname(1) ' and ' inputname(2) ' (frequencies are different)!'])
-    end
-    if ~isequal(nobs(B), nobs(C)) || ~isequal(firstdate(B),firstdate(C))
-        [B, C] = align(B, C);
-    end
-    A = dseries();
-    A.dates = B.dates;
-    A_vobs = max(vobs(B),vobs(C));
-    A.name = cell(A_vobs,1);
-    A.tex = cell(A_vobs,1);
-    for i=1:A_vobs
-        A.name(i) = {['divide(' B.name{idB(i)} ',' C.name{idC(i)} ')']};
-        A.tex(i) = {['(' B.tex{idB(i)} '/' C.tex{idC(i)} ')']};
-    end
-    A.data = bsxfun(@rdivide,B.data,C.data);
-else
-    error()
-end
-
-%@test:1
-%$ % Define a datasets.
-%$ A = rand(10,2); B = randn(10,1);
-%$
-%$ % Define names
-%$ A_name = {'A1';'A2'}; B_name = {'B1'};
-%$
-%$ t = zeros(4,1);
-%$
-%$ % Instantiate a time series object.
-%$ try
-%$    ts1 = dseries(A,[],A_name,[]);
-%$    ts2 = dseries(B,[],B_name,[]);
-%$    ts3 = ts1/ts2;
-%$    t(1) = 1;
-%$ catch
-%$    t = 0;
-%$ end
-%$
-%$ if length(t)>1
-%$    t(2) = dyn_assert(ts3.vobs,2);
-%$    t(3) = dyn_assert(ts3.nobs,10);
-%$    t(4) = dyn_assert(ts3.data,[A(:,1)./B, A(:,2)./B],1e-15);
-%$ end
-%$ T = all(t);
-%@eof:1
-
-%@test:2
-%$ % Define a datasets.
-%$ A = rand(10,2); B = pi;
-%$
-%$ % Define names
-%$ A_name = {'A1';'A2'};
-%$
-%$ t = zeros(4,1);
-%$
-%$ % Instantiate a time series object.
-%$ try
-%$    ts1 = dseries(A,[],A_name,[]);
-%$    ts2 = ts1/B;
-%$    t(1) = 1;
-%$ catch
-%$    t = 0;
-%$ end
-%$
-%$ if length(t)>1
-%$    t(2) = dyn_assert(ts2.vobs,2);
-%$    t(3) = dyn_assert(ts2.nobs,10);
-%$    t(4) = dyn_assert(ts2.data,A/B,1e-15);
-%$ end
-%$ T = all(t);
-%@eof:2
-
-%@test:3
-%$ % Define a datasets.
-%$ A = rand(10,2); B = pi;
-%$
-%$ % Define names
-%$ A_name = {'A1';'A2'};
-%$
-%$ t = zeros(4,1);
-%$
-%$ % Instantiate a time series object.
-%$ try
-%$    ts1 = dseries(A,[],A_name,[]);
-%$    ts2 = B/ts1;
-%$    t(1) = 1;
-%$ catch
-%$    t = 0;
-%$ end
-%$
-%$ if length(t)>1
-%$    t(2) = dyn_assert(ts2.vobs,2);
-%$    t(3) = dyn_assert(ts2.nobs,10);
-%$    t(4) = dyn_assert(ts2.data,B./A,1e-15);
-%$ end
-%$ T = all(t);
-%@eof:3
diff --git a/matlab/@dseries/mtimes.m b/matlab/@dseries/mtimes.m
deleted file mode 100644
index d52117dca84fb319c2f668db1535c125c92d28f2..0000000000000000000000000000000000000000
--- a/matlab/@dseries/mtimes.m
+++ /dev/null
@@ -1,197 +0,0 @@
-function A = mtimes(B,C) % --*-- Unitary tests --*--
-
-%@info:
-%! @deftypefn {Function File} {@var{A} =} mtimes (@var{B},@var{C})
-%! @anchor{@dseries/mtimes}
-%! @sp 1
-%! Overloads the mtimes method for the Dynare time series class (@ref{dseries}).
-%! @sp 2
-%! @strong{Inputs}
-%! @sp 1
-%! @table @ @var
-%! @item B
-%! Dynare time series object instantiated by @ref{dseries}.
-%! @item C
-%! Dynare time series object instantiated by @ref{dseries}.
-%! @end table
-%! @sp 1
-%! @strong{Outputs}
-%! @sp 1
-%! @table @ @var
-%! @item A
-%! Dynare time series object.
-%! @end deftypefn
-%@eod:
-
-% Copyright (C) 2012-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(B) && (isscalar(B) ||  isvector(B))
-    if ~isdseries(C)
-        error('dseries::mtimes: Second input argument must be a dseries object!')
-    end
-    A = C;
-    A.data = bsxfun(@times,C.data,B);
-    return;
-end
-
-if isnumeric(C) && (isscalar(C) || isvector(C))
-    if ~isdseries(B)
-        error('dseries::mtimes: First input argument must be a dseries object!')
-    end
-    A = B;
-    A.data = bsxfun(@times,B.data,C);
-    return
-end
-
-if isdseries(B) && isdseries(C)
-    % Element by element multiplication of two dseries object
-    if ~isequal(vobs(B), vobs(C)) && ~(isequal(vobs(B),1) || isequal(vobs(C),1))
-        error(['dseries::times: Cannot multiply ' inputname(1) ' and ' inputname(2) ' (wrong number of variables)!'])
-    else
-        if vobs(B)>vobs(C)
-            idB = 1:vobs(B);
-            idC = ones(1:vobs(B));
-        elseif vobs(B)<vobs(C)
-            idB = ones(1,vobs(C));
-            idC = 1:vobs(C);
-        else
-            idB = 1:vobs(B);
-            idC = 1:vobs(C);
-        end
-    end
-    if ~isequal(frequency(B),frequency(C))
-        error(['dseries::times: Cannot multiply ' inputname(1) ' and ' inputname(2) ' (frequencies are different)!'])
-    end
-    if ~isequal(nobs(B), nobs(C)) || ~isequal(firstdate(B),firstdate(C))
-        [B, C] = align(B, C);
-    end
-    A = dseries();
-    A.dates = B.dates;
-    A_vobs = max(vobs(B),vobs(C));
-    A.name = cell(A_vobs,1);
-    A.tex = cell(A_vobs,1);
-    for i=1:A_vobs
-        A.name(i) = {['multiply(' B.name{idB(i)} ',' C.name{idC(i)} ')']};
-        A.tex(i) = {['(' B.tex{idB(i)} '*' C.tex{idC(i)} ')']};
-    end
-    A.data = bsxfun(@times,B.data,C.data);
-else
-    error()
-end
-
-%@test:1
-%$ % Define a datasets.
-%$ A = rand(10,2); B = randn(10,1);
-%$
-%$ % Define names
-%$ A_name = {'A1';'A2'}; B_name = {'B1'};
-%$
-%$
-%$ % Instantiate a time series object.
-%$ try
-%$    ts1 = dseries(A,[],A_name,[]);
-%$    ts2 = dseries(B,[],B_name,[]);
-%$    ts3 = ts1*ts2;
-%$    t = 1;
-%$ catch
-%$    t = 0;
-%$ end
-%$
-%$ if t(1)
-%$    t(2) = dyn_assert(ts3.vobs,2);
-%$    t(3) = dyn_assert(ts3.nobs,10);
-%$    t(4) = dyn_assert(ts3.data,[A(:,1).*B, A(:,2).*B],1e-15);
-%$    t(5) = dyn_assert(ts3.name,{'multiply(A1,B1)';'multiply(A2,B1)'});
-%$ end
-%$ T = all(t);
-%@eof:1
-
-%@test:2
-%$ % Define a datasets.
-%$ A = rand(10,2); B = pi;
-%$
-%$ % Define names
-%$ A_name = {'A1';'A2'};
-%$
-%$
-%$ % Instantiate a time series object.
-%$ try
-%$    ts1 = dseries(A,[],A_name,[]);
-%$    ts2 = ts1*B;
-%$    t = 1;
-%$ catch
-%$    t = 0;
-%$ end
-%$
-%$ if t(1)
-%$    t(2) = dyn_assert(ts2.vobs,2);
-%$    t(3) = dyn_assert(ts2.nobs,10);
-%$    t(4) = dyn_assert(ts2.data,A*B,1e-15);
-%$ end
-%$ T = all(t);
-%@eof:2
-
-%@test:3
-%$ % Define a datasets.
-%$ A = rand(10,2); B = pi;
-%$
-%$ % Define names
-%$ A_name = {'A1';'A2'};
-%$
-%$
-%$ % Instantiate a time series object.
-%$ try
-%$    ts1 = dseries(A,[],A_name,[]);
-%$    ts2 = B*ts1;
-%$    t = 1;
-%$ catch
-%$    t = 0;
-%$ end
-%$
-%$ if t(1)
-%$    t(2) = dyn_assert(ts2.vobs,2);
-%$    t(3) = dyn_assert(ts2.nobs,10);
-%$    t(4) = dyn_assert(ts2.data,A*B,1e-15);
-%$ end
-%$ T = all(t);
-%@eof:3
-
-%@test:4
-%$ % Define a datasets.
-%$ A = rand(10,2); B = A(1,:);
-%$
-%$ % Define names
-%$ A_name = {'A1';'A2'};
-%$
-%$
-%$ % Instantiate a time series object.
-%$ try
-%$    ts1 = dseries(A,[],A_name,[]);
-%$    ts2 = B*ts1;
-%$    t = 1;
-%$ catch
-%$    t = 0;
-%$ end
-%$
-%$ if t(1)
-%$    t(2) = dyn_assert(ts2.vobs,2);
-%$    t(3) = dyn_assert(ts2.nobs,10);
-%$    t(4) = dyn_assert(ts2.data,bsxfun(@times,A,B),1e-15);
-%$ end
-%$ T = all(t);
-%@eof:4
diff --git a/matlab/@dseries/ne.m b/matlab/@dseries/ne.m
deleted file mode 100644
index ed6e98adce51c669a1637561aa2746caae543c0c..0000000000000000000000000000000000000000
--- a/matlab/@dseries/ne.m
+++ /dev/null
@@ -1,100 +0,0 @@
-function C = ne(A,B) % --*-- Unitary tests --*--
-
-% Overloads ne (~=) operator.
-%
-% INPUTS 
-%  o A      dseries object (T periods, N variables).
-%  o B      dseries object (T periods, N variables).
-%
-% OUTPUTS 
-%  o C      T*N matrix of zeros and ones. Element C(t,n) is nonzero iff observation t of variable n in A and B are different.  
-%
-% REMARKS 
-%  If the number of variables, the number of observations or the frequencies are different in A and B, the function returns one. 
-
-% Copyright (C) 2013 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 nargin~=2
-    error('dseries::ne: I need exactly two input arguments!')
-end
-
-if ~(isdseries(A) && isdseries(B))
-    error('dseries::ne: Both input arguments must be dseries objects!')
-end
-
-if ~isequal(nobs(A), nobs(B))
-    warning('dseries::ne: Both input arguments should have the same number of observations!')
-    C = 1;
-    return
-end
-
-if ~isequal(vobs(A), vobs(B))
-    warning('dseries::ne: Both input arguments should have the same number of observations!')
-    C = 1;
-    return
-end
-
-if ~isequal(frequency(A),frequency(B))
-    warning('dseries::ne: Both input arguments should have the same frequencies!')
-    C = 1;
-    return
-end
-
-if ~isequal(firstdate(A),firstdate(B))
-    warning('dseries::ne: Both input arguments should have the same initial period!')
-    C = 1;
-    return
-end
-
-if ~isequal(A.name,B.name)
-    warning('dseries::ne: Both input arguments do not have the same variables!')
-end
-
-if ~isequal(A.tex,B.tex)
-    warning('dseries::ne: Both input arguments do not have the same tex names!')
-end
-
-C = ne(A.data, B.data);
-
-%@test:1
-%$ % Define a datasets.
-%$ A = rand(10,3);
-%$ B = A;
-%$ B(:,3) = rand(10,1);
-%$
-%$ % Define names
-%$ A_name = {'A1';'A2';'A3'}; B_name = A_name;
-%$
-%$ t = zeros(2,1);
-%$
-%$ % Instantiate a time series object.
-%$ try
-%$    ts1 = dseries(A,[],A_name,[]);
-%$    ts2 = dseries(B,[],B_name,[]);
-%$    ts2 = ts1;
-%$    a = eq(ts1,ts2);
-%$    t(1) = 1;
-%$ catch
-%$    t = 0;
-%$ end
-%$
-%$ if length(t)>1
-%$    t(2) = dyn_assert(a,[ones(10,2), ones(10,1)]);
-%$ end
-%$ T = all(t);
-%@eof:1
\ No newline at end of file
diff --git a/matlab/@dseries/nobs.m b/matlab/@dseries/nobs.m
deleted file mode 100644
index dc6fc76536d5d8a5d86fc3c731c80a70694fbc28..0000000000000000000000000000000000000000
--- a/matlab/@dseries/nobs.m
+++ /dev/null
@@ -1,22 +0,0 @@
-function s = nobs(ts)
-
-% Returns the number of observations in a @dseries object.
-
-% 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/>.
-
-s = rows(ts.data);
\ No newline at end of file
diff --git a/matlab/@dseries/numel.m b/matlab/@dseries/numel.m
deleted file mode 100644
index 85cd84962a05b56f411ca3f60de28d691a09dd2f..0000000000000000000000000000000000000000
--- a/matlab/@dseries/numel.m
+++ /dev/null
@@ -1,20 +0,0 @@
-function n = numel(obj, varargin)
-
-% Copyright (C) 2012-2013 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/>.
-
-n = 1;
diff --git a/matlab/@dseries/plot.m b/matlab/@dseries/plot.m
deleted file mode 100644
index 058a44dd0cf1a08af81def389fb0ac868f5dd42b..0000000000000000000000000000000000000000
--- a/matlab/@dseries/plot.m
+++ /dev/null
@@ -1,84 +0,0 @@
-function h = plot(ts, varargin)
-
-% Overloads Matlab/Octave's plot function for dseries objects. 
-
-% Copyright (C) 2013 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/>.
-
-% Get the number of dseries objects
-if isequal(nargin,1)
-    ndseries = 1;
-    nvariables = vobs(ts);
-    nobservations = nobs(ts);
-else
-    if isdseries(varargin{1})
-        ndseries = 2;
-        nvariables = vobs(ts);
-        nobservations = nobs(ts);
-        if nargin>2 && any(cellfun(@isdseries,varargin(2:end)))
-            error('dseries::plot: You cannot pass more two dseries objects!')
-        end
-        if ~isequal(nvariables, vobs(varargin{1}))
-            error('dseries::plot: The two dseries objects must have the same number of variables!')
-        end
-        if ~isequal(nobservations, nobs(varargin{1}))
-            error('dseries::plot: The two dseries objects must have the same number of observations!')
-        end
-    else
-        ndseries = 1;
-        nvariables = vobs(ts);
-        nobservations = nobs(ts);
-    end
-end
-
-switch ndseries
-  case 1
-    if isequal(nvariables,1)
-        hh = plot(ts.data,varargin{:});
-    else
-        if length(varargin)
-            message = sprintf('dseries::plot: dseries object %s has %d>1 variables but you passed additional arguments to the plot function.\n                        These additional arguments won''t ne interpreted. Use the Matlab/Octave set command and the plot\n                        handle instead if you wish to modify the properties of the plotted time series.',inputname(1),nvariables);
-            warning(message)
-        end
-        hh = plot(ts.data);
-    end
-    axis tight;
-    id = get(gca,'XTick');
-    if isequal(id(1),0)
-        dates = strings([ts.dates(1)-1,ts.dates(id(2:end))]);
-    else
-        dates = strings(ts.dates(id));
-    end
-    set(gca,'XTickLabel',dates);
-  case 2
-    [ts0, ts1] = align(ts, varargin{1});
-    if isequal(nvariables,1)
-        hh = plot(ts0.data, ts1.data, varargin{2:end});
-    else
-        if length(varargin)>1
-             message = sprintf('dseries::plot: dseries objects %s and %s have %d>1 variables but you passed additional arguments to the plot function.\n                        These additional arguments won''t ne interpreted. Use the Matlab/Octave set command and the plot\n                        handle instead if you wish to modify the properties of the plotted time series.',inputname(1),inputname(2),nvariables);
-            warning(message)
-        end
-        hh = plot(ts0.data, ts1.data);
-    end
-  otherwise
-    error('dseries::plot: This is a bug! Please report the bug to the authors of Dynare.')
-end
-
-if nargout
-     h = hh;
-end
\ No newline at end of file
diff --git a/matlab/@dseries/plus.m b/matlab/@dseries/plus.m
deleted file mode 100644
index ee3f0295c0422724ebf99f5a2777cd421b5773be..0000000000000000000000000000000000000000
--- a/matlab/@dseries/plus.m
+++ /dev/null
@@ -1,325 +0,0 @@
-function A = plus(B,C) % --*-- Unitary tests --*--
-
-%@info:
-%! @deftypefn {Function File} {@var{A} =} plus (@var{B},@var{C})
-%! @anchor{@dseries/plus}
-%! @sp 1
-%! Overloads the plus method for the Dynare time series class (@ref{dseries}).
-%! @sp 2
-%! @strong{Inputs}
-%! @sp 1
-%! @table @ @var
-%! @item B
-%! Dynare time series object instantiated by @ref{dseries}.
-%! @item C
-%! Dynare time series object instantiated by @ref{dseries}.
-%! @end table
-%! @sp 1
-%! @strong{Outputs}
-%! @sp 1
-%! @table @ @var
-%! @item A
-%! Dynare time series object.
-%! @end deftypefn
-%@eod:
-
-% Copyright (C) 2011-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(B) && (isscalar(B) ||  isvector(B))
-    if ~isdseries(C)
-        error('dseries::plus: Second input argument must be a dseries object!')
-    end
-    A = C;
-    A.data = bsxfun(@plus,C.data,B);
-    return;
-end
-
-if isnumeric(C) && (isscalar(C) || isvector(C))
-    if ~isdseries(B)
-        error('dseries::plus: First input argument must be a dseries object!')
-    end
-    A = B;
-    A.data = bsxfun(@plus,B.data,C);
-    return
-end
-
-if ~isequal(vobs(B), vobs(C)) && ~(isequal(vobs(B), 1) || isequal(vobs(C), 1))
-    error(['dseries::plus: Cannot add ' inputname(1) ' and ' inputname(2) ' (wrong number of variables)!'])
-else
-    if vobs(B)>vobs(C)
-        idB = 1:vobs(B);
-        idC = ones(1,vobs(B));
-    elseif vobs(B)<vobs(C)
-        idB = ones(1,vobs(C));
-        idC = 1:vobs(C);
-    else
-        idB = 1:vobs(B);
-        idC = 1:vobs(C);
-    end
-end
-
-if ~isequal(frequency(B),frequency(C))
-    error(['dseries::plus: Cannot add ' inputname(1) ' and ' inputname(2) ' (frequencies are different)!'])
-end
-
-if ~isequal(nobs(B), nobs(C)) || ~isequal(firstdate(B),firstdate(C))
-    [B, C] = align(B, C);
-end
-
-if isempty(B)
-    A = C;
-    return
-end
-
-if isempty(C)
-    A = B;
-    return
-end
-
-A = dseries();
-
-A.data = bsxfun(@plus,B.data,C.data);
-A.dates = B.dates;
-
-A_vobs = max(vobs(B), vobs(C));
-A.name = cell(A_vobs,1);
-A.tex = cell(A_vobs,1);
-for i=1:A_vobs
-    A.name(i) = {['plus(' B.name{idB(i)} ',' C.name{idC(i)} ')']};
-    A.tex(i) = {['(' B.tex{idB(i)} '+' C.tex{idC(i)} ')']};
-end
-
-%@test:1
-%$ % Define a datasets.
-%$ A = rand(10,2); B = randn(10,1);
-%$
-%$ % Define names
-%$ A_name = {'A1';'A2'}; B_name = {'B1'};
-%$
-%$ t = zeros(5,1);
-%$
-%$ % Instantiate a time series object.
-%$ try
-%$    ts1 = dseries(A,[],A_name,[]);
-%$    ts2 = dseries(B,[],B_name,[]);
-%$    ts3 = ts1+ts2;
-%$    t(1) = 1;
-%$ catch
-%$    t = 0;
-%$ end
-%$
-%$ if length(t)>1
-%$    t(2) = dyn_assert(ts3.vobs,2);
-%$    t(3) = dyn_assert(ts3.nobs,10);
-%$    t(4) = dyn_assert(ts3.data,[A(:,1)+B, A(:,2)+B],1e-15);
-%$    t(5) = dyn_assert(ts3.name,{'plus(A1,B1)';'plus(A2,B1)'});
-%$ end
-%$ T = all(t);
-%@eof:1
-
-%@test:2
-%$ % Define a datasets.
-%$ A = rand(10,2); B = randn(10,1);
-%$
-%$ % Define names
-%$ A_name = {'A1';'A2'}; B_name = {'B1'};
-%$
-%$ t = zeros(5,1);
-%$
-%$ % Instantiate a time series object.
-%$ try
-%$    ts1 = dseries(A,[],A_name,[]);
-%$    ts2 = dseries(B,[],B_name,[]);
-%$    ts3 = ts1+ts2;
-%$    ts4 = ts3+ts1; 
-%$    t(1) = 1;
-%$ catch
-%$    t = 0;
-%$ end
-%$
-%$ if length(t)>1
-%$    t(2) = dyn_assert(ts4.vobs,2);
-%$    t(3) = dyn_assert(ts4.nobs,10);
-%$    t(4) = dyn_assert(ts4.data,[A(:,1)+B, A(:,2)+B]+A,1e-15);
-%$    t(5) = dyn_assert(ts4.name,{'plus(plus(A1,B1),A1)';'plus(plus(A2,B1),A2)'});
-%$ end
-%$ T = all(t);
-%@eof:2
-
-
-%@test:3
-%$ % Define a datasets.
-%$ A = rand(10,2); B = randn(5,1);
-%$
-%$ % Define names
-%$ A_name = {'A1';'A2'}; B_name = {'B1'};
-%$
-%$ t = zeros(5,1);
-%$
-%$ % Instantiate a time series object.
-%$ try
-%$    ts1 = dseries(A,[],A_name,[]);
-%$    ts2 = dseries(B,[],B_name,[]);
-%$    ts3 = ts1+ts2;
-%$    t(1) = 1;
-%$ catch
-%$    t = 0;
-%$ end
-%$
-%$ if length(t)>1
-%$    t(2) = dyn_assert(ts3.vobs,2);
-%$    t(3) = dyn_assert(ts3.nobs,10);
-%$    t(4) = dyn_assert(ts3.data,[A(1:5,1)+B(1:5), A(1:5,2)+B(1:5) ; NaN(5,2)],1e-15);
-%$    t(5) = dyn_assert(ts3.name,{'plus(A1,B1)';'plus(A2,B1)'});
-%$ end
-%$ T = all(t);
-%@eof:3
-
-%@test:4
-%$ t = zeros(7,1);
-%$
-%$ try
-%$     ts = dseries(transpose(1:5),'1950q1',{'Output'}, {'Y_t'});
-%$     us = dseries(transpose(1:5),'1949q4',{'Consumption'}, {'C_t'});
-%$     vs = ts+us;
-%$     t(1) = 1;
-%$ catch
-%$     t = 0;
-%$ end
-%$
-%$ if length(t)>1
-%$     t(2) = dyn_assert(ts.freq,4);
-%$     t(3) = dyn_assert(us.freq,4);
-%$     t(4) = dyn_assert(ts.init.time,[1950, 1]);
-%$     t(5) = dyn_assert(us.init.time,[1949, 4]);
-%$     t(6) = dyn_assert(vs.init.time,[1949, 4]);
-%$     t(7) = dyn_assert(vs.nobs,6);
-%$ end
-%$
-%$ T = all(t);
-%@eof:4
-
-%@test:5
-%$ t = zeros(7,1);
-%$
-%$ try
-%$     ts = dseries(transpose(1:5),'1950q1',{'Output'}, {'Y_t'});
-%$     us = dseries(transpose(1:7),'1950q1',{'Consumption'}, {'C_t'});
-%$     vs = ts+us;
-%$     t(1) = 1;
-%$ catch
-%$     t = 0;
-%$ end
-%$
-%$ if length(t)>1
-%$     t(2) = dyn_assert(ts.freq,4);
-%$     t(3) = dyn_assert(us.freq,4);
-%$     t(4) = dyn_assert(ts.init.time,[1950, 1]);
-%$     t(5) = dyn_assert(us.init.time,[1950, 1]);
-%$     t(6) = dyn_assert(vs.init.time,[1950, 1]);
-%$     t(7) = dyn_assert(vs.nobs,7);
-%$ end
-%$
-%$ T = all(t);
-%@eof:5
-
-%@test:6
-%$ t = zeros(8,1);
-%$
-%$ try
-%$     ts = dseries(transpose(1:5),'1950q1',{'Output'}, {'Y_t'});
-%$     us = dseries(transpose(1:7),'1950q1',{'Consumption'}, {'C_t'});
-%$     vs = ts+us('1950q1').data;
-%$     t(1) = 1;
-%$ catch
-%$     t = 0;
-%$ end
-%$
-%$ if length(t)>1
-%$     t(2) = dyn_assert(ts.freq,4);
-%$     t(3) = dyn_assert(us.freq,4);
-%$     t(4) = dyn_assert(ts.init.time,[1950, 1]);
-%$     t(5) = dyn_assert(us.init.time,[1950, 1]);
-%$     t(6) = dyn_assert(vs.init.time,[1950, 1]);
-%$     t(7) = dyn_assert(vs.nobs,5);
-%$     t(8) = dyn_assert(vs.data,ts.data+1);
-%$ end
-%$
-%$ T = all(t);
-%@eof:6
-
-%@test:7
-%$ t = zeros(8,1);
-%$
-%$ try
-%$     ts = dseries([transpose(1:5), transpose(1:5)],'1950q1');
-%$     us = dseries([transpose(1:7),2*transpose(1:7)],'1950q1');
-%$     vs = ts+us('1950q1').data;
-%$     t(1) = 1;
-%$ catch
-%$     t = 0;
-%$ end
-%$
-%$ if length(t)>1
-%$     t(2) = dyn_assert(ts.freq,4);
-%$     t(3) = dyn_assert(us.freq,4);
-%$     t(4) = dyn_assert(ts.init.time,[1950, 1]);
-%$     t(5) = dyn_assert(us.init.time,[1950, 1]);
-%$     t(6) = dyn_assert(vs.init.time,[1950, 1]);
-%$     t(7) = dyn_assert(vs.nobs,5);
-%$     t(8) = dyn_assert(vs.data,bsxfun(@plus,ts.data,[1, 2]));
-%$ end
-%$
-%$ T = all(t);
-%@eof:7
-
-%@test:8
-%$ ts1 = dseries(ones(3,1));
-%$ ts2 = ts1+1;
-%$ ts3 = 1+ts1;
-%$ t(1) = isequal(ts2.data, 2*ones(3,1));
-%$ t(2) = isequal(ts3.data, 2*ones(3,1));
-%$ T = all(t);
-%@eof:8
-
-%@test:9
-%$ ts1 = dseries(ones(3,2));
-%$ ts2 = ts1+1;
-%$ ts3 = 1+ts1;
-%$ t(1) = isequal(ts2.data, 2*ones(3,2));
-%$ t(2) = isequal(ts3.data, 2*ones(3,2));
-%$ T = all(t);
-%@eof:9
-
-%@test:10
-%$ ts1 = dseries(ones(3,2));
-%$ ts2 = ts1+ones(3,1);
-%$ ts3 = ones(3,1)+ts1;
-%$ t(1) = isequal(ts2.data, 2*ones(3,2));
-%$ t(2) = isequal(ts3.data, 2*ones(3,2));
-%$ T = all(t);
-%@eof:10
-
-%@test:11
-%$ ts1 = dseries(ones(3,2));
-%$ ts2 = ts1+ones(1,2);
-%$ ts3 = ones(1,2)+ts1;
-%$ t(1) = isequal(ts2.data, 2*ones(3,2));
-%$ t(2) = isequal(ts3.data, 2*ones(3,2));
-%$ T = all(t);
-%@eof:11
diff --git a/matlab/@dseries/pop.m b/matlab/@dseries/pop.m
deleted file mode 100644
index eb398322b3e43b23ed1695353cc5a3eeb8a98780..0000000000000000000000000000000000000000
--- a/matlab/@dseries/pop.m
+++ /dev/null
@@ -1,113 +0,0 @@
-function [ts,id] = pop(ts,a) % --*-- Unitary tests --*--
-
-% Removes a variable from a dseries object.
-
-%@info:
-%! @deftypefn {Function File} {@var{ts} =} pop (@var{ts}, @var{a})
-%! @anchor{dseries/pop}
-%! @sp 1
-%! Pop method for the dseries class. Removes a variable from a dseries object.
-%! @sp 2
-%! @strong{Inputs}
-%! @sp 1
-%! @table @ @var
-%! @item ts
-%! Object instantiated by @ref{dseries}.
-%! @item a
-%! String, name of the variable to be removed.
-%! @end table
-%! @sp 2
-%! @strong{Outputs}
-%! @sp 1
-%! @table @ @var
-%! @item ts
-%! Object instantiated by @ref{dseries}, without variable (@var{a}).
-%! @item id
-%! Scalar integer, position of variable (@var{a}) in the original dseries object @var{ts}.
-%! @end table
-%! @end deftypefn
-%@eod:
-
-% Copyright (C) 2013 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 nargin<2
-    % Removes the last variable
-    id = vobs(ts);
-else
-    id = find(strcmp(a,ts.name));
-end
-
-if isempty(id)
-    id = 0;
-    return
-end
-
-ts.data(:,id) = [];
-ts.name(id) = [];
-ts.tex(id) = [];
-
-%@test:1
-%$ % Define a datasets.
-%$ A = rand(10,3);
-%$
-%$ % Define names
-%$ A_name = {'A1';'A2';'A3'};
-%$
-%$ t = zeros(4,1);
-%$
-%$ % Instantiate a time series object.
-%$ try
-%$    ts1 = dseries(A,[],A_name,[]);
-%$    ts2 = pop(ts1,'A2');
-%$    t(1) = 1;
-%$ catch
-%$    t = 0;
-%$ end
-%$
-%$ if length(t)>1
-%$    t(2) = dyn_assert(ts2.vobs,2);
-%$    t(3) = dyn_assert(ts2.nobs,10);
-%$    t(4) = dyn_assert(ts2.data,[A(:,1), A(:,3)],1e-15);
-%$ end
-%$ T = all(t);
-%@eof:1
-
-%@test:2
-%$ % Define a datasets.
-%$ A = rand(10,3);
-%$
-%$ % Define names
-%$ A_name = {'A1';'A2';'A3'};
-%$
-%$ t = zeros(2,1);
-%$
-%$ % Instantiate a time series object.
-%$ try
-%$    ts1 = dseries(A,[],A_name,[]);
-%$    [ts2,id] = pop(ts1,'A4');
-%$    t(1) = 1;
-%$ catch
-%$    t = 0;
-%$ end
-%$
-%$ if length(t)>1
-%$    t(2) = dyn_assert(id,0);
-%$    t(2) = dyn_assert(isequal(ts1,ts2),1);
-%$ end
-%$ T = all(t);
-%@eof:2
diff --git a/matlab/@dseries/private/default_name.m b/matlab/@dseries/private/default_name.m
deleted file mode 100644
index 1711195c4313ddca8d499cd4d4b2f49f7cedb867..0000000000000000000000000000000000000000
--- a/matlab/@dseries/private/default_name.m
+++ /dev/null
@@ -1,27 +0,0 @@
-function names = default_name(dim)
-
-% Copyright (C) 2013 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/>.
-
-    
-names = {};
-for i=1:dim
-    names = vertcat(names, {['Variable_' int2str(i)]});
-end
-
-
-
diff --git a/matlab/@dseries/qdiff.m b/matlab/@dseries/qdiff.m
deleted file mode 100644
index e6ca19ca8d61c2ad4f792b8da5e81cfde5bd3f3d..0000000000000000000000000000000000000000
--- a/matlab/@dseries/qdiff.m
+++ /dev/null
@@ -1,107 +0,0 @@
-function us = qdiff(ts) % --*-- Unitary tests --*--
-
-%@info:
-%! @deftypefn {Function File} {@var{us} =} qdiff (@var{ts})
-%! @anchor{qdiff}
-%! @sp 1
-%! Computes quaterly differences.
-%! @sp 2
-%! @strong{Inputs}
-%! @sp 1
-%! @table @var
-%! @item ts
-%! Dynare time series object, instantiated by @ref{dseries}
-%! @end table
-%! @sp 2
-%! @strong{Outputs}
-%! @sp 1
-%! @table @var
-%! @item us
-%! Dynare time series object with transformed data field.
-%! @end table
-%! @end deftypefn
-%@eod:
-
-% Copyright (C) 2012-2013 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/>.
-
-us = ts;
-
-switch frequency(ts)
-  case 1
-    error('dseries::qgrowth: I cannot compute quaterly differences from yearly data!')
-  case 4
-    us.data(2:end,:) = ts.data(2:end,:)-ts.data(1:end-1,:);
-    us.data(1,:) = NaN;
-    for i = 1:vobs(ts)
-        us.name(i) = {['qdiff(' us.name{i} ')']};
-        us.tex(i) = {['\Delta ' us.tex{i}]};
-    end
-  case 12
-    us.data(4:end,:) = ts.data(4:end,:)-ts.data(1:end-3,:);
-    us.data(1:3,:) = NaN;
-    for i = 1:vobs(ts)
-        us.name(i) = {['qdiff(' us.name{i} ')']};
-        us.tex(i) = {['\Delta_3 ' us.tex{i}]};
-    end
-  case 52
-    error('dseries::qgrowth: I do not know yet how to compute quaterly differences from weekly data!')
-  otherwise
-    error(['dseries::ygrowth: object ' inputname(1) ' has unknown frequency']);
-end
-
-%@test:1
-%$ t = zeros(2,1);
-%$
-%$ try
-%$     data = transpose(0:1:50);
-%$     ts = dseries(data,'1950Q1');
-%$     ts = ts.qdiff;
-%$     t(1) = 1;
-%$ catch
-%$     t = 0;
-%$ end
-%$
-%$ if length(t)>1
-%$     DATA = NaN(1,ts.vobs);
-%$     DATA = [DATA; ones(ts.nobs-1,ts.vobs)];
-%$     t(2) = dyn_assert(ts.data,DATA,1e-15);
-%$ end
-%$
-%$ T = all(t);
-%@eof:1
-
-%@test:2
-%$ t = zeros(2,1);
-%$
-%$ try
-%$     data = transpose(0:1:80);
-%$     ts = dseries(data,'1950M1');
-%$     ts = ts.qdiff;
-%$     t(1) = 1;
-%$ catch
-%$     t = 0;
-%$ end
-%$
-%$ if length(t)>1
-%$     DATA = NaN(3,ts.vobs);
-%$     DATA = [DATA; 3*ones(ts.nobs-3,ts.vobs)];
-%$     t(2) = dyn_assert(ts.data,DATA,1e-15);
-%$ end
-%$
-%$ T = all(t);
-%@eof:2
diff --git a/matlab/@dseries/qgrowth.m b/matlab/@dseries/qgrowth.m
deleted file mode 100644
index 30e8d7b69f1954fa0a19ac885dc0f3d0234d0fd5..0000000000000000000000000000000000000000
--- a/matlab/@dseries/qgrowth.m
+++ /dev/null
@@ -1,107 +0,0 @@
-function us = qgrowth(ts) % --*-- Unitary tests --*--
-
-%@info:
-%! @deftypefn {Function File} {@var{us} =} qgrowth (@var{ts})
-%! @anchor{qgrowth}
-%! @sp 1
-%! Computes quaterly growth rates.
-%! @sp 2
-%! @strong{Inputs}
-%! @sp 1
-%! @table @var
-%! @item ts
-%! Dynare time series object, instantiated by @ref{dseries}
-%! @end table
-%! @sp 2
-%! @strong{Outputs}
-%! @sp 1
-%! @table @var
-%! @item us
-%! Dynare time series object with transformed data field.
-%! @end table
-%! @end deftypefn
-%@eod:
-
-% Copyright (C) 2012-2013 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/>.
-
-us = ts;
-
-switch frequency(ts)
-  case 1
-    error('dseries::qgrowth: I cannot compute quaterly growth rates from yearly data!')
-  case 4
-    us.data(2:end,:) = ts.data(2:end,:)./ts.data(1:end-1,:) - 1;
-    us.data(1,:) = NaN;
-    for i = 1:vobs(ts)
-        us.name(i) = {['qgrowth(' us.name{i} ')']};
-        us.tex(i) = {['\delta ' us.tex{i}]};
-    end
-  case 12
-    us.data(4:end,:) = ts.data(4:end,:)./ts.data(1:end-3,:) - 1;
-    us.data(1:3,:) = NaN;
-    for i = 1:vobs(ts)
-        us.name(i) = {['qgrowth(' us.name{i} ')']};
-        us.tex(i) = {['\delta_3 ' us.tex{i}]};
-    end
-  case 52
-    error('dseries::qgrowth: I do not know yet how to compute quaterly growth rates from weekly data!')
-  otherwise
-    error(['dseries::ygrowth: object ' inputname(1) ' has unknown frequency']);
-end
-
-%@test:1
-%$ t = zeros(2,1);
-%$
-%$ try
-%$     data = (1+.01).^transpose(0:1:50);
-%$     ts = dseries(data,'1950Q1');
-%$     ts = ts.qgrowth;
-%$     t(1) = 1;
-%$ catch
-%$     t = 0;
-%$ end
-%$
-%$ if length(t)>1
-%$     DATA = NaN(1,ts.vobs);
-%$     DATA = [DATA; .01*ones(ts.nobs-1,ts.vobs)];
-%$     t(2) = dyn_assert(ts.data,DATA,1e-15);
-%$ end
-%$
-%$ T = all(t);
-%@eof:1
-
-%@test:2
-%$ t = zeros(2,1);
-%$
-%$ try
-%$     data = (1+.01).^transpose(0:1:80);
-%$     ts = dseries(data,'1950M1');
-%$     ts = ts.qgrowth;
-%$     t(1) = 1;
-%$ catch
-%$     t = 0;
-%$ end
-%$
-%$ if length(t)>1
-%$     DATA = NaN(3,ts.vobs);
-%$     DATA = [DATA; (1.01^3-1)*ones(ts.nobs-3,ts.vobs)];
-%$     t(2) = dyn_assert(ts.data,DATA,1e-15);
-%$ end
-%$
-%$ T = all(t);
-%@eof:2
diff --git a/matlab/@dseries/remove.m b/matlab/@dseries/remove.m
deleted file mode 100644
index db9690cfd6c2ef800d1698ea983d3f7f6c108d66..0000000000000000000000000000000000000000
--- a/matlab/@dseries/remove.m
+++ /dev/null
@@ -1,98 +0,0 @@
-function ts = remove(ts,a) % --*-- Unitary tests --*--
-
-% Removes a variable from a dseries object (alias for the pop method).
-
-%@info:
-%! @deftypefn {Function File} {@var{ts} =} pop (@var{ts}, @var{a})
-%! @anchor{dseries/pop}
-%! @sp 1
-%! Remove method for the dseries class. Removes a variable from a dseries object.
-%! @sp 2
-%! @strong{Inputs}
-%! @sp 1
-%! @table @ @var
-%! @item ts
-%! Object instantiated by @ref{dseries}.
-%! @item a
-%! String, name of the variable to be removed.
-%! @end table
-%! @sp 2
-%! @strong{Outputs}
-%! @sp 1
-%! @table @ @var
-%! @item ts
-%! Object instantiated by @ref{dseries}, without variable (@var{a}).
-%! @end table
-%! @end deftypefn
-%@eod:
-
-% 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/>.
-
-ts = pop(ts, a);
-
-%@test:1
-%$ % Define a datasets.
-%$ A = rand(10,3);
-%$
-%$ % Define names
-%$ A_name = {'A1';'A2';'A3'};
-%$
-%$ t = zeros(4,1);
-%$
-%$ % Instantiate a time series object.
-%$ try
-%$    ts1 = dseries(A,[],A_name,[]);
-%$    ts2 = remove(ts1,'A2');
-%$    t(1) = 1;
-%$ catch
-%$    t = 0;
-%$ end
-%$
-%$ if length(t)>1
-%$    t(2) = dyn_assert(ts2.vobs,2);
-%$    t(3) = dyn_assert(ts2.nobs,10);
-%$    t(4) = dyn_assert(ts2.data,[A(:,1), A(:,3)],1e-15);
-%$ end
-%$ T = all(t);
-%@eof:1
-
-%@test:2
-%$ % Define a datasets.
-%$ A = rand(10,3);
-%$
-%$ % Define names
-%$ A_name = {'A1';'A2';'A3'};
-%$
-%$ t = zeros(4,1);
-%$
-%$ % Instantiate a time series object.
-%$ try
-%$    ts1 = dseries(A,[],A_name,[]);
-%$    ts2 = ts1.remove('A2');
-%$    t(1) = 1;
-%$ catch
-%$    t = 0;
-%$ end
-%$
-%$ if length(t)>1
-%$    t(2) = dyn_assert(ts2.vobs,2);
-%$    t(3) = dyn_assert(ts2.nobs,10);
-%$    t(4) = dyn_assert(ts2.data,[A(:,1), A(:,3)],1e-15);
-%$ end
-%$ T = all(t);
-%@eof:2
\ No newline at end of file
diff --git a/matlab/@dseries/rename.m b/matlab/@dseries/rename.m
deleted file mode 100644
index de67e2b908f0b5fe04e505e3fcaab68d6b6b725c..0000000000000000000000000000000000000000
--- a/matlab/@dseries/rename.m
+++ /dev/null
@@ -1,76 +0,0 @@
-function ts = rename(ts,old,new) % --*-- Unitary tests --*--
-
-% Copyright (C) 2013 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 ~ischar(old) || ~ischar(new)
-    error(['dseries::rename: Input arguments ''' inputname(2) ''' and ''' inputname(3) '''  have to be strings!'])
-end
-    
-idname = find(strcmp(old,ts.name));
-
-if isempty(idname)
-    error(['dseries::rename: Variable ' old ' is unknown in dseries object ' inputname(1)  '!'])
-end
-
-ts.name(idname) = {new};
-
-%@test:1
-%$ t = zeros(8,1);
-%$ ts = dseries([transpose(1:5), transpose(6:10)],'1950q1',{'Output'; 'Consumption'}, {'Y_t'; 'C_t'});
-%$ try
-%$     ts = rename(ts,'Output','Production');
-%$     t(1) = 1;
-%$ catch
-%$     t = 0;
-%$ end
-%$
-%$ if length(t)>1
-%$     t(2) = dyn_assert(ts.freq,4);
-%$     t(3) = dyn_assert(ts.init.freq,4);
-%$     t(4) = dyn_assert(ts.init.time,[1950, 1]);
-%$     t(5) = dyn_assert(ts.vobs,2);
-%$     t(6) = dyn_assert(ts.nobs,5);
-%$     t(7) = dyn_assert(ts.name,{'Production'; 'Consumption'});
-%$     t(8) = dyn_assert(ts.tex,{'Y_t'; 'C_t'});
-%$ end
-%$
-%$ T = all(t);
-%@eof:1
-
-%@test:2
-%$ t = zeros(8,1);
-%$ ts = dseries([transpose(1:5), transpose(6:10)],'1950q1',{'Output'; 'Consumption'}, {'Y_t'; 'C_t'});
-%$ try
-%$     ts = ts.rename('Output','Production');
-%$     t(1) = 1;
-%$ catch
-%$     t = 0;
-%$ end
-%$
-%$ if length(t)>1
-%$     t(2) = dyn_assert(ts.freq,4);
-%$     t(3) = dyn_assert(ts.init.freq,4);
-%$     t(4) = dyn_assert(ts.init.time,[1950, 1]);
-%$     t(5) = dyn_assert(ts.vobs,2);
-%$     t(6) = dyn_assert(ts.nobs,5);
-%$     t(7) = dyn_assert(ts.name,{'Production'; 'Consumption'});
-%$     t(8) = dyn_assert(ts.tex,{'Y_t'; 'C_t'});
-%$ end
-%$
-%$ T = all(t);
-%@eof:2
diff --git a/matlab/@dseries/save.m b/matlab/@dseries/save.m
deleted file mode 100644
index 3e8b478fc8ebad46cb55453135ef8a71d8da7385..0000000000000000000000000000000000000000
--- a/matlab/@dseries/save.m
+++ /dev/null
@@ -1,171 +0,0 @@
-function save(A,basename,format) % --*-- Unitary tests --*--
-
-% Saves a dseries object on disk.
-
-% Copyright (C) 2013 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 nargin<3 || isempty(format)
-    format = 'csv';
-end
-
-if nargin<2 || isempty(basename)
-    basename = inputname(1);
-end
-
-switch format
-  case 'm'
-    if exist([basename, '.m'],'file')
-        copyfile([basename, '.m'],[basename, '.old.m']);
-    end
-    fid = fopen([basename, '.m'],'w');
-    fprintf(fid,'%% File created on %s.\n',datestr(now));
-    fprintf(fid,'\n');
-    fprintf(fid,'FREQ__ = %s;\n',num2str(frequency(A)));
-    fprintf(fid,'INIT__ = ''%s'';\n',date2string(firstdate(A)));
-    fprintf(fid,'\n');
-    fprintf(fid,'NAMES__ = {');
-    for i=1:vobs(A)
-        fprintf(fid,[ '''' A.name{i}  '''']);
-        if i<vobs(A)
-            fprintf(fid,'; ');
-        end
-    end
-    fprintf(fid,'};\n');
-    str = 'TEX__ = {';
-    for i=1:vobs(A)-1
-        str = [str, '''%s''; '];
-    end
-    str = [str, '''%s''};'];
-    str = sprintf(str, A.tex{:});
-    pattern = '(\w*)(\\\_)';
-    str = regexprep(str, pattern, '$1\\\\_');
-    fprintf(fid,str);
-    fprintf(fid,'\n\n');
-    for v=1:vobs(A)
-        fprintf(fid,'%s = [\n', A.name{v});
-        fprintf(fid,'%15.8g\n',A.data(1:end-1,v));
-        fprintf(fid,'%15.8g];\n\n',A.data(end,v));
-    end
-    fclose(fid);
-  case 'mat'
-    FREQ__ = frequency(A);
-    INIT__ = date2string(firstdate(A));
-    NAMES__ = A.name;
-    TEX__ = A.tex;
-    str = [];
-    for v=1:vobs(A)
-        str = [str, A.name{v} ' = A.data(:,' num2str(v) ');' ];
-    end
-    eval(str);
-    if exist([basename, '.mat'],'file')
-        copyfile([basename, '.mat'],[basename, '.old.mat']);
-    end
-    save([basename '.mat'],'INIT__','FREQ__','NAMES__','TEX__',A.name{:});
-  case 'csv'
-    if exist([basename, '.csv'],'file')
-        copyfile([basename, '.csv'],[basename, '.old.csv']);
-    end
-    fid = fopen([basename, '.csv'],'w');
-    fprintf(fid,',%s', A.name{:});
-    fprintf(fid,'\n');
-    for t=1:nobs(A)
-        str = sprintf(', %15.8g',A.data(t,:));
-        fprintf(fid, '%s%s\n',date2string(A.dates(t)),str);
-    end
-    fclose(fid);
-end
-
-%@test:1
-%$ % Define a data set.
-%$ A = [transpose(1:10),2*transpose(1:10)];
-%$
-%$ % Define names
-%$ A_name = {'A1';'A2'};
-%$
-%$ % Instantiate a time series object.
-%$ try
-%$    ts1 = dseries(A,[],A_name,[]);
-%$    save(ts1,[],'csv');
-%$    t = 1;
-%$ catch
-%$    t = 0;
-%$ end
-%$
-%$ T = all(t);
-%@eof:1
-
-%@test:2
-%$ % Define a data set.
-%$ A = [transpose(1:10),2*transpose(1:10)];
-%$
-%$ % Define names
-%$ A_name = {'A1';'A2'};
-%$
-%$ % Instantiate a time series object.
-%$ try
-%$    ts1 = dseries(A,[],A_name,[]);
-%$    save(ts1,[],'m');
-%$    t = 1;
-%$ catch
-%$    t = 0;
-%$ end
-%$
-%$ T = all(t);
-%@eof:2
-
-%@test:3
-%$ % Define a data set.
-%$ A = [transpose(1:10),2*transpose(1:10)];
-%$
-%$ % Define names
-%$ A_name = {'A1';'A2'};
-%$
-%$ % Instantiate a time series object.
-%$ try
-%$    ts1 = dseries(A,[],A_name,[]);
-%$    save(ts1,[],'mat');
-%$    t = 1;
-%$ catch
-%$    t = 0;
-%$ end
-%$
-%$ T = all(t);
-%@eof:3
-
-%@test:4
-%$ % Define a data set.
-%$ A = [transpose(1:10),2*transpose(1:10)];
-%$
-%$ % Define names
-%$ A_name = {'A1';'A2'};
-%$
-%$ % Instantiate a time series object.
-%$ try
-%$    ts1 = dseries(A,[],A_name,[]);
-%$    if isoctave
-%$        ts1.save('A');
-%$    else
-%$        ts1.save;
-%$    end
-%$    t = 1;
-%$ catch
-%$    t = 0;
-%$ end
-%$
-%$ T = all(t);
-%@eof:4
diff --git a/matlab/@dseries/set_names.m b/matlab/@dseries/set_names.m
deleted file mode 100644
index 0751872ab43bcf1089100bb54bd9e66ea92b007b..0000000000000000000000000000000000000000
--- a/matlab/@dseries/set_names.m
+++ /dev/null
@@ -1,113 +0,0 @@
-function A = set_names(B,varargin) % --*-- Unitary tests --*--
-
-%@info:
-%! @deftypefn {Function File} {@var{A} =} times (@var{B},@code{varargin})
-%! @anchor{@nSeries/set_names}
-%! @sp 1
-%! Specify names of the variables in a @ref{dseries} object.
-%! @sp 2
-%! @strong{Inputs}
-%! @sp 1
-%! @table @ @var
-%! @item B
-%! Dynare time series object instantiated by @ref{dseries}.
-%! @item C
-%! Dynare time series object instantiated by @ref{dseries}.
-%! @end table
-%! @sp 1
-%! @strong{Outputs}
-%! @sp 1
-%! @table @ @var
-%! @item A
-%! Dynare time series object.
-%! @end deftypefn
-%@eod:
-
-% Copyright (C) 2012 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/>.
-
-% AUTHOR(S) stephane DOT adjemian AT univ DASH lemans DOT fr
-
-n = nargin-1;
-
-if ~isdseries(B)
-    error(['dseries::rename: ' inputname(1) ' must be a dseries object!'])
-end
-
-if ~isequal(vobs(B),n)
-    error(['dseries::rename: The number of variables in ' inputname(1) ' does not match the number of declared names!'])
-end
-
-A = B;
-
-for i=1:vobs(A)
-    if ~isempty(varargin{i})
-        A.name(i) = { varargin{i} };
-    end
-end
-
-%@test:1
-%$ % Define a datasets.
-%$ A = rand(10,3);
-%$
-%$ % Define names
-%$ A_name = {'A1';'Variable_2';'A3'};
-%$
-%$ t = zeros(4,1);
-%$
-%$ % Instantiate a time series object.
-%$ try
-%$    ts1 = dseries(A,[],[],[]);
-%$    ts2 = set_names(ts1,'A1',[],'A3');
-%$    t(1) = 1;
-%$ catch
-%$    t = 0;
-%$ end
-%$ 
-%$ if length(t)>1
-%$    t(2) = dyn_assert(ts2.vobs,3);
-%$    t(3) = dyn_assert(ts2.nobs,10);
-%$    t(4) = dyn_assert(ts2.name,A_name);
-%$ end
-%$ T = all(t);
-%@eof:1
-
-%@test:2
-%$ % Define a datasets.
-%$ A = rand(10,3);
-%$
-%$ % Define names
-%$ A_name = {'A1';'Variable_2';'A3'};
-%$
-%$ t = zeros(4,1);
-%$
-%$ % Instantiate a time series object.
-%$ try
-%$    ts1 = dseries(A,[],[],[]);
-%$    ts1 = ts1.set_names('A1',[],'A3');
-%$    t(1) = 1;
-%$ catch
-%$    t = 0;
-%$ end
-%$
-%$ if length(t)>1
-%$    t(2) = dyn_assert(ts1.vobs,3);
-%$    t(3) = dyn_assert(ts1.nobs,10);
-%$    t(4) = dyn_assert(ts1.name,A_name);
-%$ end
-%$ T = all(t);
-%@eof:2
diff --git a/matlab/@dseries/size.m b/matlab/@dseries/size.m
deleted file mode 100644
index c83090b51258e2c8afd4e370848b383bc4be82be..0000000000000000000000000000000000000000
--- a/matlab/@dseries/size.m
+++ /dev/null
@@ -1,34 +0,0 @@
-function varargout = size(o, varargin)
-
-% 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/>.
-
-switch nargout
-  case 0
-    size(o.data, varargin{:})
-  case 1
-    varargout{1} = size(o.data, varargin{:});
-  case 2
-    if isequal(nargin, 1)
-        varargout{1} = size(o.data, 1);
-        varargout{2} = size(o.data, 2);
-    else
-        error('dseries::size: Wrong calling sequence!')
-    end
-  otherwise
-    error('dseries::size: Wrong calling sequence! Cannot return more than two arguments.')
-end
\ No newline at end of file
diff --git a/matlab/@dseries/subsasgn.m b/matlab/@dseries/subsasgn.m
deleted file mode 100644
index b8abbbbde8869ef5fba4d784d4fe4fb883bc2991..0000000000000000000000000000000000000000
--- a/matlab/@dseries/subsasgn.m
+++ /dev/null
@@ -1,886 +0,0 @@
-function A = subsasgn(A,S,B) % --*-- Unitary tests --*--
-
-%@info:
-%! @deftypefn {Function File} {@var{A} =} subsasgn (@var{A}, @var{S}, @var{B})
-%! @anchor{@dseries/subsasgn}
-%! @sp 1
-%! Overloads the subsasgn method for the Dynare time series class (@ref{dseries}).
-%! @end deftypefn
-%@eod:
-
-% Copyright (C) 2012-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/>.
-
-merge_dseries_objects = 1;
-
-switch length(S)
-    case 1
-      switch S(1).type
-        case '{}' % Multiple variable selection.
-          if ~isequal(numel(S(1).subs),numel(unique(S(1).subs)))
-              error('dseries::subsasgn: Wrong syntax!')
-          end
-          for i=1:numel(S(1).subs)
-              element = S(1).subs{i};
-              idArobase = strfind(element,'@');
-              if ~isempty(idArobase)
-                  switch length(idArobase)
-                    case 2
-                      idComma = strfind(element(idArobase(1)+1:idArobase(2)-1),',');
-                      if ~isempty(idComma)
-                          elements = cell(1,numel(idComma)+1); j = 1;
-                          expression = element(idArobase(1)+1:idArobase(2)-1);
-                          while ~isempty(expression)
-                              [token, expression] = strtok(expression,',');
-                              elements(j) = {[element(1:idArobase(1)-1), token, element(idArobase(2)+1:end)]};
-                              j = j + 1;
-                          end
-                          S(1).subs = replace_object_in_a_one_dimensional_cell_array(S(1).subs, elements(:), i);
-                      else
-                          error('dseries::subsasgn: Wrong syntax, matlab''s regular expressions cannot be used here!')
-                      end
-                    case 4
-                      idComma_1 = strfind(element(idArobase(1)+1:idArobase(2)-1),',');
-                      idComma_2 = strfind(element(idArobase(3)+1:idArobase(4)-1),',');
-                      if ~isempty(idComma_1)
-                          elements = cell(1,(numel(idComma_1)+1)*(numel(idComma_2)+1)); j = 1;
-                          expression_1 = element(idArobase(1)+1:idArobase(2)-1);
-                          while ~isempty(expression_1)
-                              [token_1, expression_1] = strtok(expression_1,',');
-                              expression_2 = element(idArobase(3)+1:idArobase(4)-1);
-                              while ~isempty(expression_2)
-                                  [token_2, expression_2] = strtok(expression_2,',');
-                                  elements(j) = {[element(1:idArobase(1)-1), token_1, element(idArobase(2)+1:idArobase(3)-1), token_2, element(idArobase(4)+1:end)]};
-                                  j = j+1;
-                              end
-                          end
-                          S(1).subs = replace_object_in_a_one_dimensional_cell_array(S(1).subs, elements(:), i);
-                      else
-                          error('dseries::subsasgn: Wrong syntax, matlab''s regular expressions cannot be used here!')
-                      end
-                    otherwise
-                      error('dseries::subsasgn: Wrong syntax!')
-                  end
-              end
-          end
-          if isempty(B)
-              for i=1:length(S(1).subs)
-                  A = remove(A,S(1).subs{i});
-              end
-              return
-          end
-          if ~isequal(length(S(1).subs),vobs(B))
-              error('dseries::subsasgn: Wrong syntax!')
-          end
-          if ~isequal(S(1).subs(:),B.name)
-              for i = 1:vobs(B)
-                  if ~isequal(S(1).subs{i},B.name{i})
-                      % Rename a variable.
-                      id = find(strcmp(S(1).subs{i},A.name));
-                      if isempty(id)
-                          % Add a new variable a change its name.
-                          B.name(i) = {S(1).subs{i}};
-                          B.tex(i) = {name2tex(S(1).subs{i})};
-                      else
-                          % Rename variable and change its content.
-                          B.name(i) = A.name(id);
-                          B.tex(i) = A.tex(id);
-                      end
-                  end
-              end
-          end
-        case '.'
-          if isequal(S(1).subs,'init') && isdates(B) && isequal(length(B),1)
-              % Change the initial date (update dates member)
-              A.dates = B:B+(nobs(A)-1);
-              return
-          elseif isequal(S(1).subs,'dates') && isdates(B)
-              % Overwrite the dates member
-              A.dates = B;
-              return
-          elseif ismember(S(1).subs,{'data','name','tex'})
-              error(['dseries::subsasgn: You cannot overwrite ' S(1).subs ' member!'])
-          elseif ~isequal(S(1).subs,B.name)
-              % Single variable selection.
-              if ~isequal(S(1).subs,B.name{1})
-                  % Rename a variable.
-                  id = find(strcmp(S(1).subs,A.name));
-                  if isempty(id)
-                      % Add a new variable a change its name.
-                      B.name(1) = {S(1).subs};
-                      B.tex(1) = {name2tex(S(1).subs)};
-                  else
-                      % Rename variable and change its content.
-                      B.name(1) = A.name(id);
-                      B.tex(1) = A.tex(id);
-                  end
-              end
-          end
-        case '()' % Date(s) selection
-          if isdates(S(1).subs{1}) || isdate(S(1).subs{1})
-                if isdate(S(1).subs{1})
-                    Dates = dates(S(1).subs{1});
-                else
-                    Dates = S(1).subs{1};
-                end
-              [junk, tdx] = intersect(A.dates.time,Dates.time,'rows');
-              if isdseries(B)
-                  [junk, tdy] = intersect(B.dates.time,Dates.time,'rows');
-                  if isempty(tdy)
-                      error('dseries::subsasgn: Periods of the dseries objects on the left and right hand sides must intersect!')
-                  end
-                  if ~isequal(vobs(A), vobs(B))
-                      error('dseries::subsasgn: Dimension error! The number of variables on the left and right hand side must match.')
-                  end
-                  A.data(tdx,:) = B.data(tdy,:);
-                  merge_dseries_objects = 0;
-              elseif isnumeric(B)
-                  merge_dseries_objects = 0;
-                  if isequal(length(tdx),rows(B))
-                      if isequal(columns(A.data),columns(B))
-                          A.data(tdx,:) = B;
-                      else
-                          error('dseries::subsasgn: Dimension error! The number of variables on the left and right hand side must match.')
-                      end
-                  else
-                      error('dseries::subsassgn: Dimension error! The number of periods on the left and right hand side must match.')
-                  end
-              else
-                  error('dseries::subsasgn: The object on the right hand side must be a dseries object or a numeric array!')
-              end
-          elseif ischar(S(1).subs{1}) && isequal(S(1).subs{1},':') && isempty(A)
-              if isnumeric(B)
-                  if isequal(rows(B),1)
-                      A.data = repmat(B,A.dates.ndat,1);
-                  elseif isequal(rows(B),A.dates.ndat)
-                      A.data = B;
-                  else
-                      error('dseries::subsasgn: Wrong syntax!')
-                  end
-                  if isempty(A.name)
-                      A.name = default_name(vobs(A));
-                      A.tex = name2tex(A.name);
-                  end
-              elseif isdseries(B)
-                  if isequal(nobs(B), 1)
-                      A.data = repmat(B.data,A.dates.ndat,1);
-                  elseif isequal(nobs(B), A.dates.ndat)
-                      A.data = B;
-                  else
-                      error('dseries::subsasgn: Wrong syntax!')
-                  end
-                  if isempty(A.name)
-                      A.name = B.name;
-                      A.tex = B.tex;
-                  end
-              end
-              return
-          else
-              error('dseries::subsasgn: Wrong syntax!')
-          end
-        otherwise
-          error('dseries::subsasgn: Wrong syntax!')
-      end
-  case 2
-    merge_dseries_objects = 0;
-    if ((isequal(S(1).type,'{}') || isequal(S(1).type,'.')) && isequal(S(2).type,'()'))
-        if isequal(S(1).type,'{}')
-            sA = extract(A,S(1).subs{:});
-        else
-            sA = extract(A,S(1).subs);
-        end
-        if (isdseries(B) && isequal(vobs(sA), vobs(B))) || (isnumeric(B) && isequal(vobs(sA),columns(B))) || (isnumeric(B) && isequal(columns(B),1))
-            if isdates(S(2).subs{1})
-                [junk, tdx] = intersect(sA.dates.time,S(2).subs{1}.time,'rows');
-                if isdseries(B)
-                    [junk, tdy] = intersect(B.dates.time,S(2).subs{1}.time,'rows');
-                    if isempty(tdy)
-                        error('dseries::subsasgn: Periods of the dseries objects on the left and right hand sides must intersect!')
-                    end
-                    sA.data(tdx,:) = B.data(tdy,:);
-                elseif isnumeric(B)
-                    merge_dseries_objects = 0;
-                    if isequal(length(tdx),rows(B))
-                        if isequal(columns(sA.data),columns(B))
-                            sA.data(tdx,:) = B;
-                        elseif isequal(size(B,2),1)
-                            sA.data(tdx,:) = repmat(B,1,columns(sA.data));
-                        else
-                            error('dseries::subsasgn: Dimension error! The number of variables on the left and right hand side must match.')
-                        end
-                    else
-                        if isequal(columns(sA.data),columns(B)) && isequal(rows(B),1)
-                            sA.data(tdx,:) = repmat(B,length(tdx),1);
-                        elseif isequal(rows(B),1)
-                            sA.data(tdx,:) = B;
-                        else
-                            error('dseries::subsassgn: Dimension error! The number of periods on the left and right hand side must match.')
-                        end
-                    end
-                else
-                    error('dseries::subsasgn: The object on the right hand side must be a dseries object or a numeric array!')
-                end
-            else
-                error('dseries::subsasgn: Wrong syntax!')
-            end
-            A = merge(A,sA);
-        else
-            error('dseries::subsasgn: Dimension error! The number of variables on the left and right hand side must match.')
-        end
-    end
-  otherwise
-    error('dseries::subsasgn: Wrong syntax!')
-end
-
-if isempty(A)
-    % Assign variables to an empty dseries object.
-    A = B;
-    return
-end
-
-if merge_dseries_objects
-    A = merge(A,B);
-end
-
-%@test:1
-%$ % Define a datasets.
-%$ A = rand(10,3); B = rand(10,1);
-%$
-%$ % Instantiate two dseries object.
-%$ ts1 = dseries(A,[],{'A1';'A2';'A3'},[]);
-%$ ts2 = dseries(B,[],{'B1'},[]);
-%$
-%$ % modify first object.
-%$ try
-%$     ts1{'A2'} = ts2;
-%$     t(1) = 1;
-%$ catch
-%$     t(1) = 0;
-%$ end
-%$
-%$ % Instantiate a time series object.
-%$ if t(1)
-%$    t(2) = dyn_assert(ts1.vobs,3);
-%$    t(3) = dyn_assert(ts1.nobs,10);
-%$    t(4) = dyn_assert(ts1.name{2},'A2');
-%$    t(5) = dyn_assert(ts1.name{1},'A1');
-%$    t(6) = dyn_assert(ts1.name{3},'A3');
-%$    t(7) = dyn_assert(ts1.data,[A(:,1), B, A(:,3)],1e-15);
-%$ end
-%$ T = all(t);
-%@eof:1
-
-%@test:2
-%$ % Define a datasets.
-%$ A = rand(10,3);
-%$
-%$ % Instantiate two dseries object.
-%$ ts1 = dseries(A,[],{'A1';'A2';'A3'},[]);
-%$
-%$ % Apply the exponential function to the second variable.
-%$ ts1{'A2'} = ts1{'A2'}.exp;
-%$
-%$ % Instantiate a time series object.
-%$
-%$    t(1) = dyn_assert(ts1.vobs,3);
-%$    t(2) = dyn_assert(ts1.nobs,10);
-%$    t(3) = dyn_assert(ts1.name{2},'A2');
-%$    t(4) = dyn_assert(ts1.name{1},'A1');
-%$    t(5) = dyn_assert(ts1.name{3},'A3');
-%$    t(6) = dyn_assert(ts1.data,[A(:,1), exp(A(:,2)), A(:,3)],1e-15);
-%$ T = all(t);
-%@eof:2
-
-%@test:3
-%$ % Define a datasets.
-%$ A = rand(10,3);
-%$
-%$ % Instantiate two dseries object.
-%$ ts1 = dseries(A,[],{'A1';'A2';'A3'},[]);
-%$
-%$ % Apply the logarithm function to the first and third variables.
-%$ ts1{'A1'} = ts1{'A1'}.log;
-%$ ts1{'A3'} = ts1{'A3'}.log;
-%$
-%$ % Instantiate a time series object.
-%$
-%$    t(1) = dyn_assert(ts1.vobs,3);
-%$    t(2) = dyn_assert(ts1.nobs,10);
-%$    t(3) = dyn_assert(ts1.name{2},'A2');
-%$    t(4) = dyn_assert(ts1.name{1},'A1');
-%$    t(5) = dyn_assert(ts1.name{3},'A3');
-%$    t(6) = dyn_assert(ts1.data,[log(A(:,1)), A(:,2), log(A(:,3))],1e-15);
-%$ T = all(t);
-%@eof:3
-
-%@test:4
-%$ % Define a datasets.
-%$ A = rand(10,3);
-%$
-%$ % Instantiate two dseries object.
-%$ ts1 = dseries(A,[],{'A1';'A2';'A3'},[]);
-%$
-%$ % Apply the logarithm function to the first and third variables of ts1.
-%$ ts1{'A1','A3'} = ts1{'A1','A3'}.log;
-%$
-%$ t(1) = dyn_assert(ts1.vobs,3);
-%$ t(2) = dyn_assert(ts1.nobs,10);
-%$ t(3) = dyn_assert(ts1.name{1},'A1') && dyn_assert(ts1.name{2},'A2') && dyn_assert(ts1.name{3},'A3');
-%$ t(4) = dyn_assert(ts1.data,[log(A(:,1)), A(:,2), log(A(:,3))],1e-15);
-%$ T = all(t);
-%@eof:4
-
-%@test:5
-%$ % Define a datasets.
-%$ A = rand(10,3); B = rand(10,3);
-%$
-%$ % Instantiate two dseries object.
-%$ ts1 = dseries(A,[],{'A1';'A2';'A3'},[]);
-%$ ts2 = dseries(B,[],{'A1';'B2';'B3'},[]);
-%$
-%$ % Apply the logarithm function to the first and third variables.
-%$ ts1.A1 = ts2.A1;
-%$
-%$ % Instantiate a time series object.
-%$
-%$ t(1) = dyn_assert(ts1.vobs,3);
-%$ t(2) = dyn_assert(ts1.nobs,10);
-%$ t(3) = dyn_assert(ts1.name{1},'A1');
-%$ t(4) = dyn_assert(ts1.data(:,1),B(:,1), 1e-15);
-%$ t(5) = dyn_assert(ts1.data(:,2:3),A(:,2:3), 1e-15);
-%$ T = all(t);
-%@eof:5
-
-%@test:6
-%$ % Define a datasets.
-%$ A = rand(10,3); B = rand(10,2);
-%$
-%$ % Instantiate two dseries object.
-%$ ts1 = dseries(A,[],{'A1';'A2';'A3'},[]);
-%$ ts2 = dseries(B,[],{'B1';'B2'},[]);
-%$
-%$ % Call tested routine.
-%$ try
-%$     ts1.B2 = ts2.B2.log;
-%$     t(1) = 1;
-%$ catch
-%$     t(1) = 0;
-%$ end
-%$
-%$ % Instantiate a time series object.
-%$ if t(1)
-%$    t(2) = dyn_assert(ts1.vobs,4);
-%$    t(3) = dyn_assert(ts1.nobs,10);
-%$    t(4) = dyn_assert(ts1.name{1},'A1');
-%$    t(5) = dyn_assert(ts1.name{2},'A2');
-%$    t(6) = dyn_assert(ts1.name{3},'A3');
-%$    t(7) = dyn_assert(ts1.name{4},'B2');
-%$    t(8) = dyn_assert(ts1.data,[A(:,1), A(:,2), A(:,3), log(B(:,2))],1e-15);
-%$ end
-%$ T = all(t);
-%@eof:6
-
-%@test:7
-%$ % Define a datasets.
-%$ A = rand(10,3); B = rand(10,2);
-%$
-%$ % Instantiate two dseries object.
-%$ ts1 = dseries(A,[],{'A1';'A2';'A3'},[]);
-%$ ts2 = dseries(B,[],{'B1';'B2'},[]);
-%$
-%$ % Append B2 to the first object.
-%$ ts1{'B2'} = ts2{'B2'};
-%$ t(1) = 1;
-%$ % Instantiate a time series object.
-%$ if t(1)
-%$    t(2) = dyn_assert(ts1.vobs,4);
-%$    t(3) = dyn_assert(ts1.nobs,10);
-%$    t(4) = dyn_assert(ts1.name{1},'A1');
-%$    t(5) = dyn_assert(ts1.name{2},'A2');
-%$    t(6) = dyn_assert(ts1.name{3},'A3');
-%$    t(6) = dyn_assert(ts1.name{4},'B2');
-%$    t(7) = dyn_assert(ts1.data,[A(:,1), A(:,2), A(:,3), B(:,2)],1e-15);
-%$ end
-%$ T = all(t);
-%@eof:7
-
-%@test:8
-%$ % Define a datasets.
-%$ A = rand(10,3); B = rand(10,1);
-%$
-%$ % Instantiate two dseries object.
-%$ ts1 = dseries(A,[],{'A1';'A2';'A3'},[]);
-%$ ts2 = dseries(B,[],{'B1'},[]);
-%$
-%$ % modify first object.
-%$ try
-%$     ts1{'A4'} = ts2;
-%$     t(1) = 1;
-%$ catch
-%$     t(1) = 0;
-%$ end
-%$
-%$ % Instantiate a time series object.
-%$ if t(1)
-%$    t(2) = dyn_assert(ts1.vobs,4);
-%$    t(3) = dyn_assert(ts1.nobs,10);
-%$    t(4) = dyn_assert(ts1.name{2},'A2');
-%$    t(5) = dyn_assert(ts1.name{1},'A1');
-%$    t(6) = dyn_assert(ts1.name{3},'A3');
-%$    t(7) = dyn_assert(ts1.name{4},'A4');
-%$    t(8) = dyn_assert(ts1.data,[A, B],1e-15);
-%$ end
-%$ T = all(t);
-%@eof:8
-
-%@test:9
-%$ % Define a datasets.
-%$ A = rand(10,3); B = rand(10,2);
-%$
-%$ % Instantiate two dseries object.
-%$ ts1 = dseries(A,[],{'A1';'A2';'A3'},[]);
-%$ ts2 = dseries(B,[],{'A1';'B1'},[]);
-%$
-%$ % modify first object.
-%$ try
-%$     ts1{'A1','A4'} = ts2;
-%$     t(1) = 1;
-%$ catch
-%$     t(1) = 0;
-%$ end
-%$
-%$ % Instantiate a time series object.
-%$ if t(1)
-%$    t(2) = dyn_assert(ts1.vobs,4);
-%$    t(3) = dyn_assert(ts1.nobs,10);
-%$    t(4) = dyn_assert(ts1.name{2},'A2');
-%$    t(5) = dyn_assert(ts1.name{1},'A1');
-%$    t(6) = dyn_assert(ts1.name{3},'A3');
-%$    t(7) = dyn_assert(ts1.name{4},'A4');
-%$    t(8) = dyn_assert(ts1.data,[B(:,1), A(:,2:3), B(:,2)],1e-15);
-%$ end
-%$ T = all(t);
-%@eof:9
-
-
-%@test:10
-%$ % Define a datasets.
-%$ A = rand(10,3); B = rand(10,3);
-%$
-%$ % Instantiate two dseries object.
-%$ ts1 = dseries(A,[],{'A1';'A2';'A3'},[]);
-%$ ts2 = dseries(B,[],{'A1';'B1';'B2'},[]);
-%$
-%$ % modify first object.
-%$ try
-%$     ts1{'A@1,2@','A4'} = ts2;
-%$     t(1) = 1;
-%$ catch
-%$     t(1) = 0;
-%$ end
-%$
-%$ % Instantiate a time series object.
-%$ if t(1)
-%$    t(2) = dyn_assert(ts1.vobs,4);
-%$    t(3) = dyn_assert(ts1.nobs,10);
-%$    t(4) = dyn_assert(ts1.name{1},'A1');
-%$    t(5) = dyn_assert(ts1.name{2},'A2');
-%$    t(6) = dyn_assert(ts1.name{3},'A3');
-%$    t(7) = dyn_assert(ts1.name{4},'A4');
-%$    t(8) = dyn_assert(ts1.data,[B(:,1:2), A(:,3), B(:,3)],1e-15);
-%$ end
-%$ T = all(t);
-%@eof:10
-
-%@test:11
-%$ % Define a datasets.
-%$ A = rand(10,3); B = rand(10,5);
-%$
-%$ % Instantiate two dseries object.
-%$ ts1 = dseries(A,[],{'A_1';'A_2';'A_3'},[]);
-%$ ts2 = dseries(B,[],{'A_1';'A_2';'B_1';'B_2';'B_3'},[]);
-%$
-%$ % modify first object.
-%$ try
-%$     ts1{'@A,B@_@1,2@'} = ts2{'@A,B@_@1,2@'};
-%$     t(1) = 1;
-%$ catch
-%$     t(1) = 0;
-%$ end
-%$
-%$ % Instantiate a time series object.
-%$ if t(1)
-%$    %t(2) = dyn_assert(ts1.vobs,4);
-%$    %t(3) = dyn_assert(ts1.nobs,10);
-%$    %t(4) = dyn_assert(ts1.name,{'A1','A2';'A3';'B1';'B2'});
-%$    %t(5) = dyn_assert(ts1.data,[B(:,1:2), A(:,3), B(:,3:4)],1e-15);
-%$ end
-%$ T = all(t);
-%@eof:11
-
-%@test:12
-%$ % Define a datasets.
-%$ A = rand(40,3); B = rand(40,1);
-%$
-%$ % Instantiate two dseries object.
-%$ ts1 = dseries(A,'1950Q1',{'A1';'A2';'A3'},[]);
-%$ ts2 = dseries(B,'1950Q1',{'B1'},[]);
-%$
-%$ % modify first object.
-%$ try
-%$     d1 = dates('1950Q3');
-%$     d2 = dates('1951Q3');
-%$     rg = d1:d2;
-%$     ts1{'A1'}(rg) = ts2{'B1'}(rg);
-%$     t(1) = 1;
-%$ catch
-%$     t(1) = 0;
-%$ end
-%$
-%$ % Instantiate a time series object.
-%$ if t(1)
-%$    t(2) = dyn_assert(ts1.vobs,3);
-%$    t(3) = dyn_assert(ts1.nobs,40);
-%$    t(4) = dyn_assert(ts1.name{2},'A2');
-%$    t(5) = dyn_assert(ts1.name{1},'A1');
-%$    t(6) = dyn_assert(ts1.name{3},'A3');
-%$    t(7) = dyn_assert(ts1.data,[[A(1:2,1); B(3:7); A(8:end,1)], A(:,2:3)],1e-15);
-%$ end
-%$ T = all(t);
-%@eof:12
-
-%@test:13
-%$ % Define a datasets.
-%$ A = rand(40,3); B = rand(40,1);
-%$
-%$ % Instantiate two dseries object.
-%$ ts1 = dseries(A,'1950Q1',{'A1';'A2';'A3'},[]);
-%$ ts2 = dseries(B,'1950Q1',{'B1'},[]);
-%$
-%$ % modify first object.
-%$ try
-%$     d1 = dates('1950Q3');
-%$     d2 = dates('1951Q3');
-%$     rg = d1:d2;
-%$     ts1{'A1'}(rg) = B(3:7);
-%$     t(1) = 1;
-%$ catch
-%$     t(1) = 0;
-%$ end
-%$
-%$ % Instantiate a time series object.
-%$ if t(1)
-%$    t(2) = dyn_assert(ts1.vobs,3);
-%$    t(3) = dyn_assert(ts1.nobs,40);
-%$    t(4) = dyn_assert(ts1.name{2},'A2');
-%$    t(5) = dyn_assert(ts1.name{1},'A1');
-%$    t(6) = dyn_assert(ts1.name{3},'A3');
-%$    t(7) = dyn_assert(ts1.data,[[A(1:2,1); B(3:7); A(8:end,1)], A(:,2:3)],1e-15);
-%$ end
-%$ T = all(t);
-%@eof:13
-
-%@test:14
-%$ % Define a datasets.
-%$ A = rand(40,3); B = rand(40,1);
-%$
-%$ % Instantiate two dseries object.
-%$ ts1 = dseries(A,'1950Q1',{'A1';'A2';'A3'},[]);
-%$ ts2 = dseries(B,'1950Q1',{'B1'},[]);
-%$
-%$ % modify first object.
-%$ try
-%$     d1 = dates('1950Q3');
-%$     d2 = dates('1951Q3');
-%$     rg = d1:d2;
-%$     ts1.A1(rg) = B(3:7);
-%$     t(1) = 1;
-%$ catch
-%$     t(1) = 0;
-%$ end
-%$
-%$ % Instantiate a time series object.
-%$ if t(1)
-%$    t(2) = dyn_assert(ts1.vobs,3);
-%$    t(3) = dyn_assert(ts1.nobs,40);
-%$    t(4) = dyn_assert(ts1.name{2},'A2');
-%$    t(5) = dyn_assert(ts1.name{1},'A1');
-%$    t(6) = dyn_assert(ts1.name{3},'A3');
-%$    t(7) = dyn_assert(ts1.data,[[A(1:2,1); B(3:7); A(8:end,1)], A(:,2:3)],1e-15);
-%$ end
-%$ T = all(t);
-%@eof:14
-
-%@test:15
-%$ % Define a datasets.
-%$ A = rand(40,3); B = rand(40,1);
-%$
-%$ % Instantiate two dseries object.
-%$ ts1 = dseries(A,'1950Q1',{'A1';'A2';'A3'},[]);
-%$ ts2 = dseries(B,'1950Q1',{'B1'},[]);
-%$
-%$ % modify first object.
-%$ try
-%$     d1 = dates('1950Q3');
-%$     d2 = dates('1951Q3');
-%$     rg = d1:d2;
-%$     ts1.A1(rg) = sqrt(pi);
-%$     t(1) = 1;
-%$ catch
-%$     t(1) = 0;
-%$ end
-%$
-%$ % Instantiate a time series object.
-%$ if t(1)
-%$    t(2) = dyn_assert(ts1.vobs,3);
-%$    t(3) = dyn_assert(ts1.nobs,40);
-%$    t(4) = dyn_assert(ts1.name{2},'A2');
-%$    t(5) = dyn_assert(ts1.name{1},'A1');
-%$    t(6) = dyn_assert(ts1.name{3},'A3');
-%$    t(7) = dyn_assert(ts1.data,[[A(1:2,1); repmat(sqrt(pi),5,1); A(8:end,1)], A(:,2:3)],1e-15);
-%$ end
-%$ T = all(t);
-%@eof:15
-
-%@test:16
-%$ % Define a datasets.
-%$ A = rand(40,3); B = rand(40,1);
-%$
-%$ % Instantiate two dseries object.
-%$ ts1 = dseries(A,'1950Q1',{'A1';'A2';'A3'},[]);
-%$ ts2 = dseries(B,'1950Q1',{'B1'},[]);
-%$
-%$ % modify first object.
-%$ try
-%$     d1 = dates('1950Q3');
-%$     d2 = dates('1951Q3');
-%$     rg = d1:d2;
-%$     ts1{'A1','A2'}(rg) = sqrt(pi);
-%$     t(1) = 1;
-%$ catch
-%$     t(1) = 0;
-%$ end
-%$
-%$ % Instantiate a time series object.
-%$ if t(1)
-%$    t(2) = dyn_assert(ts1.vobs,3);
-%$    t(3) = dyn_assert(ts1.nobs,40);
-%$    t(4) = dyn_assert(ts1.name{2},'A2');
-%$    t(5) = dyn_assert(ts1.name{1},'A1');
-%$    t(6) = dyn_assert(ts1.name{3},'A3');
-%$    t(7) = dyn_assert(ts1.data,[[A(1:2,1); repmat(sqrt(pi),5,1); A(8:end,1)], [A(1:2,2); repmat(sqrt(pi),5,1); A(8:end,2)], A(:,3)],1e-15);
-%$ end
-%$ T = all(t);
-%@eof:16
-
-%@test:17
-%$ % Define a datasets.
-%$ A = rand(40,3); B = rand(40,1);
-%$
-%$ % Instantiate two dseries object.
-%$ ts1 = dseries(A,'1950Q1',{'A1';'A2';'A3'},[]);
-%$ ts2 = dseries(B,'1950Q1',{'B1'},[]);
-%$
-%$ % modify first object.
-%$ try
-%$     d1 = dates('1950Q3');
-%$     d2 = dates('1951Q3');
-%$     rg = d1:d2;
-%$     ts1{'A1','A2'}(rg) = [sqrt(pi), pi];
-%$     t(1) = 1;
-%$ catch
-%$     t(1) = 0;
-%$ end
-%$
-%$ % Instantiate a time series object.
-%$ if t(1)
-%$    t(2) = dyn_assert(ts1.vobs,3);
-%$    t(3) = dyn_assert(ts1.nobs,40);
-%$    t(4) = dyn_assert(ts1.name{2},'A2');
-%$    t(5) = dyn_assert(ts1.name{1},'A1');
-%$    t(6) = dyn_assert(ts1.name{3},'A3');
-%$    t(7) = dyn_assert(ts1.data,[[A(1:2,1); repmat(sqrt(pi),5,1); A(8:end,1)], [A(1:2,2); repmat(pi,5,1); A(8:end,2)], A(:,3)],1e-15);
-%$ end
-%$ T = all(t);
-%@eof:17
-
-%@test:18
-%$ % Define a datasets.
-%$ A = rand(40,3); B = rand(40,1);
-%$
-%$ % Instantiate two dseries object.
-%$ ts1 = dseries(A,'1950Q1',{'A1';'A2';'A3'},[]);
-%$ ts2 = dseries(B,'1950Q1',{'B1'},[]);
-%$
-%$ % modify first object.
-%$ try
-%$     d1 = dates('1950Q3');
-%$     d2 = dates('1951Q3');
-%$     rg = d1:d2;
-%$     ts1{'A1','A2'}(rg) = ones(5,1);
-%$     t(1) = 1;
-%$ catch
-%$     t(1) = 0;
-%$ end
-%$
-%$ % Instantiate a time series object.
-%$ if t(1)
-%$    t(2) = dyn_assert(ts1.vobs,3);
-%$    t(3) = dyn_assert(ts1.nobs,40);
-%$    t(4) = dyn_assert(ts1.name{2},'A2');
-%$    t(5) = dyn_assert(ts1.name{1},'A1');
-%$    t(6) = dyn_assert(ts1.name{3},'A3');
-%$    t(7) = dyn_assert(ts1.data,[[A(1:2,1); ones(5,1); A(8:end,1)], [A(1:2,2); ones(5,1); A(8:end,2)], A(:,3)],1e-15);
-%$ end
-%$ T = all(t);
-%@eof:18
-
-%@test:19
-%$ % Define a datasets.
-%$ A = rand(40,3);
-%$
-%$ % Instantiate two dseries object.
-%$ ts1 = dseries(A,'1950Q1',{'A1';'A2';'A3'},[]);
-%$
-%$ % Instantiate a dates object.
-%$ dd = dates('1952Q1');
-%$
-%$ % modify first object.
-%$ try
-%$     ts1.init = dd;
-%$     t(1) = 1;
-%$ catch
-%$     t(1) = 0;
-%$ end
-%$
-%$ % Instantiate a time series object.
-%$ if t(1)
-%$    t(2) = dyn_assert(ts1.vobs,3);
-%$    t(3) = dyn_assert(ts1.nobs,40);
-%$    t(4) = dyn_assert(ts1.name{2},'A2');
-%$    t(5) = dyn_assert(ts1.name{1},'A1');
-%$    t(6) = dyn_assert(ts1.name{3},'A3');
-%$    t(7) = dyn_assert(ts1.data,A,1e-15);
-%$    t(8) = dyn_assert(isequal(ts1.init,dd),1);
-%$    t(9) = dyn_assert(isequal(ts1.dates(1),dd),1);
-%$ end
-%$ T = all(t);
-%@eof:19
-
-%@test:20
-%$ % Define a datasets.
-%$ A = rand(40,3);
-%$
-%$ % Instantiate two dseries object.
-%$ ts1 = dseries(A,'1950Q1',{'A1';'A2';'A3'},[]);
-%$
-%$ % Instantiate a dates object.
-%$ dd = dates('1952Q1');
-%$
-%$ % modify first object.
-%$ try
-%$     ts1.dates = dd:(dd+(ts1.nobs-1));
-%$     t(1) = 1;
-%$ catch
-%$     t(1) = 0;
-%$ end
-%$
-%$ % Instantiate a time series object.
-%$ if t(1)
-%$    t(2) = dyn_assert(ts1.vobs,3);
-%$    t(3) = dyn_assert(ts1.nobs,40);
-%$    t(4) = dyn_assert(ts1.name{2},'A2');
-%$    t(5) = dyn_assert(ts1.name{1},'A1');
-%$    t(6) = dyn_assert(ts1.name{3},'A3');
-%$    t(7) = dyn_assert(ts1.data,A,1e-15);
-%$    t(8) = dyn_assert(isequal(ts1.init,dd),1);
-%$    t(9) = dyn_assert(isequal(ts1.dates(1),dd),1);
-%$ end
-%$ T = all(t);
-%@eof:20
-
-%@test:21
-%$ % Define a datasets.
-%$ A = rand(4,3);
-%$
-%$ % Instantiate an empty dseries object.
-%$ ts = dseries(dates('1950Q1'):dates('1950Q4'));
-%$
-%$ % Populate ts
-%$ try
-%$     ts(:) = A;
-%$     t(1) = 1;
-%$ catch
-%$     t(1) = 0;
-%$ end
-%$
-%$ % Instantiate a time series object.
-%$ if t(1)
-%$    t(2) = dyn_assert(ts.vobs,3);
-%$    t(3) = dyn_assert(ts.nobs,4);
-%$    t(4) = dyn_assert(ts.data,A,1e-15);
-%$ end
-%$ T = all(t);
-%@eof:21
-
-%@test:22
-%$ % Define a datasets.
-%$ A = rand(1,3);
-%$
-%$ % Instantiate an empty dseries object.
-%$ ts = dseries(dates('1950Q1'):dates('1950Q4'));
-%$
-%$ % Populate ts
-%$ try
-%$     ts(:) = A;
-%$     t(1) = 1;
-%$ catch
-%$     t(1) = 0;
-%$ end
-%$
-%$ % Instantiate a time series object.
-%$ if t(1)
-%$    t(2) = dyn_assert(ts.vobs,3);
-%$    t(3) = dyn_assert(ts.nobs,4);
-%$    t(4) = dyn_assert(ts.data,repmat(A,4,1),1e-15);
-%$ end
-%$ T = all(t);
-%@eof:22
-
-%@test:23
-%$ % Instantiate a dseries object.
-%$ ts0 = dseries(randn(10,6), '1999y');
-%$
-%$ % Try to remove Variable_2 and Variable_3
-%$ try
-%$     ts0{'Variable_@2,3@'} = [];
-%$     t(1) = 1;
-%$ catch
-%$     t(1) = 0;
-%$ end
-%$
-%$ if t(1)
-%$    % Try to display Variable_2 and Variable_3 again (should fail because already removed)
-%$    try
-%$       ts0{'Variable_@2,3@'};
-%$       t(2) = 0;
-%$    catch
-%$       t(2) = 1;
-%$    end
-%$ end
-%$ T = all(t);
-%@eof:23
\ No newline at end of file
diff --git a/matlab/@dseries/subsref.m b/matlab/@dseries/subsref.m
deleted file mode 100644
index 3f6bf582de566a6ac785e9b41d024835cda98271..0000000000000000000000000000000000000000
--- a/matlab/@dseries/subsref.m
+++ /dev/null
@@ -1,689 +0,0 @@
-function B = subsref(A, S) % --*-- Unitary tests --*--
-
-%@info:
-%! @deftypefn {Function File} {@var{us} =} subsref (@var{ts},S)
-%! @anchor{@dseries/subsref}
-%! @sp 1
-%! Overloads the subsref method for the Dynare time series class (@ref{dseries}).
-%! @sp 2
-%! @strong{Inputs}
-%! @sp 1
-%! @table @ @var
-%! @item ts
-%! Dynare time series object instantiated by @ref{dseries}.
-%! @item S
-%! Matlab's structure array S with two fields, type and subs. The type field is string containing '()', '@{@}', or '.', where '()' specifies
-%! integer subscripts, '@{@}' specifies cell array subscripts, and '.' specifies subscripted structure fields. The subs field is a cell array
-%! or a string containing the actual subscripts (see matlab's documentation).
-%! @end table
-%! @sp 1
-%! @strong{Outputs}
-%! @sp 1
-%! @table @ @var
-%! @item us
-%! Dynare time series object. Depending on the calling sequence @var{us} is a transformation of @var{ts} obtained by applying a public method on @var{ts},
-%! or a dseries object built by extracting a variable from @var{ts}, or a dseries object containing a subsample of the all the variable in @var{ts}.
-%! @end table
-%! @sp 2
-%! @strong{Example 1.} Let @var{ts} be a dseries object containing three variables named 'A1', 'A2' and 'A3'. Then the following syntax:
-%! @example
-%!   us = ts.A1;
-%! @end example
-%!will create a new dseries object @var{us} containing the variable 'A1'.
-%! @sp 1
-%! @strong{Example 2.} Let @var{ts} be a dseries object. Then the following syntax:
-%! @example
-%!   us = ts.log;
-%! @end example
-%!will create a new dseries object @var{us} containing all the variables of @var{ts} transformed by the neperian logarithm.
-%! @sp 1
-%! @strong{Example 3.} Let @var{ts} be a dseries object. The following syntax:
-%! @example
-%!   us = ts(3:50);
-%! @end example
-%!will create a new dseries object @var{us} by selecting a subsample out of @var{ts}.
-%! @end deftypefn
-%@eod:
-
-% Copyright (C) 2011-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/>.
-
-switch S(1).type
-  case '.'
-    switch S(1).subs
-      case {'data','name','tex','dates'}        % Public members.
-        if length(S)>1 && isequal(S(2).type,'()') && isempty(S(2).subs)
-            error(['dseries::subsref: ' S(1).subs ' is not a method but a member!'])
-        end
-        B = builtin('subsref', A, S(1));
-      case {'log','exp','ygrowth','qgrowth','ydiff','qdiff','abs'}         % Give "dot access" to public methods without args.
-        B = feval(S(1).subs,A);
-        if length(S)>1 && isequal(S(2).type,'()') && isempty(S(2).subs)
-            S = shiftS(S,1);
-        end
-      case 'nobs'
-        % Returns the number of observations.
-        B = rows(A.data);
-      case 'vobs'
-        % Returns the number of variables.
-        B = columns(A.data);
-      case 'init'
-        % Returns a dates object (first date).
-        B = A.dates(1);
-      case 'last'
-        % Returns a dates object (last date).
-        B = A.dates(end);
-      case 'freq'
-        % Returns an integer characterizing the data frequency (1, 4, 12 or 52)
-        B = A.dates.freq;
-      case {'lag','lead','hptrend','hpcycle','chain','detrend'} % Methods with less than two arguments.
-        if length(S)>1 && isequal(S(2).type,'()')
-            if isempty(S(2).subs)
-                B = feval(S(1).subs,A);
-                S = shiftS(S,1);
-            else
-                if length(S(2).subs{1})>1
-                    error(['dseries::subsref: ' S(1).subs{1} ' method admits no more than one argument!'])
-                end
-                B = feval(S(1).subs,A,S(2).subs{1});
-                S = shiftS(S,1);
-            end
-        else
-            B = feval(S(1).subs,A);
-        end
-      case {'cumsum','insert','pop','cumprod','remove'} % Methods with less than three argument.
-        if length(S)>1 && isequal(S(2).type,'()')
-            if isempty(S(2).subs)
-                B = feval(S(1).subs,A);
-                S = shiftS(S,1);
-            else
-                if length(S(2).subs)>2
-                    error(['dseries::subsref: ' S(1).subs{1} ' method admits no more than two arguments!'])
-                end
-                B = feval(S(1).subs,A,S(2).subs{:});
-                S = shiftS(S,1);
-            end
-        else
-            B = feval(S(1).subs,A);
-        end
-      case 'baxter_king_filter'
-        if length(S)>1 && isequal(S(2).type,'()')
-            if isempty(S(2).subs)
-                B = feval(S(1).subs,A);
-                S = shiftS(S,1);
-            else
-                B = feval(S(1).subs,A,S(2).subs{1})
-                S = shiftS(S,1);
-            end
-        else
-            B = feval(S(1).subs,A);
-        end
-      case 'save'                                                        % Save dseries object on disk (default is a csv file).
-        B = NaN;
-        if isequal(length(S),2)
-            if strcmp(S(2).type,'()')
-                if isempty(S(2).subs)
-                    save(A,inputname(1));
-                else
-                    if isempty(S(2).subs{1})
-                        save(A,inputname(1),S(2).subs{2});
-                    else
-                        save(A,S(2).subs{:});
-                    end
-                end
-                S = shiftS(S,1);
-            else
-                error('dseries::subsref: Wrong syntax.')
-            end
-        elseif isequal(length(S),1)
-            save(A,inputname(1));
-        else
-            error('dseries::subsref: Call to save method must come in last position!')
-        end
-      case 'size'
-        if isequal(length(S),2) && strcmp(S(2).type,'()')
-            if isempty(S(2).subs)
-                [x,y] = size(A);
-                B = [x, y];
-            else
-                B = size(A,S(2).subs{1});
-            end
-            S = shiftS(S,1);
-        elseif isequal(length(S),1)
-            [x,y] = size(A);
-            B = [x, y];
-        else
-            error('dseries::subsref: Call to size method must come in last position!')
-        end
-      case {'set_names','rename','tex_rename'}
-        B = feval(S(1).subs,A,S(2).subs{:});
-        S = shiftS(S,1);
-      case {'disp'}
-        feval(S(1).subs,A);
-        return
-      otherwise                                                            % Extract a sub-object by selecting one variable.
-        ndx = find(strcmp(S(1).subs,A.name));
-        if ~isempty(ndx)
-            B = dseries();
-            B.data = A.data(:,ndx);
-            B.name = A.name(ndx);
-            B.tex = A.tex(ndx);
-            B.tex  = deblank(A.tex(ndx,:));
-            B.dates = A.dates;
-        else
-            error('dseries::subsref: Unknown public method, public member or variable!')
-        end
-    end
-  case '()'
-    if ischar(S(1).subs{1}) && ~isdate(S(1).subs{1})
-        % If ts is an empty dseries object, populate this object by reading data in a file.
-        if isempty(A)
-            B = dseries(S(1).subs{1});
-        else
-            error(['dseries::subsref: dseries object ''' inputname(1) '''  is not empty!'])
-        end
-    elseif isa(S(1).subs{1},'dynTimeIndex')
-        % shift backward/forward (lag/lead) dseries object
-        shift = S(1).subs{1}.index;
-        if shift>0
-            B = feval('lead',A,shift);
-        elseif shift<0
-            B = feval('lag',A,-shift);
-        else
-            % Do nothing.
-            B = A;
-        end
-    elseif isscalar(S(1).subs{1}) && isnumeric(S(1).subs{1}) && isint(S(1).subs{1})
-        % Input is also interpreted as a backward/forward operator
-        if S(1).subs{1}>0
-            B = feval('lead', A, S(1).subs{1});
-        elseif S(1).subs{1}<0
-            B = feval('lag', A, -S(1).subs{1});
-        else
-            % Do nothing.
-            B = A;
-        end
-    elseif isdates(S(1).subs{1}) || isdate(S(1).subs{1})
-        if isdate(S(1).subs{1})
-            Dates = dates(S(1).subs{1});
-        else
-            Dates = S(1).subs{1};
-        end
-        % Test if Dates is out of bounds
-        if min(Dates)<min(A.dates)
-            error(['dseries::subsref: Indices are out of bounds! Subsample cannot start before ' date2string(A.dates(1)) '.'])
-        end
-        if  max(Dates)>max(A.dates)
-            error(['dseries::subsref: Indices are out of bounds! Subsample cannot end after ' date2string(A.dates(end)) '.'])
-        end
-        % Extract a subsample using a dates object
-        [junk,tdx] = intersect(A.dates.time,Dates.time,'rows');
-        B = dseries();
-        B.data = A.data(tdx,:);
-        B.name = A.name;
-        B.tex  = A.tex;
-        B.dates = A.dates(tdx);
-    elseif isvector(S(1).subs{1}) && all(isint(S(1).subs{1}))
-        error('dseries::subsref: It is not possible to select observations with a vector of integers. You have to index with a dates object instead!');
-    else
-        error('dseries::subsref: I have no idea of what you are trying to do!')
-    end
-  case '{}'
-    if iscellofchar(S(1).subs)
-        B = extract(A,S(1).subs{:});
-    elseif isequal(length(S(1).subs),1) && all(isint(S(1).subs{1}))
-        idx = S(1).subs{1};
-        if max(idx)>size(A.data,2) || min(idx)<1
-            error('dseries::subsref: Indices are out of bounds!')
-        end
-        B = dseries();
-        B.data = A.data(:,idx);
-        B.name = A.name(idx);
-        B.tex  = A.tex(idx);
-        B.dates = A.dates;
-    else
-        error('dseries::subsref: What the Hell are you tryin'' to do?!')
-    end
-  otherwise
-    error('dseries::subsref: What the Hell are you doin'' here?!')
-end
-
-S = shiftS(S,1);
-if ~isempty(S)
-    B = subsref(B, S);
-end
-
-%@test:1
-%$ % Define a data set.
-%$ A = [transpose(1:10),2*transpose(1:10)];
-%$
-%$ % Define names
-%$ A_name = {'A1';'A2'};
-%$
-%$ % Instantiate a time series object.
-%$ ts1 = dseries(A,[],A_name,[]);
-%$
-%$ % Call the tested method.
-%$ a = ts1(ts1.dates(2:9));
-%$
-%$ % Expected results.
-%$ e.data = [transpose(2:9),2*transpose(2:9)];
-%$ e.nobs = 8;
-%$ e.vobs = 2;
-%$ e.name = {'A1';'A2'};
-%$ e.freq = 1;
-%$ e.init = dates(1,2);
-%$
-%$ % Check the results.
-%$ t(1) = dyn_assert(a.data,e.data);
-%$ t(2) = dyn_assert(a.nobs,e.nobs);
-%$ t(3) = dyn_assert(a.vobs,e.vobs);
-%$ t(4) = dyn_assert(a.freq,e.freq);
-%$ t(5) = dyn_assert(isequal(a.init,e.init),1);
-%$ T = all(t);
-%@eof:1
-
-%@test:2
-%$ % Define a data set.
-%$ A = [transpose(1:10),2*transpose(1:10)];
-%$
-%$ % Define names
-%$ A_name = {'A1';'A2'};
-%$
-%$ % Instantiate a time series object.
-%$ ts1 = dseries(A,[],A_name,[]);
-%$
-%$ % Call the tested method.
-%$ a = ts1.A1;
-%$
-%$ % Expected results.
-%$ e.data = transpose(1:10);
-%$ e.nobs = 10;
-%$ e.vobs = 1;
-%$ e.name = {'A1'};
-%$ e.freq = 1;
-%$ e.init = dates(1,1);
-%$
-%$ % Check the results.
-%$ t(1) = dyn_assert(a.data,e.data);
-%$ t(2) = dyn_assert(isequal(a.init,e.init),1);
-%$ t(3) = dyn_assert(a.nobs,e.nobs);
-%$ t(4) = dyn_assert(a.vobs,e.vobs);
-%$ t(5) = dyn_assert(a.freq,e.freq);
-%$ T = all(t);
-%@eof:2
-
-%@test:3
-%$ % Define a data set.
-%$ A = [transpose(1:10),2*transpose(1:10)];
-%$
-%$ % Define names
-%$ A_name = {'A1';'A2'};
-%$
-%$ % Instantiate a time series object.
-%$ ts1 = dseries(A,[],A_name,[]);
-%$
-%$ % Call the tested method.
-%$ a = ts1.log;
-%$
-%$ % Expected results.
-%$ e.data = log(A);
-%$ e.nobs = 10;
-%$ e.vobs = 2;
-%$ e.name = {'A1';'A2'};
-%$ e.freq = 1;
-%$ e.init = dates(1,1);
-%$
-%$ % Check the results.
-%$ t(1) = dyn_assert(a.data,e.data);
-%$ t(2) = dyn_assert(a.nobs,e.nobs);
-%$ t(3) = dyn_assert(a.vobs,e.vobs);
-%$ t(4) = dyn_assert(a.freq,e.freq);
-%$ t(5) = dyn_assert(isequal(a.init,e.init),1);
-%$ T = all(t);
-%@eof:3
-
-%@test:4
-%$ % Create an empty dseries object.
-%$ dataset = dseries();
-%$
-%$ t = zeros(5,1);
-%$
-%$ try
-%$    A = dataset('dynseries_test_data.csv');
-%$    t(1) = 1;
-%$ catch
-%$    t = 0;
-%$ end
-%$
-%$ % Check the results.
-%$ if length(t)>1
-%$     t(2) = dyn_assert(A.nobs,4);
-%$     t(3) = dyn_assert(A.vobs,4);
-%$     t(4) = dyn_assert(A.freq,4);
-%$     t(5) = dyn_assert(isequal(A.init,dates('1990Q1')),1);
-%$ end
-%$ T = all(t);
-%@eof:4
-
-%@test:5
-%$ % Define a data set.
-%$ A = [transpose(1:10),2*transpose(1:10),3*transpose(1:10)];
-%$
-%$ % Define names
-%$ A_name = {'A1';'A2';'B1'};
-%$
-%$ % Instantiate a time series object.
-%$ ts1 = dseries(A,[],A_name,[]);
-%$
-%$ % Call the tested method.
-%$ a = ts1{'A1','B1'};
-%$
-%$ % Expected results.
-%$ e.data = A(:,[1,3]);
-%$ e.nobs = 10;
-%$ e.vobs = 2;
-%$ e.name = {'A1';'B1'};
-%$ e.freq = 1;
-%$ e.init = dates(1,1);
-%$
-%$ t(1) = dyn_assert(e.data,a.data);
-%$ t(2) = dyn_assert(e.nobs,a.nobs);
-%$ t(3) = dyn_assert(e.vobs,a.vobs);
-%$ t(4) = dyn_assert(e.name,a.name);
-%$ t(5) = dyn_assert(isequal(e.init,a.init),1);
-%$ T = all(t);
-%@eof:5
-
-%@test:6
-%$ % Define a data set.
-%$ A = rand(10,24);
-%$
-%$ % Define names
-%$ A_name = {'GDP_1';'GDP_2';'GDP_3'; 'GDP_4'; 'GDP_5'; 'GDP_6'; 'GDP_7'; 'GDP_8'; 'GDP_9'; 'GDP_10'; 'GDP_11'; 'GDP_12'; 'HICP_1';'HICP_2';'HICP_3'; 'HICP_4'; 'HICP_5'; 'HICP_6'; 'HICP_7'; 'HICP_8'; 'HICP_9'; 'HICP_10'; 'HICP_11'; 'HICP_12';};
-%$
-%$ % Instantiate a time series object.
-%$ ts1 = dseries(A,[],A_name,[]);
-%$
-%$ % Call the tested method.
-%$ a = ts1{'GDP_[0-9]'};
-%$ b = ts1{'[A-Z]_1$'};
-%$
-%$ % Expected results.
-%$ e1.data = A(:,1:12);
-%$ e1.nobs = 10;
-%$ e1.vobs = 12;
-%$ e1.name = {'GDP_1';'GDP_2';'GDP_3'; 'GDP_4'; 'GDP_5'; 'GDP_6'; 'GDP_7'; 'GDP_8'; 'GDP_9'; 'GDP_10'; 'GDP_11'; 'GDP_12'};
-%$ e1.freq = 1;
-%$ e1.init = dates(1,1);
-%$ e2.data = A(:,[1 13]);
-%$ e2.nobs = 10;
-%$ e2.vobs = 2;
-%$ e2.name = {'GDP_1';'HICP_1'};
-%$ e2.freq = 1;
-%$ e2.init = dates(1,1);
-%$
-%$ % Check results.
-%$ t(1) = dyn_assert(e1.data,a.data);
-%$ t(2) = dyn_assert(e1.nobs,a.nobs);
-%$ t(3) = dyn_assert(e1.vobs,a.vobs);
-%$ t(4) = dyn_assert(e1.name,a.name);
-%$ t(5) = dyn_assert(isequal(e1.init,a.init),1);
-%$ t(6) = dyn_assert(e2.data,b.data);
-%$ t(7) = dyn_assert(e2.nobs,b.nobs);
-%$ t(8) = dyn_assert(e2.vobs,b.vobs);
-%$ t(9) = dyn_assert(e2.name,b.name);
-%$ t(10) = dyn_assert(isequal(e2.init,b.init),1);
-%$ T = all(t);
-%@eof:6
-
-%@test:7
-%$ % Define a data set.
-%$ A = [transpose(1:10),2*transpose(1:10)];
-%$
-%$ % Define names
-%$ A_name = {'A1';'A2'};
-%$
-%$ % Instantiate a time series object.
-%$ try
-%$    ts1 = dseries(A,[],A_name,[]);
-%$    ts1.save('ts1');
-%$    t = 1;
-%$ catch
-%$    t = 0;
-%$ end
-%$
-%$ T = all(t);
-%@eof:7
-
-%@test:8
-%$ % Define a data set.
-%$ A = [transpose(1:10),2*transpose(1:10)];
-%$
-%$ % Define names
-%$ A_name = {'A1';'A2'};
-%$
-%$ % Instantiate a time series object.
-%$ try
-%$    ts1 = dseries(A,[],A_name,[]);
-%$    ts1.save('test_generated_data_file','m');
-%$    t = 1;
-%$ catch
-%$    t = 0;
-%$ end
-%$
-%$ T = all(t);
-%@eof:8
-
-%@test:9
-%$ % Define a data set.
-%$ A = [transpose(1:60),2*transpose(1:60),3*transpose(1:60)];
-%$
-%$ % Define names
-%$ A_name = {'A1';'A2';'B1'};
-%$
-%$ % Instantiate a time series object.
-%$ ts1 = dseries(A,'1971Q1',A_name,[]);
-%$
-%$ % Define the range of a subsample.
-%$ range = dates('1971Q2'):dates('1971Q4');
-%$ % Call the tested method.
-%$ a = ts1(range);
-%$
-%$ % Expected results.
-%$ e.data = A(2:4,:);
-%$ e.nobs = 3;
-%$ e.vobs = 3;
-%$ e.name = {'A1';'A2';'B1'};
-%$ e.freq = 4;
-%$ e.init = dates('1971Q2');
-%$
-%$ t(1) = dyn_assert(e.data,a.data);
-%$ t(2) = dyn_assert(e.nobs,a.nobs);
-%$ t(3) = dyn_assert(e.vobs,a.vobs);
-%$ t(4) = dyn_assert(e.name,a.name);
-%$ t(5) = dyn_assert(isequal(e.init,a.init),1);
-%$ T = all(t);
-%@eof:9
-
-%@test:10
-%$ % Define a data set.
-%$ A = [transpose(1:60),2*transpose(1:60),3*transpose(1:60)];
-%$
-%$ % Define names
-%$ A_name = {'A1';'A2';'B1'};
-%$
-%$ % Instantiate a time series object.
-%$ ts1 = dseries(A,'1971Q1',A_name,[]);
-%$
-%$ % Test the size method.
-%$ B = ts1.size();
-%$ C = ts1.size(1);
-%$ D = ts1.size(2);
-%$ E = ts1.size;
-%$
-%$ t(1) = dyn_assert(B,[60, 3]);
-%$ t(2) = dyn_assert(E,[60, 3]);
-%$ t(3) = dyn_assert(C,60);
-%$ t(4) = dyn_assert(D,3);
-%$ T = all(t);
-%@eof:10
-
-%@test:11
-%$ % Define a data set.
-%$ A = [transpose(1:60),2*transpose(1:60),3*transpose(1:60)];
-%$
-%$ % Define names
-%$ A_name = {'A1';'A2';'B1'};
-%$
-%$ % Instantiate a time series object.
-%$ ts1 = dseries(A,'1971Q1',A_name,[]);
-%$
-%$ % Test the size method.
-%$ B = ts1{1};
-%$ C = ts1{[1,3]};
-%$ D = ts1{'A1'};
-%$
-%$ t(1) = dyn_assert(B.name{1},'A1');
-%$ t(2) = dyn_assert(B.data,A(:,1));
-%$ t(3) = dyn_assert(C.name{1},'A1');
-%$ t(4) = dyn_assert(C.data(:,1),A(:,1));
-%$ t(5) = dyn_assert(C.name{2},'B1');
-%$ t(6) = dyn_assert(C.data(:,2),A(:,3));
-%$ t(7) = dyn_assert(D.name{1},'A1');
-%$ t(8) = dyn_assert(D.data,A(:,1));
-%$ T = all(t);
-%@eof:11
-
-%@test:12
-%$ % Define a data set.
-%$ A = [transpose(1:10),2*transpose(1:10)];
-%$
-%$ % Define names
-%$ A_name = {'A1';'A2'};
-%$
-%$ % Instantiate a time series object.
-%$ try
-%$    ts1 = dseries(A,[],A_name,[]);
-%$    if isoctave
-%$        ts1.save('ts1');
-%$    else
-%$        ts1.save();
-%$    end
-%$    t = 1;
-%$ catch
-%$    t = 0;
-%$ end
-%$
-%$ T = all(t);
-%@eof:12
-
-%@test:13
-%$ try
-%$     data = transpose(0:1:50);
-%$     ts = dseries(data,'1950Q1');
-%$     a = ts.lag;
-%$     b = ts.lead;
-%$     tt = dynTimeIndex();
-%$     c = ts(tt-1);
-%$     d = ts(tt+1);
-%$     t(1) = 1;
-%$ catch
-%$     t(1) = 0;
-%$ end
-%$
-%$ if t(1)>1
-%$     t(2) = (a==c);
-%$     t(3) = (b==d);
-%$ end
-%$
-%$ T = all(t);
-%@eof:13
-
-%@test:14
-%$ try
-%$     data = transpose(0:1:50);
-%$     ts = dseries(data,'1950Q1');
-%$     a = ts.lag;
-%$     b = ts.lead;
-%$     c = ts(-1);
-%$     d = ts(1);
-%$     t(1) = 1;
-%$ catch
-%$     t(1) = 0;
-%$ end
-%$
-%$ if t(1)>1
-%$     t(2) = (a==c);
-%$     t(3) = (b==d);
-%$ end
-%$
-%$ T = all(t);
-%@eof:14
-
-%@test:15
-%$ try
-%$     ds = dseries(transpose(1:5));
-%$     ts = ds(ds.dates(2:3));
-%$     t(1) = 1;
-%$ catch
-%$     t(1) = 0;
-%$ end
-%$
-%$ if t(1)>1
-%$     t(2) = isdseries(ts);
-%$     t(3) = isequal(ts.data,ds.data(2:3));
-%$ end
-%$
-%$ T = all(t);
-%@eof:15
-
-%@test:16
-%$ try
-%$     ds = dseries(transpose(1:5));
-%$     ts = ds(ds.dates(2:6));
-%$     t(1) = 0;
-%$ catch
-%$     t(1) = 1;
-%$ end
-%$
-%$ T = all(t);
-%@eof:16
-
-%@test:17
-%$ try
-%$     ds = dseries(transpose(1:5));
-%$     ts = ds(dates('1Y'):dates('6Y'));
-%$     t(1) = 0;
-%$ catch
-%$     t(1) = 1;
-%$ end
-%$
-%$ T = all(t);
-%@eof:17
-
-%@test:18
-%$ try
-%$     ds = dseries(transpose(1:5));
-%$     ts = ds(dates('-2Y'):dates('4Y'));
-%$     t(1) = 0;
-%$ catch
-%$     t(1) = 1;
-%$ end
-%$
-%$ T = all(t);
-%@eof:18
\ No newline at end of file
diff --git a/matlab/@dseries/tex_rename.m b/matlab/@dseries/tex_rename.m
deleted file mode 100644
index 86e3bf974fd852f607b878e361229bc1ff759477..0000000000000000000000000000000000000000
--- a/matlab/@dseries/tex_rename.m
+++ /dev/null
@@ -1,88 +0,0 @@
-function ts = tex_rename(ts, varargin) % --*-- Unitary tests --*--
-
-% Copyright (C) 2013 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(nargin <= 3, 'dseries::tex_rename: accepts at most three args');
-
-if nargin == 2
-    newtexname = varargin{1};
-    assert(vobs(ts) == 1, ['dseries::tex_rename: with one argument, the dseries contain only one variable.']);
-else
-    newtexname = varargin{2};
-    name = varargin{1};
-    assert(ischar(name), 'dseries::tex_rename: second input argument (name) must be a string');
-end
-
-assert(ischar(newtexname), 'dseries::tex_rename: third input argument (newtexname) name must be a string');
-
-if nargin == 2
-    idname = 1;
-else
-    idname = find(strcmp(name, ts.name));
-    if isempty(idname)
-        error(['dseries::tex_rename: Variable ' name ' is unknown in dseries object ' inputname(1)  '!'])
-    end
-end
-
-ts.tex(idname) = {newtexname};
-
-%@test:1
-%$ t = zeros(8,1);
-%$ ts = dseries([transpose(1:5), transpose(6:10)],'1950q1',{'Output'; 'Consumption'}, {'Y_t'; 'C_t'});
-%$ try
-%$     ts = tex_rename(ts,'Output','\\Delta Y_t');
-%$     t(1) = 1;
-%$ catch
-%$     t = 0;
-%$ end
-%$
-%$ if length(t)>1
-%$     t(2) = dyn_assert(ts.freq,4);
-%$     t(3) = dyn_assert(ts.init.freq,4);
-%$     t(4) = dyn_assert(ts.init.time,[1950, 1]);
-%$     t(5) = dyn_assert(ts.vobs,2);
-%$     t(6) = dyn_assert(ts.nobs,5);
-%$     t(7) = dyn_assert(ts.name,{'Output'; 'Consumption'});
-%$     t(8) = dyn_assert(ts.tex,{'\\Delta Y_t'; 'C_t'});
-%$ end
-%$
-%$ T = all(t);
-%@eof:1
-
-%@test:2
-%$ t = zeros(8,1);
-%$ ts = dseries([transpose(1:5), transpose(6:10)],'1950q1',{'Output'; 'Consumption'}, {'Y_t'; 'C_t'});
-%$ try
-%$     ts = ts.tex_rename('Output','\\Delta Y_t');
-%$     t(1) = 1;
-%$ catch
-%$     t = 0;
-%$ end
-%$
-%$ if length(t)>1
-%$     t(2) = dyn_assert(ts.freq,4);
-%$     t(3) = dyn_assert(ts.init.freq,4);
-%$     t(4) = dyn_assert(ts.init.time,[1950, 1]);
-%$     t(5) = dyn_assert(ts.vobs,2);
-%$     t(6) = dyn_assert(ts.nobs,5);
-%$     t(7) = dyn_assert(ts.name,{'Output'; 'Consumption'});
-%$     t(8) = dyn_assert(ts.tex,{'\\Delta Y_t'; 'C_t'});
-%$ end
-%$
-%$ T = all(t);
-%@eof:2
diff --git a/matlab/@dseries/uminus.m b/matlab/@dseries/uminus.m
deleted file mode 100644
index 000fbda74873b75eacecf9bfc569b2a76665144e..0000000000000000000000000000000000000000
--- a/matlab/@dseries/uminus.m
+++ /dev/null
@@ -1,81 +0,0 @@
-function A = uminus(B) % --*-- Unitary tests --*--
-
-%@info:
-%! @deftypefn {Function File} {@var{A} =} plus (@var{B},@var{C})
-%! @anchor{@dseries/uminus}
-%! @sp 1
-%! Overloads the uminus method for the Dynare time series class (@ref{dseries}).
-%! @sp 2
-%! @strong{Inputs}
-%! @sp 1
-%! @table @ @var
-%! @item B
-%! Dynare time series object instantiated by @ref{dseries}.
-%! @item C
-%! Dynare time series object instantiated by @ref{dseries}.
-%! @end table
-%! @sp 1
-%! @strong{Outputs}
-%! @sp 1
-%! @table @ @var
-%! @item A
-%! Dynare time series object.
-%! @end deftypefn
-%@eod:
-
-% Copyright (C) 2012-2013 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/>.
-
-A = dseries();
-
-A.data = -(B.data);
-A.dates = B.dates;
-
-A.name = cell(vobs(A),1);
-A.tex = cell(vobs(A),1);
-for i = 1:vobs(A)
-    A.name(i) = {[ '-' B.name{i}]};
-    A.tex(i) = {[ '-' B.tex{i}]};
-end
-
-%@test:1
-%$ % Define a datasets.
-%$ A = rand(10,2);
-%$
-%$ % Define names
-%$ A_name = {'A1';'A2'};
-%$ A_tex = {'A_1';'A_2'};
-%$ t = zeros(6,1);
-%$
-%$ % Instantiate a time series object.
-%$ try
-%$    ts1 = dseries(A,[],A_name,A_tex);
-%$    ts2 = -ts1;
-%$    t(1) = 1;
-%$ catch
-%$    t = 0;
-%$ end
-%$
-%$ if length(t)>1
-%$    t(2) = dyn_assert(ts2.vobs,2);
-%$    t(3) = dyn_assert(ts2.nobs,10);
-%$    t(4) = dyn_assert(ts2.data,-A,1e-15);
-%$    t(5) = dyn_assert(ts2.name,{'-A1';'-A2'});
-%$    t(6) = dyn_assert(ts2.tex,{'-A_1';'-A_2'});
-%$ end
-%$ T = all(t);
-%@eof:1
diff --git a/matlab/@dseries/vertcat.m b/matlab/@dseries/vertcat.m
deleted file mode 100644
index ad2af8b073611d2705937980553815a422ea6027..0000000000000000000000000000000000000000
--- a/matlab/@dseries/vertcat.m
+++ /dev/null
@@ -1,142 +0,0 @@
-function a = vertcat(varargin) % --*-- Unitary tests --*--
-
-%@info:
-%! @deftypefn {Function file} {@var{a} =} vertcat (@var{b},@var{c}, ...)
-%! @anchor{horzcat}
-%! @sp 1
-%! Method of the dseries class.
-%! @sp 1
-%! This method overloads the vertical concatenation operator, so that
-%! two (or more) time series objects containing the same variables 
-%! can be merged using the following syntax:
-%!
-%!     a = [b; c; d];
-%! @sp 2
-%! @strong{Inputs}
-%! @sp 1
-%! @table @ @var
-%! @item b
-%! Dynare time series object, instantiated by @ref{dseries}.
-%! @item c
-%! Dynare time series object, instantiated by @ref{dseries}.
-%! @end table
-%! @sp 2
-%! @strong{Outputs}
-%! @sp 1
-%! @table @var
-%! @item a
-%! Dynare time series object.
-%! @end table
-%! @end deftypefn
-%@eod:
-
-% Copyright (C) 2013 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 nargin==0
-    a = DynSeries();
-elseif nargin == 1
-    a = varargin{1};
-elseif nargin>1
-    a = varargin{1};
-    for i=2:nargin
-        a = vertcat_(a,varargin{i});
-    end
-end
-
-function d = vertcat_(b, c)
-    d = NaN;
-    if ~isequal(frequency(b), frequency(c))
-        error('dseries::vertcat: Frequencies must be common!')
-    end
-    if ~isequal(vobs(b), vobs(c))
-        error('dseries::vertcat: Number of variables must be common!')
-    end
-    if ~isequal(b.name, c.name)
-        error('dseries::vertcat: Variables must be common!')
-    end
-    d = b;
-    d.data = [b.data; c.data];
-    d.dates = [b.dates; c.dates];
-
-%@test:1
-%$ % Define a data set.
-%$ A = [transpose(1:10),2*transpose(1:10)];
-%$ B = [transpose(1:10),2*transpose(1:10)];
-%$
-%$ % Define names
-%$ A_name = {'A1';'A2'};
-%$ B_name = {'A1';'A2'};
-%$
-%$ % Define expected results.
-%$ e.init = dates(1,1);
-%$ e.freq = 1;
-%$ e.name = {'A1';'A2'};
-%$ e.data = [A;B];
-%$
-%$ % Instantiate two time series objects.
-%$ ts1 = dseries(A,[],A_name,[]);
-%$ ts2 = dseries(B,[],B_name,[]);
-%$
-%$ % Call the tested method.
-%$ ts3 = [ts1;ts2];
-%$
-%$ % Check the results.
-%$
-%$ t(1) = dyn_assert(isequal(ts3.init,e.init),1);
-%$ t(2) = dyn_assert(ts3.freq,e.freq);
-%$ t(3) = dyn_assert(ts3.data,e.data);
-%$ t(4) = dyn_assert(ts3.name,e.name);
-%$ t(5) = dyn_assert(ts3.nobs,20);
-%$ T = all(t);
-%@eof:1
-
-
-%@test:2
-%$ % Define a data set.
-%$ A = [transpose(1:10),2*transpose(1:10)];
-%$ B = [transpose(1:10),2*transpose(1:10)];
-%$ C = [transpose(1:10),3*transpose(1:10)];
-%$
-%$ % Define names
-%$ A_name = {'A1';'A2'};
-%$ B_name = {'A1';'A2'};
-%$ C_name = {'A1';'A2'};
-%$
-%$ % Define expected results.
-%$ e.init = dates(1,1);
-%$ e.freq = 1;
-%$ e.name = {'A1';'A2'};
-%$ e.data = [A;B;C];
-%$
-%$ % Instantiate two time series objects.
-%$ ts1 = dseries(A,[],A_name,[]);
-%$ ts2 = dseries(B,[],B_name,[]);
-%$ ts3 = dseries(C,[],C_name,[]);
-%$
-%$ % Call the tested method.
-%$ ts4 = [ts1; ts2; ts3];
-%$
-%$ % Check the results.
-%$
-%$ t(1) = dyn_assert(isequal(ts4.init,e.init),1);
-%$ t(2) = dyn_assert(ts4.freq,e.freq);
-%$ t(3) = dyn_assert(ts4.data,e.data);
-%$ t(4) = dyn_assert(ts4.name,e.name);
-%$ t(5) = dyn_assert(ts4.nobs,30);
-%$ T = all(t);
-%@eof:2
diff --git a/matlab/@dseries/vobs.m b/matlab/@dseries/vobs.m
deleted file mode 100644
index 37c1c80dd31eb48cfdbeda31a70e8ef5988fc33e..0000000000000000000000000000000000000000
--- a/matlab/@dseries/vobs.m
+++ /dev/null
@@ -1,22 +0,0 @@
-function s = vobs(ts)
-
-% Returns the number of variables in a @dseries object.
-
-% 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/>.
-
-s = columns(ts.data);
\ No newline at end of file
diff --git a/matlab/@dseries/ydiff.m b/matlab/@dseries/ydiff.m
deleted file mode 100644
index d50200b57f5841940c859a5f5822da32cde21f5b..0000000000000000000000000000000000000000
--- a/matlab/@dseries/ydiff.m
+++ /dev/null
@@ -1,171 +0,0 @@
-function us = ydiff(ts) % --*-- Unitary tests --*--
-
-%@info:
-%! @deftypefn {Function File} {@var{us} =} ydiff (@var{ts})
-%! @anchor{ydiff}
-%! @sp 1
-%! Computes annual differences.
-%! @sp 2
-%! @strong{Inputs}
-%! @sp 1
-%! @table @var
-%! @item ts
-%! Dynare time series object, instantiated by @ref{dseries}
-%! @end table
-%! @sp 2
-%! @strong{Outputs}
-%! @sp 1
-%! @table @var
-%! @item us
-%! Dynare time series object with transformed data field.
-%! @end table
-%! @end deftypefn
-%@eod:
-
-% Copyright (C) 2012-2013 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/>.
-
-us = ts;
-
-switch frequency(ts)
-  case 1
-    us.data(2:end,:) = ts.data(2:end,:)-ts.data(1:end-1,:);
-    us.data(1,:) = NaN;
-    for i = 1:vobs(ts)
-        us.name(i) = {['ydiff(' us.name{i} ')']};
-        us.tex(i) = {['\Delta ' us.tex{i}]};
-    end
-  case 4
-    us.data(5:end,:) = ts.data(5:end,:)-ts.data(1:end-4,:);
-    us.data(1:4,:) = NaN;
-    for i = 1:vobs(ts)
-        us.name(i) = {['ydiff(' us.name{i} ')']};
-        us.tex(i) = {['\Delta_4 ' us.tex{i}]};
-    end
-  case 12
-    us.data(13:end,:) = ts.data(13:end,:)-ts.data(1:end-12,:);
-    us.data(1:12,:) = NaN;
-    for i = 1:vobs(ts)
-        us.name(i) = {['ydiff(' us.name{i} ')']};
-        us.tex(i) = {['\Delta_{12} ' us.tex{i}]};
-    end
-  case 52
-    us.data(53:end,:) = ts.data(53:end,:)-ts.data(1:end-52,:);
-    us.data(1:52,:) = NaN;
-    for i = 1:vobs(ts)
-        us.name(i) = {['ydiff(' us.name{i} ')']};
-        us.tex(i) = {['\Delta_{52} ' us.tex{i}]};
-    end
-  otherwise
-    error(['dseries::ygrowth: object ' inputname(1) ' has unknown frequency']);
-end
-
-%@test:1
-%$ t = zeros(4,1);
-%$
-%$ try
-%$     data = transpose(1:100);
-%$     ts = dseries(data,'1950Q1',{'A1'},{'A_1'});
-%$     ts = ts.ydiff;
-%$     t(1) = 1;
-%$ catch
-%$     t = 0;
-%$ end
-%$
-%$
-%$ if length(t)>1
-%$     DATA = NaN(4,ts.vobs);
-%$     DATA = [DATA; 4*ones(ts.nobs-4,ts.vobs)];
-%$     t(2) = dyn_assert(ts.data,DATA);
-%$     t(3) = dyn_assert(ts.name{1},['ydiff(A1)']);
-%$     t(4) = dyn_assert(ts.tex{1},['\\Delta_4 A_1']);
-%$ end
-%$
-%$ T = all(t);
-%@eof:1
-
-%@test:2
-%$ t = zeros(4,1);
-%$
-%$ try
-%$     data = transpose(1:100);
-%$     ts = dseries(data,'1950M1',{'A1'},{'A_1'});
-%$     ts = ts.ydiff;
-%$     t(1) = 1;
-%$ catch
-%$     t = 0;
-%$ end
-%$
-%$
-%$ if length(t)>1
-%$     DATA = NaN(12,ts.vobs);
-%$     DATA = [DATA; 12*ones(ts.nobs-12,ts.vobs)];
-%$     t(2) = dyn_assert(ts.data,DATA);
-%$     t(3) = dyn_assert(ts.name{1},['ydiff(A1)']);
-%$     t(4) = dyn_assert(ts.tex{1},['\\Delta_{12} A_1']);
-%$ end
-%$
-%$ T = all(t);
-%@eof:2
-
-%@test:3
-%$ t = zeros(2,1);
-%$
-%$ try
-%$     data = transpose(1:100);
-%$     ts = dseries(data,'1950W1',{'A1'},{'A_1'});
-%$     ts = ts.ydiff;
-%$     t(1) = 1;
-%$ catch
-%$     t = 0;
-%$ end
-%$
-%$
-%$ if length(t)>1
-%$     DATA = NaN(52,ts.vobs);
-%$     DATA = [DATA; 52*ones(ts.nobs-52,ts.vobs)];
-%$     t(2) = dyn_assert(ts.data,DATA);
-%$     t(3) = dyn_assert(ts.name{1},['ydiff(A1)']);
-%$     t(4) = dyn_assert(ts.tex{1},['\\Delta_{52} A_1']);
-%$ end
-%$
-%$ T = all(t);
-%@eof:3
-
-%@test:4
-%$ t = zeros(4,1);
-%$
-%$ try
-%$     data = transpose(1:100);
-%$     ts = dseries(data,'1950Y',{'A1'},{'A_1'});
-%$     ts = ts.ydiff;
-%$     t(1) = 1;
-%$ catch
-%$     t = 0;
-%$ end
-%$
-%$
-%$ if length(t)>1
-%$     DATA = NaN(1,ts.vobs);
-%$     DATA = [DATA; ones(ts.nobs-1,ts.vobs)];
-%$     t(2) = dyn_assert(ts.data,DATA);
-%$     t(3) = dyn_assert(ts.name{1},['ydiff(A1)']);
-%$     t(4) = dyn_assert(ts.tex{1},['\\Delta A_1']);
-%$ end
-%$
-%$ T = all(t);
-%@eof:4
diff --git a/matlab/@dseries/ygrowth.m b/matlab/@dseries/ygrowth.m
deleted file mode 100644
index 9b50c38c93b97d4bc73fc1c31d05a6e9030036ad..0000000000000000000000000000000000000000
--- a/matlab/@dseries/ygrowth.m
+++ /dev/null
@@ -1,141 +0,0 @@
-function us = ygrowth(ts) % --*-- Unitary tests --*--
-
-%@info:
-%! @deftypefn {Function File} {@var{us} =} ygrowth (@var{ts})
-%! @anchor{ygrowth}
-%! @sp 1
-%! Computes annual growth rates.
-%! @sp 2
-%! @strong{Inputs}
-%! @sp 1
-%! @table @var
-%! @item ts
-%! Dynare time series object, instantiated by @ref{dseries}
-%! @end table
-%! @sp 2
-%! @strong{Outputs}
-%! @sp 1
-%! @table @var
-%! @item us
-%! Dynare time series object with transformed data field.
-%! @end table
-%! @end deftypefn
-%@eod:
-
-% Copyright (C) 2012-2013 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/>.
-
-us = ts;
-
-switch frequency(ts)
-  case 1
-    us.data(2:end,:) = ts.data(2:end,:)./ts.data(1:end-1,:) - 1;
-    us.data(1,:) = NaN;
-    for i = 1:vobs(ts)
-        us.name(i) = {['ygrowth(' us.name{i} ')']};
-        us.tex(i) = {['\delta ' us.tex{i}]};
-    end
-  case 4
-    us.data(5:end,:) = ts.data(5:end,:)./ts.data(1:end-4,:) - 1;
-    us.data(1:4,:) = NaN;
-    for i = 1:vobs(ts)
-        us.name(i) = {['ygrowth(' us.name{i} ')']};
-        us.tex(i) = {['\delta_4 ' us.tex{i}]};
-    end
-  case 12
-    us.data(13:end,:) = ts.data(13:end,:)./ts.data(1:end-12,:) - 1;
-    us.data(1:12,:) = NaN;
-    for i = 1:vobs(ts)
-        us.name(i) = {['ygrowth(' us.name{i} ')']};
-        us.tex(i) = {['\delta_{12} ' us.tex{i}]};
-    end
-  case 52
-    us.data(53:end,:) = ts.data(53:end,:)./ts.data(1:end-52,:) - 1;
-    us.data(1:52,:) = NaN;
-    for i = 1:vobs(ts)
-        us.name(i) = {['ygrowth(' us.name{i} ')']};
-        us.tex(i) = {['\delta_{52} ' us.tex{i}]};
-    end
-  otherwise
-    error(['dseries::ygrowth: object ' inputname(1) ' has unknown frequency']);
-end
-
-%@test:1
-%$ t = zeros(2,1);
-%$
-%$ try
-%$     data = repmat(transpose(1:4),100,1);
-%$     ts = dseries(data,'1950Q1');
-%$     ts = ts.ygrowth;
-%$     t(1) = 1;
-%$ catch
-%$     t = 0;
-%$ end
-%$
-%$
-%$ if length(t)>1
-%$     DATA = NaN(4,ts.vobs);
-%$     DATA = [DATA; zeros(ts.nobs-4,ts.vobs)];
-%$     t(2) = dyn_assert(ts.data,DATA);
-%$ end
-%$
-%$ T = all(t);
-%@eof:1
-
-%@test:2
-%$ t = zeros(2,1);
-%$
-%$ try
-%$     data = repmat(transpose(1:12),100,1);
-%$     ts = dseries(data,'1950M1');
-%$     ts = ts.ygrowth;
-%$     t(1) = 1;
-%$ catch
-%$     t = 0;
-%$ end
-%$
-%$
-%$ if length(t)>1
-%$     DATA = NaN(12,ts.vobs);
-%$     DATA = [DATA; zeros(ts.nobs-12,ts.vobs)];
-%$     t(2) = dyn_assert(ts.data,DATA);
-%$ end
-%$
-%$ T = all(t);
-%@eof:2
-
-%@test:3
-%$ t = zeros(2,1);
-%$
-%$ try
-%$     data = repmat(transpose(1:52),100,1);
-%$     ts = dseries(data,'1950W1');
-%$     ts = ts.ygrowth;
-%$     t(1) = 1;
-%$ catch
-%$     t = 0;
-%$ end
-%$
-%$
-%$ if length(t)>1
-%$     DATA = NaN(52,ts.vobs);
-%$     DATA = [DATA; zeros(ts.nobs-52,ts.vobs)];
-%$     t(2) = dyn_assert(ts.data,DATA);
-%$ end
-%$
-%$ T = all(t);
-%@eof:3
diff --git a/matlab/CutSample.m b/matlab/CutSample.m
index 55bad478e188c4cc7c0438041010fb8cc2606fb3..a3efbb01ad43ead1a02b7d031206fe048b3b5e97 100644
--- a/matlab/CutSample.m
+++ b/matlab/CutSample.m
@@ -52,7 +52,7 @@ end
 TotalNumberOfMhFiles = sum(record.MhDraws(:,2));
 TotalNumberOfMhDraws = sum(record.MhDraws(:,1));
 MAX_nruns = ceil(options_.MaxNumberOfBytes/(npar+2)/8);
-FirstDraw = max(1,floor(options_.mh_drop*TotalNumberOfMhDraws));
+FirstDraw = max(1,floor(options_.mh_drop*TotalNumberOfMhDraws)+1);
 FirstMhFile = ceil(FirstDraw/MAX_nruns);
 FirstLine = FirstDraw-(FirstMhFile-1)*MAX_nruns;
 record.KeepedDraws.FirstMhFile = FirstMhFile;
@@ -70,9 +70,9 @@ end
 % Save updated mh-history file.
 update_last_mh_history_file(MetropolisFolder, ModelName, record);
 
-fprintf('Estimation::mcmc: Total number of MH draws: %d.\n',TotalNumberOfMhDraws);
+fprintf('Estimation::mcmc: Total number of MH draws per chain: %d.\n',TotalNumberOfMhDraws);
 fprintf('Estimation::mcmc: Total number of generated MH files: %d.\n',TotalNumberOfMhFiles);
 fprintf('Estimation::mcmc: I''ll use mh-files %d to %d.\n',FirstMhFile,TotalNumberOfMhFiles);
 fprintf('Estimation::mcmc: In MH-file number %d I''ll start at line %d.\n',FirstMhFile,FirstLine);
-fprintf('Estimation::mcmc: Finally I keep %d draws.\n',TotalNumberOfMhDraws-FirstDraw);
+fprintf('Estimation::mcmc: Finally I keep %d draws per chain.\n',TotalNumberOfMhDraws-FirstDraw+1);
 skipline()
\ No newline at end of file
diff --git a/matlab/DsgeSmoother.m b/matlab/DsgeSmoother.m
index 11517a934cf7d898acf22dc436d1dad25d7ebd20..309f2d9ab89241b93733b58e5c3224cd6b75a38a 100644
--- a/matlab/DsgeSmoother.m
+++ b/matlab/DsgeSmoother.m
@@ -117,13 +117,13 @@ if options_.lik_init == 1               % Kalman filter
         kalman_algo = 1;
     end
 	if options_.lyapunov_fp == 1
-        Pstar = lyapunov_symm(T,Q,options_.lyapunov_fixed_point_tol,options_.lyapunov_complex_threshold, 3, R);
+        Pstar = lyapunov_symm(T,R*Q*R',options_.lyapunov_fixed_point_tol,options_.lyapunov_complex_threshold, 3, [], options_.debug);
     elseif options_.lyapunov_db == 1
         Pstar = disclyap_fast(T,R*Q*R',options_.lyapunov_doubling_tol);
     elseif options_.lyapunov_srs == 1
-        Pstar = lyapunov_symm(T,Q,options_.lyapunov_fixed_point_tol,options_.lyapunov_complex_threshold, 4, R);
+        Pstar = lyapunov_symm(T,Q,options_.lyapunov_fixed_point_tol,options_.lyapunov_complex_threshold, 4, R, options_.debug);
     else
-        Pstar = lyapunov_symm(T,R*Q*R',options_.qz_criterium,options_.lyapunov_complex_threshold);
+        Pstar = lyapunov_symm(T,R*Q*R',options_.qz_criterium,options_.lyapunov_complex_threshold, [], [], options_.debug);
     end;
     Pinf        = [];
 elseif options_.lik_init == 2           % Old Diffuse Kalman filter
@@ -160,13 +160,13 @@ elseif options_.lik_init == 5            % Old diffuse Kalman filter only for th
     R_tmp = R(stable, :);
     T_tmp = T(stable,stable);
     if options_.lyapunov_fp == 1
-        Pstar_tmp = lyapunov_symm(T_tmp,Q,options_.lyapunov_fixed_point_tol,options_.lyapunov_complex_threshold, 3, R_tmp);
+        Pstar_tmp = lyapunov_symm(T_tmp,R_tmp*Q*R_tmp',options_.lyapunov_fixed_point_tol,options_.lyapunov_complex_threshold, 3, [], options_.debug);
     elseif options_.lyapunov_db == 1
         Pstar_tmp = disclyap_fast(T_tmp,R_tmp*Q*R_tmp',options_.lyapunov_doubling_tol);
     elseif options_.lyapunov_srs == 1
-        Pstar_tmp = lyapunov_symm(T_tmp,Q,options_.lyapunov_fixed_point_tol,options_.lyapunov_complex_threshold, 4, R_tmp);
+        Pstar_tmp = lyapunov_symm(T_tmp,Q,options_.lyapunov_fixed_point_tol,options_.lyapunov_complex_threshold, 4, R_tmp, options_.debug);
     else
-        Pstar_tmp = lyapunov_symm(T_tmp,R_tmp*Q*R_tmp',options_.qz_criterium,options_.lyapunov_complex_threshold);
+        Pstar_tmp = lyapunov_symm(T_tmp,R_tmp*Q*R_tmp',options_.qz_criterium,options_.lyapunov_complex_threshold, [], [], options_.debug);
     end
     Pstar(stable, stable) = Pstar_tmp;
     Pinf  = [];
diff --git a/matlab/GetPosteriorParametersStatistics.m b/matlab/GetPosteriorParametersStatistics.m
index cbcc318b4f05c488d608a328bcca4769ff7a21eb..f674e071f8e1b04618409da6afb2dfe8def9b922 100644
--- a/matlab/GetPosteriorParametersStatistics.m
+++ b/matlab/GetPosteriorParametersStatistics.m
@@ -75,7 +75,7 @@ catch
     [marginal,oo_] = marginal_density(M_, options_, estim_params_, oo_);
     disp(sprintf('Log data density is %f.',oo_.MarginalDensity.ModifiedHarmonicMean))
 end
-num_draws=length(NumberOfDraws*options_.mh_nblck);
+num_draws=NumberOfDraws*options_.mh_nblck;
 hpd_draws = round((1-options_.mh_conf_sig)*num_draws);
 if hpd_draws<2
     fprintf('posterior_moments: There are not enough draws computes to compute HPD Intervals. Skipping their computation.\n')
diff --git a/matlab/McMCDiagnostics_core.m b/matlab/McMCDiagnostics_core.m
index 83756f19b3617fb1d48e7fae27443d17a59b2662..4b447817173b005eb5ca1d07faaa846c71b7927b 100644
--- a/matlab/McMCDiagnostics_core.m
+++ b/matlab/McMCDiagnostics_core.m
@@ -1,23 +1,39 @@
 function myoutput = McMCDiagnostics_core(myinputs,fpar,npar,whoiam, ThisMatlab)
+% function myoutput = McMCDiagnostics_core(myinputs,fpar,npar,whoiam, ThisMatlab)
+% Computes the Brooks/Gelman (1998) convergence diagnostics, both the
+% parameteric and the non-parameteric versions
+% 
 % PARALLEL CONTEXT
 % Core functionality for MCMC Diagnostics, which can be parallelized.
 % See also the comment in random_walk_metropolis_hastings_core.m funtion.
-
-
+% 
+% 
 % INPUTS
 %   See See the comment in random_walk_metropolis_hastings_core.m funtion.
 
 % OUTPUTS
 % o myoutput  [struc]
-%  Contained UDIAG.
+%   Contains:
+%       - UDIAG [by 6] double   1st column: length of total sequence interval
+%                               2nd column: sum of length of within sequence intervals; used to compute mean length of within sequence intervals
+%                               3nd column: within sequence variance
+%                               4nd column: sum of within sequence variances; used to compute mean within sequence variances
+%                               5nd column: within sequence kurtosis
+%                               6nd column: sum of within sequence kurtoses; used to compute mean within sequence kurtoses
+%               Averaging to compute mean moments is done in
+%               McMCDiagnostics
 %
 % ALGORITHM
-%   Portion of McMCDiagnostics.m function.
+%   Computes part of the convergence diagnostics, the rest is computed in McMCDiagnostics.m .
+%   The methodology and terminology is based on: Brooks/Gelman (1998): General 
+%   Methods for Monitoring Convergence of Iterative Simulations, Journal of Computational 
+%   and Graphical Statistics, Volume 7, Number 4, Pages 434-455
+% 
 %
 % SPECIAL REQUIREMENTS.
 %   None.
 
-% Copyright (C) 2006-2011 Dynare Team
+% Copyright (C) 2006-2014 Dynare Team
 %
 % This file is part of Dynare.
 %
@@ -59,7 +75,7 @@ if ~exist('MetropolisFolder'),
     MetropolisFolder = CheckPath('metropolis',M_.dname);
 end
 
-ALPHA = 0.2;                                % increase too much with the number of simulations.
+ALPHA = 0.2; % percentile for non-parametric statistic
 tmp = zeros(NumberOfDraws*nblck,3);
 UDIAG = zeros(NumberOfLines,6,npar-fpar+1);
 
@@ -80,7 +96,7 @@ for j=fpar:npar,
     else
         fprintf('    Parameter %d...  ',j);
     end
-    for b = 1:nblck
+    for b = 1:nblck %load draws from different chains into 1 matrix
         startline = 0;
         for n = 1:NumberOfMcFilesPerBlock
             load([MetropolisFolder '/' M_.fname '_mh',int2str(n),'_blck' int2str(b) '.mat'],'x2');
@@ -89,29 +105,29 @@ for j=fpar:npar,
             startline = startline + nx2;
         end
     end
-    tmp(:,2) = kron(transpose(1:nblck),ones(NumberOfDraws,1));
-    tmp(:,3) = kron(ones(nblck,1),time');
-    tmp = sortrows(tmp,1);
-    ligne   = 0;
-    for iter  = Origin:StepSize:NumberOfDraws
-        ligne = ligne+1;
-        linea = ceil(mh_drop*iter);
-        n     = iter-linea+1;
-        cinf  = round(n*ALPHA/2);
-        csup  = round(n*(1-ALPHA/2));
-        CINF  = round(nblck*n*ALPHA/2);
-        CSUP  = round(nblck*n*(1-ALPHA/2));
-        temp  = tmp(find((tmp(:,3)>=linea) & (tmp(:,3)<=iter)),1:2);
-        UDIAG(ligne,1,j-fpar+1) = temp(CSUP,1)-temp(CINF,1);
-        moyenne = mean(temp(:,1));%% Pooled mean.
-        UDIAG(ligne,3,j-fpar+1) = sum((temp(:,1)-moyenne).^2)/(nblck*n-1);
-        UDIAG(ligne,5,j-fpar+1) = sum(abs(temp(:,1)-moyenne).^3)/(nblck*n-1);
+    tmp(:,2) = kron(transpose(1:nblck),ones(NumberOfDraws,1)); %add info about chain associated with draw into 2nd column
+    tmp(:,3) = kron(ones(nblck,1),time'); %add timeline for draws to third column
+    tmp = sortrows(tmp,1); %sort draws according to size for non-parametric percentile computation
+    window_iter   = 0;
+    for iter  = Origin:StepSize:NumberOfDraws %begin of window
+        window_iter = window_iter+1;
+        linea = ceil(mh_drop*iter);         %compute first non-discarded draw; drops fraction of sample at each iteration for computational efficiency, see Brooks/Gelman (1998), p.438
+        n     = iter-linea+1;               %number of draws from each block in current batch
+        cinf  = round(n*ALPHA/2);           %lower bound for alpha percentile of within series
+        csup  = round(n*(1-ALPHA/2));       %upper bound for alpha percentile of within series
+        CINF  = round(nblck*n*ALPHA/2);     %lower bound for alpha percentile of pooled series
+        CSUP  = round(nblck*n*(1-ALPHA/2)); %upper bound for alpha percentile of pooled series
+        temp  = tmp(find((tmp(:,3)>=linea) & (tmp(:,3)<=iter)),1:2);    %extract pooled draws in current batch
+        UDIAG(window_iter,1,j-fpar+1) = temp(CSUP,1)-temp(CINF,1);      %length of total sequence interval
+        pooled_mean = mean(temp(:,1));      % Pooled mean.
+        UDIAG(window_iter,3,j-fpar+1) = sum((temp(:,1)-pooled_mean).^2)/(nblck*n-1);        %within sequence variance
+        UDIAG(window_iter,5,j-fpar+1) = sum(abs(temp(:,1)-pooled_mean).^3)/(nblck*n-1);     %within sequence third moment
         for i=1:nblck
             pmet = temp(find(temp(:,2)==i));
-            UDIAG(ligne,2,j-fpar+1) = UDIAG(ligne,2,j-fpar+1) + pmet(csup,1)-pmet(cinf,1);
-            moyenne = mean(pmet,1); %% Within mean.
-            UDIAG(ligne,4,j-fpar+1) = UDIAG(ligne,4,j-fpar+1) + sum((pmet(:,1)-moyenne).^2)/(n-1);
-            UDIAG(ligne,6,j-fpar+1) = UDIAG(ligne,6,j-fpar+1) + sum(abs(pmet(:,1)-moyenne).^3)/(n-1);
+            UDIAG(window_iter,2,j-fpar+1) = UDIAG(window_iter,2,j-fpar+1) + pmet(csup,1)-pmet(cinf,1); %sum of length of within sequence intervals; used to compute mean length of within sequence intervals
+            within_mean = mean(pmet,1); %% Within mean in current chain.
+            UDIAG(window_iter,4,j-fpar+1) = UDIAG(window_iter,4,j-fpar+1) + sum((pmet(:,1)-within_mean).^2)/(n-1); %sum of within sequence variances; used to compute mean within sequence variances
+            UDIAG(window_iter,6,j-fpar+1) = UDIAG(window_iter,6,j-fpar+1) + sum(abs(pmet(:,1)-within_mean).^3)/(n-1); %sum of within sequence kurtoses; used to compute mean within sequence kurtoses
         end
     end
     if isoctave
diff --git a/matlab/PosteriorIRF_core1.m b/matlab/PosteriorIRF_core1.m
index 0d0a1a752e4ba9921bc39a74ffb61344b9e02167..891703f51dbb97a9d07c738c8e7ca6946b2931d5 100644
--- a/matlab/PosteriorIRF_core1.m
+++ b/matlab/PosteriorIRF_core1.m
@@ -77,6 +77,7 @@ if options_.dsge_var
     NumberOfLagsTimesNvobs = myinputs.NumberOfLagsTimesNvobs;
     Companion_matrix = myinputs.Companion_matrix;
     stock_irf_bvardsge = zeros(options_.irf,nvobs,M_.exo_nbr,MAX_nirfs_dsgevar);
+    bounds = prior_bounds(bayestopt_,options_);
 end
 
 
@@ -189,7 +190,7 @@ while fpar<B
     end
     if MAX_nirfs_dsgevar
         IRUN = IRUN+1;
-        [fval,junk1,junk2,cost_flag,info,PHI,SIGMAu,iXX] =  dsge_var_likelihood(deep',dataset_,dataset_info,options_,M_,estim_params_,bayestopt_,oo_);
+        [fval,junk1,junk2,cost_flag,info,PHI,SIGMAu,iXX] =  dsge_var_likelihood(deep',dataset_,dataset_info,options_,M_,estim_params_,bayestopt_,bounds,oo_);
         dsge_prior_weight = M_.params(strmatch('dsge_prior_weight',M_.param_names));
         DSGE_PRIOR_WEIGHT = floor(dataset_.nobs*(1+dsge_prior_weight));
         SIGMA_inv_upper_chol = chol(inv(SIGMAu*dataset_.nobs*(dsge_prior_weight+1)));
diff --git a/matlab/UnivariateSpectralDensity.m b/matlab/UnivariateSpectralDensity.m
index 0303cd3064383ee359dc6bf85fc7a87476db1209..d2eb851e831cd50e0eee5757f78ef14139b0129b 100644
--- a/matlab/UnivariateSpectralDensity.m
+++ b/matlab/UnivariateSpectralDensity.m
@@ -93,7 +93,7 @@ for i=M_.maximum_lag:-1:2
 end
 Gamma = zeros(nvar,cutoff+1);
 [A,B] = kalman_transition_matrix(dr,ikx',1:nx,M_.exo_nbr);
-[vx, u] =  lyapunov_symm(A,B*M_.Sigma_e*B',options_.qz_criterium,options_.lyapunov_complex_threshold);
+[vx, u] =  lyapunov_symm(A,B*M_.Sigma_e*B',options_.qz_criterium,options_.lyapunov_complex_threshold,[],[],options_.debug);
 iky = iv(ivar);
 if ~isempty(u)
     iky = iky(find(any(abs(ghx(iky,:)*u) < options_.Schur_vec_tol,2)));
diff --git a/matlab/check_prior_bounds.m b/matlab/check_prior_bounds.m
index 5e39fb2f0b8dce9575623677f9f19197b5780bbe..5214ce010c0a02f2891eec0763ef3ca284bc736c 100644
--- a/matlab/check_prior_bounds.m
+++ b/matlab/check_prior_bounds.m
@@ -27,7 +27,7 @@ function check_prior_bounds(xparam1,bounds,M_,estim_params_,options_,bayestopt_)
 % You should have received a copy of the GNU General Public License
 % along with Dynare.  If not, see <http://www.gnu.org/licenses/>.
 
-outside_bound_pars=find(xparam1 < bounds(:,1) | xparam1 > bounds(:,2));
+outside_bound_pars=find(xparam1 < bounds.lb | xparam1 > bounds.ub);
 if ~isempty(outside_bound_pars)
     for ii=1:length(outside_bound_pars)
         outside_bound_par_names{ii,1}=get_the_name(outside_bound_pars(ii),0,M_,estim_params_,options_);
diff --git a/matlab/common_strings_in_cell_arrays.m b/matlab/common_strings_in_cell_arrays.m
index fdea23aa35222b977dea6ec7a92a863068abacfc..06277f95fdd30a097242f7a05aef86506ba78b23 100644
--- a/matlab/common_strings_in_cell_arrays.m
+++ b/matlab/common_strings_in_cell_arrays.m
@@ -77,9 +77,9 @@ end
 %$ end
 %$
 %$ if length(t)>1
-%$    t(2) = dyn_assert(n,m);
-%$    t(3) = dyn_assert(n,0);
-%$    t(4) = dyn_assert(isempty(message),1);
+%$    t(2) = dassert(n,m);
+%$    t(3) = dassert(n,0);
+%$    t(4) = dassert(isempty(message),1);
 %$ end
 %$ T = all(t);
 %@eof:1
@@ -98,9 +98,9 @@ end
 %$ end
 %$
 %$ if length(t)>1
-%$    t(2) = dyn_assert(n,m);
-%$    t(3) = dyn_assert(n,2);
-%$    t(4) = dyn_assert(message,'A2 and A4');
+%$    t(2) = dassert(n,m);
+%$    t(3) = dassert(n,2);
+%$    t(4) = dassert(message,'A2 and A4');
 %$ end
 %$ T = all(t);
 %@eof:2
@@ -119,9 +119,9 @@ end
 %$ end
 %$
 %$ if length(t)>1
-%$    t(2) = dyn_assert(n,m);
-%$    t(3) = dyn_assert(n,3);
-%$    t(4) = dyn_assert(message,'A2, A4 and A1');
+%$    t(2) = dassert(n,m);
+%$    t(3) = dassert(n,3);
+%$    t(4) = dassert(message,'A2, A4 and A1');
 %$ end
 %$ T = all(t);
 %@eof:3
diff --git a/matlab/compute_mh_covariance_matrix.m b/matlab/compute_mh_covariance_matrix.m
index 05b0a42620113714959036ecf0452fa88abd32b8..8b62a2afe269b7080d5e600110ea0eba5f00d417 100644
--- a/matlab/compute_mh_covariance_matrix.m
+++ b/matlab/compute_mh_covariance_matrix.m
@@ -32,7 +32,7 @@ function [posterior_mean,posterior_covariance,posterior_mode,posterior_kernel_at
 % 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_ options_ estim_params_
+global M_ options_ estim_params_ bayestopt_
 
 
 n = estim_params_.np + ...
@@ -76,5 +76,6 @@ end
 xparam1 = posterior_mode';
 hh = inv(posterior_covariance);
 fval = posterior_kernel_at_the_mode;
+parameter_names = bayestopt_.name;
 
-save([M_.fname '_mh_mode.mat'],'xparam1','hh','fval');
\ No newline at end of file
+save([M_.fname '_mh_mode.mat'],'xparam1','hh','fval','parameter_names');
\ No newline at end of file
diff --git a/matlab/compute_model_moments.m b/matlab/compute_model_moments.m
index 7b8e514571a02e020718f0b6596d03f9e766f065..1c89a5e07dfee184832b99247aff6ce7f5d892af 100644
--- a/matlab/compute_model_moments.m
+++ b/matlab/compute_model_moments.m
@@ -28,4 +28,5 @@ function moments=compute_model_moments(dr,M_,options_)
 % You should have received a copy of the GNU General Public License
 % along with Dynare.  If not, see <http://www.gnu.org/licenses/>.
 
-moments = th_autocovariances(dr,options_.varlist,M_,options_);
+[ivar,vartan,options_] = get_variables_list(options_,M_);
+moments = th_autocovariances(dr,ivar,M_,options_,options_.nodecomposition);
diff --git a/matlab/compute_moments_varendo.m b/matlab/compute_moments_varendo.m
index 6482afb746b403f7480344aabdc80ab1fa17618d..8a294606f9d15ec9fe24f40f70bca8c53b831cac 100644
--- a/matlab/compute_moments_varendo.m
+++ b/matlab/compute_moments_varendo.m
@@ -55,6 +55,7 @@ NumberOfEndogenousVariables = rows(var_list_);
 NumberOfExogenousVariables = M_.exo_nbr;
 list_of_exogenous_variables = M_.exo_names;
 NumberOfLags = options_.ar;
+NoDecomposition = options_.nodecomposition;
 if isfield(options_,'conditional_variance_decomposition')
     Steps = options_.conditional_variance_decomposition;
 else
@@ -95,18 +96,20 @@ else
 end
 % VARIANCE DECOMPOSITION.
 if M_.exo_nbr > 1
-    if posterior
-        for i=1:NumberOfEndogenousVariables
-            for j=1:NumberOfExogenousVariables
-                oo_ = posterior_analysis('decomposition',var_list_(i,:),M_.exo_names(j,:),[],options_,M_,oo_);
+    if ~NoDecomposition
+        if posterior
+            for i=1:NumberOfEndogenousVariables
+                for j=1:NumberOfExogenousVariables
+                    oo_ = posterior_analysis('decomposition',var_list_(i,:),M_.exo_names(j,:),[],options_,M_,oo_);
+                end
             end
-        end
-    else
-        for i=1:NumberOfEndogenousVariables
-            for j=1:NumberOfExogenousVariables
-                oo_ = prior_analysis('decomposition',var_list_(i,:),M_.exo_names(j,:),[],options_,M_,oo_);
+        else
+            for i=1:NumberOfEndogenousVariables
+                for j=1:NumberOfExogenousVariables
+                    oo_ = prior_analysis('decomposition',var_list_(i,:),M_.exo_names(j,:),[],options_,M_,oo_);
+                end
             end
-        end        
+        end
     end
     % CONDITIONAL VARIANCE DECOMPOSITION.
     if Steps
diff --git a/matlab/convert_dyn_45_to_44.m b/matlab/convert_dyn_45_to_44.m
new file mode 100644
index 0000000000000000000000000000000000000000..ed1e704af76bf1c13d008fc47af4c988101a1021
--- /dev/null
+++ b/matlab/convert_dyn_45_to_44.m
@@ -0,0 +1,89 @@
+function []=convert_dyn_45_to_44
+% function []=convert_dyn_45_to_44
+% This function converts the oo_-structure fields that have been changed in Dynare 4.5. 
+% following https://github.com/DynareTeam/dynare/pull/771 to the old format
+% of Dynare 4.4
+
+global M_ oo_ options_
+
+%% add initial conditions to Bayesian forecasts
+if isfield(oo_,'PointForecast')
+    var_names=fieldnames(oo_.PointForecast.HPDinf);
+    moment_names=fieldnames(oo_.PointForecast);
+    for moment_iter=1:length(moment_names)
+        for var_iter=1:length(var_names)
+            if strcmp(moment_names{moment_iter},'deciles')
+                oo_.MeanForecast.(moment_names{moment_iter}).(var_names{var_iter})=...
+                    [oo_.SmoothedVariables.(moment_names{moment_iter}).(var_names{var_iter})(:,end)*ones(M_.maximum_endo_lag,1)  oo_.MeanForecast.(moment_names{moment_iter}).(var_names{var_iter})];
+                oo_.PointForecast.(moment_names{moment_iter}).(var_names{var_iter})=...
+                    [oo_.SmoothedVariables.(moment_names{moment_iter}).(var_names{var_iter})(:,end)*ones(M_.maximum_endo_lag,1) oo_.PointForecast.(moment_names{moment_iter}).(var_names{var_iter})];                
+            else
+                oo_.MeanForecast.(moment_names{moment_iter}).(var_names{var_iter})=...
+                    [oo_.SmoothedVariables.(moment_names{moment_iter}).(var_names{var_iter})(end)*ones(M_.maximum_endo_lag,1); oo_.MeanForecast.(moment_names{moment_iter}).(var_names{var_iter})];
+                oo_.PointForecast.(moment_names{moment_iter}).(var_names{var_iter})=...
+                    [oo_.SmoothedVariables.(moment_names{moment_iter}).(var_names{var_iter})(end)*ones(M_.maximum_endo_lag,1); oo_.PointForecast.(moment_names{moment_iter}).(var_names{var_iter})];
+            end
+        end
+    end
+end
+
+%% change HPD-fields back to row vectors
+if isfield(oo_.PointForecast,'HPDinf')
+    names=fieldnames(oo_.PointForecast.HPDinf);
+    for ii=1:length(names)
+        oo_.PointForecast.HPDinf.(names{ii})=oo_.PointForecast.HPDinf.(names{ii})';
+        oo_.PointForecast.HPDsup.(names{ii})=oo_.PointForecast.HPDsup.(names{ii})';
+    end
+end
+
+if isfield(oo_.MeanForecast,'HPDinf')
+    names=fieldnames(oo_.MeanForecast.HPDinf);
+    for ii=1:length(names)
+        oo_.MeanForecast.HPDinf.(names{ii})=oo_.MeanForecast.HPDinf.(names{ii})';
+        oo_.MeanForecast.HPDsup.(names{ii})=oo_.MeanForecast.HPDsup.(names{ii})';
+    end
+end
+
+if isfield(oo_.UpdatedVariables,'HPDinf')
+    names=fieldnames(oo_.UpdatedVariables.HPDinf);
+    for ii=1:length(names)
+        oo_.UpdatedVariables.HPDinf.(names{ii})=oo_.UpdatedVariables.HPDinf.(names{ii})';
+        oo_.UpdatedVariables.HPDsup.(names{ii})=oo_.UpdatedVariables.HPDsup.(names{ii})';
+    end
+end
+
+if isfield(oo_.SmoothedVariables,'HPDinf')
+    names=fieldnames(oo_.SmoothedVariables.HPDinf);
+    for ii=1:length(names)
+        oo_.SmoothedVariables.HPDinf.(names{ii})=oo_.SmoothedVariables.HPDinf.(names{ii})';
+        oo_.SmoothedVariables.HPDsup.(names{ii})=oo_.SmoothedVariables.HPDsup.(names{ii})';
+    end
+end
+
+if isfield(oo_.FilteredVariables,'HPDinf')
+    names=fieldnames(oo_.FilteredVariables.HPDinf);
+    for ii=1:length(names)
+        oo_.FilteredVariables.HPDinf.(names{ii})=oo_.FilteredVariables.HPDinf.(names{ii})';
+        oo_.FilteredVariables.HPDsup.(names{ii})=oo_.FilteredVariables.HPDsup.(names{ii})';
+    end
+end
+
+if isfield(oo_.SmoothedShocks,'HPDinf')
+    names=fieldnames(oo_.SmoothedShocks.HPDinf);
+    for ii=1:length(names)
+        oo_.SmoothedShocks.HPDinf.(names{ii})=oo_.SmoothedShocks.HPDinf.(names{ii})';
+        oo_.SmoothedShocks.HPDsup.(names{ii})=oo_.SmoothedShocks.HPDsup.(names{ii})';
+    end
+end
+
+%% padd classical filtered variables with redundant zeros
+if isfield(oo_,'FilteredVariables')
+    names=fieldnames(oo_.FilteredVariables);
+    for ii=1:length(names)
+        %make sure Bayesian fields are not affect
+        if ~strcmp(names{ii},'Mean') && ~strcmp(names{ii},'Median') && ~strcmp(names{ii},'deciles') ...
+                && ~strcmp(names{ii},'Var') && ~strcmp(names{ii},'HPDinf') && ~strcmp(names{ii},'HPDsup') 
+            oo_.FilteredVariables.(names{ii})=[0; oo_.FilteredVariables.(names{ii}); zeros(options_.nk-1,1)];
+        end
+    end
+end
diff --git a/matlab/cubature_with_gaussian_weight.m b/matlab/cubature_with_gaussian_weight.m
index 1e011790813372668b212fb7b2b29636069dfcb0..ecc69230dd75847af8841ef993767f254b52f8bf 100644
--- a/matlab/cubature_with_gaussian_weight.m
+++ b/matlab/cubature_with_gaussian_weight.m
@@ -159,10 +159,10 @@ function m = ee(n,i,j)
 %$ % Compute (approximated) fourth order moments.
 %$ m4 = nodes.^4*weights;
 %$
-%$ t(2) = dyn_assert(m1,zeros(d,1),1e-12);
-%$ t(3) = dyn_assert(m2,ones(d,1),1e-12);
-%$ t(4) = dyn_assert(m3,zeros(d,1),1e-12);
-%$ t(5) = dyn_assert(m4,d*ones(d,1),1e-10);
+%$ t(2) = dassert(m1,zeros(d,1),1e-12);
+%$ t(3) = dassert(m2,ones(d,1),1e-12);
+%$ t(4) = dassert(m3,zeros(d,1),1e-12);
+%$ t(5) = dassert(m4,d*ones(d,1),1e-10);
 %$ T = all(t);
 %@eof:1
 
@@ -201,10 +201,10 @@ function m = ee(n,i,j)
 %$ % Compute (approximated) fourth order moments.
 %$ m4 = nodes.^4*weights;
 %$
-%$ t(2) = dyn_assert(m1,zeros(d,1),1e-12);
-%$ t(3) = dyn_assert(m2,transpose(1:d),1e-12);
-%$ t(4) = dyn_assert(m3,zeros(d,1),1e-12);
-%$ t(5) = dyn_assert(m4,d*transpose(1:d).^2,1e-10);
+%$ t(2) = dassert(m1,zeros(d,1),1e-12);
+%$ t(3) = dassert(m2,transpose(1:d),1e-12);
+%$ t(4) = dassert(m3,zeros(d,1),1e-12);
+%$ t(5) = dassert(m4,d*transpose(1:d).^2,1e-10);
 %$ T = all(t);
 %@eof:2
 
@@ -237,9 +237,9 @@ function m = ee(n,i,j)
 %$ % Compute (approximated) second order moments.
 %$ m2 = bsxfun(@times,nodes,transpose(weights))*transpose(nodes);
 %$
-%$ t(2) = dyn_assert(m1,zeros(d,1),1e-12);
-%$ t(3) = dyn_assert(diag(m2),transpose(1:d),1e-12);
-%$ t(4) = dyn_assert(m2(:),vec(diag(diag(m2))),1e-12);
+%$ t(2) = dassert(m1,zeros(d,1),1e-12);
+%$ t(3) = dassert(diag(m2),transpose(1:d),1e-12);
+%$ t(4) = dassert(m2(:),vec(diag(diag(m2))),1e-12);
 %$ T = all(t);
 %@eof:3
 
@@ -280,9 +280,9 @@ function m = ee(n,i,j)
 %$ % Compute (approximated) third order moments.
 %$ m3 = nodes.^3*weights;
 %$
-%$ t(2) = dyn_assert(m1,zeros(d,1),1e-12);
-%$ t(3) = dyn_assert(m2(:),vec(Sigma),1e-12);
-%$ t(4) = dyn_assert(m3,zeros(d,1),1e-12);
+%$ t(2) = dassert(m1,zeros(d,1),1e-12);
+%$ t(3) = dassert(m2(:),vec(Sigma),1e-12);
+%$ t(4) = dassert(m3,zeros(d,1),1e-12);
 %$ T = all(t);
 %@eof:4
 
@@ -322,11 +322,11 @@ function m = ee(n,i,j)
 %$ % Compute (approximated) fifth order moments.
 %$ m5 = nodes.^5*weights;
 %$
-%$ t(2) = dyn_assert(m1,zeros(d,1),1e-12);
-%$ t(3) = dyn_assert(m2,ones(d,1),1e-12);
-%$ t(4) = dyn_assert(m3,zeros(d,1),1e-12);
-%$ t(5) = dyn_assert(m4,3*ones(d,1),1e-12);
-%$ t(6) = dyn_assert(m5,zeros(d,1),1e-12);
+%$ t(2) = dassert(m1,zeros(d,1),1e-12);
+%$ t(3) = dassert(m2,ones(d,1),1e-12);
+%$ t(4) = dassert(m3,zeros(d,1),1e-12);
+%$ t(5) = dassert(m4,3*ones(d,1),1e-12);
+%$ t(6) = dassert(m5,zeros(d,1),1e-12);
 %$ T = all(t);
 %@eof:5
 
@@ -361,8 +361,8 @@ function m = ee(n,i,j)
 %$ % Compute (approximated) third order moments.
 %$ m3 = nodes.^3*weights;
 %$
-%$ t(2) = dyn_assert(m1,zeros(d,1),1e-12);
-%$ t(3) = dyn_assert(m2,ones(d,1),1e-12);
-%$ t(4) = dyn_assert(m3,zeros(d,1),1e-12);
+%$ t(2) = dassert(m1,zeros(d,1),1e-12);
+%$ t(3) = dassert(m2,ones(d,1),1e-12);
+%$ t(4) = dassert(m3,zeros(d,1),1e-12);
 %$ T = all(t);
 %@eof:6
diff --git a/matlab/cycle_reduction.m b/matlab/cycle_reduction.m
index f9cb2c9b5dd43647d832895b718499cbf1ed2b70..019c39a190dc6e25d8455e4f678441881fb92b84 100644
--- a/matlab/cycle_reduction.m
+++ b/matlab/cycle_reduction.m
@@ -143,7 +143,7 @@ end
 %$
 %$ % Check the results.
 %$ if t(1) && t(2)
-%$     t(3) = dyn_assert(X1,X2,1e-12);
+%$     t(3) = dassert(X1,X2,1e-12);
 %$ end
 %$
 %$ T = all(t);
diff --git a/matlab/disp_th_moments.m b/matlab/disp_th_moments.m
index 0c1a245a6db5874bd0d500ef703aa1fa72a2993f..3db312cdcb897e43593243c72b1da8034d479df2 100644
--- a/matlab/disp_th_moments.m
+++ b/matlab/disp_th_moments.m
@@ -20,6 +20,8 @@ function disp_th_moments(dr,var_list)
 
 global M_ oo_ options_
 
+nodecomposition = options_.nodecomposition;
+
 if size(var_list,1) == 0
     var_list = M_.endo_names(1:M_.orig_endo_nbr, :);
 end
@@ -34,7 +36,7 @@ for i=1:nvar
     end
 end
 
-[oo_.gamma_y,stationary_vars] = th_autocovariances(dr,ivar,M_,options_);
+[oo_.gamma_y,stationary_vars] = th_autocovariances(dr,ivar,M_,options_, nodecomposition);
 m = dr.ys(ivar);
 non_stationary_vars = setdiff(1:length(ivar),stationary_vars);
 m(non_stationary_vars) = NaN;
@@ -50,8 +52,10 @@ z = [ m sd s2 ];
 oo_.mean = m;
 oo_.var = oo_.gamma_y{1};
 
-if M_.exo_nbr > 1 && size(stationary_vars, 1) > 0
-    oo_.variance_decomposition=100*oo_.gamma_y{options_.ar+2};
+if size(stationary_vars, 1) > 0
+    if ~nodecomposition
+        oo_.variance_decomposition=100*oo_.gamma_y{options_.ar+2};
+    end
     if ~options_.noprint %options_.nomoments == 0
         if options_.order == 2
             title='APROXIMATED THEORETICAL MOMENTS';
@@ -66,7 +70,8 @@ if M_.exo_nbr > 1 && size(stationary_vars, 1) > 0
         lh = size(labels,2)+2;
         dyntable(title,headers,labels,z,lh,11,4);
 
-        skipline()
+        if M_.exo_nbr > 1 && ~nodecomposition
+            skipline()
             if options_.order == 2
                 title='APPROXIMATED VARIANCE DECOMPOSITION (in percent)';            
             else
@@ -81,7 +86,9 @@ if M_.exo_nbr > 1 && size(stationary_vars, 1) > 0
             headers = char(' ',headers);
             lh = size(deblank(M_.endo_names(ivar(stationary_vars),:)),2)+2;
             dyntable(title,headers,deblank(M_.endo_names(ivar(stationary_vars), ...
-                                                         :)),100*oo_.gamma_y{options_.ar+2}(stationary_vars,:),lh,8,2);
+                                                         :)),100* ...
+                     oo_.gamma_y{options_.ar+2}(stationary_vars,:),lh,8,2);
+        end
     end
     
     conditional_variance_steps = options_.conditional_variance_decomposition;
diff --git a/matlab/display_problematic_vars_Jacobian.m b/matlab/display_problematic_vars_Jacobian.m
index 0cb42b581a4edb613dbe911a1a94b0fe800f352e..b77c608043304b6ad366fda28969ee901291fe32 100644
--- a/matlab/display_problematic_vars_Jacobian.m
+++ b/matlab/display_problematic_vars_Jacobian.m
@@ -36,6 +36,11 @@ function []=display_problematic_vars_Jacobian(problemrow,problemcol,M_,x,type,ca
 if nargin<6
     caller_string='';
 end
+aux_vars_type = [M_.aux_vars.type];
+aux_eq_nbr = max(find(aux_vars_type == 6)); 
+if isempty(aux_eq_nbr)
+    aux_eq_nbr=0;
+end
 if strcmp(type,'dynamic')
     for ii=1:length(problemrow)
         [var_row,var_index]=find(M_.lead_lag_incidence==problemcol(ii));
@@ -47,10 +52,33 @@ if strcmp(type,'dynamic')
             type_string='lead of';
         end
         if var_index<=M_.orig_endo_nbr
-            fprintf('Derivative of Equation %d with respect to %s Variable %s  (initial value of %s: %g) \n',problemrow(ii),type_string,deblank(M_.endo_names(var_index,:)),deblank(M_.endo_names(var_index,:)),x(var_index))
+            if problemrow(ii)<=aux_eq_nbr
+                eq_nbr=problemrow(ii);
+                fprintf('Derivative of Auxiliary Equation %d with respect to %s Variable %s  (initial value of %s: %g) \n',eq_nbr,type_string,deblank(M_.endo_names(var_index,:)),deblank(M_.endo_names(var_index,:)),x(var_index))
+            else
+                eq_nbr=problemrow(ii)-aux_eq_nbr;
+                fprintf('Derivative of Equation %d with respect to %s Variable %s  (initial value of %s: %g) \n',eq_nbr,type_string,deblank(M_.endo_names(var_index,:)),deblank(M_.endo_names(var_index,:)),x(var_index))
+            end
         else %auxiliary vars
-            orig_var_index=M_.aux_vars(1,var_index-M_.orig_endo_nbr).orig_index;
-            fprintf('Derivative of Equation %d with respect to %s Variable %s  (initial value of %s: %g) \n',problemrow(ii),type_string,deblank(M_.endo_names(orig_var_index,:)),deblank(M_.endo_names(orig_var_index,:)),x(orig_var_index))            
+            if M_.aux_vars(1,problemcol(ii)-M_.orig_endo_nbr).type ==6 %Ramsey Lagrange Multiplier 
+                if problemrow(ii)<=aux_eq_nbr
+                    eq_nbr=problemrow(ii);
+                    fprintf('Derivative of Auxiliary Equation %d with respect to %s of Langrange multiplier of equation %s (initial value: %g) \n',eq_nbr,type_string,M_.aux_vars(1,problemcol(ii)-M_.orig_endo_nbr).eq_nbr,x(problemcol(ii)))            
+                else
+                    eq_nbr=problemrow(ii)-aux_eq_nbr;
+                    fprintf('Derivative of Equation %d with respect to %s of Langrange multiplier of equation %s (initial value: %g) \n',eq_nbr,type_string,M_.aux_vars(1,problemcol(ii)-M_.orig_endo_nbr).eq_nbr,x(problemcol(ii)))            
+                end
+            else
+                if problemrow(ii)<=aux_eq_nbr
+                    eq_nbr=problemrow(ii);
+                    orig_var_index=M_.aux_vars(1,var_index-M_.orig_endo_nbr).orig_index;
+                    fprintf('Derivative of Auxiliary Equation %d with respect to %s Variable %s  (initial value of %s: %g) \n',eq_nbr,type_string,deblank(M_.endo_names(orig_var_index,:)),deblank(M_.endo_names(orig_var_index,:)),x(orig_var_index))            
+                else
+                    eq_nbr=problemrow(ii)-aux_eq_nbr;
+                    orig_var_index=M_.aux_vars(1,var_index-M_.orig_endo_nbr).orig_index;
+                    fprintf('Derivative of Equation %d with respect to %s Variable %s  (initial value of %s: %g) \n',eq_nbr,type_string,deblank(M_.endo_names(orig_var_index,:)),deblank(M_.endo_names(orig_var_index,:)),x(orig_var_index))            
+                end
+            end
         end    
     end
     fprintf('\n%s  The problem most often occurs, because a variable with\n',caller_string)
@@ -59,10 +87,33 @@ if strcmp(type,'dynamic')
 elseif strcmp(type,'static')
     for ii=1:length(problemrow)
         if problemcol(ii)<=M_.orig_endo_nbr
-            fprintf('Derivative of Equation %d with respect to Variable %s  (initial value of %s: %g) \n',problemrow(ii),deblank(M_.endo_names(problemcol(ii),:)),deblank(M_.endo_names(problemcol(ii),:)),x(problemcol(ii)))
+            if problemrow(ii)<=aux_eq_nbr
+                eq_nbr=problemrow(ii);
+                fprintf('Derivative of Auxiliary Equation %d with respect to Variable %s  (initial value of %s: %g) \n',eq_nbr,deblank(M_.endo_names(problemcol(ii),:)),deblank(M_.endo_names(problemcol(ii),:)),x(problemcol(ii)))
+            else
+                eq_nbr=problemrow(ii)-aux_eq_nbr;
+                fprintf('Derivative of Equation %d with respect to Variable %s  (initial value of %s: %g) \n',eq_nbr,deblank(M_.endo_names(problemcol(ii),:)),deblank(M_.endo_names(problemcol(ii),:)),x(problemcol(ii)))
+            end
         else %auxiliary vars
-            orig_var_index=M_.aux_vars(1,problemcol(ii)-M_.orig_endo_nbr).orig_index;
-            fprintf('Derivative of Equation %d with respect to Variable %s  (initial value of %s: %g) \n',problemrow(ii),deblank(M_.endo_names(orig_var_index,:)),deblank(M_.endo_names(orig_var_index,:)),x(problemcol(ii)))            
+            if M_.aux_vars(1,problemcol(ii)-M_.orig_endo_nbr).type ==6 %Ramsey Lagrange Multiplier 
+                if problemrow(ii)<=aux_eq_nbr
+                    eq_nbr=problemrow(ii);
+                    fprintf('Derivative of Auxiliary Equation %s with respect to Lagrange multiplier of equation %d (initial value: %g) \n',eq_nbr,M_.aux_vars(1,problemcol(ii)-M_.orig_endo_nbr).eq_nbr,x(problemcol(ii)))            
+                else
+                    eq_nbr=problemrow(ii)-aux_eq_nbr;
+                    fprintf('Derivative of Equation %s with respect to Lagrange multiplier of equation %d (initial value: %g) \n',eq_nbr,M_.aux_vars(1,problemcol(ii)-M_.orig_endo_nbr).eq_nbr,x(problemcol(ii)))            
+                end
+            else
+            if problemrow(ii)<=aux_eq_nbr
+                eq_nbr=problemrow(ii);
+                orig_var_index=M_.aux_vars(1,problemcol(ii)-M_.orig_endo_nbr).orig_index;
+                fprintf('Derivative of Auxiliary Equation %d with respect to Variable %s  (initial value of %s: %g) \n',eq_nbr,deblank(M_.endo_names(orig_var_index,:)),deblank(M_.endo_names(orig_var_index,:)),x(problemcol(ii)))            
+            else
+                eq_nbr=problemrow(ii)-aux_eq_nbr;
+                orig_var_index=M_.aux_vars(1,problemcol(ii)-M_.orig_endo_nbr).orig_index;
+                fprintf('Derivative of Equation %d with respect to Variable %s  (initial value of %s: %g) \n',eq_nbr,deblank(M_.endo_names(orig_var_index,:)),deblank(M_.endo_names(orig_var_index,:)),x(problemcol(ii)))            
+            end
+            end
         end
     end
     fprintf('\n%s  The problem most often occurs, because a variable with\n',caller_string)
diff --git a/matlab/distributions/inverse_gamma_specification.m b/matlab/distributions/inverse_gamma_specification.m
index 1a073775c4cf31776373fd1f588baadd55a034de..20b1b9b35d9fe9e0f19d7ee2b3237c9eaccd6f9e 100644
--- a/matlab/distributions/inverse_gamma_specification.m
+++ b/matlab/distributions/inverse_gamma_specification.m
@@ -139,11 +139,11 @@ end
 %$ [s3,nu3] = inverse_gamma_specification(.75,.1,1,0);
 %$ [s4,nu4] = inverse_gamma_specification(.75,.1,1,1);
 %$ % Check the results.
-%$ t(1) = dyn_assert(s0,s1,1e-6);
-%$ t(2) = dyn_assert(nu0,nu1,1e-6);
+%$ t(1) = dassert(s0,s1,1e-6);
+%$ t(2) = dassert(nu0,nu1,1e-6);
 %$ t(3) = isnan(s4);
 %$ t(4) = isnan(nu4);
-%$ t(5) = dyn_assert(s3,16.240907971002265,1e-6);;
-%$ t(6) = dyn_assert(nu3,30.368398202624046,1e-6);;
+%$ t(5) = dassert(s3,16.240907971002265,1e-6);;
+%$ t(6) = dassert(nu3,30.368398202624046,1e-6);;
 %$ T = all(t);
 %@eof:1
\ No newline at end of file
diff --git a/matlab/dr_block.m b/matlab/dr_block.m
index 1878d572cea27887fd110f942cd485b6acf8cdce..2bca7bbe333f02df77a6d454b7bf21159146d5a0 100644
--- a/matlab/dr_block.m
+++ b/matlab/dr_block.m
@@ -51,7 +51,7 @@ function [dr,info,M_,options_,oo_] = dr_block(dr,task,M_,options_,oo_)
 % along with Dynare.  If not, see <http://www.gnu.org/licenses/>.
 
 info = 0;
-verbose = 0;
+verbose = options_.verbosity;
 if options_.order > 1
     error('2nd and 3rd order approximation not implemented with block option')
 end
@@ -463,17 +463,17 @@ for i = 1:Size;
             %First order approximation
             if task ~= 1
                 if nba ~= nyf
-                    sorted_roots = sort(abs(dr.eigval));
                     if isfield(options_,'indeterminacy_continuity')
                         if options_.indeterminacy_msv == 1
-                            [ss,tt,w,q] = qz(e',d');
+                            [ss,tt,w,q] = qz(E',D');
                             [ss,tt,w,junk] = reorder(ss,tt,w,q);
                             ss = ss';
                             tt = tt';
                             w  = w';
-                            %nba = nyf;
+                            nba = nyf;
                         end
                     else
+					    sorted_roots = sort(abs(data(i).eigval));
                         if nba > nyf
                             temp = sorted_roots(nd-nba+1:nd-nyf)-1-options_.qz_criterium;
                             info(1) = 3;
diff --git a/matlab/draw_prior_density.m b/matlab/draw_prior_density.m
index 1d364eecfd4261dfd012926b7ddeefe26a7e6eba..0f7b7045066a7bac9a61ecc528634c9d2b608b93 100644
--- a/matlab/draw_prior_density.m
+++ b/matlab/draw_prior_density.m
@@ -114,6 +114,4 @@ end
 binf = abscissa(1);
 bsup = abscissa(end);
 x = abscissa;
-f = dens;
-f(find(x<bayestopt_.lb(indx)))=0;
-f(find(x>bayestopt_.ub(indx)))=0;
+f = dens;
\ No newline at end of file
diff --git a/matlab/dsge_likelihood.m b/matlab/dsge_likelihood.m
index 7f32d6a71327adb4d69f64fe28e52a79fba08714..585b7e97a2bf01bd74225b996e133a7d23ce9f84 100644
--- a/matlab/dsge_likelihood.m
+++ b/matlab/dsge_likelihood.m
@@ -1,4 +1,4 @@
-function [fval,DLIK,Hess,exit_flag,ys,trend_coeff,info,Model,DynareOptions,BayesInfo,DynareResults] = dsge_likelihood(xparam1,DynareDataset,DatasetInfo,DynareOptions,Model,EstimatedParameters,BayesInfo,DynareResults,derivatives_info)
+function [fval,DLIK,Hess,exit_flag,SteadyState,trend_coeff,info,Model,DynareOptions,BayesInfo,DynareResults] = dsge_likelihood(xparam1,DynareDataset,DatasetInfo,DynareOptions,Model,EstimatedParameters,BayesInfo,BoundsInfo,DynareResults,derivatives_info)
 % Evaluates the posterior kernel of a dsge model using the specified
 % kalman_algo; the resulting posterior includes the 2*pi constant of the
 % likelihood function
@@ -39,7 +39,7 @@ function [fval,DLIK,Hess,exit_flag,ys,trend_coeff,info,Model,DynareOptions,Bayes
 %! Integer scalar, equal to zero if the routine return with a penalty (one otherwise).
 %! @item ys
 %! Vector of doubles, steady state level for the endogenous variables.
-%! @item trend_coeffs
+%! @item trend_coeff
 %! Matrix of doubles, coefficients of the deterministic trend in the measurement equation.
 %! @item info
 %! Integer scalar, error code.
@@ -136,16 +136,15 @@ global objective_function_penalty_base
 
 % Initialization of the returned variables and others...
 fval        = [];
-ys          = [];
+SteadyState = [];
 trend_coeff = [];
 exit_flag   = 1;
 info        = 0;
-singularity_flag = 0;
 DLIK        = [];
 Hess       = [];
 
 if DynareOptions.estimation_dll
-    [fval,exit_flag,ys,trend_coeff,info,params,H,Q] ...
+    [fval,exit_flag,SteadyState,trend_coeff,info,params,H,Q] ...
         = logposterior(xparam1,DynareDataset, DynareOptions,Model, ...
                           EstimatedParameters,BayesInfo,DynareResults);
     mexErrCheck('logposterior', exit_flag);
@@ -154,7 +153,7 @@ if DynareOptions.estimation_dll
         Model.H = H;
     end
     Model.Sigma_e = Q;
-    DynareResults.dr.ys = ys;
+    DynareResults.dr.ys = SteadyState;
     return
 end
 
@@ -178,9 +177,9 @@ end
 %------------------------------------------------------------------------------
 
 % Return, with endogenous penalty, if some parameters are smaller than the lower bound of the prior domain.
-if ~isequal(DynareOptions.mode_compute,1) && any(xparam1<BayesInfo.lb)
-    k = find(xparam1<BayesInfo.lb);
-    fval = objective_function_penalty_base+sum((BayesInfo.lb(k)-xparam1(k)).^2);
+if ~isequal(DynareOptions.mode_compute,1) && any(xparam1<BoundsInfo.lb)
+    k = find(xparam1<BoundsInfo.lb);
+    fval = objective_function_penalty_base+sum((BoundsInfo.lb(k)-xparam1(k)).^2);
     exit_flag = 0;
     info = 41;
     if analytic_derivation,
@@ -190,9 +189,9 @@ if ~isequal(DynareOptions.mode_compute,1) && any(xparam1<BayesInfo.lb)
 end
 
 % Return, with endogenous penalty, if some parameters are greater than the upper bound of the prior domain.
-if ~isequal(DynareOptions.mode_compute,1) && any(xparam1>BayesInfo.ub)
-    k = find(xparam1>BayesInfo.ub);
-    fval = objective_function_penalty_base+sum((xparam1(k)-BayesInfo.ub(k)).^2);
+if ~isequal(DynareOptions.mode_compute,1) && any(xparam1>BoundsInfo.ub)
+    k = find(xparam1>BoundsInfo.ub);
+    fval = objective_function_penalty_base+sum((xparam1(k)-BoundsInfo.ub(k)).^2);
     exit_flag = 0;
     info = 42;
     if analytic_derivation,
@@ -258,8 +257,8 @@ end
 [T,R,SteadyState,info,Model,DynareOptions,DynareResults] = dynare_resolve(Model,DynareOptions,DynareResults,'restrict');
 
 % Return, with endogenous penalty when possible, if dynare_resolve issues an error code (defined in resol).
-if info(1) == 1 || info(1) == 2 || info(1) == 5 || info(1) == 7 || info(1) ...
-            == 8 || info(1) == 22 || info(1) == 24 || info(1) == 19 || info(1) == 25
+if info(1) == 1 || info(1) == 2 || info(1) == 5 || info(1) == 7 || info(1) == 8 || ...
+            info(1) == 22 || info(1) == 24 || info(1) == 19 || info(1) == 25 || info(1) == 10
     fval = objective_function_penalty_base+1;
     info = info(1);
     exit_flag = 0;
@@ -315,7 +314,8 @@ if BayesInfo.with_trend
     end
     trend = repmat(constant,1,DynareDataset.nobs)+trend_coeff*[1:DynareDataset.nobs];
 else
-    trend = repmat(constant,1,DynareDataset.nobs);
+   trend_coeff = zeros(DynareDataset.vobs,1);
+   trend = repmat(constant,1,DynareDataset.nobs);
 end
 
 % Get needed informations for kalman filter routines.
@@ -367,13 +367,13 @@ switch DynareOptions.lik_init
         kalman_algo = 1;
     end
     if DynareOptions.lyapunov_fp == 1
-        Pstar = lyapunov_symm(T,Q,DynareOptions.lyapunov_fixed_point_tol,DynareOptions.lyapunov_complex_threshold, 3, R);
+        Pstar = lyapunov_symm(T,R*Q'*R',DynareOptions.lyapunov_fixed_point_tol,DynareOptions.lyapunov_complex_threshold, 3, [], DynareOptions.debug);
     elseif DynareOptions.lyapunov_db == 1
         Pstar = disclyap_fast(T,R*Q*R',DynareOptions.lyapunov_doubling_tol);
     elseif DynareOptions.lyapunov_srs == 1
-        Pstar = lyapunov_symm(T,Q,DynareOptions.lyapunov_fixed_point_tol,DynareOptions.lyapunov_complex_threshold, 4, R);
+        Pstar = lyapunov_symm(T,Q,DynareOptions.lyapunov_fixed_point_tol,DynareOptions.lyapunov_complex_threshold, 4, R, DynareOptions.debug);
     else
-        Pstar = lyapunov_symm(T,R*Q*R',DynareOptions.qz_criterium,DynareOptions.lyapunov_complex_threshold);
+        Pstar = lyapunov_symm(T,R*Q*R',DynareOptions.qz_criterium,DynareOptions.lyapunov_complex_threshold, [], [], DynareOptions.debug);
     end;
     Pinf  = [];
     a     = zeros(mm,1);
@@ -448,7 +448,7 @@ switch DynareOptions.lik_init
                                                         zeros(mmm,1), Pinf, Pstar, ...
                                                         kalman_tol, riccati_tol, DynareOptions.presample, ...
                                                         T,R,Q,H1,Z,mmm,pp,rr);
-        diffuse_periods = length(dlik);
+        diffuse_periods = size(dlik,1);
     end
     if isnan(dLIK),
         info = 45;
@@ -469,7 +469,7 @@ switch DynareOptions.lik_init
     if err
         disp(['dsge_likelihood:: I am not able to solve the Riccati equation, so I switch to lik_init=1!']);
         DynareOptions.lik_init = 1;
-        Pstar = lyapunov_symm(T,R*Q*R',DynareOptions.qz_criterium,DynareOptions.lyapunov_complex_threshold);
+        Pstar = lyapunov_symm(T,R*Q*R',DynareOptions.qz_criterium,DynareOptions.lyapunov_complex_threshold, [], [], DynareOptions.debug);
     end
     Pinf  = [];
     a = zeros(mm,1);
@@ -490,13 +490,13 @@ switch DynareOptions.lik_init
     R_tmp = R(stable, :);
     T_tmp = T(stable,stable);
     if DynareOptions.lyapunov_fp == 1
-        Pstar_tmp = lyapunov_symm(T_tmp,Q,DynareOptions.lyapunov_fixed_point_tol,DynareOptions.lyapunov_complex_threshold, 3, R_tmp);
+        Pstar_tmp = lyapunov_symm(T_tmp,R_tmp*Q*R_tmp',DynareOptions.lyapunov_fixed_point_tol,DynareOptions.lyapunov_complex_threshold, 3, [], DynareOptions.debug);
     elseif DynareOptions.lyapunov_db == 1
         Pstar_tmp = disclyap_fast(T_tmp,R_tmp*Q*R_tmp',DynareOptions.lyapunov_doubling_tol);
     elseif DynareOptions.lyapunov_srs == 1
-        Pstar_tmp = lyapunov_symm(T_tmp,Q,DynareOptions.lyapunov_fixed_point_tol,DynareOptions.lyapunov_complex_threshold, 4, R_tmp);
+        Pstar_tmp = lyapunov_symm(T_tmp,Q,DynareOptions.lyapunov_fixed_point_tol,DynareOptions.lyapunov_complex_threshold, 4, R_tmp, DynareOptions.debug);
     else
-        Pstar_tmp = lyapunov_symm(T_tmp,R_tmp*Q*R_tmp',DynareOptions.qz_criterium,DynareOptions.lyapunov_complex_threshold);
+        Pstar_tmp = lyapunov_symm(T_tmp,R_tmp*Q*R_tmp',DynareOptions.qz_criterium,DynareOptions.lyapunov_complex_threshold, [], [], DynareOptions.debug);
     end    
     Pstar(stable, stable) = Pstar_tmp;
     Pinf  = [];
@@ -523,7 +523,7 @@ if analytic_derivation,
     DLIK = [];
     AHess = [];
     iv = DynareResults.dr.restrict_var_list;
-    if nargin<9 || isempty(derivatives_info)
+    if nargin<10 || isempty(derivatives_info)
         [A,B,nou,nou,Model,DynareOptions,DynareResults] = dynare_resolve(Model,DynareOptions,DynareResults);
         if ~isempty(EstimatedParameters.var_exo)
             indexo=EstimatedParameters.var_exo(:,1);
@@ -576,14 +576,14 @@ if analytic_derivation,
     for i=1:EstimatedParameters.nvx
         k =EstimatedParameters.var_exo(i,1);
         DQ(k,k,i) = 2*sqrt(Q(k,k));
-        dum =  lyapunov_symm(T,DOm(:,:,i),DynareOptions.qz_criterium,DynareOptions.lyapunov_complex_threshold);
+        dum =  lyapunov_symm(T,DOm(:,:,i),DynareOptions.qz_criterium,DynareOptions.lyapunov_complex_threshold,[],[],DynareOptions.debug);
 %         kk = find(abs(dum) < 1e-12);
 %         dum(kk) = 0;
         DP(:,:,i)=dum;
         if full_Hess
         for j=1:i,
             jcount=jcount+1;
-            dum =  lyapunov_symm(T,dyn_unvech(D2Om(:,jcount)),DynareOptions.qz_criterium,DynareOptions.lyapunov_complex_threshold);
+            dum =  lyapunov_symm(T,dyn_unvech(D2Om(:,jcount)),DynareOptions.qz_criterium,DynareOptions.lyapunov_complex_threshold,[],[],DynareOptions.debug);
 %             kk = (abs(dum) < 1e-12);
 %             dum(kk) = 0;
             D2P(:,jcount)=dyn_vech(dum);
@@ -603,7 +603,7 @@ if analytic_derivation,
     offset = offset + EstimatedParameters.nvn;
     if DynareOptions.lik_init==1,
     for j=1:EstimatedParameters.np
-        dum =  lyapunov_symm(T,DT(:,:,j+offset)*Pstar*T'+T*Pstar*DT(:,:,j+offset)'+DOm(:,:,j+offset),DynareOptions.qz_criterium,DynareOptions.lyapunov_complex_threshold);
+        dum =  lyapunov_symm(T,DT(:,:,j+offset)*Pstar*T'+T*Pstar*DT(:,:,j+offset)'+DOm(:,:,j+offset),DynareOptions.qz_criterium,DynareOptions.lyapunov_complex_threshold,[],[],DynareOptions.debug);
 %         kk = find(abs(dum) < 1e-12);
 %         dum(kk) = 0;
         DP(:,:,j+offset)=dum;
@@ -617,7 +617,7 @@ if analytic_derivation,
             D2Tij = reshape(D2T(:,jcount),size(T));
             D2Omij = dyn_unvech(D2Om(:,jcount));
             tmp = D2Tij*Pstar*T' + T*Pstar*D2Tij' + DTi*DPj*T' + DTj*DPi*T' + T*DPj*DTi' + T*DPi*DTj' + DTi*Pstar*DTj' + DTj*Pstar*DTi' + D2Omij;
-            dum = lyapunov_symm(T,tmp,DynareOptions.qz_criterium,DynareOptions.lyapunov_complex_threshold);
+            dum = lyapunov_symm(T,tmp,DynareOptions.qz_criterium,DynareOptions.lyapunov_complex_threshold,[],[],DynareOptions.debug);
 %             dum(abs(dum)<1.e-12) = 0;
             D2P(:,jcount) = dyn_vech(dum);
 %             D2P(:,:,j+offset,i) = dum;
diff --git a/matlab/dsge_var_likelihood.m b/matlab/dsge_var_likelihood.m
index b08239ca2a87b01b297f6da5543c039b08664882..07b5d1b735ec3048f5d5afc4e3d9cb6f1573a8e6 100644
--- a/matlab/dsge_var_likelihood.m
+++ b/matlab/dsge_var_likelihood.m
@@ -1,4 +1,4 @@
-function [fval,grad,hess,exit_flag,info,PHI,SIGMAu,iXX,prior] = dsge_var_likelihood(xparam1,DynareDataset,DynareInfo,DynareOptions,Model,EstimatedParameters,BayesInfo,DynareResults)
+function [fval,grad,hess,exit_flag,info,PHI,SIGMAu,iXX,prior] = dsge_var_likelihood(xparam1,DynareDataset,DynareInfo,DynareOptions,Model,EstimatedParameters,BayesInfo,BoundsInfo,DynareResults)
 % Evaluates the posterior kernel of the bvar-dsge model.
 %
 % INPUTS
@@ -81,18 +81,18 @@ fval = [];
 exit_flag = 1;
 
 % Return, with endogenous penalty, if some dsge-parameters are smaller than the lower bound of the prior domain.
-if DynareOptions.mode_compute ~= 1 && any(xparam1 < BayesInfo.lb)
-    k = find(xparam1 < BayesInfo.lb);
-    fval = objective_function_penalty_base+sum((BayesInfo.lb(k)-xparam1(k)).^2);
+if DynareOptions.mode_compute ~= 1 && any(xparam1 < BoundsInfo.lb)
+    k = find(xparam1 < BoundsInfo.lb);
+    fval = objective_function_penalty_base+sum((BoundsInfo.lb(k)-xparam1(k)).^2);
     exit_flag = 0;
     info = 41;
     return;
 end
 
 % Return, with endogenous penalty, if some dsge-parameters are greater than the upper bound of the prior domain.
-if DynareOptions.mode_compute ~= 1 && any(xparam1 > BayesInfo.ub)
-    k = find(xparam1 > BayesInfo.ub);
-    fval = objective_function_penalty_base+sum((xparam1(k)-BayesInfo.ub(k)).^2);
+if DynareOptions.mode_compute ~= 1 && any(xparam1 > BoundsInfo.ub)
+    k = find(xparam1 > BoundsInfo.ub);
+    fval = objective_function_penalty_base+sum((xparam1(k)-BoundsInfo.ub(k)).^2);
     exit_flag = 0;
     info = 42;
     return;
@@ -132,8 +132,8 @@ end
 [T,R,SteadyState,info,Model,DynareOptions,DynareResults] = dynare_resolve(Model,DynareOptions,DynareResults,'restrict');
 
 % Return, with endogenous penalty when possible, if dynare_resolve issues an error code (defined in resol).
-if info(1) == 1 || info(1) == 2 || info(1) == 5 || info(1) == 7 || info(1) ...
-            == 8 || info(1) == 22 || info(1) == 24 || info(1) == 25
+if info(1) == 1 || info(1) == 2 || info(1) == 5 || info(1) == 7 || info(1) == 8 || ...
+            info(1) == 22 || info(1) == 24 || info(1) == 25 || info(1) == 10
     fval = objective_function_penalty_base+1;
     info = info(1);
     exit_flag = 0;
@@ -162,7 +162,7 @@ end
 %------------------------------------------------------------------------------
 
 % Compute the theoretical second order moments
-tmp0 = lyapunov_symm(T,R*Q*R',DynareOptions.qz_criterium,DynareOptions.lyapunov_complex_threshold);
+tmp0 = lyapunov_symm(T,R*Q*R',DynareOptions.qz_criterium,DynareOptions.lyapunov_complex_threshold, [], [], DynareOptions.debug);
 mf  = BayesInfo.mf1;
 
 % Get the non centered second order moments
diff --git a/matlab/dyn_ramsey_static.m b/matlab/dyn_ramsey_static.m
index 32eaa745bd549855324ab66dfca103f5ced98298..99d5e09397024f7c3256fa807bbcb1bbd14d5c19 100644
--- a/matlab/dyn_ramsey_static.m
+++ b/matlab/dyn_ramsey_static.m
@@ -1,4 +1,4 @@
-function [steady_state,params,check] = dyn_ramsey_static(x,M,options_,oo)
+function [steady_state,params,check] = dyn_ramsey_static(ys_init,M,options_,oo)
 
 % function  [steady_state,params,check] = dyn_ramsey_static_(x)
 % Computes the static first order conditions for optimal policy
@@ -14,7 +14,7 @@ function [steady_state,params,check] = dyn_ramsey_static(x,M,options_,oo)
 % SPECIAL REQUIREMENTS
 %    none
 
-% Copyright (C) 2003-2012 Dynare Team
+% Copyright (C) 2003-2014 Dynare Team
 %
 % This file is part of Dynare.
 %
@@ -32,38 +32,36 @@ function [steady_state,params,check] = dyn_ramsey_static(x,M,options_,oo)
 % along with Dynare.  If not, see <http://www.gnu.org/licenses/>.
 
 
-steady_state = [];
 params = M.params;
 check = 0;
-options_.steadystate.nocheck = 1;
+options_.steadystate.nocheck = 1; %disable checking because Lagrange multipliers are not accounted for in evaluate_steady_state_file
 % dyn_ramsey_static_1 is a subfunction
 nl_func = @(x) dyn_ramsey_static_1(x,M,options_,oo);
 
 % check_static_model is a subfunction
-if check_static_model(oo.steady_state,M,options_,oo)
-    steady_state = oo.steady_state;
+if check_static_model(ys_init,M,options_,oo) && ~options_.steadystate_flag
+    steady_state = ys_init;
     return
 elseif options_.steadystate_flag
     k_inst = [];
-    instruments = options_.instruments;
     inst_nbr = size(options_.instruments,1);
     for i = 1:inst_nbr
         k_inst = [k_inst; strmatch(options_.instruments(i,:), ...
                                    M.endo_names,'exact')];
     end
     if inst_nbr == 1
-        inst_val = csolve(nl_func,oo.steady_state(k_inst),'',options_.solve_tolf,100);
+        inst_val = csolve(nl_func,ys_init(k_inst),'',options_.solve_tolf,100); %solve for instrument, using univariate solver, starting at initial value for instrument
     else
-        [inst_val,info1] = dynare_solve(nl_func,ys(k_inst),0);
+        [inst_val,info1] = dynare_solve(nl_func,ys_init(k_inst),0); %solve for instrument, using multivariate solver, starting at initial value for instrument
     end
-    ys(k_inst) = inst_val;
+    ys_init(k_inst) = inst_val;
     exo_ss = [oo.exo_steady_state oo.exo_det_steady_state];
-    [xx,params,check] = evaluate_steady_state_file(ys,exo_ss,M,options_);
-    [junk,jun,steady_state] = nl_func(inst_val);
+    [xx,params,check] = evaluate_steady_state_file(ys_init,exo_ss,M,options_); %run steady state file again to update parameters
+    [junk,junk,steady_state] = nl_func(inst_val); %compute and return steady state
 else
     n_var = M.orig_endo_nbr;
     xx = oo.steady_state(1:n_var);
-    [xx,info1] = dynare_solve(nl_func,xx,0);
+    [xx,check] = dynare_solve(nl_func,xx,0);
     [junk,junk,steady_state] = nl_func(xx);
 end
 
@@ -78,24 +76,14 @@ mult = [];
 params = M.params;
 endo_nbr = M.endo_nbr;
 endo_names = M.endo_names;
-exo_nbr = M.exo_nbr;
 orig_endo_nbr = M.orig_endo_nbr;
 aux_vars_type = [M.aux_vars.type];
 orig_endo_aux_nbr = orig_endo_nbr + min(find(aux_vars_type == 6)) - 1; 
 orig_eq_nbr = M.orig_eq_nbr;
 inst_nbr = orig_endo_aux_nbr - orig_eq_nbr;
 % indices of Lagrange multipliers
-i_mult = [orig_endo_aux_nbr+(1:orig_eq_nbr)]';
 fname = M.fname;
-max_lead = M.maximum_lead;
-max_lag = M.maximum_lag;
 
-% indices of all endogenous variables
-i_endo = [1:endo_nbr]';
-% indices of endogenous variable except instruments
-% i_inst = M.instruments;
-% lead_lag incidence matrix
-i_lag = M.lead_lag_incidence;
 
 if options_.steadystate_flag
     k_inst = [];
@@ -104,18 +92,19 @@ if options_.steadystate_flag
         k_inst = [k_inst; strmatch(instruments(i,:), ...
                                    endo_names,'exact')];
     end
-    oo.steady_state(k_inst) = x;
-    [x,params,check] = evaluate_steady_state_file(oo.steady_state,...
+    ys_init=zeros(size(oo.steady_state)); %create starting vector for steady state computation as only instrument value is handed over
+    ys_init(k_inst) = x; %set instrument, the only value required for steady state computation, to current value
+    [x,params,check] = evaluate_steady_state_file(ys_init,... %returned x now has size endo_nbr as opposed to input size of n_instruments
                                                   [oo.exo_steady_state; ...
                                                   oo.exo_det_steady_state], ...
                                                   M,options_);
 end
 
-xx = zeros(endo_nbr,1);
-xx(1:length(x)) = x;
-% setting steady state of auxiliary variables
-% that depends on original endogenous variables
-if any([M.aux_vars.type] ~= 6)
+xx = zeros(endo_nbr,1); %initialize steady state vector
+xx(1:M.orig_endo_nbr) = x(1:M.orig_endo_nbr); %set values of original endogenous variables based on steady state file or initial value
+
+% setting steady state of auxiliary variables that depends on original endogenous variables
+if any([M.aux_vars.type] ~= 6) %auxiliary variables other than multipliers
     needs_set_auxiliary_variables = 1;
     fh = str2func([M.fname '_set_auxiliary_variables']);
     s_a_v_func = @(z) fh(z,... 
@@ -130,7 +119,6 @@ end
 % value and Jacobian of objective function
 ex = zeros(1,M.exo_nbr);
 [U,Uy,Uyy] = feval([fname '_objective_static'],x,ex, params);
-Uy = Uy';
 Uyy = reshape(Uyy,endo_nbr,endo_nbr);
 
 % set multipliers and auxiliary variables that
diff --git a/matlab/dynare_config.m b/matlab/dynare_config.m
index 0202f7bfce7aaebcc4b4be9334d41999a1d94951..c0b5c4294c6f40a04428a9a2b52b748d92f3bbfd 100644
--- a/matlab/dynare_config.m
+++ b/matlab/dynare_config.m
@@ -58,12 +58,12 @@ addpath([dynareroot '/particle/'])
 addpath([dynareroot '/gsa/'])
 addpath([dynareroot '/ep/'])
 addpath([dynareroot '/lmmcp/'])
+addpath([dynareroot '/modules/dates/src/'])
+addpath([dynareroot '/modules/dseries/src/'])
 addpath([dynareroot '/utilities/doc/'])
-addpath([dynareroot '/utilities/tests/'])
-addpath([dynareroot '/utilities/dates/'])
+addpath([dynareroot '/utilities/tests/src/'])
 addpath([dynareroot '/utilities/dataset/'])
 addpath([dynareroot '/utilities/general/'])
-addpath([dynareroot '/utilities/dseries/'])
 addpath([dynareroot '/reports/'])
 
 % For functions that exist only under some Octave versions
@@ -91,6 +91,11 @@ if isoctave
     addpath([dynareroot '/missing/ilu'])
 end
 
+% corrcoef with two outputs is missing in Octave (ticket #796)
+if isoctave && ~user_has_octave_forge_package('nan')
+    addpath([dynareroot '/missing/corrcoef'])
+end
+
 % strjoin is missing in older versions of MATLAB and in Octave < 3.8
 if (isoctave && octave_ver_less_than('3.8')) || ...
         (~isoctave && matlab_ver_less_than('8.1'))
@@ -110,7 +115,7 @@ if isoctave
 else
     % Add win32 specific paths for Dynare Windows package
     if strcmp(computer, 'PCWIN')
-        mexpath = [dynareroot '../mex/matlab/win32-7.5-8.3'];
+        mexpath = [dynareroot '../mex/matlab/win32-7.5-8.4'];
         if exist(mexpath, 'dir')
             addpath(mexpath)
         end
@@ -124,7 +129,7 @@ else
                 addpath(mexpath)
             end
         else
-            mexpath = [dynareroot '../mex/matlab/win64-7.8-8.3'];
+            mexpath = [dynareroot '../mex/matlab/win64-7.8-8.4'];
             if exist(mexpath, 'dir')
                 addpath(mexpath)
             end
diff --git a/matlab/dynare_estimation.m b/matlab/dynare_estimation.m
index ed2e3d84a4b2b81fc36eb0ce579d0c0ef2a56258..07b8c50a65e0413823e1349a97f68e34f57db9e3 100644
--- a/matlab/dynare_estimation.m
+++ b/matlab/dynare_estimation.m
@@ -155,49 +155,39 @@ if nnobs > 1 && horizon > 0
             offsetx = 0;
         end
         vname = deblank(var_list(i,:));
-        maxlag = M_.maximum_lag;
         for j=1:nnobs
             if mh_replic > 0
-                eval(['oo_.RecursiveForecast.Mean.' vname '(j,:) =' ...
-                      'oo_recursive_{' int2str(nobs(j))  '}.MeanForecast.Mean.' ...
-                      vname '(maxlag+1:end);']);
-                eval(['oo_.RecursiveForecast.HPDinf.' vname '(j,:) =' ...
-                      'oo_recursive_{' int2str(nobs(j))  '}.MeanForecast.HPDinf.' ...
-                      vname '(maxlag+1:end);']);
-                eval(['oo_.RecursiveForecast.HPDsup.' vname '(j,:) =' ...
-                      'oo_recursive_{' int2str(nobs(j))  '}.MeanForecast.HPDsup.' ...
-                      vname '(maxlag+1:end);']);
-                eval(['oo_.RecursiveForecast.HPDTotalinf.' vname '(j,:) =' ...
-                      'oo_recursive_{' int2str(nobs(j))  '}.PointForecast.HPDinf.' ...
-                      vname '(maxlag+1:end);']);
-                eval(['oo_.RecursiveForecast.HPDTotalsup.' vname '(j,:) =' ...
-                      'oo_recursive_{' int2str(nobs(j))  '}.PointForecast.HPDsup.' ...
-                      vname '(maxlag+1:end);']);
+                oo_.RecursiveForecast.Mean.(vname)(j,:) = ...
+                      oo_recursive_{nobs(j)}.MeanForecast.Mean.(vname);
+                oo_.RecursiveForecast.HPDinf.(vname)(j,:) = ...
+                      oo_recursive_{nobs(j)}.MeanForecast.HPDinf.(vname);
+                oo_.RecursiveForecast.HPDsup.(vname)(j,:) = ...
+                      oo_recursive_{nobs(j)}.MeanForecast.HPDsup.(vname);
+                oo_.RecursiveForecast.HPDTotalinf.(vname)(j,:) = ...
+                      oo_recursive_{nobs(j)}.PointForecast.HPDinf.(vname);
+                oo_.RecursiveForecast.HPDTotalsup.(vname)(j,:) = ...
+                      oo_recursive_{nobs(j)}.PointForecast.HPDsup.(vname);
             else
-                eval(['oo_.RecursiveForecast.Mean.' vname '(j,:) =' ...
-                      'oo_recursive_{' int2str(nobs(j))  '}.forecast.Mean.' ...
-                      vname ';']);
-                eval(['oo_.RecursiveForecast.HPDinf.' vname '(j,:) =' ...
-                      'oo_recursive_{' int2str(nobs(j))  '}.forecast.HPDinf.' ...
-                      vname ';']);
-                eval(['oo_.RecursiveForecast.HPDsup.' vname '(j,:) =' ...
-                      'oo_recursive_{' int2str(nobs(j))  '}.forecast.HPDsup.' ...
-                      vname ';']);
-            end
+                oo_.RecursiveForecast.Mean.(vname)(j,:) =...
+                      oo_recursive_{nobs(j)}.forecast.Mean.(vname);
+                oo_.RecursiveForecast.HPDinf.(vname)(j,:) =...
+                      oo_recursive_{nobs(j)}.forecast.HPDinf.(vname);
+                oo_.RecursiveForecast.HPDsup.(vname)(j,:) =...
+                      oo_recursive_{nobs(j)}.forecast.HPDsup.(vname);
+              end
             x = nobs(1)+nobs(j)-nobs(1)+(1:horizon);
 
-            y = eval(['oo_.RecursiveForecast.Mean.' vname '(j,:)']);
-            y1 = eval(['oo_.RecursiveForecast.HPDinf.' vname '(j,:)']);
-            y2 = eval(['oo_.RecursiveForecast.HPDsup.' vname '(j,:)']);
+            y = oo_.RecursiveForecast.Mean.(vname)(j,:);
+            y1 = oo_.RecursiveForecast.HPDinf.(vname)(j,:);
+            y2 = oo_.RecursiveForecast.HPDsup.(vname)(j,:);
             plot(x,y,'-b','linewidth',2)
             plot(x,y1,'--g', ...
                  'linewidth',1.5)
             plot(x,y2,'--g', ...
                  'linewidth',1.5)
             if mh_replic
-                y3 = eval(['oo_.RecursiveForecast.HPDTotalinf.' vname '(j,:)']);
-                y4 = eval(['oo_.RecursiveForecast.HPDTotalsup.' vname ...
-                           '(j,:)']);
+                y3 = oo_.RecursiveForecast.HPDTotalinf.(vname)(j,:);
+                y4 = oo_.RecursiveForecast.HPDTotalsup.(vname)(j,:);
                 plot(x,y3,'--r', ...
                      'linewidth',1.5)
                 plot(x,y4,'--r','linewidth',1.5)
diff --git a/matlab/dynare_estimation_1.m b/matlab/dynare_estimation_1.m
index bd132c565208b8b25e4a9a51f416387b731add07..111a1181431a8764da2dbcdf45d14e8fdf908be6 100644
--- a/matlab/dynare_estimation_1.m
+++ b/matlab/dynare_estimation_1.m
@@ -71,6 +71,27 @@ end
 if ~options_.dsge_var
     if options_.particle.status
         objective_function = str2func('non_linear_dsge_likelihood');
+        if options_.particle.filter_algorithm.sis == 1
+            options_.particle.algorithm = 'sequential_importance_particle_filter';
+        else
+            if options_.particle.filter_algorithm.apf == 1
+                options_.particle.algorithm = 'auxiliary_particle_filter';
+            else
+                if options_.particle.filter_algorithm.gf == 1
+                    options_.particle.algorithm = 'gaussian_filter';
+                else
+                    if options_.particle.filter_algorithm.gmf == 1
+                        options_.particle.algorithm = 'gaussian_mixture_filter';
+                    else
+                        if options_.particle.filter_algorithm.cpf == 1
+                            options_.particle.algorithm = 'conditional_particle_filter';
+                        else
+                            error('Estimation: Unknown filter!')
+                        end
+                    end
+                end
+            end
+        end
     else
         objective_function = str2func('dsge_likelihood');
     end
@@ -78,7 +99,7 @@ else
     objective_function = str2func('dsge_var_likelihood');
 end
 
-[dataset_, dataset_info, xparam1, hh, M_, options_, oo_, estim_params_, bayestopt_] = ...
+[dataset_, dataset_info, xparam1, hh, M_, options_, oo_, estim_params_, bayestopt_, bounds] = ...
     dynare_estimation_init(var_list_, dname, [], M_, options_, oo_, estim_params_, bayestopt_);
 
 if options_.dsge_var
@@ -107,9 +128,9 @@ else
     full_calibration_detected=0;
 end
 if options_.use_calibration_initialization %set calibration as starting values
-    [xparam1,estim_params_]=do_parameter_initialization(estim_params_,xparam1_calib,xparam1); %get explicitly initialized parameters that have precedence to calibrated values
+    [xparam1,estim_params_]=do_parameter_initialization(estim_params_,xparam1_calib,xparam1);   %get explicitly initialized parameters that have precedence to calibrated values
     try
-        check_prior_bounds(xparam1,[bayestopt_.lb bayestopt_.ub],M_,estim_params_,options_,bayestopt_); %check whether calibration satisfies prior bounds
+        check_prior_bounds(xparam1,bounds,M_,estim_params_,options_,bayestopt_); %check whether calibration satisfies prior bounds
     catch
         e = lasterror();
         fprintf('Cannot use parameter values from calibration as they violate the prior bounds.')
@@ -141,9 +162,6 @@ np  = estim_params_.np ;  % Number of deep parameters.
 nx  = nvx+nvn+ncx+ncn+np; % Total number of parameters to be estimated.
 %% Set the names of the priors.
 pnames = ['     ';'beta ';'gamm ';'norm ';'invg ';'unif ';'invg2'];
-%% Set parameters bounds
-lb = bayestopt_.lb;
-ub = bayestopt_.ub;
 
 dr = oo_.dr;
 
@@ -167,7 +185,7 @@ end
 
 %% perform initial estimation checks;
 try
-    oo_ = initial_estimation_checks(objective_function,xparam1,dataset_,dataset_info,M_,estim_params_,options_,bayestopt_,oo_);
+    oo_ = initial_estimation_checks(objective_function,xparam1,dataset_,dataset_info,M_,estim_params_,options_,bayestopt_,bounds,oo_);
 catch % if check fails, provide info on using calibration if present
     e = lasterror();
     if full_calibration_detected %calibrated model present and no explicit starting values
@@ -208,7 +226,7 @@ if isequal(options_.mode_compute,0) && isempty(options_.mode_file) && options_.m
                   ' = atT(i,:)'';']);
             if options_.nk > 0
                 eval(['oo_.FilteredVariables.' deblank(M_.endo_names(i1,:)) ...
-                      ' = squeeze(aK(1,i,:));']);
+                      ' = squeeze(aK(1,i,2:end-(options_.nk-1)));']);
             end
             eval(['oo_.UpdatedVariables.' deblank(M_.endo_names(i1,:)) ' = updated_variables(i,:)'';']);
         end
@@ -237,7 +255,8 @@ if ~isequal(options_.mode_compute,0) && ~options_.mh_posterior_mode_estimation
             optim_options = optimset(optim_options,'GradObj','on','TolX',1e-7);
         end
         [xparam1,fval,exitflag,output,lamdba,grad,hessian_fmincon] = ...
-            fmincon(objective_function,xparam1,[],[],[],[],lb,ub,[],optim_options,dataset_,dataset_info,options_,M_,estim_params_,bayestopt_,oo_);
+            fmincon(objective_function,xparam1,[],[],[],[],bounds.lb,bounds.ub,[],optim_options,dataset_,dataset_info,options_,M_,estim_params_,bayestopt_,bounds,oo_);
+        fprintf('\nFinal value of minus the log posterior (or likelihood):%f \n', fval);
       case 2
         error('ESTIMATION: mode_compute=2 option (Lester Ingber''s Adaptive Simulated Annealing) is no longer available')
       case 3
@@ -255,18 +274,18 @@ if ~isequal(options_.mode_compute,0) && ~options_.mh_posterior_mode_estimation
             optim_options = optimset(optim_options,'GradObj','on');
         end
         if ~isoctave
-            [xparam1,fval,exitflag] = fminunc(objective_function,xparam1,optim_options,dataset_,dataset_info_,options_,M_,estim_params_,bayestopt_,oo_);
+            [xparam1,fval,exitflag] = fminunc(objective_function,xparam1,optim_options,dataset_,dataset_info_,options_,M_,estim_params_,bayestopt_,bounds,oo_);
         else
             % Under Octave, use a wrapper, since fminunc() does not have a 4th arg
-            func = @(x) objective_function(x, dataset_,dataset_info,options_,M_,estim_params_,bayestopt_,oo_);
+            func = @(x) objective_function(x, dataset_,dataset_info,options_,M_,estim_params_,bayestopt_,bounds,oo_);
             [xparam1,fval,exitflag] = fminunc(func,xparam1,optim_options);
         end
+        fprintf('\nFinal value of minus the log posterior (or likelihood):%f \n', fval);
       case 4
         % Set default options.
         H0 = 1e-4*eye(nx);
         crit = 1e-7;
         nit = 1000;
-        verbose = 2;
         numgrad = options_.gradient_method;
         epsilon = options_.gradient_epsilon;
         % Change some options.
@@ -297,9 +316,9 @@ if ~isequal(options_.mode_compute,0) && ~options_.mh_posterior_mode_estimation
         end
         % Call csminwell.
         [fval,xparam1,grad,hessian_csminwel,itct,fcount,retcodehat] = ...
-            csminwel1(objective_function, xparam1, H0, analytic_grad, crit, nit, numgrad, epsilon, dataset_, dataset_info, options_, M_, estim_params_, bayestopt_, oo_);
+            csminwel1(objective_function, xparam1, H0, analytic_grad, crit, nit, numgrad, epsilon, dataset_, dataset_info, options_, M_, estim_params_, bayestopt_,bounds, oo_);
         % Disp value at the mode.
-        disp(sprintf('Objective function at mode: %f',fval))
+        fprintf('\nFinal value of minus the log posterior (or likelihood):%f \n', fval);
       case 5
         if isfield(options_,'hess')
             flag = options_.hess;
@@ -325,12 +344,26 @@ if ~isequal(options_.mode_compute,0) && ~options_.mh_posterior_mode_estimation
         else
             nit=1000;
         end
-        [xparam1,hh,gg,fval,invhess] = newrat(objective_function,xparam1,analytic_grad,crit,nit,flag,dataset_, dataset_info, options_,M_,estim_params_,bayestopt_,oo_);
+        [xparam1,hh,gg,fval,invhess] = newrat(objective_function,xparam1,analytic_grad,crit,nit,0,dataset_, dataset_info, options_,M_,estim_params_,bayestopt_,bounds,oo_);
         if options_.analytic_derivation,
             options_.analytic_derivation = ana_deriv;
+        else
+            if flag ==0,
+                options_.cova_compute = 1;
+                kalman_algo0 = options_.kalman_algo;
+                if ~((options_.kalman_algo == 2) || (options_.kalman_algo == 4)),
+                    options_.kalman_algo=2;
+                    if options_.lik_init == 3,
+                        options_.kalman_algo=4;
+                    end
+                end
+                hh = reshape(mr_hessian(0,xparam1,objective_function,1,crit,dataset_, dataset_info, options_,M_,estim_params_,bayestopt_,bounds,oo_), nx, nx);
+                options_.kalman_algo = kalman_algo0;
+            end
         end
         parameter_names = bayestopt_.name;
-        save([M_.fname '_mode.mat'],'xparam1','hh','gg','fval','invhess','parameter_names');
+        save([M_.fname '_mode.mat'],'xparam1','hh','parameter_names');
+        fprintf('\nFinal value of minus the log posterior (or likelihood):%f \n', fval);
       case 6
         % Set default options
         gmhmaxlikOptions = options_.gmhmaxlik;
@@ -375,7 +408,7 @@ if ~isequal(options_.mode_compute,0) && ~options_.mh_posterior_mode_estimation
             end
         end
         % Evaluate the objective function.
-        fval = feval(objective_function,xparam1,dataset_, dataset_info, options_,M_,estim_params_,bayestopt_,oo_);
+        fval = feval(objective_function,xparam1,dataset_, dataset_info, options_,M_,estim_params_,bayestopt_,bounds,oo_);
         OldMode = fval;
         if ~exist('MeanPar','var')
             MeanPar = xparam1;
@@ -407,8 +440,8 @@ if ~isequal(options_.mode_compute,0) && ~options_.mh_posterior_mode_estimation
                     flag = 'LastCall';
                 end
                 [xparam1,PostVar,Scale,PostMean] = ...
-                    gmhmaxlik(objective_function,xparam1,[lb ub],gmhmaxlikOptions,Scale,flag,MeanPar,CovJump,dataset_,dataset_info,options_,M_,estim_params_,bayestopt_,oo_);
-                fval = feval(objective_function,xparam1,dataset_,dataset_info,options_,M_,estim_params_,bayestopt_,oo_);
+                    gmhmaxlik(objective_function,xparam1,[bounds.lb bounds.ub],gmhmaxlikOptions,Scale,flag,MeanPar,CovJump,dataset_,dataset_info,options_,M_,estim_params_,bayestopt_,bounds,oo_);
+                fval = feval(objective_function,xparam1,dataset_,dataset_info,options_,M_,estim_params_,bayestopt_,bounds,oo_);
                 options_.mh_jscale = Scale;
                 mouvement = max(max(abs(PostVar-OldPostVar)));
                 skipline()
@@ -426,12 +459,12 @@ if ~isequal(options_.mode_compute,0) && ~options_.mh_posterior_mode_estimation
                     flag = 'LastCall';
                 end
                 [xparam1,PostVar,Scale,PostMean] = ...
-                    gmhmaxlik(objective_function,xparam1,[lb ub],...
-                              gmhmaxlikOptions,Scale,flag,PostMean,PostVar,dataset_,dataset_info,options_,M_,estim_params_,bayestopt_,oo_);
-                fval = feval(objective_function,xparam1,dataset_,dataset_info,options_,M_,estim_params_,bayestopt_,oo_);
+                    gmhmaxlik(objective_function,xparam1,[bounds.lb bounds.ub],...
+                              gmhmaxlikOptions,Scale,flag,PostMean,PostVar,dataset_,dataset_info,options_,M_,estim_params_,bayestopt_,bounds,oo_);
+                fval = feval(objective_function,xparam1,dataset_,dataset_info,options_,M_,estim_params_,bayestopt_,bounds,oo_);
                 options_.mh_jscale = Scale;
                 mouvement = max(max(abs(PostVar-OldPostVar)));
-                fval = feval(objective_function,xparam1,dataset_,dataset_info,options_,M_,estim_params_,bayestopt_,oo_);
+                fval = feval(objective_function,xparam1,dataset_,dataset_info,options_,M_,estim_params_,bayestopt_,bounds,oo_);
                 skipline()
                 disp('========================================================== ')
                 disp(['   Change in the covariance matrix = ' num2str(mouvement) '.'])
@@ -449,7 +482,7 @@ if ~isequal(options_.mode_compute,0) && ~options_.mh_posterior_mode_estimation
         skipline()
         disp(['Optimal value of the scale parameter = ' num2str(Scale)])
         skipline()
-        disp(['Final value of the log posterior (or likelihood): ' num2str(fval)])
+        fprintf('\nFinal value of minus the log posterior (or likelihood):%f \n', fval);
         skipline()
         parameter_names = bayestopt_.name;
         save([M_.fname '_mode.mat'],'xparam1','hh','parameter_names');
@@ -464,7 +497,8 @@ if ~isequal(options_.mode_compute,0) && ~options_.mh_posterior_mode_estimation
         if isfield(options_,'optim_opt')
             eval(['optim_options = optimset(optim_options,' options_.optim_opt ');']);
         end
-        [xparam1,fval,exitflag] = fminsearch(objective_function,xparam1,optim_options,dataset_,dataset_info,options_,M_,estim_params_,bayestopt_,oo_);
+        [xparam1,fval,exitflag] = fminsearch(objective_function,xparam1,optim_options,dataset_,dataset_info,options_,M_,estim_params_,bayestopt_,bounds,oo_);
+        fprintf('\nFinal value of minus the log posterior (or likelihood):%f \n', fval);
       case 8
         % Dynare implementation of the simplex algorithm.
         simplexOptions = options_.simplex;
@@ -489,7 +523,8 @@ if ~isequal(options_.mode_compute,0) && ~options_.mh_posterior_mode_estimation
                 end
             end
         end
-        [xparam1,fval,exitflag] = simplex_optimization_routine(objective_function,xparam1,simplexOptions,dataset_,dataset_info,options_,M_,estim_params_,bayestopt_,oo_);
+        [xparam1,fval,exitflag] = simplex_optimization_routine(objective_function,xparam1,simplexOptions,bayestopt_.name,dataset_,dataset_info,options_,M_,estim_params_,bayestopt_,bounds,oo_);
+        fprintf('\nFinal value of minus the log posterior (or likelihood):%f \n', fval);
       case 9
         % Set defaults
         H0 = 1e-4*ones(nx,1);
@@ -514,9 +549,9 @@ if ~isequal(options_.mode_compute,0) && ~options_.mh_posterior_mode_estimation
         end
         warning('off','CMAES:NonfinitenessRange');
         warning('off','CMAES:InitialSigma');
-        [x, fval, COUNTEVAL, STOPFLAG, OUT, BESTEVER] = cmaes(func2str(objective_function),xparam1,H0,cmaesOptions,dataset_,dataset_info,options_,M_,estim_params_,bayestopt_,oo_);
+        [x, fval, COUNTEVAL, STOPFLAG, OUT, BESTEVER] = cmaes(func2str(objective_function),xparam1,H0,cmaesOptions,dataset_,dataset_info,options_,M_,estim_params_,bayestopt_,bounds,oo_);
         xparam1=BESTEVER.x;
-        disp(sprintf('\n Objective function at mode: %f',fval))
+        fprintf('\nFinal value of minus the log posterior (or likelihood):%f \n', BESTEVER.f);
       case 10
         simpsaOptions = options_.simpsa;
         if isfield(options_,'optim_opt')
@@ -545,16 +580,18 @@ if ~isequal(options_.mode_compute,0) && ~options_.mh_posterior_mode_estimation
         end
         simpsaOptionsList = options2cell(simpsaOptions);
         simpsaOptions = simpsaset(simpsaOptionsList{:});
-        [xparam1, fval, exitflag] = simpsa(func2str(objective_function),xparam1,lb,ub,simpsaOptions,dataset_,dataset_info,options_,M_,estim_params_,bayestopt_,oo_);
+        [xparam1, fval, exitflag] = simpsa(func2str(objective_function),xparam1,bounds.lb,bounds.ub,simpsaOptions,dataset_,dataset_info,options_,M_,estim_params_,bayestopt_,bounds,oo_);
+        fprintf('\nFinal value of minus the log posterior (or likelihood):%f \n', fval);
       case 11
          options_.cova_compute = 0 ;
-         [xparam1,stdh,lb_95,ub_95,med_param] = online_auxiliary_filter(xparam1,dataset_,dataset_info,options_,M_,estim_params_,bayestopt_,oo_) ;
+         [xparam1,stdh,lb_95,ub_95,med_param] = online_auxiliary_filter(xparam1,dataset_,dataset_info,options_,M_,estim_params_,bayestopt_,bounds,oo_) ;
       case 101
         myoptions=soptions;
         myoptions(2)=1e-6; %accuracy of argument
         myoptions(3)=1e-6; %accuracy of function (see Solvopt p.29)
         myoptions(5)= 1.0;
-        [xparam1,fval]=solvopt(xparam1,objective_function,[],myoptions,dataset_,dataset_info,options_,M_,estim_params_,bayestopt_,oo_);
+        [xparam1,fval]=solvopt(xparam1,objective_function,[],myoptions,dataset_,dataset_info,options_,M_,estim_params_,bayestopt_,bounds,oo_);
+        fprintf('\nFinal value of minus the log posterior (or likelihood):%f \n', fval);
       case 102
         %simulating annealing
         %        LB=zeros(size(xparam1))-20;
@@ -591,10 +628,12 @@ if ~isequal(options_.mode_compute,0) && ~options_.mh_posterior_mode_estimation
         disp(['c vector   ' num2str(c')]);
 
         [xparam1, fval, nacc, nfcnev, nobds, ier, t, vm] = sa(objective_function,xparam1,maxy,rt_,epsilon,ns,nt ...
-                                                              ,neps,maxevl,LB,UB,c,idisp ,t,vm,dataset_,dataset_info,options_,M_,estim_params_,bayestopt_,oo_);
+                                                              ,neps,maxevl,LB,UB,c,idisp ,t,vm,dataset_,dataset_info,options_,M_,estim_params_,bayestopt_,bounds,oo_);
+        fprintf('\nFinal value of minus the log posterior (or likelihood):%f \n', fval);
       otherwise
         if ischar(options_.mode_compute)
-            [xparam1, fval, retcode ] = feval(options_.mode_compute,objective_function,xparam1,dataset_,dataset_info,options_,M_,estim_params_,bayestopt_,oo_);
+            [xparam1, fval, retcode ] = feval(options_.mode_compute,objective_function,xparam1,dataset_,dataset_info,options_,M_,estim_params_,bayestopt_,bounds,oo_);
+            fprintf('\nFinal value of minus the log posterior (or likelihood):%f \n', fval);
         else
             error(['dynare_estimation:: mode_compute = ' int2str(options_.mode_compute) ' option is unknown!'])
         end
@@ -605,11 +644,13 @@ if ~isequal(options_.mode_compute,0) && ~options_.mh_posterior_mode_estimation
                 ana_deriv = options_.analytic_derivation;
                 options_.analytic_derivation = 2;
                 [junk1, junk2, hh] = feval(objective_function,xparam1, ...
-                    dataset_,dataset_info,options_,M_,estim_params_,bayestopt_,oo_);
+                    dataset_,dataset_info,options_,M_,estim_params_,bayestopt_,bounds,oo_);
                 options_.analytic_derivation = ana_deriv;
-            else
+            elseif ~(isequal(options_.mode_compute,5) && flag==0), 
+                % with flag==0, we force to use the hessian from outer
+                % product gradient of optimizer 5
                 hh = reshape(hessian(objective_function,xparam1, ...
-                    options_.gstep,dataset_,dataset_info,options_,M_,estim_params_,bayestopt_,oo_),nx,nx);
+                    options_.gstep,dataset_,dataset_info,options_,M_,estim_params_,bayestopt_,bounds,oo_),nx,nx);
             end
         end
     end
@@ -664,7 +705,7 @@ if ~options_.mh_posterior_mode_estimation && options_.cova_compute
         disp('=> posterior variance of the estimated parameters are not positive.')
         disp('You should try to change the initial values of the parameters using')
         disp('the estimated_params_init block, or use another optimization routine.')
-        params_at_bound=find(xparam1==ub | xparam1==lb);
+        params_at_bound=find(xparam1==bounds.ub | xparam1==bounds.lb);
         if ~isempty(params_at_bound)
             for ii=1:length(params_at_bound)
             params_at_bound_name{ii,1}=get_the_name(params_at_bound(ii),0,M_,estim_params_,options_);
@@ -678,6 +719,7 @@ if ~options_.mh_posterior_mode_estimation && options_.cova_compute
             fprintf('   - Check your model for mistakes.\n')
             fprintf('   - Check whether model and data are consistent (correct observation equation).\n')
             fprintf('   - Shut off prior_trunc.\n')
+            fprintf('   - Change the optimization bounds.\n')
             fprintf('   - Use a different mode_compute like 6 or 9.\n')
             fprintf('   - Check whether the parameters estimated are identified.\n')
             fprintf('   - Increase the informativeness of the prior.\n')
@@ -689,7 +731,7 @@ end
 if options_.mode_check.status == 1 && ~options_.mh_posterior_mode_estimation
     ana_deriv = options_.analytic_derivation;
     options_.analytic_derivation = 0;
-    mode_check(objective_function,xparam1,hh,dataset_,dataset_info,options_,M_,estim_params_,bayestopt_,oo_);
+    mode_check(objective_function,xparam1,hh,dataset_,dataset_info,options_,M_,estim_params_,bayestopt_,bounds,oo_);
     options_.analytic_derivation = ana_deriv;
 end
 
@@ -723,7 +765,7 @@ if any(bayestopt_.pshape > 0) && ~options_.mh_posterior_mode_estimation
         estim_params_nbr = size(xparam1,1);
         scale_factor = -sum(log10(diag(invhess)));
         log_det_invhess = -estim_params_nbr*log(scale_factor)+log(det(scale_factor*invhess));
-        likelihood = feval(objective_function,xparam1,dataset_,dataset_info,options_,M_,estim_params_,bayestopt_,oo_);
+        likelihood = feval(objective_function,xparam1,dataset_,dataset_info,options_,M_,estim_params_,bayestopt_,bounds,oo_);
         oo_.MarginalDensity.LaplaceApproximation = .5*estim_params_nbr*log(2*pi) + .5*log_det_invhess - likelihood;
         skipline()
         disp(sprintf('Log data density [Laplace approximation] is %f.',oo_.MarginalDensity.LaplaceApproximation))
@@ -743,11 +785,7 @@ end
 if (any(bayestopt_.pshape  >0 ) && options_.mh_replic) || ...
         (any(bayestopt_.pshape >0 ) && options_.load_mh_file)  %% not ML estimation
     bounds = prior_bounds(bayestopt_,options_);
-    bounds(:,1)=max(bounds(:,1),lb);
-    bounds(:,2)=min(bounds(:,2),ub);
-    bayestopt_.lb = bounds(:,1);
-    bayestopt_.ub = bounds(:,2);
-    outside_bound_pars=find(xparam1 < bounds(:,1) | xparam1 > bounds(:,2));
+    outside_bound_pars=find(xparam1 < bounds.lb | xparam1 > bounds.ub);
     if ~isempty(outside_bound_pars)
         for ii=1:length(outside_bound_pars)
             outside_bound_par_names{ii,1}=get_the_name(ii,0,M_,estim_params_,options_);
@@ -787,8 +825,7 @@ if (any(bayestopt_.pshape  >0 ) && options_.mh_replic) || ...
         CutSample(M_, options_, estim_params_);
         %% Estimation of the marginal density from the Mh draws:
         if options_.mh_replic
-            [marginal,oo_] = marginal_density(M_, options_, estim_params_, ...
-                                              oo_);
+            [marginal,oo_] = marginal_density(M_, options_, estim_params_, oo_);
             % Store posterior statistics by parameter name
             oo_ = GetPosteriorParametersStatistics(estim_params_, M_, options_, bayestopt_, oo_);
             if ~options_.nograph
@@ -820,8 +857,8 @@ if (any(bayestopt_.pshape  >0 ) && options_.mh_replic) || ...
             end
             prior_posterior_statistics('posterior',dataset_,dataset_info);
         end
-        xparam = get_posterior_parameters('mean');
-        M_ = set_all_parameters(xparam,estim_params_,M_);
+        xparam1 = get_posterior_parameters('mean');
+        M_ = set_all_parameters(xparam1,estim_params_,M_);
     end
 end
 
@@ -858,7 +895,7 @@ if (~((any(bayestopt_.pshape > 0) && options_.mh_replic) || (any(bayestopt_.psha
                             'atT(i,:)'';']);
         if options_.nk > 0
             eval(['oo_.FilteredVariables.' deblank(M_.endo_names(i1,:)) ...
-                  ' = squeeze(aK(1,i,:));']);
+                  ' = squeeze(aK(1,i,2:end-(options_.nk-1)));']);
         end
         eval(['oo_.UpdatedVariables.' deblank(M_.endo_names(i1,:)) ...
               ' = updated_variables(i,:)'';']);
@@ -942,9 +979,6 @@ if (~((any(bayestopt_.pshape > 0) && options_.mh_replic) || (any(bayestopt_.psha
     if options_.prefilter == 1
         yf = atT(bayestopt_.mf,:)+repmat(dataset_info.descriptive.mean',1,gend);
     elseif options_.loglinear == 1
-        gend
-        bayestopt_.mfys
-        ys
         yf = atT(bayestopt_.mf,:)+repmat(log(ys(bayestopt_.mfys)),1,gend)+...
              trend_coeff*[1:gend];
     else
diff --git a/matlab/dynare_estimation_init.m b/matlab/dynare_estimation_init.m
index 1294f7b5fd063b21f20b19fb1ab8fe8b769fc33a..454375def536e073143fbde73b86569eca04b52d 100644
--- a/matlab/dynare_estimation_init.m
+++ b/matlab/dynare_estimation_init.m
@@ -1,24 +1,38 @@
-function [dataset_, dataset_info, xparam1, hh, M_, options_, oo_, estim_params_,bayestopt_, fake] = dynare_estimation_init(var_list_, dname, gsa_flag, M_, options_, oo_, estim_params_, bayestopt_)
+function [dataset_, dataset_info, xparam1, hh, M_, options_, oo_, estim_params_,bayestopt_, bounds] = dynare_estimation_init(var_list_, dname, gsa_flag, M_, options_, oo_, estim_params_, bayestopt_)
 
 % function dynare_estimation_init(var_list_, gsa_flag)
-% preforms initialization tasks before estimation or
+% performs initialization tasks before estimation or
 % global sensitivity analysis
 %
 % INPUTS
-%   var_list_:  selected endogenous variables vector
-%   dname:      alternative directory name
-%   gsa_flag:   flag for GSA operation (optional)
-%
+%   var_list_:      selected endogenous variables vector
+%   dname:          alternative directory name
+%   gsa_flag:       flag for GSA operation (optional)
+%   M_:             structure storing the model information
+%   options_:       structure storing the options
+%   oo_:            structure storing the results
+%   estim_params_:  structure storing information about estimated
+%                   parameters
+%   bayestopt_:     structure storing information about priors
+%   optim:          structure storing optimization bounds
+    
 % OUTPUTS
-%   data:    data after required transformation
-%   rawdata:  data as in the data file
-%   xparam1:    initial value of estimated parameters as returned by
-%               set_prior()
-%
+%   dataset_:       the dataset after required transformation
+%   dataset_info:   Various informations about the dataset (descriptive statistics and missing observations).
+%   xparam1:        initial value of estimated parameters as returned by
+%                   set_prior() or loaded from mode-file
+%   hh:             hessian matrix at the loaded mode (or empty matrix)
+%   M_:             structure storing the model information
+%   options_:       structure storing the options
+%   oo_:            structure storing the results
+%   estim_params_:  structure storing information about estimated
+%                   parameters
+%   bayestopt_:     structure storing information about priors
+% 
 % SPECIAL REQUIREMENTS
 %   none
 
-% Copyright (C) 2003-2013 Dynare Team
+% Copyright (C) 2003-2014 Dynare Team
 %
 % This file is part of Dynare.
 %
@@ -275,22 +289,17 @@ if ~isempty(estim_params_)
         end
         % Set prior bounds
         bounds = prior_bounds(bayestopt_,options_);
-        bounds(:,1)=max(bounds(:,1),lb);
-        bounds(:,2)=min(bounds(:,2),ub);
+        bounds.lb = max(bounds.lb,lb);
+        bounds.ub = min(bounds.ub,ub);
     else  % estimated parameters but no declared priors
         % No priors are declared so Dynare will estimate the model by
         % maximum likelihood with inequality constraints for the parameters.
         options_.mh_replic = 0;% No metropolis.
-        bounds(:,1) = lb;
-        bounds(:,2) = ub;
+        bounds.lb = lb;
+        bounds.ub = ub;
     end
     % Test if initial values of the estimated parameters are all between the prior lower and upper bounds.
     check_prior_bounds(xparam1,bounds,M_,estim_params_,options_,bayestopt_)
-
-    lb = bounds(:,1);
-    ub = bounds(:,2);
-    bayestopt_.lb = lb;
-    bayestopt_.ub = ub;
 end
 
 if isempty(estim_params_)% If estim_params_ is empty (e.g. when running the smoother on a calibrated model)
@@ -298,8 +307,6 @@ if isempty(estim_params_)% If estim_params_ is empty (e.g. when running the smoo
         error('Estimation: the ''estimated_params'' block is mandatory (unless you are running a smoother)')
     end
     xparam1 = [];
-    bayestopt_.lb = [];
-    bayestopt_.ub = [];
     bayestopt_.jscale = [];
     bayestopt_.pshape = [];
     bayestopt_.p1 = [];
@@ -377,9 +384,15 @@ oo_.dr.restrict_columns = [ic; length(k2)+(1:nspred-npred)'];
 k3 = [];
 k3p = [];
 if options_.selected_variables_only
-    for i=1:size(var_list_,1)
-        k3 = [k3; strmatch(var_list_(i,:),M_.endo_names(dr.order_var,:), 'exact')];
-        k3p = [k3; strmatch(var_list_(i,:),M_.endo_names, 'exact')];
+    if options_.forecast > 0 && options_.mh_replic == 0 && ~options_.load_mh_file
+        fprintf('\nEstimation: The selected_variables_only option is incompatible with classical forecasts. It will be ignored.\n')
+        k3 = (1:M_.endo_nbr)';
+        k3p = (1:M_.endo_nbr)';    
+    else
+        for i=1:size(var_list_,1)
+            k3 = [k3; strmatch(var_list_(i,:),M_.endo_names(dr.order_var,:), 'exact')];
+            k3p = [k3; strmatch(var_list_(i,:),M_.endo_names, 'exact')];
+        end
     end
 else
     k3 = (1:M_.endo_nbr)';
@@ -444,8 +457,15 @@ if options_.analytic_derivation,
         [tmp1, params] = evaluate_steady_state(oo_.steady_state,M,options_,oo_,steadystate_check_flag);
         change_flag=any(find(params-M.params));
         if change_flag,
-            disp('The steadystate file changed the values for the following parameters: '),
-            disp(M.param_names(find(params-M.params),:))
+            skipline();
+            if any(isnan(params))
+                disp('After computing the steadystate, the following parameters are still NaN: '),
+                disp(M.param_names(isnan(params),:))
+            end
+            if any(find(params(~isnan(params))-M.params(~isnan(params))))
+                disp('The steadystate file changed the values for the following parameters: '),
+                disp(M.param_names(find(params(~isnan(params))-M.params(~isnan(params))),:))
+            end
             disp('The derivatives of jacobian and steady-state will be computed numerically'),
             disp('(re-set options_.analytic_derivation_mode= -2)'),
             options_.analytic_derivation_mode= -2;
@@ -458,6 +478,13 @@ k = find(isnan(bayestopt_.jscale));
 bayestopt_.jscale(k) = options_.mh_jscale;
 
 % Build the dataset
+if ~isempty(options_.datafile)
+    [pathstr,name,ext] = fileparts(options_.datafile);
+    if strcmp(name,M_.fname)
+        error('Data-file and mod-file are not allowed to have the same name. Please change the name of the data file.')
+    end
+end
+
 [dataset_, dataset_info, newdatainterfaceflag] = makedataset(options_, options_.dsge_var*options_.dsge_varlag, gsa_flag);
 
 % Set options_.nobs if needed
diff --git a/matlab/dynare_identification.m b/matlab/dynare_identification.m
index 9a883e9d23fd6aef6255318f6d75a9f653d7aae0..33f2c151e7901c05cb76793853f90ced902a7f08 100644
--- a/matlab/dynare_identification.m
+++ b/matlab/dynare_identification.m
@@ -130,22 +130,6 @@ options_.plot_priors = 0;
 options_.smoother=1;
 [dataset_,dataset_info,xparam1,hh, M_, options_, oo_, estim_params_,bayestopt_]=dynare_estimation_init(M_.endo_names,fname_,1, M_, options_, oo_, estim_params_, bayestopt_);
 options_ident.analytic_derivation_mode = options_.analytic_derivation_mode;
-if isempty(dataset_),
-    dataset_.info.ntobs = periods;
-    dataset_.info.nvobs = length(options_.varobs);
-    dataset_.info.varobs = options_.varobs;
-    dataset_.rawdata = [];
-    dataset_.missing.state = 0;
-    for jdata=1:periods,
-        temp1{jdata}=[1:dataset_.info.nvobs]';
-    end
-    dataset_.missing.aindex = temp1;
-    dataset_.missing.vindex = [];
-    dataset_.missing.number_of_observations = [];
-    dataset_.missing.no_more_missing_observations = 1;
-    dataset_.descriptive.mean = [];
-    dataset_.data = [];
-end
 
 if prior_exist
     if any(bayestopt_.pshape > 0)
diff --git a/matlab/dynare_sensitivity.m b/matlab/dynare_sensitivity.m
index 1d9eeef7f5fadf1f3e8187bdcc3a074753ef61f8..9d4a5085d398682c04c567681738e3a173f89762 100644
--- a/matlab/dynare_sensitivity.m
+++ b/matlab/dynare_sensitivity.m
@@ -36,6 +36,10 @@ x0=[];
 
 options_gsa = set_default_option(options_gsa,'datafile',[]);
 options_gsa = set_default_option(options_gsa,'rmse',0);
+options_gsa = set_default_option(options_gsa,'useautocorr',0);
+
+options_gsa = set_default_option(options_gsa,'moment_calibration',options_.endogenous_prior_restrictions.moment);
+options_gsa = set_default_option(options_gsa,'irf_calibration',options_.endogenous_prior_restrictions.irf);
 if isfield(options_gsa,'nograph'),
     options_.nograph=options_gsa.nograph;
 end
@@ -100,7 +104,6 @@ if options_gsa.identification,
     options_gsa = set_default_option(options_gsa,'trans_ident',0);
     options_gsa = set_default_option(options_gsa,'load_ident_files',0);
     options_gsa = set_default_option(options_gsa,'ar',1);
-    options_gsa = set_default_option(options_gsa,'useautocorr',0);
     options_.ar = options_gsa.ar;
     if options_gsa.morris==0,
         disp('The option morris = 0 is no longer supported (Type I errors)')
@@ -142,13 +145,13 @@ options_gsa = set_default_option(options_gsa,'load_stab',0);
 options_gsa = set_default_option(options_gsa,'alpha2_stab',0);
 options_gsa = set_default_option(options_gsa,'ksstat',0.1);
 options_gsa = set_default_option(options_gsa,'pvalue_ks',0.001);
-options_gsa = set_default_option(options_gsa,'pvalue_corr',0.001);
+options_gsa = set_default_option(options_gsa,'pvalue_corr',1.e-5);
 %options_gsa = set_default_option(options_gsa,'load_mh',0);
 % REDFORM mapping
 options_gsa = set_default_option(options_gsa,'logtrans_redform',0);
 options_gsa = set_default_option(options_gsa,'threshold_redform',[]);
 options_gsa = set_default_option(options_gsa,'ksstat_redform',0.001);
-options_gsa = set_default_option(options_gsa,'alpha2_redform',0);
+options_gsa = set_default_option(options_gsa,'alpha2_redform',1.e-5);
 options_gsa = set_default_option(options_gsa,'namendo',[]);
 options_gsa = set_default_option(options_gsa,'namlagendo',[]);
 options_gsa = set_default_option(options_gsa,'namexo',[]);
@@ -158,7 +161,7 @@ options_gsa = set_default_option(options_gsa,'var_rmse',char(options_.varobs));
 options_gsa = set_default_option(options_gsa,'pfilt_rmse',0.1);
 options_gsa = set_default_option(options_gsa,'istart_rmse',options_.presample+1);
 options_gsa = set_default_option(options_gsa,'alpha_rmse',0.001);
-options_gsa = set_default_option(options_gsa,'alpha2_rmse',0);
+options_gsa = set_default_option(options_gsa,'alpha2_rmse',1.e-5);
 
 if options_gsa.redform && options_gsa.neighborhood_width==0 && isempty(options_gsa.threshold_redform),
     options_gsa.pprior=1;
@@ -239,6 +242,10 @@ end
 % redform_map(namendo, namlagendo, namexo, icomp, pprior, ilog, threshold)
 
 options_.opt_gsa = options_gsa;
+if ~isempty(options_gsa.moment_calibration) || ~isempty(options_gsa.irf_calibration),
+    map_calibration(OutputDirectoryName, M_, options_, oo_, estim_params_,bayestopt_);
+end
+
 if options_gsa.identification,
     map_ident_(OutputDirectoryName,options_gsa);
 end
diff --git a/matlab/dynare_solve.m b/matlab/dynare_solve.m
index f5f166d410a38054e039f6386249a010f2f5db2f..a4b9db9ab8697642f9d759be04770aad7b75a651 100644
--- a/matlab/dynare_solve.m
+++ b/matlab/dynare_solve.m
@@ -8,7 +8,7 @@ function [x,info] = dynare_solve(func,x,jacobian_flag,varargin)
 %    jacobian_flag=1:  jacobian given by the 'func' function
 %    jacobian_flag=0:  jacobian obtained numerically
 %    varargin:         list of arguments following jacobian_flag
-%    
+%
 % OUTPUTS
 %    x:                solution
 %    info=1:           the model can not be solved
@@ -16,7 +16,7 @@ function [x,info] = dynare_solve(func,x,jacobian_flag,varargin)
 % SPECIAL REQUIREMENTS
 %    none
 
-% Copyright (C) 2001-2012 Dynare Team
+% Copyright (C) 2001-2014 Dynare Team
 %
 % This file is part of Dynare.
 %
@@ -47,7 +47,7 @@ if jacobian_flag
         M=evalin('base','M_'); %get variable names from workspace
         fprintf('\nSTEADY:  The Jacobian contains Inf or NaN. The problem arises from: \n\n')
         display_problematic_vars_Jacobian(infrow,infcol,M,x,'static','STEADY: ')
-        error('An element of the Jacobian is not finite or NaN') 
+        error('An element of the Jacobian is not finite or NaN')
     end
 else
     fvec = feval(func,x,varargin{:});
@@ -62,7 +62,7 @@ if ~isempty(i)
     disp(i')
     disp('Please check for example')
     disp('   i) if all parameters occurring in these equations are defined')
-    disp('  ii) that no division by an endogenous variable initialized to 0 occurs') 
+    disp('  ii) that no division by an endogenous variable initialized to 0 occurs')
     info = 1;
     x = NaN(size(fvec));
     return;
@@ -80,8 +80,8 @@ if options_.solve_algo == 0
     end
     options=optimset('fsolve');
     options.MaxFunEvals = 50000;
-    options.MaxIter = 2000;
-    options.TolFun=1e-8;
+    options.MaxIter = options_.steady.maxit;
+    options.TolFun = tolf;
     options.Display = 'iter';
     if jacobian_flag
         options.Jacobian = 'on';
@@ -102,7 +102,7 @@ if options_.solve_algo == 0
             exitval = 3;
         end;
     end
-    
+
     if exitval > 0
         info = 0;
     else
@@ -135,7 +135,7 @@ elseif options_.solve_algo == 2 || options_.solve_algo == 4
     end
 
     [j1,j2,r,s] = dmperm(fjac);
-    
+
     if options_.debug
         disp(['DYNARE_SOLVE (solve_algo=2|4): number of blocks = ' num2str(length(r))]);
     end
@@ -173,5 +173,5 @@ elseif options_.solve_algo == 10
         info = 1;
     end
 else
-    error('DYNARE_SOLVE: option solve_algo must be one of [0,1,2,3,4,9]')
+    error('DYNARE_SOLVE: option solve_algo must be one of [0,1,2,3,4,9,10]')
 end
diff --git a/matlab/endogenous_prior_restrictions.m b/matlab/endogenous_prior_restrictions.m
index e28a726ae5642123cf3b823d4c22433f89bf9c4c..617116a890dbca4e70feb197227384e9d02f5861 100644
--- a/matlab/endogenous_prior_restrictions.m
+++ b/matlab/endogenous_prior_restrictions.m
@@ -1,8 +1,8 @@
-function info = endogenous_prior_restrictions(T,R,Model,DynareOptions,DynareResults);
-% Check for prior (sign) restrictions on irf's 
+function [info, info_irf, info_moment, data_irf, data_moment] = endogenous_prior_restrictions(T,R,Model,DynareOptions,DynareResults);
+% Check for prior (sign) restrictions on irf's and theoretical moments
 %
 % INPUTS
-%    T          [double]     n*n state space matrix 
+%    T          [double]     n*n state space matrix
 %    R          [double]     n*k matrix of shocks
 %    Model      [structure]
 %    DynareOptions [structure]
@@ -11,6 +11,9 @@ function info = endogenous_prior_restrictions(T,R,Model,DynareOptions,DynareResu
 % OUTPUTS
 %    info     [double]  check if prior restrictions are matched by the
 %                       model and related info
+%    info_irf [double] array of test checks for all individual irf restrictions
+%    info_moment [double] array of test checks for all individual moment restrictions
+%    
 
 % Copyright (C) 2013 Dynare Team
 %
@@ -29,45 +32,146 @@ function info = endogenous_prior_restrictions(T,R,Model,DynareOptions,DynareResu
 % You should have received a copy of the GNU General Public License
 % along with Dynare.  If not, see <http://www.gnu.org/licenses/>.
 
-endo_prior_restrictions= DynareOptions.endogenous_prior_restrictions;
-info=0;
-if isempty(endo_prior_restrictions.irf),
-    % no restriction to be checked
-    return
-end
-if DynareOptions.order>1,
-    error('The algorithm for prior (sign) restrictions on irf''s is currently restricted to first-order decision rules')
-	return
-end
-infos=[0 0];
-varlist=Model.endo_names(DynareResults.dr.order_var,:);
-varlist=varlist(DynareResults.dr.restrict_var_list,:);
-NT=1;
-for j=1:size(endo_prior_restrictions.irf,1),
-    NT=max(NT,endo_prior_restrictions.irf{j,3});
-end
-for t=1:NT,
-    RR = T^(t-1)*R;
+info=[0 0];
+info_irf=[];
+info_moment=[];
+data_irf=[];
+data_moment=[];
+
+endo_prior_restrictions.irf= DynareOptions.endogenous_prior_restrictions.irf;
+endo_prior_restrictions.moment= DynareOptions.endogenous_prior_restrictions.moment;
+
+if ~isempty(endo_prior_restrictions.irf),
+   data_irf=cell(size(endo_prior_restrictions.irf,1),1);    
+    if DynareOptions.order>1,
+        error('The algorithm for prior (sign) restrictions on irf''s is currently restricted to first-order decision rules')
+        return
+    end
+    varlist=Model.endo_names(DynareResults.dr.order_var,:);
+    if isempty(T),
+        [T,R,SteadyState,infox,Model,DynareOptions,DynareResults] = dynare_resolve(Model,DynareOptions,DynareResults);
+    else % check if T and R are given in the restricted form!!!
+        if size(T,1)<size(varlist,1),
+            varlist=varlist(DynareResults.dr.restrict_var_list,:); 
+        end
+        % check if endo_prior_restrictions.irf{:,1} variables are in varlist
+        varlistok=1;
+        for j=1:size(endo_prior_restrictions.irf,1)
+            if isempty(strmatch(endo_prior_restrictions.irf{j,1},varlist,'exact'))
+                varlistok=0;
+            end
+        end
+        if ~varlistok
+            varlist=Model.endo_names(DynareResults.dr.order_var,:);
+            [T,R,SteadyState,infox,Model,DynareOptions,DynareResults] = dynare_resolve(Model,DynareOptions,DynareResults);
+        end
+    end
+    NT=1;
     for j=1:size(endo_prior_restrictions.irf,1),
-	    if endo_prior_restrictions.irf{j,3}~=t,
-		   continue,
-		end
-        iendo=strmatch(endo_prior_restrictions.irf{j,1},varlist,'exact');
-        iexo=strmatch(endo_prior_restrictions.irf{j,2},Model.exo_names,'exact');
-        if (RR(iendo,iexo)>endo_prior_restrictions.irf{j,4}(1)) && (RR(iendo,iexo)<endo_prior_restrictions.irf{j,4}(2)),
-            infos(j,:)=[0, 0];
+        NT=max(NT,max(endo_prior_restrictions.irf{j,3}));
+    end
+    info_irf=ones(size(endo_prior_restrictions.irf,1),2);
+    for t=1:NT,
+        if ~DynareOptions.relative_irf,
+            RR = T^(t-1)*R*diag(sqrt(diag(Model.Sigma_e)));
         else
-            if RR(iendo,iexo)<endo_prior_restrictions.irf{j,4}(1),
-                delt = (RR(iendo,iexo)-endo_prior_restrictions.irf{j,4}(1))^2;
+            RR = T^(t-1)*R*100;
+        end
+        for j=1:size(endo_prior_restrictions.irf,1),
+            if endo_prior_restrictions.irf{j,3}~=t,
+                continue,
+            end
+            iendo=strmatch(endo_prior_restrictions.irf{j,1},varlist,'exact');
+            iexo=strmatch(endo_prior_restrictions.irf{j,2},Model.exo_names,'exact');
+            data_irf{j}=[data_irf{j}; [t RR(iendo,iexo)]];
+            if (RR(iendo,iexo)>endo_prior_restrictions.irf{j,4}(1)) && (RR(iendo,iexo)<endo_prior_restrictions.irf{j,4}(2)),
+                info_irf(j,:)=info_irf(j,:).*[0, 0];
             else
-                delt = (RR(iendo,iexo)-endo_prior_restrictions.irf{j,4}(2))^2;
-            end            
-            infos(j,:)=[49, delt];
+                if RR(iendo,iexo)<endo_prior_restrictions.irf{j,4}(1),
+                    delt = (RR(iendo,iexo)-endo_prior_restrictions.irf{j,4}(1))^2;
+                else
+                    delt = (RR(iendo,iexo)-endo_prior_restrictions.irf{j,4}(2))^2;
+                end
+                info_irf(j,:)=info_irf(j,:).*[49, delt];
+            end
         end
     end
+    if any(info_irf),
+        info=[49,sum(info_irf(:,2))];
+    end
+    
 end
-if any(infos),
-    info=[49,sum(infos(:,2))];
+
+if ~isempty(endo_prior_restrictions.moment),
+    
+    if DynareOptions.order>1,
+        error('The algorithm for prior (sign) restrictions on moments is currently restricted to first-order decision rules')
+        return
+    end
+    
+    data_moment=cell(size(endo_prior_restrictions.moment,1),1);
+    var_list_=endo_prior_restrictions.moment{1,1};
+    for  j=1:size(endo_prior_restrictions.moment,1),
+        tmp=endo_prior_restrictions.moment{j,1};
+        if ~ismember(tmp,cellstr(var_list_)),
+            var_list_ = char(var_list_, tmp);
+        end
+        tmp=endo_prior_restrictions.moment{j,2};
+        if ~ismember(tmp,cellstr(var_list_)),
+            var_list_ = char(var_list_, tmp);
+        end
+    end
+    NTmax=0;
+    NTmin=0;
+    for j=1:size(endo_prior_restrictions.moment,1),
+        NTmax=max(NTmax,max(endo_prior_restrictions.moment{j,3}));
+        NTmin=min(NTmin,min(endo_prior_restrictions.moment{j,3}));
+    end
+    info_moment=ones(size(endo_prior_restrictions.moment,1),2);
+    nvar = size(var_list_,1);
+    ivar=zeros(nvar,1);
+    for i=1:nvar
+        i_tmp = strmatch(var_list_(i,:),Model.endo_names,'exact');
+        if isempty(i_tmp)
+            error (['One of the variable specified does not exist']) ;
+        else
+            ivar(i) = i_tmp;
+        end
+    end
+    DynareOptions.ar = max(abs(NTmin),NTmax);
+    [gamma_y,stationary_vars] = th_autocovariances(DynareResults.dr, ivar, Model, DynareOptions,1);
+    for t=NTmin:NTmax,
+        RR = gamma_y{abs(t)+1};     
+        if t==0,
+            RR = RR./(sqrt(diag(RR))*sqrt(diag(RR))')-eye(nvar)+diag(diag(gamma_y{t+1})); % becomes correlation            
+        end
+        for j=1:size(endo_prior_restrictions.moment,1),
+            if endo_prior_restrictions.moment{j,3}~=t,
+                continue,
+            end
+            iendo1 = strmatch(endo_prior_restrictions.moment{j,1},var_list_,'exact');
+            iendo2 = strmatch(endo_prior_restrictions.moment{j,2},var_list_,'exact');
+            if t>0
+                tmp0 = iendo1;
+                iendo1=iendo2;
+                iendo2=tmp0;
+            end
+            data_moment{j}=[data_moment{j}; [t RR(iendo1,iendo2)]];
+            if (RR(iendo1,iendo2)>endo_prior_restrictions.moment{j,4}(1)) && (RR(iendo1,iendo2)<endo_prior_restrictions.moment{j,4}(2)),
+                info_moment(j,:)=info_moment(j,:).*[0, 0];
+            else
+                if RR(iendo1,iendo2)<endo_prior_restrictions.moment{j,4}(1),
+                    delt = (RR(iendo1,iendo2)-endo_prior_restrictions.moment{j,4}(1))^2;
+                else
+                    delt = (RR(iendo1,iendo2)-endo_prior_restrictions.moment{j,4}(2))^2;
+                end
+                info_moment(j,:)=info_moment(j,:).*[49, delt];
+            end
+        end
+    end
+    if any(info_moment),
+        info=[49, info(2) + sum(info_moment(:,2))];
+    end
 end
 return
 
diff --git a/matlab/ep/extended_path.m b/matlab/ep/extended_path.m
index 4867c39124dbe22fc6f4ed627dea1d3cdddb4f29..c17a66c21884b134fb1567420c1f68e684a0144f 100644
--- a/matlab/ep/extended_path.m
+++ b/matlab/ep/extended_path.m
@@ -397,16 +397,23 @@ while (t<sample_size)
         oo_.ep.failures.periods = [oo_.ep.failures.periods t];
         oo_.ep.failures.previous_period = [oo_.ep.failures.previous_period  endo_simul_1(:,1)];
         oo_.ep.failures.shocks = [oo_.ep.failures.shocks  shocks];
+        endo_simul_1 = repmat(steady_state,1,periods1+2);
+        endo_simul_1(:,1) = time_series(:,tsimul-1);
     end
 end% (while) loop over t
 
 dyn_waitbar_close(hh);
 
+if isnan(options_.initial_period)
+    initial_period = dates(1,1);
+else
+    initial_period = optins_.initial_period;
+end
 if nargout
-    ts = dseries(transpose([initial_conditions, time_series]),options_.initial_period,cellstr(M_.endo_names));
+    ts = dseries(transpose([initial_conditions, time_series]),initial_period,cellstr(M_.endo_names));
 else
     oo_.endo_simul = [initial_conditions, time_series];
-    ts = dseries(transpose(oo_.endo_simul),options_.initial_period,cellstr(M_.endo_names));
+    ts = dseries(transpose(oo_.endo_simul),initial_period,cellstr(M_.endo_names));
     dyn2vec;
 end
 
diff --git a/matlab/ep_residuals.m b/matlab/ep_residuals.m
index 66593ae502717e19bc337eab959925dc1424091b..56b554de8738927f8beacbebcba944a72d1b3216 100644
--- a/matlab/ep_residuals.m
+++ b/matlab/ep_residuals.m
@@ -34,7 +34,7 @@ function r = ep_residuals(x, y, ix, iy, steadystate, dr, maximum_lag, endo_nbr)
 % 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_
+global oo_ options_
 
 persistent k1 k2 weight
 
@@ -45,7 +45,7 @@ if isempty(k1)
     weight = 0.0;
 end
 
-verbose = 0;
+verbose = options_.ep.verbosity;
 
 % Copy the shocks in exo_simul.
 oo_.exo_simul(maximum_lag+1,ix) = exp(transpose(x));
diff --git a/matlab/evaluate_likelihood.m b/matlab/evaluate_likelihood.m
index 14abbd0d4b8fbab6dac06d59c0bd637dd4228075..7e6c1f087b71c646c5ec5a0585b02213385f8324 100644
--- a/matlab/evaluate_likelihood.m
+++ b/matlab/evaluate_likelihood.m
@@ -70,6 +70,6 @@ if isempty(dataset)
     [dataset, dataset_info] = makedataset(options_);
 end
 
-llik = -dsge_likelihood(parameters,dataset,dataset_info,options_,M_,estim_params_,bayestopt_,oo_);
+llik = -dsge_likelihood(parameters,dataset,dataset_info,options_,M_,estim_params_,bayestopt_,prior_bounds(bayestopt_,options_),oo_);
 ldens = evaluate_prior(parameters);
 llik = llik - ldens;
\ No newline at end of file
diff --git a/matlab/evaluate_steady_state.m b/matlab/evaluate_steady_state.m
index dcaa561333bf71edd3f188ef73ead6c1e79946ad..c55d570124a70593cffcaba6419c8f4273a55e4c 100644
--- a/matlab/evaluate_steady_state.m
+++ b/matlab/evaluate_steady_state.m
@@ -52,7 +52,135 @@ function [ys,params,info] = evaluate_steady_state(ys_init,M,options,oo,steadysta
     end
 
     if options.ramsey_policy
-        [ys,params] = dyn_ramsey_static(ys_init,M,options,oo);
+        if steadystate_flag
+            % explicit steady state file
+            [ys,params,info] = evaluate_steady_state_file(ys_init,exo_ss,M, ...
+                                                           options);
+            %test whether it solves model conditional on the instruments
+            resids = evaluate_static_model(ys,exo_ss,params,M,options);
+            n_multipliers=M.endo_nbr-M.orig_endo_nbr;
+            nan_indices=find(isnan(resids(n_multipliers+1:end)));
+
+            if ~isempty(nan_indices)
+                fprintf('\nevaluate_steady_state: The steady state file computation for the Ramsey problem resulted in NaNs.\n')
+                fprintf('evaluate_steady_state: The steady state was computed conditional on the following initial instrument values: \n')
+                for ii = 1:size(options.instruments,1);
+                    fprintf('\t %s \t %f \n',options.instruments(ii,:),ys_init(strmatch(options.instruments(ii,:),M.endo_names,'exact')))
+                end
+                fprintf('evaluate_steady_state: The problem occured in the following equations: \n')
+                fprintf('\t Equation(s): ')
+                for ii=1:length(nan_indices)
+                        fprintf('%d, ',nan_indices(ii));
+                end
+                skipline();
+                fprintf('evaluate_steady_state: If those initial values are not admissable, change them using an initval-block.\n')
+                skipline(2);
+                check=1;
+                info(1) = 84;
+                info(2) = resids'*resids;
+                return;
+            end
+            if max(abs(resids(n_multipliers+1:end))) > options.dynatol.f %does it solve for all variables except for the Lagrange multipliers
+                fprintf('\nevaluate_steady_state: The steady state file does not solve the steady state for the Ramsey problem.\n')
+                fprintf('evaluate_steady_state: Conditional on the following instrument values: \n')
+                for ii = 1:size(options.instruments,1);
+                    fprintf('\t %s \t %f \n',options.instruments(ii,:),ys_init(strmatch(options.instruments(ii,:),M.endo_names,'exact')))
+                end
+                fprintf('evaluate_steady_state: the following equations have non-zero residuals: \n')
+                for ii=n_multipliers+1:M.endo_nbr
+                    if abs(resids(ii)) > options.dynatol.f/100
+                        fprintf('\t Equation number %d: %f\n',ii-n_multipliers, resids(ii))
+                    end
+                end
+                skipline(2);
+                info(1) = 85;
+                info(2) = resids'*resids;
+                return;
+            end
+        end
+        if options.debug
+            infrow=find(isinf(ys_init));
+            if ~isempty(infrow)
+                fprintf('\nevaluate_steady_state: The initial values for the steady state of the following variables are Inf:\n');
+                for iter=1:length(infrow)
+                    fprintf('%s\n',M.endo_names(infrow(iter),:));
+                end
+            end
+            nanrow=find(isnan(ys_init));
+            if ~isempty(nanrow)
+                fprintf('\nevaluate_steady_state: The initial values for the steady state of the following variables are NaN:\n');
+                for iter=1:length(nanrow)
+                    fprintf('%s\n',M.endo_names(nanrow(iter),:));
+                end
+            end
+        end
+        %either if no steady state file or steady state file without problems
+        [ys,params,info] = dyn_ramsey_static(ys_init,M,options,oo);
+        if info
+           info=81;%case should not happen
+           return;
+        end
+        %check whether steady state really solves the model
+        resids = evaluate_static_model(ys,exo_ss,params,M,options);
+
+        n_multipliers=M.endo_nbr-M.orig_endo_nbr;
+        nan_indices_multiplier=find(isnan(resids(1:n_multipliers)));
+        nan_indices=find(isnan(resids(n_multipliers+1:end)));
+
+        if ~isempty(nan_indices)
+            fprintf('\nevaluate_steady_state: The steady state computation for the Ramsey problem resulted in NaNs.\n')
+            fprintf('evaluate_steady_state: The steady state computation resulted in the following instrument values: \n')
+            for i = 1:size(options.instruments,1);
+                fprintf('\t %s \t %f \n',options.instruments(i,:),ys(strmatch(options.instruments(i,:),M.endo_names,'exact')))
+            end
+            fprintf('evaluate_steady_state: The problem occured in the following equations: \n')
+            fprintf('\t Equation(s): ')
+            for ii=1:length(nan_indices)
+                    fprintf('%d, ',nan_indices(ii));
+            end
+            skipline();
+            info(1) = 82;
+            return;
+        end
+
+        if ~isempty(nan_indices_multiplier)
+            fprintf('\nevaluate_steady_state: The steady state computation for the Ramsey problem resulted in NaNs in the auxiliary equations.\n')
+            fprintf('evaluate_steady_state: The steady state computation resulted in the following instrument values: \n')
+            for i = 1:size(options.instruments,1);
+                fprintf('\t %s \t %f \n',options.instruments(i,:),ys(strmatch(options.instruments(i,:),M.endo_names,'exact')))
+            end
+            fprintf('evaluate_steady_state: The problem occured in the following equations: \n')
+            fprintf('\t Auxiliary equation(s): ')
+            for ii=1:length(nan_indices_multiplier)
+                    fprintf('%d, ',nan_indices_multiplier(ii));
+            end
+            skipline();
+            info(1) = 83;
+            return;
+        end
+
+        if max(abs(resids)) > options.dynatol.f %does it solve for all variables including the auxiliary ones
+            fprintf('\nevaluate_steady_state: The steady state for the Ramsey problem could not be computed.\n')
+            fprintf('evaluate_steady_state: The steady state computation stopped with the following instrument values:: \n')
+            for i = 1:size(options.instruments,1);
+                fprintf('\t %s \t %f \n',options.instruments(i,:),ys_init(strmatch(options.instruments(i,:),M.endo_names,'exact')))
+            end
+            fprintf('evaluate_steady_state: The following equations have non-zero residuals: \n')
+            for ii=1:n_multipliers
+                if abs(resids(ii)) > options.dynatol.f/100
+                    fprintf('\t Auxiliary Ramsey equation number %d: %f\n',ii, resids(ii))
+                end
+            end
+            for ii=n_multipliers+1:M.endo_nbr
+                if abs(resids(ii)) > options.dynatol.f/100
+                    fprintf('\t Equation number %d: %f\n',ii-n_multipliers, resids(ii))
+                end
+            end
+            skipline(2);
+            info(1) = 81;
+            info(2) = resids'*resids;
+            return;
+        end
     elseif steadystate_flag
         % explicit steady state file
         [ys,params,info] = evaluate_steady_state_file(ys_init,exo_ss,M, ...
@@ -95,11 +223,11 @@ function [ys,params,info] = evaluate_steady_state(ys_init,M,options,oo,steadysta
                             fprintf('STEADY:  Derivative of Equation %d with respect to Variable %s  (initial value of %s: %g) \n',infrow(ii),deblank(M.endo_names(infcol(ii),:)),deblank(M.endo_names(infcol(ii),:)),ys_init(infcol(ii)))
                         else %auxiliary vars
                             orig_var_index=M.aux_vars(1,infcol(ii)-M.orig_endo_nbr).orig_index;
-                            fprintf('STEADY:  Derivative of Equation %d with respect to Variable %s  (initial value of %s: %g) \n',infrow(ii),deblank(M.endo_names(orig_var_index,:)),deblank(M.endo_names(orig_var_index,:)),ys_init(infcol(ii)))            
+                            fprintf('STEADY:  Derivative of Equation %d with respect to Variable %s  (initial value of %s: %g) \n',infrow(ii),deblank(M.endo_names(orig_var_index,:)),deblank(M.endo_names(orig_var_index,:)),ys_init(infcol(ii)))
                         end
                     end
                     disp('STEADY: Check whether your model in truly linear\n')
-                end            
+                end
             end
         end
     else
@@ -109,13 +237,8 @@ function [ys,params,info] = evaluate_steady_state(ys_init,M,options,oo,steadysta
     end
 
     if check
-        if options.steadystate_flag
-            info(1)= 19;
-            resid = check1 ;
-        else
-            info(1)= 20;
-            resid = evaluate_static_model(ys_init,exo_ss,params,M,options);
-        end
+        info(1)= 20;
+        resid = evaluate_static_model(ys_init,exo_ss,params,M,options);
         info(2) = resid'*resid ;
         if isnan(info(2))
             info(1)=22;
@@ -147,7 +270,7 @@ function [ys,params,info] = evaluate_steady_state(ys_init,M,options,oo,steadysta
             return
         end
     end
-    
+
     if ~isreal(ys)
         info(1) = 21;
         info(2) = sum(imag(ys).^2);
@@ -160,4 +283,3 @@ function [ys,params,info] = evaluate_steady_state(ys_init,M,options,oo,steadysta
         info(2) = NaN;
         return
     end
-
diff --git a/matlab/forcst.m b/matlab/forcst.m
index c125e1fc533c84adb2aaa6f00e7b04b5f5635966..dc269e5117b4ecee0afb61ef1c12fb73154dcc69 100644
--- a/matlab/forcst.m
+++ b/matlab/forcst.m
@@ -67,6 +67,7 @@ sigma_u = B*M_.Sigma_e*B';
 sigma_u1 = ghu1*M_.Sigma_e*ghu1';
 sigma_y = 0;
 
+var_yf=NaN(horizon,nvar); %initialize
 for i=1:horizon
     sigma_y1 = ghx1*sigma_y*ghx1'+sigma_u1;
     var_yf(i,:) = diag(sigma_y1)';
diff --git a/matlab/gauss_hermite_weights_and_nodes.m b/matlab/gauss_hermite_weights_and_nodes.m
index 70d5abae441e1ecebcf7a44e146ac9555530551c..a9a75b4e1bc3c151cccee441c11c2e8e3160ccd2 100644
--- a/matlab/gauss_hermite_weights_and_nodes.m
+++ b/matlab/gauss_hermite_weights_and_nodes.m
@@ -69,8 +69,8 @@ nodes = sqrt(2)*nodes;
 %$ enodes = [-2.020182870; -0.9585724646; 0; 0.9585724646;   2.020182870]; 
 %$
 %$ % Check the results.
-%$ t(1) = dyn_assert(1.0,sum_of_weights,1e-12);
-%$ t(2) = dyn_assert(enodes,nodes/sqrt(2),1e-8);
+%$ t(1) = dassert(1.0,sum_of_weights,1e-12);
+%$ t(2) = dassert(enodes,nodes/sqrt(2),1e-8);
 %$ T = all(t);
 %@eof:1
 
@@ -83,9 +83,9 @@ nodes = sqrt(2)*nodes;
 %$ variance = sum(weights.*(nodes.^2));
 %$
 %$ % Check the results.
-%$ t(1) = dyn_assert(1.0,sum_of_weights,1e-12);
-%$ t(2) = dyn_assert(1.0,variance,1e-12);
-%$ t(3) = dyn_assert(0.0,expectation,1e-12);
+%$ t(1) = dassert(1.0,sum_of_weights,1e-12);
+%$ t(2) = dassert(1.0,variance,1e-12);
+%$ t(3) = dassert(0.0,expectation,1e-12);
 %$ T = all(t);
 %@eof:2
 
@@ -102,9 +102,9 @@ nodes = sqrt(2)*nodes;
 %$ variance = transpose(WEIGHTS)*NODES.^2;
 %$
 %$ % Check the results.
-%$ t(1) = dyn_assert(1.0,sum_of_weights,1e-12);
-%$ t(2) = dyn_assert(ones(1,2),variance,1e-12);
-%$ t(3) = dyn_assert(zeros(1,2),expectation,1e-12);
+%$ t(1) = dassert(1.0,sum_of_weights,1e-12);
+%$ t(2) = dassert(ones(1,2),variance,1e-12);
+%$ t(3) = dassert(zeros(1,2),expectation,1e-12);
 %$ T = all(t);
 %@eof:3
 
@@ -117,8 +117,8 @@ nodes = sqrt(2)*nodes;
 %$ variance = sum(weights.*((nodes*.1).^2));
 %$
 %$ % Check the results.
-%$ t(1) = dyn_assert(1.0,sum_of_weights,1e-12);
-%$ t(2) = dyn_assert(.01,variance,1e-12);
-%$ t(3) = dyn_assert(0.0,expectation,1e-12);
+%$ t(1) = dassert(1.0,sum_of_weights,1e-12);
+%$ t(2) = dassert(.01,variance,1e-12);
+%$ t(3) = dassert(0.0,expectation,1e-12);
 %$ T = all(t);
 %@eof:4
diff --git a/matlab/gauss_legendre_weights_and_nodes.m b/matlab/gauss_legendre_weights_and_nodes.m
index 63aae899900c912144c4489501f1c052ee480d7f..a1b6fc2903421f21c55fb6e71a19508880146f49 100644
--- a/matlab/gauss_legendre_weights_and_nodes.m
+++ b/matlab/gauss_legendre_weights_and_nodes.m
@@ -96,16 +96,16 @@ end
 %$ f7 = [.1294849661; .2797053914; .3818300505]; f7 = [f7; .4179591836; flipud(f7)];
 %$
 %$ % Check the results.
-%$ t(1) = dyn_assert(e2,n2,1e-9);
-%$ t(2) = dyn_assert(e3,n3,1e-9);
-%$ t(3) = dyn_assert(e4,n4,1e-9);
-%$ t(4) = dyn_assert(e5,n5,1e-9);
-%$ t(5) = dyn_assert(e7,n7,1e-9);
-%$ t(6) = dyn_assert(w2,f2,1e-9);
-%$ t(7) = dyn_assert(w3,f3,1e-9);
-%$ t(8) = dyn_assert(w4,f4,1e-9);
-%$ t(9) = dyn_assert(w5,f5,1e-9);
-%$ t(10) = dyn_assert(w7,f7,1e-9);
+%$ t(1) = dassert(e2,n2,1e-9);
+%$ t(2) = dassert(e3,n3,1e-9);
+%$ t(3) = dassert(e4,n4,1e-9);
+%$ t(4) = dassert(e5,n5,1e-9);
+%$ t(5) = dassert(e7,n7,1e-9);
+%$ t(6) = dassert(w2,f2,1e-9);
+%$ t(7) = dassert(w3,f3,1e-9);
+%$ t(8) = dassert(w4,f4,1e-9);
+%$ t(9) = dassert(w5,f5,1e-9);
+%$ t(10) = dassert(w7,f7,1e-9);
 %$ T = all(t);
 %@eof:1
 
@@ -116,7 +116,7 @@ end
 %$
 %$ for i=1:nmax
 %$     [n,w] = gauss_legendre_weights_and_nodes(i);
-%$     t(i) = dyn_assert(sum(w),2,1e-12);
+%$     t(i) = dassert(sum(w),2,1e-12);
 %$ end
 %$
 %$ T = all(t);
@@ -127,6 +127,6 @@ end
 %$ % Check that the 
 %$ t(1) = all(n>pi);
 %$ t(2) = all(n<2*pi);
-%$ t(3) = dyn_assert(sum(w),pi,1e-12);
+%$ t(3) = dassert(sum(w),pi,1e-12);
 %$ T = all(t);
 %@eof:3
\ No newline at end of file
diff --git a/matlab/getJJ.m b/matlab/getJJ.m
index 1facc956b98fd0e0b669ac58aaf08fbe33eedf7b..e27ed22b8d08355dcdc005725223766a6bbc9141 100644
--- a/matlab/getJJ.m
+++ b/matlab/getJJ.m
@@ -56,7 +56,7 @@ else
     %     return
     %   end
     m = length(A);
-    GAM =  lyapunov_symm(A,B*M_.Sigma_e*B',options_.qz_criterium,options_.lyapunov_complex_threshold,1);
+    GAM =  lyapunov_symm(A,B*M_.Sigma_e*B',options_.qz_criterium,options_.lyapunov_complex_threshold,1,[],options_.debug);
     k = find(abs(GAM) < 1e-12);
     GAM(k) = 0;
     %   if useautocorr,
@@ -70,7 +70,7 @@ else
     %   end
     %   XX =  lyapunov_symm_mr(A,BB,options_.qz_criterium,options_.lyapunov_complex_threshold,0);
     for j=1:length(indexo),
-        dum =  lyapunov_symm(A,dOm(:,:,j),options_.qz_criterium,options_.lyapunov_complex_threshold,2);
+        dum =  lyapunov_symm(A,dOm(:,:,j),options_.qz_criterium,options_.lyapunov_complex_threshold,2,[],options_.debug);
         %     dum =  XX(:,:,j);
         k = find(abs(dum) < 1e-12);
         dum(k) = 0;
@@ -95,7 +95,7 @@ else
     end
     nexo = length(indexo);
     for j=1:length(indx),
-        dum =  lyapunov_symm(A,dA(:,:,j+nexo)*GAM*A'+A*GAM*dA(:,:,j+nexo)'+dOm(:,:,j+nexo),options_.qz_criterium,options_.lyapunov_complex_threshold,2);
+        dum =  lyapunov_symm(A,dA(:,:,j+nexo)*GAM*A'+A*GAM*dA(:,:,j+nexo)'+dOm(:,:,j+nexo),options_.qz_criterium,options_.lyapunov_complex_threshold,2,[],options_.debug);
         %     dum =  XX(:,:,j);
         k = find(abs(dum) < 1e-12);
         dum(k) = 0;
@@ -128,7 +128,8 @@ end
 if nargout >2,
     %     sy=sy(mf,mf);
     options_.ar=nlags;
-    [GAM,stationary_vars] = th_autocovariances(oo_.dr,oo_.dr.order_var(mf),M_,options_);
+    nodecomposition = 1;
+    [GAM,stationary_vars] = th_autocovariances(oo_.dr,oo_.dr.order_var(mf),M_,options_,nodecomposition);
     sy=sqrt(diag(GAM{1}));
     sy=sy*sy';
     if useautocorr,
diff --git a/matlab/get_prior_info.m b/matlab/get_prior_info.m
index d2ec1810e1bf3a60336c7df6ce59229f3c219c45..cea8ffe4658378f40365231662e93b1cd2735c6c 100644
--- a/matlab/get_prior_info.m
+++ b/matlab/get_prior_info.m
@@ -144,8 +144,8 @@ if size(M_.param_names,1)==size(M_.param_names_tex,1)% All the parameters have a
                 PriorStandardDeviation, ...
                 LowerBound, ...
                 UpperBound, ...
-                PriorIntervals(i,1), ...
-                PriorIntervals(i,2) );
+                PriorIntervals.lb(i), ...
+                PriorIntervals.ub(i) );
     end
     fprintf(fidTeX,'\\end{longtable}\n ');    
     fprintf(fidTeX,'\\end{center}\n');
diff --git a/matlab/get_variance_of_endogenous_variables.m b/matlab/get_variance_of_endogenous_variables.m
index d97619a1ed6f6b8c18978208a52839f4a041835c..df03a1a489536bc1ba4d72404f5f4b4931e07dea 100644
--- a/matlab/get_variance_of_endogenous_variables.m
+++ b/matlab/get_variance_of_endogenous_variables.m
@@ -45,19 +45,16 @@ n = length(i_var);
 
 [A,B] = kalman_transition_matrix(dr,nstatic+(1:nspred),1:nc,M_.exo_nbr);
 
-[vx,u] = lyapunov_symm(A,B*Sigma_e*B',options_.qz_criterium,options_.lyapunov_complex_threshold);
+[vx,u] = lyapunov_symm(A,B*Sigma_e*B',options_.qz_criterium,options_.lyapunov_complex_threshold, [], [], options_.debug);
 
 if size(u,2) > 0
-    i_stat_0 = find(any(abs(A*u) < options_.Schur_vec_tol,2));
-    i_stat = find(any(abs(ghx*u) < options_.Schur_vec_tol,2));
-    
+    i_stat = find(any(abs(ghx*u) < options_.Schur_vec_tol,2)); %only set those variances of objective function for which variance is finite     
     ghx = ghx(i_stat,:);
     ghu = ghu(i_stat,:);
 else
-    i_stat_0 = 1:size(ghx,2);
     i_stat = (1:n)';
 end
 
 vx1 = Inf*ones(n,n);
-vx1(i_stat,i_stat) = ghx(:,i_stat_0)*vx(i_stat_0,i_stat_0)*ghx(:,i_stat_0)'+ghu*Sigma_e*ghu';
+vx1(i_stat,i_stat) = ghx*vx*ghx'+ghu*Sigma_e*ghu';
 
diff --git a/matlab/global_initialization.m b/matlab/global_initialization.m
index 39f9659d19b58d1ce8bd0360e09c695d88b1fdc5..ebe2a04d2a65a4938c28315f4f22d59c395066bb 100644
--- a/matlab/global_initialization.m
+++ b/matlab/global_initialization.m
@@ -57,8 +57,8 @@ options_.solve_tolf = eps^(1/3);
 options_.solve_tolx = eps^(2/3);
 
 options_.dp.maxit = 3000;
-options_.steady.maxit = 10;
-options_.simul.maxit = 10;
+options_.steady.maxit = 50;
+options_.simul.maxit = 50;
 
 options_.mode_check.status = 0;
 options_.mode_check.neighbourhood_size = .5;
@@ -144,6 +144,7 @@ options_.relative_irf = 0;
 options_.ar = 5;
 options_.hp_filter = 0;
 options_.hp_ngrid = 512;
+options_.nodecomposition = 0;
 options_.nomoments = 0;
 options_.nocorr = 0;
 options_.periods = 0;
@@ -220,15 +221,11 @@ particle.initial_state_prior_std = .1;
 % Set the default order of approximation of the model (perturbation).
 particle.perturbation = 2;
 % Set the default number of particles.
-particle.number_of_particles = 500;
+particle.number_of_particles = 5000;
 % Set the default approximation order (Smolyak)
 particle.smolyak_accuracy = 3;
 % By default we don't use pruning
 particle.pruning = 0;
-% Set default algorithm
-particle.algorithm = 'sequential_importance_particle_filter';
-% Set the Gaussian approximation method for Importance sampling
-particle.IS_approximation_method = 'unscented';
 % Set the Gaussian approximation method for particles distributions
 particle.approximation_method = 'unscented';
 % Set unscented parameters alpha, beta and kappa for gaussian approximation
@@ -236,11 +233,27 @@ particle.unscented.alpha = .01;
 particle.unscented.beta = 2;
 particle.unscented.kappa = 0;
 % Configuration of resampling in case of particles
-particle.resampling.status = 'systematic'; % 'none', 'generic', 'smoothed'
-particle.resampling.neff_threshold = .5;
-% Choice of the resampling method
-particle.resampling.method1 = 'traditional' ;
-particle.resampling.method2 = 'kitagawa';
+particle.resampling.status.systematic = 1;
+particle.resampling.status.none = 0;
+particle.resampling.status.generic = 0;
+particle.resampling.threshold = .5;
+particle.resampling.method.kitagawa = 1;
+particle.resampling.method.smooth = 0;
+particle.resampling.method.stratified = 0;
+% Set default algorithm
+particle.filter_algorithm.sis = 1;
+particle.filter_algorithm.apf = 0;
+particle.filter_algorithm.gf = 0;
+particle.filter_algorithm.gmf = 0;
+particle.filter_algorithm.cpf = 0;
+% Approximation of the proposal distribution
+particle.proposal_approximation.cubature = 1;
+particle.proposal_approximation.unscented = 0;
+particle.proposal_approximation.montecarlo = 0;
+% Approximation of the particle distribution
+particle.distribution_approximation.cubature = 0;
+particle.distribution_approximation.unscented = 1;
+particle.distribution_approximation.montecarlo = 0;
 % Number of partitions for the smoothed resampling method
 particle.resampling.number_of_partitions = 200;
 % Configuration of the mixture filters
@@ -466,6 +479,8 @@ simplex.tolerance.f = 1e-4;
 simplex.maxiter = 5000;
 simplex.maxfcallfactor = 500;
 simplex.maxfcall = [];
+simplex.verbosity = 2;
+simplex.delta_factor=0.05;
 options_.simplex = simplex;
 
 % CMAES optimization routine.
@@ -609,11 +624,11 @@ options_.risky_steadystate = 0;
 % endogenous prior
 options_.endogenous_prior = 0;
 options_.endogenous_prior_restrictions.irf={};
+options_.endogenous_prior_restrictions.moment={};
 
 % OSR Optimal Simple Rules
 options_.osr.tolf=1e-7;
 options_.osr.maxit=1000;
-options_.osr.verbose=2;
 
 % use GPU
 options_.gpu = 0;
diff --git a/matlab/gsa/map_calibration.m b/matlab/gsa/map_calibration.m
new file mode 100644
index 0000000000000000000000000000000000000000..da933023daef9cbfe4db9616d8936d52ec410451
--- /dev/null
+++ b/matlab/gsa/map_calibration.m
@@ -0,0 +1,370 @@
+function map_calibration(OutputDirectoryName, Model, DynareOptions, DynareResults, EstimatedParameters, BayesInfo)
+
+% 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/>.
+
+fname_ = Model.fname;
+pnames = Model.param_names(EstimatedParameters.param_vals(:,1),:);
+pvalue_ks = DynareOptions.opt_gsa.pvalue_ks;
+indx_irf = [];
+indx_moment = [];
+DynareOptions.nodisplay = 1;
+init = ~DynareOptions.opt_gsa.load_stab;
+
+options_mcf.pvalue_ks = DynareOptions.opt_gsa.pvalue_ks;
+options_mcf.pvalue_corr = DynareOptions.opt_gsa.pvalue_corr;
+options_mcf.alpha2 = DynareOptions.opt_gsa.alpha2_stab;
+options_mcf.param_names = pnames;
+options_mcf.fname_ = fname_;
+options_mcf.OutputDirectoryName = OutputDirectoryName;
+
+skipline()
+disp('Sensitivity analysis for calibration criteria')
+
+if DynareOptions.opt_gsa.ppost,
+    filetoload=dir([Model.dname filesep 'metropolis' filesep fname_ '_param_irf*.mat']);
+    lpmat=[];
+    for j=1:length(filetoload),
+        load([Model.dname filesep 'metropolis' filesep fname_ '_param_irf',int2str(j),'.mat'])
+        lpmat = [lpmat; stock];
+        clear stock
+    end
+    type = 'post';
+else
+    if DynareOptions.opt_gsa.pprior
+        filetoload=[OutputDirectoryName '/' fname_ '_prior'];
+        load(filetoload,'lpmat','lpmat0','istable','iunstable','iindeterm','iwrong' ,'infox')
+        lpmat = [lpmat0 lpmat];
+        type = 'prior';
+    else
+        filetoload=[OutputDirectoryName '/' fname_ '_mc'];
+        load(filetoload,'lpmat','lpmat0','istable','iunstable','iindeterm','iwrong' ,'infox')
+        lpmat = [lpmat0 lpmat];
+        type = 'mc';
+    end        
+end
+[Nsam, np] = size(lpmat);
+npar = size(pnames,1);
+nshock = np - npar;
+
+nbr_irf_restrictions = size(DynareOptions.endogenous_prior_restrictions.irf,1);
+nbr_moment_restrictions = size(DynareOptions.endogenous_prior_restrictions.moment,1);
+
+if init
+mat_irf=cell(nbr_irf_restrictions,1);
+for ij=1:nbr_irf_restrictions,
+    mat_irf{ij}=NaN(Nsam,length(DynareOptions.endogenous_prior_restrictions.irf{ij,3}));
+end
+
+mat_moment=cell(nbr_moment_restrictions,1);
+for ij=1:nbr_moment_restrictions,
+    mat_moment{ij}=NaN(Nsam,length(DynareOptions.endogenous_prior_restrictions.moment{ij,3}));
+end
+
+irestrictions = [1:Nsam];
+h = dyn_waitbar(0,'Please wait...');
+for j=1:Nsam,
+    Model = set_all_parameters(lpmat(j,:)',EstimatedParameters,Model);
+    [Tt,Rr,SteadyState,info] = dynare_resolve(Model,DynareOptions,DynareResults,'restrict');
+    if info(1)==0,
+        [info, info_irf, info_moment, data_irf, data_moment]=endogenous_prior_restrictions(Tt,Rr,Model,DynareOptions,DynareResults);
+        if ~isempty(info_irf)
+            for ij=1:nbr_irf_restrictions,
+                mat_irf{ij}(j,:)=data_irf{ij}(:,2)';
+            end
+            indx_irf(j,:)=info_irf(:,1);
+        end
+        if ~isempty(info_moment)
+            for ij=1:nbr_moment_restrictions,
+                mat_moment{ij}(j,:)=data_moment{ij}(:,2)';
+            end
+            indx_moment(j,:)=info_moment(:,1);
+        end
+    else
+        irestrictions(j)=0;
+    end
+    dyn_waitbar(j/Nsam,h,['MC iteration ',int2str(j),'/',int2str(Nsam)])
+end
+dyn_waitbar_close(h);
+
+irestrictions=irestrictions(find(irestrictions));
+xmat=lpmat(irestrictions,:);
+skipline()
+endo_prior_restrictions=DynareOptions.endogenous_prior_restrictions;
+save([OutputDirectoryName,filesep,fname_,'_',type,'_restrictions'],'xmat','mat_irf','mat_moment','irestrictions','indx_irf','indx_moment','endo_prior_restrictions');
+else
+load([OutputDirectoryName,filesep,fname_,'_',type,'_restrictions'],'xmat','mat_irf','mat_moment','irestrictions','indx_irf','indx_moment','endo_prior_restrictions');
+end    
+if ~isempty(indx_irf),
+    
+    % For single legend search which has maximum nbr of restrictions 
+    all_irf_couples = cellstr([char(endo_prior_restrictions.irf(:,1)) char(endo_prior_restrictions.irf(:,2))]);
+    irf_couples = unique(all_irf_couples);
+    nbr_irf_couples = size(irf_couples,1);
+    plot_indx = NaN(nbr_irf_couples,1);
+    time_matrix=cell(nbr_irf_couples,1);
+    irf_matrix=cell(nbr_irf_couples,1);
+    irf_mean=cell(nbr_irf_couples,1);
+    irf_median=cell(nbr_irf_couples,1);
+    irf_var=cell(nbr_irf_couples,1);
+    irf_HPD=cell(nbr_irf_couples,1);
+    irf_distrib=cell(nbr_irf_couples,1);
+    maxijv=0;
+    for ij=1:nbr_irf_restrictions
+        if length(endo_prior_restrictions.irf{ij,3})>maxijv
+            maxij=ij;maxijv=length(endo_prior_restrictions.irf{ij,3});
+        end
+        plot_indx(ij) = find(strcmp(irf_couples,all_irf_couples(ij,:)));
+        time_matrix{plot_indx(ij)} = [time_matrix{plot_indx(ij)} endo_prior_restrictions.irf{ij,3}];
+    end
+    
+    indx_irf = indx_irf(irestrictions,:);
+    h1=dyn_figure(DynareOptions,'name',[type ' evaluation of irf restrictions']);
+    nrow=ceil(sqrt(nbr_irf_couples));
+    ncol=nrow;
+    if nrow*(nrow-1)>nbr_irf_couples,
+        ncol=nrow-1;
+    end
+    for ij=1:nbr_irf_restrictions,
+        mat_irf{ij}=mat_irf{ij}(irestrictions,:);
+        irf_matrix{plot_indx(ij)} = [irf_matrix{plot_indx(ij)} mat_irf{ij}];
+        for ik=1:size(mat_irf{ij},2),
+            [Mean,Median,Var,HPD,Distrib] = ...
+                posterior_moments(mat_irf{ij}(:,ik),0,DynareOptions.mh_conf_sig);
+            irf_mean{plot_indx(ij)} = [irf_mean{plot_indx(ij)}; Mean];
+            irf_median{plot_indx(ij)} = [irf_median{plot_indx(ij)}; Median];
+            irf_var{plot_indx(ij)} = [irf_var{plot_indx(ij)}; Var];
+            irf_HPD{plot_indx(ij)} = [irf_HPD{plot_indx(ij)}; HPD];
+            irf_distrib{plot_indx(ij)} = [irf_distrib{plot_indx(ij)}; Distrib'];
+        end
+        leg = num2str(endo_prior_restrictions.irf{ij,3}(1));
+        aleg = num2str(endo_prior_restrictions.irf{ij,3}(1));
+        if size(mat_irf{ij},2)>1,
+            leg = [leg,':' ,num2str(endo_prior_restrictions.irf{ij,3}(end))];
+            aleg = [aleg,'-' ,num2str(endo_prior_restrictions.irf{ij,3}(end))];
+        end        
+        if length(time_matrix{plot_indx(ij)})==1,
+            figure(h1),
+            subplot(nrow,ncol, plot_indx(ij)),
+            hc = cumplot(mat_irf{ij}(:,ik));
+            set(hc,'color','k','linewidth',2)
+            hold all,
+            a=axis;
+            x1val=max(endo_prior_restrictions.irf{ij,4}(1),a(1));
+            x2val=min(endo_prior_restrictions.irf{ij,4}(2),a(2));
+            hp = patch([x1val x2val x2val x1val],a([3 3 4 4]),'b');
+            set(hp,'FaceAlpha', 0.5)
+            hold off,
+            %         hold off,
+            title([endo_prior_restrictions.irf{ij,1},' vs ',endo_prior_restrictions.irf{ij,2}, '(', leg,')'],'interpreter','none'),
+            %set(legend_h,'Xlim',[0 1]);
+            %         if ij==maxij
+            %             leg1 = num2str(endo_prior_restrictions.irf{ij,3}(:));
+            %             [legend_h,object_h,plot_h,text_strings]=legend(leg1);
+            %             Position=get(legend_h,'Position');Position(1:2)=[-0.055 0.95-Position(4)];
+            %             set(legend_h,'Position',Position);
+            %         end
+        end
+        % hc = get(h,'Children');
+        %for i=2:2:length(hc)
+        %end
+        indx1 = find(indx_irf(:,ij)==0);
+        indx2 = find(indx_irf(:,ij)~=0);
+        atitle0=[endo_prior_restrictions.irf{ij,1},' vs ',endo_prior_restrictions.irf{ij,2}, '(', leg,')'];
+        fprintf(['%4.1f%% of the prior support matches IRF ',atitle0,' inside [%4.1f, %4.1f]\n'],length(indx1)/length(irestrictions)*100,endo_prior_restrictions.irf{ij,4})
+        % aname=[type '_irf_calib_',int2str(ij)];
+        aname=[type '_irf_calib_',endo_prior_restrictions.irf{ij,1},'_vs_',endo_prior_restrictions.irf{ij,2},'_',aleg];
+        atitle=[type ' IRF Calib: Parameter(s) driving ',endo_prior_restrictions.irf{ij,1},' vs ',endo_prior_restrictions.irf{ij,2}, '(', leg,')'];
+        options_mcf.amcf_name = aname;
+        options_mcf.amcf_title = atitle;
+        options_mcf.beha_title = 'IRF prior restriction';
+        options_mcf.nobeha_title = 'NO IRF prior restriction';
+        options_mcf.title = atitle0;
+        if ~isempty(indx1) && ~isempty(indx2)
+            mcf_analysis(xmat(:,nshock+1:end), indx1, indx2, options_mcf, DynareOptions);
+        end
+
+%         [proba, dproba] = stab_map_1(xmat, indx1, indx2, aname, 0);
+%         indplot=find(proba<pvalue_ks);
+%         if ~isempty(indplot)
+%             stab_map_1(xmat, indx1, indx2, aname, 1, indplot, OutputDirectoryName,[],atitle);
+%         end
+    end
+    figure(h1);
+    for ij=1:nbr_irf_couples,
+        if length(time_matrix{ij})>1,
+            subplot(nrow,ncol, ij)
+            itmp = (find(plot_indx==ij));
+            plot(time_matrix{ij},[max(irf_matrix{ij})' min(irf_matrix{ij})'],'k--','linewidth',2)
+            hold on,
+            plot(time_matrix{ij},irf_median{ij},'k','linewidth',2)
+            plot(time_matrix{ij},[irf_distrib{ij}],'k-')
+            a=axis;
+            tmp=[];
+            for ir=1:length(itmp),
+                for it=1:length(endo_prior_restrictions.irf{itmp(ir),3})
+                temp_index = find(time_matrix{ij}==endo_prior_restrictions.irf{itmp(ir),3}(it));
+                tmp(temp_index,:) = endo_prior_restrictions.irf{itmp(ir),4};
+                end
+            end
+%             tmp = cell2mat(endo_prior_restrictions.irf(itmp,4));
+            tmp(isinf(tmp(:,1)),1)=a(3);
+            tmp(isinf(tmp(:,2)),2)=a(4);
+            hp = patch([time_matrix{ij} time_matrix{ij}(end:-1:1)],tmp(:),'b');
+            set(hp,'FaceAlpha',[0.5])
+            plot(a(1:2),[0 0],'r')
+            hold off,
+            axis([max(1,a(1)) a(2:4)])
+            box on,
+            set(gca,'xtick',sort(time_matrix{ij}))
+            itmp = min(itmp);
+            title([endo_prior_restrictions.irf{itmp,1},' vs ',endo_prior_restrictions.irf{itmp,2}],'interpreter','none'),
+        end
+    end
+    dyn_saveas(h1,[OutputDirectoryName,filesep,fname_,'_',type,'_irf_restrictions'],DynareOptions);
+
+    skipline()
+end
+
+if ~isempty(indx_moment)
+    options_mcf.param_names = char(BayesInfo.name);
+    all_moment_couples = cellstr([char(endo_prior_restrictions.moment(:,1)) char(endo_prior_restrictions.moment(:,2))]);
+    moment_couples = unique(all_moment_couples);
+    nbr_moment_couples = size(moment_couples,1);
+    plot_indx = NaN(nbr_moment_couples,1);
+    time_matrix=cell(nbr_moment_couples,1);
+    moment_matrix=cell(nbr_moment_couples,1);
+    moment_mean=cell(nbr_moment_couples,1);
+    moment_median=cell(nbr_moment_couples,1);
+    moment_var=cell(nbr_moment_couples,1);
+    moment_HPD=cell(nbr_moment_couples,1);
+    moment_distrib=cell(nbr_moment_couples,1);
+    % For single legend search which has maximum nbr of restrictions 
+    maxijv=0;
+    for ij=1:nbr_moment_restrictions
+        if length(endo_prior_restrictions.moment{ij,3})>maxijv
+            maxij=ij;maxijv=length(endo_prior_restrictions.moment{ij,3});
+        end
+        plot_indx(ij) = find(strcmp(moment_couples,all_moment_couples(ij,:)));
+        time_matrix{plot_indx(ij)} = [time_matrix{plot_indx(ij)} endo_prior_restrictions.moment{ij,3}];
+    end
+    
+    indx_moment = indx_moment(irestrictions,:);
+    h2=dyn_figure(DynareOptions,'name',[type ' evaluation of moment restrictions']);
+    nrow=ceil(sqrt(nbr_moment_couples));
+    ncol=nrow;
+    if nrow*(nrow-1)>nbr_moment_couples,
+        ncol=nrow-1;
+    end
+    
+    for ij=1:nbr_moment_restrictions,
+        mat_moment{ij}=mat_moment{ij}(irestrictions,:);
+        moment_matrix{plot_indx(ij)} = [moment_matrix{plot_indx(ij)} mat_moment{ij}];
+        for ik=1:size(mat_moment{ij},2),
+            [Mean,Median,Var,HPD,Distrib] = ...
+                posterior_moments(mat_moment{ij}(:,ik),0,DynareOptions.mh_conf_sig);
+            moment_mean{plot_indx(ij)} = [moment_mean{plot_indx(ij)}; Mean];
+            moment_median{plot_indx(ij)} = [moment_median{plot_indx(ij)}; Median];
+            moment_var{plot_indx(ij)} = [moment_var{plot_indx(ij)}; Var];
+            moment_HPD{plot_indx(ij)} = [moment_HPD{plot_indx(ij)}; HPD];
+            moment_distrib{plot_indx(ij)} = [moment_distrib{plot_indx(ij)}; Distrib'];
+        end
+        leg = num2str(endo_prior_restrictions.moment{ij,3}(1));
+        aleg = num2str(endo_prior_restrictions.moment{ij,3}(1));
+        if size(mat_moment{ij},2)>1,
+            leg = [leg,':' ,num2str(endo_prior_restrictions.moment{ij,3}(end))];
+            aleg = [aleg,'_' ,num2str(endo_prior_restrictions.moment{ij,3}(end))];
+        end
+        if length(time_matrix{plot_indx(ij)})==1,
+            figure(h2),
+            subplot(nrow,ncol,plot_indx(ij)),
+            hc = cumplot(mat_moment{ij}(:,ik));
+            set(hc,'color','k','linewidth',2)
+            hold all,
+            %     hist(mat_moment{ij}),
+            a=axis;
+            x1val=max(endo_prior_restrictions.moment{ij,4}(1),a(1));
+            x2val=min(endo_prior_restrictions.moment{ij,4}(2),a(2));
+            hp = patch([x1val x2val x2val x1val],a([3 3 4 4]),'b');
+            set(hp,'FaceAlpha', 0.5)
+            hold off,
+            title([endo_prior_restrictions.moment{ij,1},' vs ',endo_prior_restrictions.moment{ij,2},'(',leg,')'],'interpreter','none'),
+%         if ij==maxij
+%             leg1 = num2str(endo_prior_restrictions.moment{ij,3}(:));
+%             [legend_h,object_h,plot_h,text_strings]=legend(leg1);
+%             Position=get(legend_h,'Position');Position(1:2)=[-0.055 0.95-Position(4)];
+%             set(legend_h,'Position',Position);
+%         end
+        end
+        indx1 = find(indx_moment(:,ij)==0);
+        indx2 = find(indx_moment(:,ij)~=0);
+        atitle0=[endo_prior_restrictions.moment{ij,1},' vs ',endo_prior_restrictions.moment{ij,2}, '(', leg,')'];
+        fprintf(['%4.1f%% of the prior support matches MOMENT ',atitle0,' inside [%4.1f, %4.1f]\n'],length(indx1)/length(irestrictions)*100,endo_prior_restrictions.moment{ij,4})
+        % aname=[type '_moment_calib_',int2str(ij)];
+        aname=[type '_moment_calib_',endo_prior_restrictions.moment{ij,1},'_vs_',endo_prior_restrictions.moment{ij,2},'_',aleg];
+        atitle=[type ' MOMENT Calib: Parameter(s) driving ',endo_prior_restrictions.moment{ij,1},' vs ',endo_prior_restrictions.moment{ij,2}, '(', leg,')'];
+        options_mcf.amcf_name = aname;
+        options_mcf.amcf_title = atitle;
+        options_mcf.beha_title = 'moment prior restriction';
+        options_mcf.nobeha_title = 'NO moment prior restriction';
+        options_mcf.title = atitle0;
+        if ~isempty(indx1) && ~isempty(indx2)
+            mcf_analysis(xmat, indx1, indx2, options_mcf, DynareOptions);
+        end
+        
+%         [proba, dproba] = stab_map_1(xmat, indx1, indx2, aname, 0);
+%         indplot=find(proba<pvalue_ks);
+%         if ~isempty(indplot)
+%             stab_map_1(xmat, indx1, indx2, aname, 1, indplot, OutputDirectoryName,[],atitle);
+%         end
+    end
+    figure(h2);
+    for ij=1:nbr_moment_couples,
+        if length(time_matrix{ij})>1,
+            subplot(nrow,ncol, ij)
+            itmp = (find(plot_indx==ij));
+            plot(time_matrix{ij},[max(moment_matrix{ij})' min(moment_matrix{ij})'],'k--','linewidth',2)
+            hold on,
+            plot(time_matrix{ij},moment_median{ij},'k','linewidth',2)
+            plot(time_matrix{ij},[moment_distrib{ij}],'k-')
+            a=axis;
+            tmp=[];
+            for ir=1:length(itmp),
+                for it=1:length(endo_prior_restrictions.moment{itmp(ir),3})
+                temp_index = find(time_matrix{ij}==endo_prior_restrictions.moment{itmp(ir),3}(it));
+                tmp(temp_index,:) = endo_prior_restrictions.moment{itmp(ir),4};
+                end
+            end
+%             tmp = cell2mat(endo_prior_restrictions.moment(itmp,4));
+            tmp(isinf(tmp(:,1)),1)=a(3);
+            tmp(isinf(tmp(:,2)),2)=a(4);
+            hp = patch([time_matrix{ij} time_matrix{ij}(end:-1:1)],tmp(:),'b');
+            set(hp,'FaceAlpha',[0.5])
+            plot(a(1:2),[0 0],'r')
+            hold off,
+            axis(a)
+            box on,
+            set(gca,'xtick',sort(time_matrix{ij}))
+            itmp = min(itmp);
+            title([endo_prior_restrictions.moment{itmp,1},' vs ',endo_prior_restrictions.moment{itmp,2}],'interpreter','none'),
+        end
+    end
+    dyn_saveas(h2,[OutputDirectoryName,filesep,fname_,'_',type,'_moment_restrictions'],DynareOptions);
+    skipline()
+end
+return
+
diff --git a/matlab/gsa/mcf_analysis.m b/matlab/gsa/mcf_analysis.m
new file mode 100644
index 0000000000000000000000000000000000000000..fb46c51bcd4b7c18bd58575d9facaeb489ac39a8
--- /dev/null
+++ b/matlab/gsa/mcf_analysis.m
@@ -0,0 +1,61 @@
+function mcf_analysis(lpmat, ibeha, inobeha, options_mcf, DynareOptions)
+%
+% Written by Marco Ratto
+% Joint Research Centre, The European Commission,
+% marco.ratto@jrc.ec.europa.eu
+%
+
+% Copyright (C) 2014 European Commission
+%
+% 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/>.
+
+pvalue_ks = options_mcf.pvalue_ks;
+pvalue_corr = options_mcf.pvalue_corr;
+alpha2 = options_mcf.alpha2;
+param_names = options_mcf.param_names;
+amcf_name = options_mcf.amcf_name;
+amcf_title = options_mcf.amcf_title;
+beha_title = options_mcf.beha_title;
+nobeha_title = options_mcf.nobeha_title;
+title = options_mcf.title;
+fname_ = options_mcf.fname_;
+OutputDirectoryName = options_mcf.OutputDirectoryName;
+
+[proba, dproba] = stab_map_1(lpmat, ibeha, inobeha, [],0);
+%         indindet=find(dproba>ksstat);
+indmcf=find(proba<pvalue_ks);
+[tmp,jtmp] = sort(proba(indmcf),2,'ascend');
+indmcf = indmcf(jtmp);
+if ~isempty(indmcf)
+    disp(['Smirnov statistics in driving ', title])
+    for j=1:length(indmcf),
+        disp([param_names(indmcf(j),:),'   d-stat = ', num2str(dproba(indmcf(j)),'%1.3f'),'   p-value = ', num2str(proba(indmcf(j)),'%1.3f')])
+    end
+    skipline()
+end
+if length(ibeha)>10 && length(inobeha)>10,
+    indcorr1 = stab_map_2(lpmat(ibeha,:),alpha2, pvalue_corr, beha_title);
+    indcorr2 = stab_map_2(lpmat(inobeha,:),alpha2, pvalue_corr, nobeha_title);
+    indcorr = union(indcorr1(:), indcorr2(:));
+    indcorr = indcorr(~ismember(indcorr(:),indmcf));
+    indmcf = [indmcf(:); indcorr(:)];
+end
+if ~isempty(indmcf)
+    skipline()
+    scatter_mcf(lpmat(ibeha,indmcf),lpmat(inobeha,indmcf), param_names(indmcf,:), ...
+        '.', [fname_,'_',amcf_name], OutputDirectoryName, amcf_title,[], DynareOptions, ...
+        beha_title, nobeha_title)
+end
diff --git a/matlab/gsa/prior_draw_gsa.m b/matlab/gsa/prior_draw_gsa.m
index a1277e3461edbb60017d55c32e8c1a1b77e79bfa..9c6b2cb16797e4237aa6e2e1da6198fcde9dd176 100644
--- a/matlab/gsa/prior_draw_gsa.m
+++ b/matlab/gsa/prior_draw_gsa.m
@@ -42,8 +42,7 @@ function pdraw = prior_draw_gsa(init,rdraw)
 % 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_ options_ estim_params_  bayestopt_
-global bayestopt_
+global bayestopt_ options_
 persistent npar pshape p6 p7 p3 p4 lbcum ubcum
   
 if init
@@ -56,30 +55,30 @@ if init
     pdraw = zeros(npar,1);
     lbcum = zeros(npar,1);
     ubcum = ones(npar,1);
-    
+    bounds = prior_bounds(bayestopt_,options_);
     % set bounds for cumulative probabilities
     for i = 1:npar
       switch pshape(i)
         case 5% Uniform prior.
-          p4(i) = min(p4(i),bayestopt_.ub(i));
-          p3(i) = max(p3(i),bayestopt_.lb(i));
+          p4(i) = min(p4(i),bounds.ub(i));
+          p3(i) = max(p3(i),bounds.lb(i));
         case 3% Gaussian prior.
-          lbcum(i) = 0.5 * erfc(-(bayestopt_.lb(i)-p6(i))/p7(i) ./ sqrt(2));;
-          ubcum(i) = 0.5 * erfc(-(bayestopt_.ub(i)-p6(i))/p7(i) ./ sqrt(2));;
+          lbcum(i) = 0.5 * erfc(-(bounds.lb(i)-p6(i))/p7(i) ./ sqrt(2));;
+          ubcum(i) = 0.5 * erfc(-(bounds.ub(i)-p6(i))/p7(i) ./ sqrt(2));;
         case 2% Gamma prior.
-          lbcum(i) = gamcdf(bayestopt_.lb(i)-p3(i),p6(i),p7(i));
-          ubcum(i) = gamcdf(bayestopt_.ub(i)-p3(i),p6(i),p7(i));
+          lbcum(i) = gamcdf(bounds.lb(i)-p3(i),p6(i),p7(i));
+          ubcum(i) = gamcdf(bounds.ub(i)-p3(i),p6(i),p7(i));
         case 1% Beta distribution (TODO: generalized beta distribution)
-          lbcum(i) = betainc((bayestopt_.lb(i)-p3(i))./(p4(i)-p3(i)),p6(i),p7(i));
-          ubcum(i) = betainc((bayestopt_.ub(i)-p3(i))./(p4(i)-p3(i)),p6(i),p7(i));
+          lbcum(i) = betainc((bounds.lb(i)-p3(i))./(p4(i)-p3(i)),p6(i),p7(i));
+          ubcum(i) = betainc((bounds.ub(i)-p3(i))./(p4(i)-p3(i)),p6(i),p7(i));
         case 4% INV-GAMMA1 distribution
           % TO BE CHECKED
-          lbcum(i) = gamcdf(1/(bayestopt_.ub(i)-p3(i))^2,p7(i)/2,2/p6(i));
-          ubcum(i) = gamcdf(1/(bayestopt_.lb(i)-p3(i))^2,p7(i)/2,2/p6(i));
+          lbcum(i) = gamcdf(1/(bounds.ub(i)-p3(i))^2,p7(i)/2,2/p6(i));
+          ubcum(i) = gamcdf(1/(bounds.lb(i)-p3(i))^2,p7(i)/2,2/p6(i));
         case 6% INV-GAMMA2 distribution
           % TO BE CHECKED
-          lbcum(i) = gamcdf(1/(bayestopt_.ub(i)-p3(i)),p7(i)/2,2/p6(i));
-          ubcum(i) = gamcdf(1/(bayestopt_.lb(i)-p3(i)),p7(i)/2,2/p6(i));
+          lbcum(i) = gamcdf(1/(bounds.ub(i)-p3(i)),p7(i)/2,2/p6(i));
+          ubcum(i) = gamcdf(1/(bounds.lb(i)-p3(i)),p7(i)/2,2/p6(i));
         otherwise
           % Nothing to do here.
       end
diff --git a/matlab/gsa/redform_map.m b/matlab/gsa/redform_map.m
index 2a2e9b02791ef75f3d5ab07fff31f962509b1e3e..7421e1c923d6efdd079a4223876e4955ebd0dc57 100644
--- a/matlab/gsa/redform_map.m
+++ b/matlab/gsa/redform_map.m
@@ -54,6 +54,8 @@ alpha2=0;
 pvalue_ks = options_gsa_.ksstat_redform;
 pvalue_corr = options_gsa_.alpha2_redform;
 
+bounds = prior_bounds(bayestopt_,options_);
+
 pnames = M_.param_names(estim_params_.param_vals(:,1),:);
 if nargin==0,
     dirname='';
@@ -98,7 +100,7 @@ end
 offset = length(bayestopt_.pshape)-np;
 if options_gsa_.prior_range,
     pshape=5*(ones(np,1));
-    pd =  [NaN(np,1) NaN(np,1) bayestopt_.lb(offset+1:end) bayestopt_.ub(offset+1:end)];
+    pd =  [NaN(np,1) NaN(np,1) bounds.lb(offset+1:end) bounds.ub(offset+1:end)];
 else
     pshape = bayestopt_.pshape(offset+1:end);
     pd =  [bayestopt_.p6(offset+1:end) bayestopt_.p7(offset+1:end) bayestopt_.p3(offset+1:end) bayestopt_.p4(offset+1:end)];
diff --git a/matlab/gsa/scatter_mcf.m b/matlab/gsa/scatter_mcf.m
new file mode 100644
index 0000000000000000000000000000000000000000..90d363cb3c7e4c11567026cdfa433988946f83d4
--- /dev/null
+++ b/matlab/gsa/scatter_mcf.m
@@ -0,0 +1,167 @@
+function  scatter_mcf(X,Y,vnames,plotsymbol, fnam, dirname, figtitle, xparam1, DynareOptions, beha_name, non_beha_name)
+% Frontend to the Sensitivity Analysis Toolbox for DYNARE
+%
+% Reference:
+% M. Ratto, Global Sensitivity Analysis for Macroeconomic models, MIMEO, 2006.
+
+% 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/>.
+
+% PURPOSE: Pairwise scatter plots of the columns of x and y after
+% Monte Carlo filtering
+%---------------------------------------------------
+% USAGE:    scatter_mcf(x,y,vnames,pltsym,diagon)
+%        or scatter_mcf(x,y) which relies on defaults
+% where:
+%        x = an nxk matrix with columns containing behavioural sample
+%        y = an mxk matrix with columns containing non-behavioural sample
+%   vnames = a vector of variable names
+%            (default = numeric labels 1,2,3 etc.)
+%   pltsym = a plt symbol
+%            (default = '.' for npts > 100, 'o' for npts < 100
+
+
+Z=[X;Y];
+[n,p] = size(X);
+% X = X - ones(n,1)*min(Z);
+% X = X ./ (ones(n,1)*max(Z));
+[n,p] = size(Y);
+% Y = Y - ones(n,1)*min(Z);
+% Y = Y ./ (ones(n,1)*max(Z));
+[n,p] = size(Z);
+clear Z;
+
+nflag = 0;
+if nargin >=3
+    nflag = 1;
+end;
+
+if nargin<4 || isempty(plotsymbol)
+    if n*p<100, plotsymbol = 'o';
+    else plotsymbol = '.';
+    end
+end
+
+if nargin<5
+    fnam='';
+end
+if nargin<6,
+  dirname='';
+  nograph=1;
+else
+  nograph=0;    
+end
+if nargin<7,
+  figtitle=fnam;
+end
+if nargin<8,
+  xparam1=[];
+end
+if nargin<10,
+  beha_name = 'BEHAVIOUR';
+  non_beha_name = 'NON-BEHAVIOUR';
+end
+if nargin==10,
+  non_beha_name = ['NON-' beha_name];
+end
+
+fig_nam_=[fnam];
+if ~nograph,
+    hh=dyn_figure(DynareOptions,'name',figtitle);
+end
+
+bf = 0.1;
+ffs = 0.05/(p-1);
+ffl = (1-2*bf-0.05)/p;
+if p>1,
+    fL = linspace(bf,1-bf+ffs,p+1);
+else
+    fL = bf;
+end
+for i = 1:p
+    for j = 1:p
+        h = axes('position',[fL(i),fL(p+1-j),ffl,ffl]);
+        if i==j
+            h1=cumplot(X(:,j));
+            %             set(h1,'color',[0 0 1], 'linestyle','--','LineWidth',1.5)
+            set(h1,'color',[0 0 1],'LineWidth',1.5)
+            hold on,
+            h2=cumplot(Y(:,j));
+            set(h2,'color',[1 0 0],'LineWidth',1.5)
+            if ~isempty(xparam1)
+                hold on, plot(xparam1([j j]),[0 1],'k--')
+            end
+            if j<p
+                set(gca,'XTickLabel',[],'XTick',[]);
+            else
+                grid off
+            end
+            set(gca,'YTickLabel',[],'YTick',[]);
+        else
+            if j>i
+                plot(X(:,i),X(:,j),[plotsymbol,'b'])
+                hold on,
+                plot(Y(:,i),Y(:,j),[plotsymbol,'r'])
+            else
+                plot(Y(:,i),Y(:,j),[plotsymbol,'r'])
+                hold on,
+                plot(X(:,i),X(:,j),[plotsymbol,'b'])
+            end
+            if ~isempty(xparam1)
+                hold on, plot(xparam1(i),xparam1(j),'k*')
+            end
+            hold off;
+            %             axis([-0.1 1.1 -0.1 1.1])
+            if i<p,
+                set(gca,'YTickLabel',[],'YTick',[]);
+            else
+                set(gca,'yaxislocation','right');
+            end
+            if j<p
+                set(gca,'XTickLabel',[],'XTick',[]);
+            end
+        end
+        if nflag == 1
+            set(gca,'fontsize',9);
+        end;
+        if i==1
+            if nflag == 1
+                ylabel(vnames(j,:),'Rotation',45,'interpreter','none', ...
+                    'HorizontalAlignment','right','VerticalAlignment','middle');
+            else
+                ylabel([num2str(j),' '],'Rotation',90)
+            end;
+        end
+        if j==1
+            if nflag == 1
+                title(vnames(i,:),'interpreter','none','Rotation',45, ...
+                    'HorizontalAlignment','left','VerticalAlignment','bottom')
+            else
+                title(num2str(i))
+            end;
+        end
+        drawnow
+    end
+end
+if ~isoctave
+    annotation('textbox', [0.1,0,0.35,0.05],'String', beha_name,'Color','Blue','horizontalalignment','center');
+    annotation('textbox', [0.55,0,0.35,0.05],'String', non_beha_name,'Color','Red','horizontalalignment','center');
+end
+
+if ~nograph,
+    dyn_saveas(hh,[dirname,filesep,fig_nam_],DynareOptions);
+end
\ No newline at end of file
diff --git a/matlab/gsa/stab_map_.m b/matlab/gsa/stab_map_.m
index c184c20aa9e9ba3102582493bbed8d1e711a802c..f7db079df6f0fdf104f14ffb9667a5b368d9517d 100644
--- a/matlab/gsa/stab_map_.m
+++ b/matlab/gsa/stab_map_.m
@@ -96,10 +96,19 @@ p2 = bayestopt_.p2(nshock+1:end);
 p3 = bayestopt_.p3(nshock+1:end);
 p4 = bayestopt_.p4(nshock+1:end);
 
+bounds = prior_bounds(bayestopt_,options_);
+
 if nargin==0,
     OutputDirectoryName='';
 end
 
+options_mcf.pvalue_ks = pvalue_ks;
+options_mcf.pvalue_corr = pvalue_corr;
+options_mcf.alpha2 = alpha2;
+options_mcf.param_names = char(bayestopt_.name(nshock+1:end));
+options_mcf.fname_ = fname_;
+options_mcf.OutputDirectoryName = OutputDirectoryName;
+
 opt=options_;
 options_.periods=0;
 options_.nomoments=1;
@@ -157,7 +166,7 @@ if fload==0,
                 lpmat0(:,j) = randperm(Nsam)'./(Nsam+1); %latin hypercube
             end
             if opt_gsa.prior_range
-                lpmat0(:,j)=lpmat0(:,j).*(bayestopt_.ub(j)-bayestopt_.lb(j))+bayestopt_.lb(j);
+                lpmat0(:,j)=lpmat0(:,j).*(bounds.ub(j)-bounds.lb(j))+bounds.lb(j);
             end
         end
         if opt_gsa.prior_range
@@ -168,7 +177,7 @@ if fload==0,
             %         end
             %       end
             for j=1:np,
-                lpmat(:,j)=lpmat(:,j).*(bayestopt_.ub(j+nshock)-bayestopt_.lb(j+nshock))+bayestopt_.lb(j+nshock);
+                lpmat(:,j)=lpmat(:,j).*(bounds.ub(j+nshock)-bounds.lb(j+nshock))+bounds.lb(j+nshock);
             end
         else
             xx=prior_draw_gsa(0,[lpmat0 lpmat]);
@@ -221,20 +230,20 @@ if fload==0,
         if neighborhood_width>0,
             for j=1:nshock,
                 lpmat0(:,j) = randperm(Nsam)'./(Nsam+1); %latin hypercube
-                ub=min([bayestopt_.ub(j) xparam1(j)*(1+neighborhood_width)]);
-                lb=max([bayestopt_.lb(j) xparam1(j)*(1-neighborhood_width)]);
+                ub=min([bounds.ub(j) xparam1(j)*(1+neighborhood_width)]);
+                lb=max([bounds.lb(j) xparam1(j)*(1-neighborhood_width)]);
                 lpmat0(:,j)=lpmat0(:,j).*(ub-lb)+lb;
             end
             for j=1:np,
-                ub=min([bayestopt_.ub(j+nshock) xparam1(j+nshock)*(1+neighborhood_width)]);
-                lb=max([bayestopt_.lb(j+nshock) xparam1(j+nshock)*(1-neighborhood_width)]);
+                ub=min([bounds.ub(j+nshock) xparam1(j+nshock)*(1+neighborhood_width)]);
+                lb=max([bounds.lb(j+nshock) xparam1(j+nshock)*(1-neighborhood_width)]);
                 lpmat(:,j)=lpmat(:,j).*(ub-lb)+lb;
             end
         else
             d = chol(inv(hh));
             lp=randn(Nsam*2,nshock+np)*d+kron(ones(Nsam*2,1),xparam1');
             for j=1:Nsam*2,
-                lnprior(j) = any(lp(j,:)'<=bayestopt_.lb | lp(j,:)'>=bayestopt_.ub);
+                lnprior(j) = any(lp(j,:)'<=bounds.lb | lp(j,:)'>=bounds.ub);
             end
             ireal=[1:2*Nsam];
             ireal=ireal(find(lnprior==0));
@@ -252,14 +261,13 @@ if fload==0,
     iunstable=[1:Nsam];
     iindeterm=zeros(1,Nsam);
     iwrong=zeros(1,Nsam);
+    inorestriction=zeros(1,Nsam);
+    irestriction=zeros(1,Nsam);
     for j=1:Nsam,
-        M_.params(estim_params_.param_vals(:,1)) = lpmat(j,:)';
+        M_ = set_all_parameters([lpmat0(j,:) lpmat(j,:)]',estim_params_,M_);
         %try stoch_simul([]);
         try
             [Tt,Rr,SteadyState,info,M_,options_,oo_] = dynare_resolve(M_,options_,oo_,'restrict');
-            if info(1)==0,
-                info=endogenous_prior_restrictions(Tt,Rr,M_,options_,oo_);
-            end
             infox(j,1)=info(1);
             if infox(j,1)==0 && ~exist('T'),
                 dr_=oo_.dr;
@@ -301,7 +309,6 @@ if fload==0,
         dr_ = oo_.dr;
         if isfield(dr_,'ghx'),
             egg(:,j) = sort(dr_.eigval);
-            iunstable(j)=0;
             if prepSA
                 jstab=jstab+1;
                 T(:,:,jstab) = [dr_.ghx dr_.ghu];
@@ -315,6 +322,15 @@ if fload==0,
                 nboth = dr_.nboth;
                 nfwrd = dr_.nfwrd;
             end
+            info=endogenous_prior_restrictions(Tt,Rr,M_,options_,oo_);
+            infox(j,1)=info(1);
+            if info(1),
+                iwrong(j)=j;
+                inorestriction(j)=j;
+            else
+                iunstable(j)=0;
+                irestriction(j)=j;
+            end
         else
             istable(j)=0;
             if isfield(dr_,'eigval')
@@ -346,10 +362,13 @@ if fload==0,
     else
         T=[];
     end
-    istable=istable(find(istable));  % stable params
-    iunstable=iunstable(find(iunstable));   % unstable params
+    istable=istable(find(istable));  % stable params ignoring restrictions
+    irestriction=irestriction(find(irestriction));  % stable params & restrictions OK
+    inorestriction=inorestriction(find(inorestriction));  % stable params violating restrictions
+    iunstable=iunstable(find(iunstable));   % violation of BK & restrictions & solution could not be found (whatever goes wrong)
     iindeterm=iindeterm(find(iindeterm));  % indeterminacy
     iwrong=iwrong(find(iwrong));  % dynare could not find solution
+    ixun=iunstable(find(~ismember(iunstable,[iindeterm,iwrong]))); % explosive roots
 
     %     % map stable samples
     %     istable=[1:Nsam];
@@ -393,22 +412,22 @@ if fload==0,
     if pprior,
         if ~prepSA
             save([OutputDirectoryName filesep fname_ '_prior.mat'], ...
-                'bkpprior','lpmat','lpmat0','iunstable','istable','iindeterm','iwrong', ...
+                'bkpprior','lpmat','lpmat0','irestriction','iunstable','istable','iindeterm','iwrong','ixun', ...
                 'egg','yys','nspred','nboth','nfwrd','infox')
         else
             save([OutputDirectoryName filesep fname_ '_prior.mat'], ...
-                'bkpprior','lpmat','lpmat0','iunstable','istable','iindeterm','iwrong', ...
+                'bkpprior','lpmat','lpmat0','irestriction','iunstable','istable','iindeterm','iwrong','ixun', ...
                 'egg','yys','T','nspred','nboth','nfwrd','infox')
         end
 
     else
         if ~prepSA
             save([OutputDirectoryName filesep fname_ '_mc.mat'], ...
-                'lpmat','lpmat0','iunstable','istable','iindeterm','iwrong', ...
+                'lpmat','lpmat0','irestriction','iunstable','istable','iindeterm','iwrong','ixun', ...
                 'egg','yys','nspred','nboth','nfwrd','infox')
         else
             save([OutputDirectoryName filesep fname_ '_mc.mat'], ...
-                'lpmat','lpmat0','iunstable','istable','iindeterm','iwrong', ...
+                'lpmat','lpmat0','irestriction','iunstable','istable','iindeterm','iwrong','ixun', ...
                 'egg','yys','T','nspred','nboth','nfwrd','infox')
         end
     end
@@ -418,7 +437,7 @@ else
     else
         filetoload=[OutputDirectoryName filesep fname_ '_mc.mat'];
     end
-    load(filetoload,'lpmat','lpmat0','iunstable','istable','iindeterm','iwrong','egg','yys','nspred','nboth','nfwrd','infox')
+    load(filetoload,'lpmat','lpmat0','irestriction','iunstable','istable','iindeterm','iwrong','ixun','egg','yys','nspred','nboth','nfwrd','infox')
     Nsam = size(lpmat,1);
     if pprior==0,
         eval(['load ' options_.mode_file '.mat;']);
@@ -465,38 +484,25 @@ else
 end
 
 if pprior
-    % univariate
-    aname='prior_stab'; atitle='Prior StabMap: Parameter driving non-existence of unique stable solution (Unacceptable)';
-    aindetname=[aname, '_indet']; aindettitle='Prior StabMap: Parameter driving indeterminacy';
-    aunstablename=[aname, '_unst'];  aunstabletitle='Prior StabMap: Parameter driving explosiveness of solution';
-    awronguniname=[aname, '_wrong']; awrongunititle='Prior StabMap: Parameter driving inability to find solution';
-    % bivariate
-    auname='prior_unacceptable'; autitle='Prior StabMap: non-existence of unique stable solution (Unacceptable)';
     aunstname='prior_unstable'; aunsttitle='Prior StabMap: explosiveness of solution';
     aindname='prior_indeterm'; aindtitle='Prior StabMap: Indeterminacy';
     awrongname='prior_wrong'; awrongtitle='Prior StabMap: inability to find solution';
-    asname='prior_stable'; astitle='Prior StabMap: unique Stable Saddle-Path';
+    acalibname='prior_calib'; acalibtitle='Prior StabMap: IRF/moment restrictions';
+    asname='prior_stable'; atitle='Prior StabMap: Parameter driving non-existence of unique stable solution (Unacceptable)';
 else
-    % univariate
-    aname='mc_stab'; atitle='MC (around posterior mode) StabMap: Parameter driving non-existence of unique stable solution (Unacceptable)';
-    aindetname=[aname, '_indet']; aindettitle='MC (around posterior mode) StabMap: Parameter driving indeterminacy';
-    aunstablename=[aname, '_unst'];  aunstabletitle='MC (around posterior mode) StabMap: Parameter driving explosiveness of solution';
-    awronguniname=[aname, '_wrong']; awrongunititle='MC (around posterior mode) StabMap: Parameter driving inability to find solution';
-    % bivariate
-    auname='mc_unacceptable'; autitle='MC (around posterior mode) StabMap: non-existence of unique stable solution (Unacceptable)';
     aunstname='mc_unstable'; aunsttitle='MC (around posterior mode) StabMap: explosiveness of solution';
     aindname='mc_indeterm';  aindtitle='MC (around posterior mode) StabMap: Indeterminacy';
     awrongname='mc_wrong'; awrongtitle='MC (around posterior mode) StabMap: inability to find solution';
-    asname='mc_stable'; astitle='MC (around posterior mode) StabMap: Unique Stable Saddle-Path';
+    acalibname='mc_calib'; acalibtitle='MC (around posterior mode) StabMap: IRF/moment restrictions';
+    asname='mc_stable'; atitle='MC (around posterior mode) StabMap: Parameter driving non-existence of unique stable solution (Unacceptable)';
 end
-delete([OutputDirectoryName,filesep,fname_,'_',aname,'_*.*']);
-%delete([OutputDirectoryName,filesep,fname_,'_',aname,'_SA_*.*']);
-delete([OutputDirectoryName,filesep,fname_,'_',asname,'_corr_*.*']);
-delete([OutputDirectoryName,filesep,fname_,'_',auname,'_corr_*.*']);
-delete([OutputDirectoryName,filesep,fname_,'_',aunstname,'_corr_*.*']);
-delete([OutputDirectoryName,filesep,fname_,'_',aindname,'_corr_*.*']);
+delete([OutputDirectoryName,filesep,fname_,'_',asname,'.*']);
+delete([OutputDirectoryName,filesep,fname_,'_',acalibname,'.*']);
+delete([OutputDirectoryName,filesep,fname_,'_',aindname,'.*']);
+delete([OutputDirectoryName,filesep,fname_,'_',aunstname,'.*']);
+delete([OutputDirectoryName,filesep,fname_,'_',awrongname,'.*']);
 
-if length(iunstable)>0 && length(iunstable)<Nsam,
+if length(iunstable)>0 || length(iwrong)>0,
     fprintf(['%4.1f%% of the prior support gives unique saddle-path solution.\n'],length(istable)/Nsam*100)
     fprintf(['%4.1f%% of the prior support gives explosive dynamics.\n'],(length(iunstable)-length(iwrong)-length(iindeterm) )/Nsam*100)
     if ~isempty(iindeterm),
@@ -504,137 +510,115 @@ if length(iunstable)>0 && length(iunstable)<Nsam,
     end
     if ~isempty(iwrong),
         skipline()
-        disp(['For ',num2str(length(iwrong)/Nsam*100,'%1.3f'),'\% of the prior support dynare could not find a solution.'])
+        disp(['For ',num2str(length(iwrong)/Nsam*100,'%4.1f'),'% of the prior support dynare could not find a solution.'])
         skipline()
         if any(infox==1),
-            disp(['    For ',num2str(length(find(infox==1))/Nsam*100,'%1.3f'),'\% The model doesn''t determine the current variables uniquely.'])
+            disp(['    For ',num2str(length(find(infox==1))/Nsam*100,'%4.1f'),'% The model doesn''t determine the current variables uniquely.'])
         end
         if any(infox==2),
-            disp(['    For ',num2str(length(find(infox==2))/Nsam*100,'%1.3f'),'\% MJDGGES returned an error code.'])
+            disp(['    For ',num2str(length(find(infox==2))/Nsam*100,'%4.1f'),'% MJDGGES returned an error code.'])
         end
         if any(infox==6),
-            disp(['    For ',num2str(length(find(infox==6))/Nsam*100,'%1.3f'),'\% The jacobian evaluated at the deterministic steady state is complex.'])
+            disp(['    For ',num2str(length(find(infox==6))/Nsam*100,'%4.1f'),'% The jacobian evaluated at the deterministic steady state is complex.'])
         end
         if any(infox==19),
-            disp(['    For ',num2str(length(find(infox==19))/Nsam*100,'%1.3f'),'\% The steadystate routine thrown an exception (inconsistent deep parameters).'])
+            disp(['    For ',num2str(length(find(infox==19))/Nsam*100,'%4.1f'),'% The steadystate routine thrown an exception (inconsistent deep parameters).'])
         end
         if any(infox==20),
-            disp(['    For ',num2str(length(find(infox==20))/Nsam*100,'%1.3f'),'\% Cannot find the steady state.'])
+            disp(['    For ',num2str(length(find(infox==20))/Nsam*100,'%4.1f'),'% Cannot find the steady state.'])
         end
         if any(infox==21),
-            disp(['    For ',num2str(length(find(infox==21))/Nsam*100,'%1.3f'),'\% The steady state is complex.'])
+            disp(['    For ',num2str(length(find(infox==21))/Nsam*100,'%4.1f'),'% The steady state is complex.'])
         end
         if any(infox==22),
-            disp(['    For ',num2str(length(find(infox==22))/Nsam*100,'%1.3f'),'\% The steady has NaNs.'])
+            disp(['    For ',num2str(length(find(infox==22))/Nsam*100,'%4.1f'),'% The steady has NaNs.'])
         end
         if any(infox==23),
-            disp(['    For ',num2str(length(find(infox==23))/Nsam*100,'%1.3f'),'\% M_.params has been updated in the steadystate routine and has complex valued scalars.'])
+            disp(['    For ',num2str(length(find(infox==23))/Nsam*100,'%4.1f'),'% M_.params has been updated in the steadystate routine and has complex valued scalars.'])
         end
         if any(infox==24),
-            disp(['    For ',num2str(length(find(infox==24))/Nsam*100,'%1.3f'),'\% M_.params has been updated in the steadystate routine and has some NaNs.'])
+            disp(['    For ',num2str(length(find(infox==24))/Nsam*100,'%4.1f'),'% M_.params has been updated in the steadystate routine and has some NaNs.'])
         end
         if any(infox==30),
-            disp(['    For ',num2str(length(find(infox==30))/Nsam*100,'%1.3f'),'\% Ergodic variance can''t be computed.'])
+            disp(['    For ',num2str(length(find(infox==30))/Nsam*100,'%4.1f'),'% Ergodic variance can''t be computed.'])
         end
         if any(infox==49),
-            disp(['    For ',num2str(length(find(infox==49))/Nsam*100,'%1.3f'),'\% The model violates one (many) endogenous prior restriction(s).'])
+            disp(['    For ',num2str(length(find(infox==49))/Nsam*100,'%4.1f'),'% The model violates one (many) endogenous prior restriction(s).'])
         end
 
     end
     skipline()
-    % Blanchard Kahn
-    [proba, dproba] = stab_map_1(lpmat, istable, iunstable, aname,0);
-%     indstab=find(dproba>ksstat);
-    indstab=find(proba<pvalue_ks);
-    disp('Smirnov statistics in driving acceptable behaviour')
-    for j=1:length(indstab),
-        disp([M_.param_names(estim_params_.param_vals(indstab(j),1),:),'   d-stat = ', num2str(dproba(indstab(j)),'%1.3f'),'   p-value = ', num2str(proba(indstab(j)),'%1.3f')])
-    end
-    skipline()
-    if ~isempty(indstab)
-        stab_map_1(lpmat, istable, iunstable, aname, 1, indstab, OutputDirectoryName,[],atitle);
-    end
-    ixun=iunstable(find(~ismember(iunstable,[iindeterm,iwrong])));
-    if ~isempty(iindeterm),
-        [proba, dproba] = stab_map_1(lpmat, [1:Nsam], iindeterm, aindetname ,0);
-%         indindet=find(dproba>ksstat);
-        indindet=find(proba<pvalue_ks);
-        disp('Smirnov statistics in driving indeterminacy')
-        for j=1:length(indindet),
-            disp([M_.param_names(estim_params_.param_vals(indindet(j),1),:),'   d-stat = ', num2str(dproba(indindet(j)),'%1.3f'),'   p-value = ', num2str(proba(indindet(j)),'%1.3f')])
-        end
-        skipline()
-        if ~isempty(indindet)
-            stab_map_1(lpmat, [1:Nsam], iindeterm, aindetname, 1, indindet, OutputDirectoryName,[],aindettitle);
-        end
-    end
+    if length(iunstable)<Nsam || length(istable)>1
+        itot = [1:Nsam];
+        % Blanchard Kahn
+        itmp = itot(find(~ismember(itot,istable)));
+        options_mcf.amcf_name = asname;
+        options_mcf.amcf_title = atitle;
+        options_mcf.beha_title = 'unique Stable Saddle-Path';
+        options_mcf.nobeha_title = 'NO unique Stable Saddle-Path';
+        options_mcf.title = 'unique solution';
+        mcf_analysis(lpmat, istable, itmp, options_mcf, options_)
 
-    if ~isempty(ixun),
-        [proba, dproba] = stab_map_1(lpmat, [1:Nsam], ixun, aunstablename,0);
-%         indunst=find(dproba>ksstat);
-        indunst=find(proba<pvalue_ks);
-        disp('Smirnov statistics in driving instability')
-        for j=1:length(indunst),
-            disp([M_.param_names(estim_params_.param_vals(indunst(j),1),:),'   d-stat = ', num2str(dproba(indunst(j)),'%1.3f'),'   p-value = ', num2str(proba(indunst(j)),'%1.3f')])
+        if ~isempty(iindeterm),
+            itmp = itot(find(~ismember(itot,iindeterm)));
+            options_mcf.amcf_name = aindname;
+            options_mcf.amcf_title = aindtitle;
+            options_mcf.beha_title = 'NO indeterminacy';
+            options_mcf.nobeha_title = 'indeterminacy';
+            options_mcf.title = 'indeterminacy';
+            mcf_analysis(lpmat, itmp, iindeterm, options_mcf, options_)
         end
-        skipline()
-        if ~isempty(indunst)
-            stab_map_1(lpmat, [1:Nsam], ixun, aunstablename, 1, indunst, OutputDirectoryName,[],aunstabletitle);
+        
+        if ~isempty(ixun),
+            itmp = itot(find(~ismember(itot,ixun)));
+            options_mcf.amcf_name = aunstname;
+            options_mcf.amcf_title = aunsttitle;
+            options_mcf.beha_title = 'NO explosive solution';
+            options_mcf.nobeha_title = 'explosive solution';
+            options_mcf.title = 'instability';
+            mcf_analysis(lpmat, itmp, ixun, options_mcf, options_)
         end
-    end
-
-    if ~isempty(iwrong),
-        [proba, dproba] = stab_map_1(lpmat, [1:Nsam], iwrong, awronguniname,0);
-%         indwrong=find(dproba>ksstat);
-        indwrong=find(proba<pvalue_ks);
-        disp('Smirnov statistics in driving no solution')
-        for j=1:length(indwrong),
-            disp([M_.param_names(estim_params_.param_vals(indwrong(j),1),:),'   d-stat = ', num2str(dproba(indwrong(j)),'%1.3f'),'   p-value = ', num2str(proba(indwrong(j)),'%1.3f')])
+        
+        inorestriction = istable(find(~ismember(istable,irestriction))); % what went wrong beyong prior restrictions
+        iwrong = iwrong(find(~ismember(iwrong,inorestriction))); % what went wrong beyong prior restrictions
+        if ~isempty(iwrong),
+            itmp = itot(find(~ismember(itot,iwrong)));
+            options_mcf.amcf_name = awrongname;
+            options_mcf.amcf_title = awrongtitle;
+            options_mcf.beha_title = 'NO inability to find a solution';
+            options_mcf.nobeha_title = 'inability to find a solution';
+            options_mcf.title = 'inability to find a solution';
+            mcf_analysis(lpmat, itmp, iwrong, options_mcf, options_)
         end
-        skipline()
-        if ~isempty(indwrong)
-            stab_map_1(lpmat, [1:Nsam], iwrong, awronguniname, 1, indwrong, OutputDirectoryName,[],awrongunititle);
+        
+        if ~isempty(irestriction),
+            options_mcf.param_names = char(bayestopt_.name);
+            options_mcf.amcf_name = acalibname;
+            options_mcf.amcf_title = acalibtitle;
+            options_mcf.beha_title = 'prior IRF/moment calibration';
+            options_mcf.nobeha_title = 'NO prior IRF/moment calibration';
+            options_mcf.title = 'prior restrictions';
+            mcf_analysis([lpmat0 lpmat], irestriction, inorestriction, options_mcf, options_)
+            iok = irestriction(1);
+            x0 = [lpmat0(iok,:)'; lpmat(iok,:)'];
+        else
+            iok = istable(1);
+            x0=0.5.*(bounds.ub(1:nshock)-bounds.lb(1:nshock))+bounds.lb(1:nshock);
+            x0 = [x0; lpmat(iok,:)'];
         end
-    end
-
-    skipline()
-    disp('Starting bivariate analysis:')
-
-    c0=corrcoef(lpmat(istable,:));
-    c00=tril(c0,-1);
-
-    if length(istable)>10,
-        stab_map_2(lpmat(istable,:),alpha2, pvalue_corr, asname, OutputDirectoryName,xparam1,astitle);
-    end
-    if length(iunstable)>10,
-        stab_map_2(lpmat(iunstable,:),alpha2, pvalue_corr, auname, OutputDirectoryName,xparam1,autitle);
-    end
-    if length(iindeterm)>10,
-        stab_map_2(lpmat(iindeterm,:),alpha2, pvalue_corr, aindname, OutputDirectoryName,xparam1,aindtitle);
-    end
-    if length(ixun)>10,
-        stab_map_2(lpmat(ixun,:),alpha2, pvalue_corr, aunstname, OutputDirectoryName,xparam1,aunsttitle);
-    end
-    if length(iwrong)>10,
-        stab_map_2(lpmat(iwrong,:),alpha2, pvalue_corr, awrongname, OutputDirectoryName,xparam1,awrongtitle);
-    end
-
-    x0=0.5.*(bayestopt_.ub(1:nshock)-bayestopt_.lb(1:nshock))+bayestopt_.lb(1:nshock);
-    x0 = [x0; lpmat(istable(1),:)'];
-    if istable(end)~=Nsam
-        M_.params(estim_params_.param_vals(:,1)) = lpmat(istable(1),:)';
+        
+        M_ = set_all_parameters(x0,estim_params_,M_);
         [oo_.dr,info,M_,options_,oo_] = resol(0,M_,options_,oo_);
         %     stoch_simul([]);
-    end
-else
-    if length(iunstable)==0,
-        disp('All parameter values in the specified ranges give unique saddle-path solution!')
-        x0=0.5.*(bayestopt_.ub(1:nshock)-bayestopt_.lb(1:nshock))+bayestopt_.lb(1:nshock);
-        x0 = [x0; lpmat(istable(1),:)'];
     else
         disp('All parameter values in the specified ranges are not acceptable!')
         x0=[];
     end
+else
+    disp('All parameter values in the specified ranges give unique saddle-path solution,')
+    disp('and match prior IRF/moment restriction(s) if any!')
+    x0=0.5.*(bounds.ub(1:nshock)-bounds.lb(1:nshock))+bounds.lb(1:nshock);
+    x0 = [x0; lpmat(istable(1),:)'];
 
 end
 
diff --git a/matlab/gsa/stab_map_1.m b/matlab/gsa/stab_map_1.m
index 314c3ddc6b9ac696c28e42b769b7b0f190bb2b3b..681db4724d992d687cfc581ba6549ff3e891834d 100644
--- a/matlab/gsa/stab_map_1.m
+++ b/matlab/gsa/stab_map_1.m
@@ -81,25 +81,29 @@ if isempty(ipar),
 end
 nparplot=length(ipar);
 if iplot && ~options_.nograph
-  lpmat=lpmat(:,ipar);
-  ftit=bayestopt_.name(ipar+nshock*(1-ishock));
-  
-for i=1:ceil(nparplot/12),
-  hh=dyn_figure(options_,'name',atitle);
-  for j=1+12*(i-1):min(nparplot,12*i),
-    subplot(3,4,j-12*(i-1))
-    if ~isempty(ibehaviour),
-      h=cumplot(lpmat(ibehaviour,j));
-      set(h,'color',[0 0 1], 'linestyle',':','LineWidth',1.5)
+    lpmat=lpmat(:,ipar);
+    ftit=bayestopt_.name(ipar+nshock*(1-ishock));
+    
+    for i=1:ceil(nparplot/12),
+        hh=dyn_figure(options_,'name',atitle);
+        for j=1+12*(i-1):min(nparplot,12*i),
+            subplot(3,4,j-12*(i-1))
+            if ~isempty(ibehaviour),
+                h=cumplot(lpmat(ibehaviour,j));
+                set(h,'color',[0 0 1], 'linestyle',':','LineWidth',1.5)
+            end
+            hold on,
+            if ~isempty(inonbehaviour),
+                h=cumplot(lpmat(inonbehaviour,j));
+                set(h,'color',[0 0 0],'LineWidth',1.5)
+            end
+            %     title([ftit{j},'. D-stat ', num2str(dproba(ipar(j)),2)],'interpreter','none')
+            title([ftit{j},'. p-value ', num2str(proba(ipar(j)),2)],'interpreter','none')
+        end
+        if nparplot>12,
+            dyn_saveas(hh,[dirname,filesep,fname_,'_',aname,'_SA_',int2str(i)],options_);
+        else
+            dyn_saveas(hh,[dirname,filesep,fname_,'_',aname,'_SA'],options_);
+        end
     end
-    hold on,
-    if ~isempty(inonbehaviour),
-      h=cumplot(lpmat(inonbehaviour,j));
-      set(h,'color',[0 0 0],'LineWidth',1.5)
-    end
-%     title([ftit{j},'. D-stat ', num2str(dproba(ipar(j)),2)],'interpreter','none')
-    title([ftit{j},'. p-value ', num2str(proba(ipar(j)),2)],'interpreter','none')
-  end
-  dyn_saveas(hh,[dirname,filesep,fname_,'_',aname,'_SA_',int2str(i)],options_);
-end
 end
diff --git a/matlab/gsa/stab_map_2.m b/matlab/gsa/stab_map_2.m
index d4e94f02e82221e4a5d4338f1dfb213e0af31a31..7848de1c6e235bb3559aa82342693ba1a10aa174 100644
--- a/matlab/gsa/stab_map_2.m
+++ b/matlab/gsa/stab_map_2.m
@@ -1,4 +1,4 @@
-function stab_map_2(x,alpha2, pvalue, fnam, dirname,xparam1,figtitle)
+function indcorr = stab_map_2(x,alpha2, pvalue_crit, fnam, dirname,xparam1,figtitle)
 % function stab_map_2(x, alpha2, pvalue, fnam, dirname,xparam1)
 %
 % Written by Marco Ratto
@@ -32,11 +32,13 @@ global bayestopt_ estim_params_ options_ oo_ M_
 npar=size(x,2);
 nsam=size(x,1);
 ishock= npar>estim_params_.np;
+nograph = options_.nograph;
 if nargin<4,
   fnam='';
 end
 if nargin<5,
   dirname='';
+  nograph=1;
 end
 if nargin<6,
   xparam1=[];
@@ -53,7 +55,7 @@ nshock = nshock + estim_params_.nvn;
 nshock = nshock + estim_params_.ncx;
 nshock = nshock + estim_params_.ncn;
 
-c0=corrcoef(x);
+[c0, pvalue] = corrcoef(x);
 c00=tril(c0,-1);
 fig_nam_=[fname_,'_',fnam,'_corr_'];
 
@@ -70,13 +72,13 @@ end
 disp([' '])
 disp(['Correlation analysis for ',fnam])
 
+indcorr = [];
 for j=1:npar,
     i2=find(abs(c00(:,j))>alpha2);
     if length(i2)>0,
         for jx=1:length(i2),
-            tval  = abs(c00(i2(jx),j)*sqrt( (nsam-2)/(1-c00(i2(jx),j)^2) ));
-            tcr = tcrit(nsam-2,pvalue);
-            if tval>tcr,
+            if pvalue(j,i2(jx))<pvalue_crit,
+                indcorr = [indcorr; [j i2(jx)]];
                 j2=j2+1;
                 if ishock,
                     tmp_name = (['[',bayestopt_.name{j},',',bayestopt_.name{i2(jx)},']']);
@@ -85,7 +87,7 @@ for j=1:npar,
                 end
                 fprintf(1,'%20s: corrcoef = %7.3f\n',tmp_name,c0(i2(jx),j));
                     
-                if ~options_.nograph,
+                if ~nograph,
                 if mod(j2,12)==1,
                     ifig=ifig+1;
                     hh=dyn_figure(options_,'name',[figtitle,' sample bivariate projection ', num2str(ifig)]);
@@ -118,12 +120,12 @@ for j=1:npar,
             
         end
     end
-    if ~options_.nograph && (j==(npar)) && j2>0 && (mod(j2,12)~=0),
+    if ~nograph && (j==(npar)) && j2>0 && (mod(j2,12)~=0),
         dyn_saveas(hh,[dirname,filesep,fig_nam_,int2str(ifig)],options_);
     end
     
 end
 if j2==0,
-    disp(['No correlation term with pvalue <', num2str(pvalue),' found for ',fnam])
+    disp(['No correlation term with pvalue <', num2str(pvalue_crit),' and |corr. coef.| >',num2str(alpha2),' found for ',fnam])
 end
 %close all
diff --git a/matlab/hessian.m b/matlab/hessian.m
index d536c27a3b0ec17b75f718a2e5cb47d89e31e7c3..13ddc2f44bcdadf8ca52fce23c7df149ac50ebca 100644
--- a/matlab/hessian.m
+++ b/matlab/hessian.m
@@ -1,5 +1,5 @@
-function hessian_mat = hessian(func,x,gstep,varargin)
-% function hessian_mat = hessian(func,x,gstep,varargin)
+function hessian_mat = hessian(func,x,gstep,varargin) % --*-- Unitary tests --*--
+
 % Computes second order partial derivatives
 %
 % INPUTS
@@ -12,13 +12,21 @@ function hessian_mat = hessian(func,x,gstep,varargin)
 %    hessian_mat [double]   Hessian matrix
 %
 % ALGORITHM
-%    Uses Abramowitz and Stegun (1965) formulas 25.3.24 and 25.3.27 p. 884
+%    Uses Abramowitz and Stegun (1965) formulas 25.3.23 
+% \[
+%     \frac{\partial^2 f_{0,0}}{\partial {x^2}} = \frac{1}{h^2}\left( f_{1,0} - 2f_{0,0} + f_{ - 1,0} \right)
+% \]
+% and 25.3.27 p. 884
+% 
+% \[
+%     \frac{\partial ^2f_{0,0}}{\partial x\partial y} = \frac{-1}{2h^2}\left(f_{1,0} + f_{-1,0} + f_{0,1} + f_{0,-1} - 2f_{0,0} - f_{1,1} - f_{-1,-1} \right)
+% \]
 %
 % SPECIAL REQUIREMENTS
 %    none
 %  
 
-% Copyright (C) 2001-2012 Dynare Team
+% Copyright (C) 2001-2014 Dynare Team
 %
 % This file is part of Dynare.
 %
@@ -49,34 +57,87 @@ xh1=x;
 f0=feval(func,x,varargin{:});
 f1=zeros(size(f0,1),n);
 f_1=f1;
-for i=1:n    
+for i=1:n
+    %do step up
     xh1(i)=x(i)+h1(i);
     f1(:,i)=feval(func,xh1,varargin{:});
+    %do step up
     xh1(i)=x(i)-h_1(i);
     f_1(:,i)=feval(func,xh1,varargin{:});
-    xh1(i)=x(i);
-    i=i+1;
+    xh1(i)=x(i);%reset parameter
 end
 xh_1=xh1;
 hessian_mat = zeros(size(f0,1),n*n);
+temp=f1+f_1-f0*ones(1,n); %term f_(1,0)+f_(-1,0)-f_(0,0) used later
 for i=1:n    
-    if i > 1        
+    if i > 1  %fill symmetric part of Hessian based on previously computed results      
         k=[i:n:n*(i-1)];
         hessian_mat(:,(i-1)*n+1:(i-1)*n+i-1)=hessian_mat(:,k);
     end     
-    hessian_mat(:,(i-1)*n+i)=(f1(:,i)+f_1(:,i)-2*f0)./(h1(i)*h_1(i));
-    temp=f1+f_1-f0*ones(1,n);
+    hessian_mat(:,(i-1)*n+i)=(f1(:,i)+f_1(:,i)-2*f0)./(h1(i)*h_1(i)); %formula 25.3.23
     for j=i+1:n        
+        %step in up direction
         xh1(i)=x(i)+h1(i);
         xh1(j)=x(j)+h_1(j);
+        %step in down direction
         xh_1(i)=x(i)-h1(i);
         xh_1(j)=x(j)-h_1(j);
-        hessian_mat(:,(i-1)*n+j)=-(-feval(func,xh1,varargin{:})-feval(func,xh_1,varargin{:})+temp(:,i)+temp(:,j))./(2*h1(i)*h_1(j));
+        hessian_mat(:,(i-1)*n+j)=-(-feval(func,xh1,varargin{:})-feval(func,xh_1,varargin{:})+temp(:,i)+temp(:,j))./(2*h1(i)*h_1(j)); %formula 25.3.27
+        %reset grid points
         xh1(i)=x(i);
         xh1(j)=x(j);
         xh_1(i)=x(i);
         xh_1(j)=x(j);
-        j=j+1;
     end    
-    i=i+1;
-end
\ No newline at end of file
+end
+
+
+%@test:1
+%$ % Create a function.
+%$ fid = fopen('exfun.m','w+');
+%$ fprintf(fid,'function [f,g,H] = exfun(xvar)\\n');
+%$ fprintf(fid,'x = xvar(1);\\n');
+%$ fprintf(fid,'y = xvar(2);\\n');
+%$ fprintf(fid,'f = x^2* log(y);\\n');
+%$ fprintf(fid,'if nargout>1\\n');
+%$ fprintf(fid,'    g = zeros(2,1);\\n');
+%$ fprintf(fid,'    g(1) = 2*x*log(y);\\n');
+%$ fprintf(fid,'    g(2) = x*x/y;\\n');
+%$ fprintf(fid,'end\\n');
+%$ fprintf(fid,'if nargout>2\\n');
+%$ fprintf(fid,'    H = zeros(2,2);\\n');
+%$ fprintf(fid,'    H(1,1) = 2*log(y);\\n');
+%$ fprintf(fid,'    H(1,2) = 2*x/y;\\n');
+%$ fprintf(fid,'    H(2,1) = H(1,2);\\n');
+%$ fprintf(fid,'    H(2,2) = -x*x/(y*y);\\n');
+%$ fprintf(fid,'    H = H(:);\\n');
+%$ fprintf(fid,'end\\n');
+%$ fclose(fid);
+%$
+%$ rehash;
+%$
+%$ t = zeros(5,1);
+%$
+%$ % Evaluate the Hessian at (1,e)
+%$ try
+%$    H = hessian('exfun',[1; exp(1)],[1e-2; 1]);
+%$    t(1) = 1;
+%$ catch
+%$    t(1) = 0;
+%$ end
+%$
+%$ % Compute the true Hessian matrix
+%$ [f, g, Htrue] = exfun([1 exp(1)]);
+%$
+%$ % Delete exfun routine from disk.
+%$ delete('exfun.m');
+%$
+%$ % Compare the values in H and Htrue
+%$ if t(1)
+%$    t(2) = dassert(abs(H(1)-Htrue(1))<1e-6,true);
+%$    t(3) = dassert(abs(H(2)-Htrue(2))<1e-6,true);
+%$    t(4) = dassert(abs(H(3)-Htrue(3))<1e-6,true);
+%$    t(5) = dassert(abs(H(4)-Htrue(4))<1e-6,true);
+%$ end
+%$ T = all(t);
+%@eof:1
diff --git a/matlab/identification_analysis.m b/matlab/identification_analysis.m
index ce39b30cc8b0ffec5c347031792f409ed51dfb1e..0706988386f8529b991e4641904a4bfa3824d641 100644
--- a/matlab/identification_analysis.m
+++ b/matlab/identification_analysis.m
@@ -134,18 +134,17 @@ if info(1)==0,
             options_.noprint = 1;
             options_.order = 1;
             options_.SpectralDensity.trigger = 0;
-            options_.periods = dataset_.nobs+100;
+            options_.periods = periods+100;
             if options_.kalman_algo > 2,
                 options_.kalman_algo = 1;
             end
             analytic_derivation = options_.analytic_derivation;
             options_.analytic_derivation = -2;
             info = stoch_simul(char(options_.varobs));
-            dataset_ = dseries(oo_.endo_simul(options_.varobs_id,100+1:end),dataset_.dates(1),dataset_.names,dataset_.tex);
-            %data_info.data=oo_.endo_simul(options_.varobs_id,100+1:end);
-            %                         datax=data;
+            dataset_ = dseries(oo_.endo_simul(options_.varobs_id,100+1:end)',dates('1Q1'), options_.varobs);            
             derivatives_info.no_DLIK=1;
-            [fval,DLIK,AHess,cost_flag,ys,trend_coeff,info,M_,options_,bayestopt_,oo_] = dsge_likelihood(params',dataset_,dataset_info,options_,M_,estim_params_,bayestopt_,oo_,derivatives_info);
+            bounds = prior_bounds(bayestopt_,options_);
+            [fval,DLIK,AHess,cost_flag,ys,trend_coeff,info,M_,options_,bayestopt_,oo_] = dsge_likelihood(params',dataset_,dataset_info,options_,M_,estim_params_,bayestopt_,bounds,oo_,derivatives_info);
 %                 fval = DsgeLikelihood(xparam1,data_info,options_,M_,estim_params_,bayestopt_,oo_);
             options_.analytic_derivation = analytic_derivation;
             AHess=-AHess;
diff --git a/matlab/independent_metropolis_hastings_core.m b/matlab/independent_metropolis_hastings_core.m
index 7a9a25c7998de36b7e361afc0b2c2d55f8362554..3e2ae2e42f6a95dcadd2af38e9c846d614f8a107 100644
--- a/matlab/independent_metropolis_hastings_core.m
+++ b/matlab/independent_metropolis_hastings_core.m
@@ -150,7 +150,7 @@ for b = fblck:nblck,
     j = 1;
     while j <= nruns(b)
         par = feval(ProposalFun, xparam1, proposal_covariance, n);
-        if all( par(:) > mh_bounds(:,1) ) && all( par(:) < mh_bounds(:,2) )
+        if all( par(:) > mh_bounds.lb ) && all( par(:) < mh_bounds.ub )
             try
                 logpost = - feval(TargetFun, par(:),varargin{:});
             catch,
diff --git a/matlab/initial_estimation_checks.m b/matlab/initial_estimation_checks.m
index c4cbf5ab96966991f47adfb95b929fbdeb6762e0..73637948c9ddb68e9e3019ccfce31317b2842cdf 100644
--- a/matlab/initial_estimation_checks.m
+++ b/matlab/initial_estimation_checks.m
@@ -1,4 +1,4 @@
-function DynareResults = initial_estimation_checks(objective_function,xparam1,DynareDataset,DatasetInfo,Model,EstimatedParameters,DynareOptions,BayesInfo,DynareResults)
+function DynareResults = initial_estimation_checks(objective_function,xparam1,DynareDataset,DatasetInfo,Model,EstimatedParameters,DynareOptions,BayesInfo,BoundsInfo,DynareResults)
 % function initial_estimation_checks(xparam1,gend,data,data_index,number_of_observations,no_more_missing_observations)
 % Checks data (complex values, ML evaluation, initial values, BK conditions,..)
 %
@@ -69,11 +69,18 @@ if any(BayesInfo.pshape) % if Bayesian estimation
     end
 end
 
+%% display warning if some parameters are still NaN
+test_for_deep_parameters_calibration(Model);
     
 % Evaluate the likelihood.
 ana_deriv = DynareOptions.analytic_derivation;
 DynareOptions.analytic_derivation=0;
-[fval,junk1,junk2,a,b,c,d] = feval(objective_function,xparam1,DynareDataset,DatasetInfo,DynareOptions,Model,EstimatedParameters,BayesInfo,DynareResults);
+if ~isequal(DynareOptions.mode_compute,11)
+  [fval,junk1,junk2,a,b,c,d] = feval(objective_function,xparam1,DynareDataset,DatasetInfo,DynareOptions,Model,EstimatedParameters,BayesInfo,BoundsInfo,DynareResults);
+else 
+    b=0;
+    fval = 0;
+end
 DynareOptions.analytic_derivation=ana_deriv;
 
 if DynareOptions.dsge_var || strcmp(func2str(objective_function),'non_linear_dsge_likelihood')
@@ -104,4 +111,6 @@ if any(abs(DynareResults.steady_state(BayesInfo.mfys))>1e-9) && (DynareOptions.p
     error('You should change something in your mod file...')
 end
 
-disp(['Initial value of the log posterior (or likelihood): ' num2str(-fval)]);
+if ~isequal(DynareOptions.mode_compute,11)
+    disp(['Initial value of the log posterior (or likelihood): ' num2str(-fval)]);
+end
diff --git a/matlab/insert_column_vector_in_a_matrix.m b/matlab/insert_column_vector_in_a_matrix.m
index 6ab517e3f81fd4389607dc1f482ceff595ae4d38..387a0d5406cbb61bd4217c94e396137b96d53490 100644
--- a/matlab/insert_column_vector_in_a_matrix.m
+++ b/matlab/insert_column_vector_in_a_matrix.m
@@ -58,9 +58,9 @@ end
 %$ end
 %$ 
 %$ if t(1)
-%$   t(2) = dyn_assert(A4,[A,b],1e-15);
-%$   t(3) = dyn_assert(A1,[b,A],1e-15);
-%$   t(4) = dyn_assert(A2,[A(:,1), b, A(:,2:end)],1e-15);
+%$   t(2) = dassert(A4,[A,b],1e-15);
+%$   t(3) = dassert(A1,[b,A],1e-15);
+%$   t(4) = dassert(A2,[A(:,1), b, A(:,2:end)],1e-15);
 %$ end
 %$ T = all(t);
 %@eof:1
\ No newline at end of file
diff --git a/matlab/insert_object_in_a_one_dimensional_cell_array.m b/matlab/insert_object_in_a_one_dimensional_cell_array.m
index 3eb82e0ba0caed883b9537f2a8565e5b91ec5cce..6532afbb77b496f88d1f46e4bfe53e9fd1ef4f1c 100644
--- a/matlab/insert_object_in_a_one_dimensional_cell_array.m
+++ b/matlab/insert_object_in_a_one_dimensional_cell_array.m
@@ -65,9 +65,9 @@ end
 %$ end
 %$
 %$ if t(1)
-%$   t(2) = dyn_assert(C4,[A;b]);
-%$   t(3) = dyn_assert(C1,[b;A],1e-15);
-%$   t(4) = dyn_assert(C2,[A(1); b; A(2:3)]);
+%$   t(2) = dassert(C4,[A;b]);
+%$   t(3) = dassert(C1,[b;A],1e-15);
+%$   t(4) = dassert(C2,[A(1); b; A(2:3)]);
 %$ end
 %$ T = all(t);
 %@eof:1
\ No newline at end of file
diff --git a/matlab/internals.m b/matlab/internals.m
index 273f1401ecf0f7d3a354123a2168cc26f3d4274b..4fc079ec28fd4f2064cfe3245f055a6ba48eb2bc 100644
--- a/matlab/internals.m
+++ b/matlab/internals.m
@@ -82,10 +82,10 @@ if strcmpi(flag,'--test')
         dynare_path = dynare_config([],0);
         number_of_matlab_routines = length(varargin);
         for i=1:number_of_matlab_routines
-            dynTest(varargin{i},dynare_path);
+            dtest(varargin{i},[dynare_path '..' filesep 'tests']);
         end
     else
-        disp('You have to specify at least one matlab routine after --test flag!')
+        disp('You have to specify at least one Matlab routine after --test flag!')
     end
     return
 end
@@ -126,8 +126,8 @@ if strcmpi(flag,'--load-mh-history') || strcmpi(flag,'--display-mh-history')
             disp(repmat('-',1,ltr));
             skipline()
             disp([' o Number of MCMC files is ' num2str(sum(o.MhDraws(:,2)))]);
-            disp([' o Number of draws is ' num2str(sum(o.MhDraws(:,1)))]);
-            disp([' o Overall acceptance ratio is ' num2str(oar(b)*100,'%5.2f') '%']);
+            disp([' o Number of draws per chain is ' num2str(sum(o.MhDraws(:,1)))]);
+            disp([' o Acceptance ratio in the current chain is ' num2str(oar(b)*100,'%5.2f') '%']);
             disp([' o Initial value of the posterior kernel is: ' num2str(oo.InitialLogPost(b),'%10.5f')])
             disp([' o Last value of the posterior kernel is: ' num2str(o.LastLogPost(b),'%10.5f')])
             disp([' o State of the chain:'])
@@ -137,7 +137,7 @@ if strcmpi(flag,'--load-mh-history') || strcmpi(flag,'--display-mh-history')
             d1s = size(d1,2);
             d2s = size(d2,2);
             c0 = repmat('   ',length(names)+2,1);
-            c1 = char(' ', repmat('+',1,size(cell2mat(names),2)), cell2mat(names));
+            c1 = char(' ', repmat('+',1,size(char(names),2)), char(names));
             s1 = char(' || ','++++',repmat(' || ', length(names),1));
             t1 = repmat(' ',1,d1s);
             if d1s<=7
@@ -179,9 +179,9 @@ if strcmpi(flag,'--info')
         dynInfo(varargin{1})
     else
         if nargin<2
-            disp('You have to specify a matlab routine after --info flag!')
+            disp('You have to specify a Matlab routine after --info flag!')
         else
-            disp('I can only show internal documentation for one matlab routine!')
+            disp('I can only show internal documentation for one Matlab routine!')
         end
     end
     return
diff --git a/matlab/kalman/likelihood/univariate_kalman_filter.m b/matlab/kalman/likelihood/univariate_kalman_filter.m
index 850119460de3c423ac9292dc54024880a80142ac..2f79f42a5caf4392c38c9033771c7b5dd00c42c9 100644
--- a/matlab/kalman/likelihood/univariate_kalman_filter.m
+++ b/matlab/kalman/likelihood/univariate_kalman_filter.m
@@ -111,7 +111,7 @@ smpl = last-start+1;
 % Initialize some variables.
 QQ   = R*Q*transpose(R);   % Variance of R times the vector of structural innovations.
 t    = start;              % Initialization of the time index.
-lik  = zeros(smpl,1);      % Initialization of the vector gathering the densities.
+lik  = zeros(smpl,pp);     % Initialization of the matrix gathering the densities at each time and each observable
 LIK  = Inf;                % Default value of the log likelihood.
 oldP = Inf;
 l2pi = log(2*pi);
@@ -178,7 +178,7 @@ while notsteady && t<=last
             if t>=no_more_missing_observations
                 K(:,i) = Ki;
             end
-            lik(s) = lik(s) + log(Fi) + prediction_error*prediction_error/Fi + l2pi;
+            lik(s,i) = log(Fi) + prediction_error*prediction_error/Fi + l2pi;
             if analytic_derivation,
                 if analytic_derivation==2,
                     [Da,DP,DLIKt,D2a,D2P, Hesst] = univariate_computeDLIK(k,i,z(i,:),Zflag,prediction_error,Ki,PZ,Fi,Da,DYss,DP,DH(d_index(i),:),notsteady,D2a,D2Yss,D2P);
@@ -214,7 +214,7 @@ while notsteady && t<=last
 end
 
 % Divide by two.
-lik(1:s) = .5*lik(1:s);
+lik(1:s,:) = .5*lik(1:s,:);
 if analytic_derivation,
     DLIK = DLIK/2;
     dlik = dlik/2;
@@ -234,22 +234,22 @@ if t <= last
             [tmp, tmp2] = univariate_kalman_filter_ss(Y,t,last,a,P,kalman_tol,T,H,Z,pp,Zflag, ...
                 analytic_derivation,Da,DT,DYss,DP,DH,asy_hess);
         end
-        lik(s+1:end)=tmp2{1};
+        lik(s+1:end,:)=tmp2{1};
         dlik(s+1:end,:)=tmp2{2};
         DLIK = DLIK + tmp{2};
         if analytic_derivation==2 || asy_hess,
             Hess = Hess + tmp{3};
         end
     else
-        [tmp, lik(s+1:end)] = univariate_kalman_filter_ss(Y,t,last,a,P,kalman_tol,T,H,Z,pp,Zflag);
+        [tmp, lik(s+1:end,:)] = univariate_kalman_filter_ss(Y,t,last,a,P,kalman_tol,T,H,Z,pp,Zflag);
     end
 end
 
 % Compute minus the log-likelihood.
 if presample > diffuse_periods
-    LIK = sum(lik(1+presample-diffuse_periods:end));
+    LIK = sum(sum(lik(1+presample-diffuse_periods:end,:)));
 else
-    LIK = sum(lik);
+    LIK = sum(sum(lik));
 end
 
 if analytic_derivation,
diff --git a/matlab/kalman/likelihood/univariate_kalman_filter_d.m b/matlab/kalman/likelihood/univariate_kalman_filter_d.m
index 7bf16ef5754a3f622d706b3a20ff6905cfd16242..ba047a2915a4baa0656178a6646853dc854d39dc 100644
--- a/matlab/kalman/likelihood/univariate_kalman_filter_d.m
+++ b/matlab/kalman/likelihood/univariate_kalman_filter_d.m
@@ -108,7 +108,7 @@ t    = start;              % Initialization of the time index.
 dlikk= zeros(smpl,1);      % Initialization of the vector gathering the densities.
 dLIK = Inf;                % Default value of the log likelihood.
 oldK = Inf;
-llik = NaN(smpl,pp);
+llik = zeros(smpl,pp);
 
 newRank = rank(Pinf,kalman_tol);
 l2pi = log(2*pi);
@@ -165,3 +165,4 @@ dlikk = .5*dlikk(1:s);
 llik  = .5*llik(1:s,:);
 
 dLIK = sum(dlikk(1+presample:end));
+dlikk = llik;
\ No newline at end of file
diff --git a/matlab/kalman/likelihood/univariate_kalman_filter_ss.m b/matlab/kalman/likelihood/univariate_kalman_filter_ss.m
index f5aef05af06955a471c4e2dc3d6874e3bf8ddbe5..0f6171055c408c1cd9cfb8fd92a05ef103432d3e 100644
--- a/matlab/kalman/likelihood/univariate_kalman_filter_ss.m
+++ b/matlab/kalman/likelihood/univariate_kalman_filter_ss.m
@@ -79,7 +79,7 @@ smpl = last-start+1;
 
 % Initialize some variables.
 t    = start;              % Initialization of the time index.
-likk = zeros(smpl,1);      % Initialization of the vector gathering the densities.
+likk = zeros(smpl,pp);      % Initialization of the vector gathering the densities.
 LIK  = Inf;                % Default value of the log likelihood.
 l2pi = log(2*pi);
 asy_hess=0;
@@ -131,7 +131,7 @@ while t<=last
             Ki = PPZ/Fi;
             a  = a + Ki*prediction_error;
             PP = PP - PPZ*Ki';
-            likk(s) = likk(s) + log(Fi) + prediction_error*prediction_error/Fi + l2pi;
+            likk(s,i) = log(Fi) + prediction_error*prediction_error/Fi + l2pi;
             if analytic_derivation,
                 if analytic_derivation==2,
                     [Da,DPP,DLIKt,D2a,D2PP, Hesst] = univariate_computeDLIK(k,i,Z(i,:),Zflag,prediction_error,Ki,PPZ,Fi,Da,DYss,DPP,DH(i,:),0,D2a,D2Yss,D2PP);
@@ -159,7 +159,7 @@ end
 
 likk = .5*likk;
 
-LIK = sum(likk);
+LIK = sum(sum(likk));
 if analytic_derivation,
     dlikk = dlikk/2;
     DLIK = DLIK/2;
diff --git a/matlab/lmmcp/dyn_lmmcp.m b/matlab/lmmcp/dyn_lmmcp.m
index ce3db1c7b286591e5d6cf373fc15449f2087d66b..39ed96d89267579acb231d60057cbbf9c26e94ec 100644
--- a/matlab/lmmcp/dyn_lmmcp.m
+++ b/matlab/lmmcp/dyn_lmmcp.m
@@ -72,6 +72,6 @@ func_handle = @(x) dyn_lmmcp_func(x,model_dynamic, Y0, YT, exo_simul, ...
                                   lead_lag_incidence, i_cols_A1, i_cols_1, ...
                                   i_cols_T, i_cols_j,nnzA,eq_index);
 
-[x, info] = lmmcp(func_handle,x,LB,UB);
+[x, info] = lmmcp(func_handle,x,LB,UB,options.lmmcp);
 
 endo_simul = [Y0 reshape(x,ny,periods) YT];
\ No newline at end of file
diff --git a/matlab/load_csv_file_data.m b/matlab/load_csv_file_data.m
index 7317ca33084f35d0c54c7cb566eb8dc7e8f2bf80..639ed5b30a82115e72408089a4460d01f6b8d2f3 100644
--- a/matlab/load_csv_file_data.m
+++ b/matlab/load_csv_file_data.m
@@ -42,14 +42,20 @@ assert(exist(file, 'file') == 2, ['load_csv_file_data: I can''t find file ' file
 
 if isoctave
     if ~user_has_octave_forge_package('io')
-        error('The io package is required to read CSV files from Octave')
+        try
+            pkg load io
+        catch
+            error(['The io package is required to read CSV files from Octave. ' ...
+                'It can be installed by running the following from the Octave ' ...
+                ' command line: pkg install -forge io']);
+        end
     end
     A = csv2cell(file);
     [data, T, L] = parsecell(A);
     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 = {};
diff --git a/matlab/load_m_file_data.m b/matlab/load_m_file_data.m
index 20e1b28a77b57a1748abb9575af1db29c33e305b..5c2e47881fd817154139fc5db5b85cb9dedc6b5f 100644
--- a/matlab/load_m_file_data.m
+++ b/matlab/load_m_file_data.m
@@ -86,30 +86,38 @@ data = [];
 varlist = {};
 
 if isempty(varlist0)
-    for i=1:length(list_of_variables)
-        if isequal(list_of_variables(i).name,'freq') || isequal(list_of_variables(i).name,'time') || isequal(list_of_variables(i).name,'data') ...
-                || isequal(list_of_variables(i).name,'varlist') ...
-                || isequal(list_of_variables(i).name,'varlist0') ...
-                || isequal(list_of_variables(i).name,'list_of_variables') ...
-                || isequal(list_of_variables(i).name,'tex') ...                
+    for current_variable_index=1:length(list_of_variables)
+        if isequal(list_of_variables(current_variable_index).name,'freq') ...
+                || isequal(list_of_variables(current_variable_index).name,'time') ...
+                || isequal(list_of_variables(current_variable_index).name,'data') ...
+                || isequal(list_of_variables(current_variable_index).name,'varlist') ...
+                || isequal(list_of_variables(current_variable_index).name,'varlist0') ...
+                || isequal(list_of_variables(current_variable_index).name,'list_of_variables') ...
+                || isequal(list_of_variables(current_variable_index).name,'tex') ...
             continue
         end
-        if list_of_variables(i).global || list_of_variables(i).persistent
+        if list_of_variables(current_variable_index).global || list_of_variables(current_variable_index).persistent
+            % A variable cannot be a global or persistent variable.
             continue
         end
-        if list_of_variables(i).complex || ~strcmp(list_of_variables(i).class,'double')
+        if list_of_variables(current_variable_index).complex || ~strcmp(list_of_variables(current_variable_index).class,'double')
+            % A variable cannot be complex.
+            continue
+        end
+        if list_of_variables(current_variable_index).size(2)>1
+            % A variable must be passed as a column vector.
             continue
         end
         try
-            eval(['data = [data, ' list_of_variables(i).name '];'])
-            eval(['varlist = {varlist{:}, ''' list_of_variables(i).name '''};']) 
+            eval(['data = [data, ' list_of_variables(current_variable_index).name '];'])
+            eval(['varlist = {varlist{:}, ''' list_of_variables(current_variable_index).name '''};'])
         catch
             error(['load_m_file:: All the vectors (variables) in ' inputname(1) ' must have the same number of rows (observations)!'])
         end
     end
 else
-    for i=1:length(varlist0)
-       eval(['data = [data, ' varlist0{i} '];']) 
+    for current_variable_index=1:length(varlist0)
+       eval(['data = [data, ' varlist0{current_variable_index} '];'])
     end
     varlist = varlist0;
 end
@@ -138,13 +146,13 @@ end
 %$ end
 %$
 %$ % Check the results.
-%$ t(2) = dyn_assert(freq,4);
-%$ t(3) = dyn_assert(isa(init,'dates'),1);
-%$ t(4) = dyn_assert(init.freq,4);
-%$ t(5) = dyn_assert(init.time,[1938 4]);
-%$ t(6) = dyn_assert(varlist,{'azert';'yuiop'});
-%$ t(7) = dyn_assert(tex,{'azert';'yuiop'});
-%$ t(8) = dyn_assert(data(:,1),[1;2;3;4;5]);
-%$ t(9) = dyn_assert(data(:,2),[2;3;4;5;6]);
+%$ t(2) = dassert(freq,4);
+%$ t(3) = dassert(isa(init,'dates'),1);
+%$ t(4) = dassert(init.freq,4);
+%$ t(5) = dassert(init.time,[1938 4]);
+%$ t(6) = dassert(varlist,{'azert';'yuiop'});
+%$ t(7) = dassert(tex,{'azert';'yuiop'});
+%$ t(8) = dassert(data(:,1),[1;2;3;4;5]);
+%$ t(9) = dassert(data(:,2),[2;3;4;5;6]);
 %$ T = all(t);
 %@eof:1
diff --git a/matlab/load_m_file_data_legacy.m b/matlab/load_m_file_data_legacy.m
new file mode 100644
index 0000000000000000000000000000000000000000..9442abfac94db2ca2e65cbb69b13c4784747de8a
--- /dev/null
+++ b/matlab/load_m_file_data_legacy.m
@@ -0,0 +1,47 @@
+function data  = load_m_file_data_legacy(datafile, varobs)
+
+% 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/>.
+
+cXDHdrXnqo5KwwVpTRuc6OprAW = datafile(1:end-2);
+[pathtocXDHdrXnqo5KwwVpTRuc6OprAW,cXDHdrXnqo5KwwVpTRuc6OprAW,junk] = fileparts(cXDHdrXnqo5KwwVpTRuc6OprAW);
+
+if ~isempty(pathtocXDHdrXnqo5KwwVpTRuc6OprAW)
+    OvMuQsJgjwzYG5Pni0TzU8Acb2YBJva = pwd();
+    cd(pathtocXDHdrXnqo5KwwVpTRuc6OprAW);
+end
+
+eval(cXDHdrXnqo5KwwVpTRuc6OprAW);
+
+if ~isempty(pathtocXDHdrXnqo5KwwVpTRuc6OprAW)
+    cd(OvMuQsJgjwzYG5Pni0TzU8Acb2YBJva);
+end
+
+try
+    data = dseries(eval(cellofstring4eval(varobs)),[],varobs);
+catch
+    errmsg = sprintf('makedataset: Check that all the variables listed in varobs exist in %s and have the same number of observations.',datafile);
+    error(errmsg)
+end
+
+function str = cellofstring4eval(A)
+    n = length(A);
+    str = '[';
+    for i=1:n-1
+        str = [str, A{i}, ','];
+    end
+    str = [str, A{n}, ']'];
\ No newline at end of file
diff --git a/matlab/load_mat_file_data.m b/matlab/load_mat_file_data.m
index 955d996851c452e55858d3945cc57473ee269024..98825a49a3113f4648a3aa619b27f067b7a0bd90 100644
--- a/matlab/load_mat_file_data.m
+++ b/matlab/load_mat_file_data.m
@@ -108,14 +108,14 @@ end
 %$ end
 %$
 %$ % Check the results.
-%$ t(2) = dyn_assert(freq,12);
-%$ t(3) = dyn_assert(isa(init,'dates'),1);
-%$ t(4) = dyn_assert(init.freq,12);
-%$ t(5) = dyn_assert(init.time,[1938 11]);
-%$ t(6) = dyn_assert(varlist,{'hagop';'bedros'});
-%$ t(7) = dyn_assert(varlist,{'hagop';'bedros'});
-%$ t(8) = dyn_assert(data(:,1),[1;2;3;4;5]);
-%$ t(9) = dyn_assert(data(:,2),[2;3;4;5;6]);
+%$ t(2) = dassert(freq,12);
+%$ t(3) = dassert(isa(init,'dates'),true);
+%$ t(4) = dassert(init.freq,12);
+%$ t(5) = dassert(init.time,[1938 11]);
+%$ t(6) = dassert(varlist,{'hagop';'bedros'});
+%$ t(7) = dassert(varlist,{'hagop';'bedros'});
+%$ t(8) = dassert(data(:,1),[1;2;3;4;5]);
+%$ t(9) = dassert(data(:,2),[2;3;4;5;6]);
 %$ T = all(t);
 %@eof:1
 
@@ -142,13 +142,13 @@ end
 %$ end
 %$
 %$ % Check the results.
-%$ t(2) = dyn_assert(freq,12);
-%$ t(3) = dyn_assert(isa(init,'dates'),1);
-%$ t(4) = dyn_assert(init.freq,12);
-%$ t(5) = dyn_assert(init.time,[1938 11]);
-%$ t(6) = dyn_assert(varlist,{'hagop';'bedros'});
-%$ t(7) = dyn_assert(varlist,{'hagop';'bedros'});
-%$ t(8) = dyn_assert(data(:,1),[1;2;3;4;5]);
-%$ t(9) = dyn_assert(data(:,2),[2;3;4;5;6]);
+%$ t(2) = dassert(freq,12);
+%$ t(3) = dassert(isa(init,'dates'),true);
+%$ t(4) = dassert(init.freq,12);
+%$ t(5) = dassert(init.time,[1938 11]);
+%$ t(6) = dassert(varlist,{'hagop';'bedros'});
+%$ t(7) = dassert(varlist,{'hagop';'bedros'});
+%$ t(8) = dassert(data(:,1),[1;2;3;4;5]);
+%$ t(9) = dassert(data(:,2),[2;3;4;5;6]);
 %$ T = all(t);
 %@eof:2
diff --git a/matlab/lyapunov_symm.m b/matlab/lyapunov_symm.m
index bb78d3932a64f8586c719c76d828af31232841ce..b694b1354a8b5e40c7822890fc3dd3995b481276 100644
--- a/matlab/lyapunov_symm.m
+++ b/matlab/lyapunov_symm.m
@@ -1,4 +1,4 @@
-function [x,u] = lyapunov_symm(a,b,third_argument,lyapunov_complex_threshold,method, R)
+function [x,u] = lyapunov_symm(a,b,third_argument,lyapunov_complex_threshold,method, R, debug)  % --*-- Unitary tests --*--
 % Solves the Lyapunov equation x-a*x*a' = b, for b and x symmetric matrices.
 % If a has some unit roots, the function computes only the solution of the stable subsystem.
 %  
@@ -12,21 +12,22 @@ function [x,u] = lyapunov_symm(a,b,third_argument,lyapunov_complex_threshold,met
 %   lyapunov_complex_threshold  [double]    scalar, complex block threshold for the upper triangular matrix T.
 %   method                      [integer]   Scalar, if method=0 [default] then U, T, n and k are not persistent.  
 %                                                      method=1 then U, T, n and k are declared as persistent 
-%                                                               variables and the schur decomposition is triggered.    
+%                                                               variables and the Schur decomposition is triggered.    
 %                                                      method=2 then U, T, n and k are declared as persistent 
-%                                                               variables and the schur decomposition is not performed.
+%                                                               variables and the Schur decomposition is not performed.
 %                                                      method=3 fixed point method
 % OUTPUTS
 %   x:      [double]    m*m solution matrix of the lyapunov equation, where m is the dimension of the stable subsystem.
 %   u:      [double]    Schur vectors associated with unit roots  
 %
 % ALGORITHM
-%   Uses reordered Schur decomposition
+%   Uses reordered Schur decomposition (Bartels-Stewart algorithm)
+%   [method<3] or a fixed point algorithm (method==4)
 %
 % SPECIAL REQUIREMENTS
 %   None
 
-% Copyright (C) 2006-2012 Dynare Team
+% Copyright (C) 2006-2014 Dynare Team
 %
 % This file is part of Dynare.
 %
@@ -42,22 +43,29 @@ function [x,u] = lyapunov_symm(a,b,third_argument,lyapunov_complex_threshold,met
 %
 % You should have received a copy of the GNU General Public License
 % along with Dynare.  If not, see <http://www.gnu.org/licenses/>.
-if nargin<5
+
+if nargin<5 || isempty(method)
     method = 0;
 end
 
+if nargin<7
+    debug = 0;
+end
+
 if method == 3
     persistent X method1;
     if ~isempty(method1)
         method = method1;
     end;
     tol = third_argument;
-    fprintf(' [methode=%d] ',method);
+    if debug
+        fprintf('lyapunov_symm:: [method=%d] \n',method);
+    end
     if method == 3
         %tol = 1e-10;
         it_fp = 0;
         evol = 100;
-        if isempty(X)
+        if isempty(X) || length(X)~=length(b)
             X = b;
             max_it_fp = 2000;
         else
@@ -72,9 +80,11 @@ if method == 3
             %evol = max(sum(abs(X - X_old)')); %norm_inf
             it_fp = it_fp + 1;
         end;
-        fprintf('lyapunov it_fp=%d evol=%g\n',it_fp,evol);
+        if debug
+            fprintf('lyapunov_symm:: lyapunov fixed_point iterations=%d norm=%g\n',it_fp,evol);
+        end
         if it_fp >= max_it_fp
-            disp(['convergence not achieved in solution of Lyapunov equation after ' int2str(it_fp) ' iterations, switching method from 3 to 0']);
+            disp(['lyapunov_symm:: convergence not achieved in solution of Lyapunov equation after ' int2str(it_fp) ' iterations, switching method from 3 to 0']);
             method1 = 0;
             method = 0;
         else
@@ -173,3 +183,116 @@ if i == 1
 end
 x = U(:,k+1:end)*x*U(:,k+1:end)';
 u = U(:,1:k);
+
+%@test:1
+%$ t = NaN(10,1);
+%$ lyapunov_complex_threshold = 1e-15;
+%$ qz_zero_threshold = 1e-6;
+%$ qz_criterium=1-qz_zero_threshold;
+%$ lyapunov_fixed_point_tol = 1e-10;
+%$ lyapunov_doubling_tol = 1e-16;
+%$
+%$ n_small=8;
+%$ m_small=10;
+%$ T_small=randn(n_small,n_small);
+%$ T_small=0.99*T_small/max(abs(eigs(T_small)));
+%$ tmp2=randn(m_small,m_small);
+%$ Q_small=tmp2*tmp2';
+%$ R_small=randn(n_small,m_small);
+%$ 
+%$ n_large=9;
+%$ m_large=11;
+%$ T_large=randn(n_large,n_large);
+%$ T_large=0.99*T_large/max(abs(eigs(T_large)));
+%$ tmp2=randn(m_large,m_large);
+%$ Q_large=tmp2*tmp2';
+%$ R_large=randn(n_large,m_large);
+%$ 
+%$ % DynareOptions.lyapunov_fp == 1
+%$ try
+%$    Pstar1_small = lyapunov_symm(T_small,R_small*Q_small*R_small',lyapunov_fixed_point_tol,lyapunov_fixed_point_tol,3, [], 0);
+%$    Pstar1_large = lyapunov_symm(T_large,R_large*Q_large*R_large',lyapunov_fixed_point_tol,lyapunov_fixed_point_tol,3, [], 0);
+%$    t(1) = 1;
+%$ catch
+%$    t(1) = 0;
+%$ end
+%$
+%$ % Dynareoptions.lyapunov_db == 1
+%$ try
+%$    Pstar2_small = disclyap_fast(T_small,R_small*Q_small*R_small',lyapunov_doubling_tol);
+%$    Pstar2_large = disclyap_fast(T_large,R_large*Q_large*R_large',lyapunov_doubling_tol);
+%$    t(2) = 1;
+%$ catch
+%$    t(2) = 0;
+%$ end
+%$
+%$ % Dynareoptions.lyapunov_srs == 1
+%$ if (isoctave && user_has_octave_forge_package('control')) || (~isoctave && user_has_matlab_license('control_toolbox'))
+%$     try
+%$        Pstar3_small = lyapunov_symm(T_small,Q_small,lyapunov_fixed_point_tol,lyapunov_complex_threshold,4,R_small,0);
+%$        Pstar3_large = lyapunov_symm(T_large,Q_large,lyapunov_fixed_point_tol,lyapunov_complex_threshold,4,R_large,0);
+%$        t(3) = 1;
+%$     catch
+%$        t(3) = 0;
+%$     end
+%$ else
+%$     t(3) = 1;
+%$ end
+%$
+%$ % Standard
+%$ try
+%$     Pstar4_small = lyapunov_symm(T_small,R_small*Q_small*R_small',qz_criterium, lyapunov_complex_threshold, [], [], 0);
+%$     Pstar4_large = lyapunov_symm(T_large,R_large*Q_large*R_large',qz_criterium, lyapunov_complex_threshold, [], [], 0);
+%$    t(4) = 1;
+%$ catch
+%$    t(4) = 0;
+%$ end
+%$
+%$ % Test the results.
+%$
+%$ if max(max(abs(Pstar1_small-Pstar2_small)))>1e-8
+%$    t(5) = 0;
+%$ else
+%$    t(5) = 1;
+%$ end
+%$
+%$ if (isoctave && user_has_octave_forge_package('control')) || (~isoctave && user_has_matlab_license('control_toolbox'))
+%$    if max(max(abs(Pstar1_small-Pstar3_small)))>1e-8
+%$       t(6) = 0;
+%$    else
+%$       t(6) = 1;
+%$    end
+%$ else
+%$    t(6) = 1;
+%$ end
+%$
+%$ if max(max(abs(Pstar1_small-Pstar4_small)))>1e-8
+%$    t(7) = 0;
+%$ else
+%$    t(7) = 1;
+%$ end
+%$
+%$ if max(max(abs(Pstar1_large-Pstar2_large)))>1e-8
+%$    t(8) = 0;
+%$ else
+%$    t(8) = 1;
+%$ end
+%$
+%$ if (isoctave && user_has_octave_forge_package('control')) || (~isoctave && user_has_matlab_license('control_toolbox'))
+%$    if max(max(abs(Pstar1_large-Pstar3_large)))>1e-8
+%$       t(9) = 0;
+%$    else
+%$       t(9) = 1;
+%$    end
+%$ else
+%$    t(9) = 1;
+%$ end
+%$
+%$ if max(max(abs(Pstar1_large-Pstar4_large)))>1e-8
+%$    t(10) = 0;
+%$ else
+%$    t(10) = 1;
+%$ end
+%$
+%$ T = all(t);
+%@eof:1
\ No newline at end of file
diff --git a/matlab/maximize_prior_density.m b/matlab/maximize_prior_density.m
index 09cb3d774bebefd68a985beb131b289d813772b5..01e9ffc8db93af8c55f38de47f04e9a4a2bdd105 100644
--- a/matlab/maximize_prior_density.m
+++ b/matlab/maximize_prior_density.m
@@ -36,7 +36,6 @@ number_of_estimated_parameters = length(iparams);
 H0 = 1e-4*eye(number_of_estimated_parameters);
 crit = 1e-7;
 nit = 1000;
-verbose = 2;
 gradient_method = 2;
 gradient_epsilon = 1e-6;
 
diff --git a/matlab/metropolis_hastings_initialization.m b/matlab/metropolis_hastings_initialization.m
index 7fb056553842a8387c9c1a110d22ea7bc32dfd25..e8f4d0ef156fd80d62af87b542539d077bd07f62 100644
--- a/matlab/metropolis_hastings_initialization.m
+++ b/matlab/metropolis_hastings_initialization.m
@@ -108,9 +108,9 @@ if ~options_.load_mh_file && ~options_.mh_recover
             trial = 1;
             while validate == 0 && trial <= 10
                 candidate = rand_multivariate_normal( transpose(xparam1), d * options_.mh_init_scale, npar);
-                if all(candidate(:) > mh_bounds(:,1)) && all(candidate(:) < mh_bounds(:,2)) 
+                if all(candidate(:) > mh_bounds.lb) && all(candidate(:) < mh_bounds.ub) 
                     ix2(j,:) = candidate;
-                    ilogpo2(j) = - feval(TargetFun,ix2(j,:)',dataset_,dataset_info,options_,M_,estim_params_,bayestopt_,oo_);
+                    ilogpo2(j) = - feval(TargetFun,ix2(j,:)',dataset_,dataset_info,options_,M_,estim_params_,bayestopt_,mh_bounds,oo_);
                     if ~isfinite(ilogpo2(j)) % if returned log-density is
                                              % Inf or Nan (penalized value)
                         validate = 0;
@@ -150,9 +150,9 @@ if ~options_.load_mh_file && ~options_.mh_recover
     else% Case 2: one chain (we start from the posterior mode)
         fprintf(fidlog,['  Initial values of the parameters:\n']);
         candidate = transpose(xparam1(:));%
-        if all(candidate(:) > mh_bounds(:,1)) && all(candidate(:) < mh_bounds(:,2)) 
+        if all(candidate(:) > mh_bounds.lb) && all(candidate(:) < mh_bounds.ub) 
             ix2 = candidate;
-            ilogpo2 = - feval(TargetFun,ix2',dataset_,dataset_info,options_,M_,estim_params_,bayestopt_,oo_);
+            ilogpo2 = - feval(TargetFun,ix2',dataset_,dataset_info,options_,M_,estim_params_,bayestopt_,mh_bounds,oo_);
             disp('Estimation::mcmc: Initialization at the posterior mode.')
             skipline()
             fprintf(fidlog,['    Blck ' int2str(1) 'params:\n']);
diff --git a/matlab/missing/corrcoef/corrcoef.m b/matlab/missing/corrcoef/corrcoef.m
new file mode 100644
index 0000000000000000000000000000000000000000..c918c61043ddf89d11f1556f2ec315b651389859
--- /dev/null
+++ b/matlab/missing/corrcoef/corrcoef.m
@@ -0,0 +1,387 @@
+function [R,sig,ci1,ci2,nan_sig] = corrcoef(X,Y,varargin)
+% CORRCOEF calculates the correlation matrix from pairwise correlations.
+%   The input data can contain missing values encoded with NaN.
+%   Missing data (NaN's) are handled by pairwise deletion [15].
+%   In order to avoid possible pitfalls, use case-wise deletion or
+%   or check the correlation of NaN's with your data (see below).
+%   A significance test for testing the Hypothesis
+%   'correlation coefficient R is significantly different to zero'
+%   is included.
+%
+% [...] = CORRCOEF(X);
+%      calculates the (auto-)correlation matrix of X
+% [...] = CORRCOEF(X,Y);
+%      calculates the crosscorrelation between X and Y
+%
+% [...] = CORRCOEF(..., Mode);
+%       Mode='Pearson' or 'parametric' [default]
+%               gives the correlation coefficient
+%               also known as the 'product-moment coefficient of correlation'
+%               or 'Pearson''s correlation' [1]
+%       Mode='Spearman'     gives 'Spearman''s Rank Correlation Coefficient'
+%               This replaces SPEARMAN.M
+%       Mode='Rank'         gives a nonparametric Rank Correlation Coefficient
+%               This is the "Spearman rank correlation with proper handling of ties"
+%               This replaces RANKCORR.M
+%
+% [...] = CORRCOEF(..., param1, value1, param2, value2, ... );
+%	param       value
+%	'Mode'		type of correlation
+%		'Pearson','parametric'
+%		'Spearman'
+%		'rank'
+%	'rows'		how do deal with missing values encoded as NaN's.
+%		'complete': remove all rows with at least one NaN
+%		'pairwise': [default]
+%	'alpha'		0.01	: significance level to compute confidence interval
+%
+% [R,p,ci1,ci2,nansig] = CORRCOEF(...);
+%   R is the correlation matrix
+%	R(i,j) is the correlation coefficient r between X(:,i) and Y(:,j)
+%  p    gives the significance of R
+%	It tests the null hypothesis that the product moment correlation coefficient is zero
+%       using Student's t-test on the statistic t = r*sqrt(N-2)/sqrt(1-r^2)
+%       where N is the number of samples (Statistics, M. Spiegel, Schaum series).
+%  p > alpha: do not reject the Null hypothesis: 'R is zero'.
+%  p < alpha: The alternative hypothesis 'R is larger than zero' is true with probability (1-alpha).
+%  ci1	lower (1-alpha) confidence interval
+%  ci2	upper (1-alpha) confidence interval
+%	If no alpha is provided, the default alpha is 0.01. This can be changed with function flag_implicit_significance.
+%  nan_sig  p-value whether H0: 'NaN''s are not correlated' could be correct
+%       if nan_sig < alpha, H1 ('NaNs are correlated') is very likely.
+%
+% The result is only valid if the occurence of NaN's is uncorrelated. In
+% order to avoid this pitfall, the correlation of NaN's should be checked
+% or case-wise deletion should be applied.
+%   Case-Wise deletion can be implemented
+%    ix = ~any(isnan([X,Y]),2);
+%    [...] = CORRCOEF(X(ix,:),Y(ix,:),...);
+%
+%  Correlation (non-random distribution) of NaN's can be checked with
+%       [nan_R,nan_sig]=corrcoef(X,isnan(X))
+%   or  [nan_R,nan_sig]=corrcoef([X,Y],isnan([X,Y]))
+%   or  [R,p,ci1,ci2] = CORRCOEF(...);
+%
+% Further recommandation related to the correlation coefficient:
+% + LOOK AT THE SCATTERPLOTS to make sure that the relationship is linear
+% + Correlation is not causation because
+%	it is not clear which parameter is 'cause' and which is 'effect' and
+%       the observed correlation between two variables might be due to the action of other, unobserved variables.
+%
+% see also: SUMSKIPNAN, COVM, COV, COR, SPEARMAN, RANKCORR, RANKS,
+%       PARTCORRCOEF, flag_implicit_significance
+%
+% REFERENCES:
+% on the correlation coefficient
+% [ 1] http://mathworld.wolfram.com/CorrelationCoefficient.html
+% [ 2] http://www.geography.btinternet.co.uk/spearman.htm
+% [ 3] Hogg, R. V. and Craig, A. T. Introduction to Mathematical Statistics, 5th ed.  New York: Macmillan, pp. 338 and 400, 1995.
+% [ 4] Lehmann, E. L. and D'Abrera, H. J. M. Nonparametrics: Statistical Methods Based on Ranks, rev. ed. Englewood Cliffs, NJ: Prentice-Hall, pp. 292, 300, and 323, 1998.
+% [ 5] Press, W. H.; Flannery, B. P.; Teukolsky, S. A.; and Vetterling, W. T. Numerical Recipes in FORTRAN: The Art of Scientific Computing, 2nd ed. Cambridge, England: Cambridge University Press, pp. 634-637, 1992
+% [ 6] http://mathworld.wolfram.com/SpearmanRankCorrelationCoefficient.html
+% on the significance test of the correlation coefficient
+% [11] http://www.met.rdg.ac.uk/cag/STATS/corr.html
+% [12] http://www.janda.org/c10/Lectures/topic06/L24-significanceR.htm
+% [13] http://faculty.vassar.edu/lowry/ch4apx.html
+% [14] http://davidmlane.com/hyperstat/B134689.html
+% [15] http://www.statsoft.com/textbook/stbasic.html%Correlations
+% others
+% [20] http://www.tufts.edu/~gdallal/corr.htm
+% [21] Fisher transformation http://en.wikipedia.org/wiki/Fisher_transformation
+
+%       $Id: corrcoef.m 9387 2011-12-15 10:42:14Z schloegl $
+%       Copyright (C) 2000-2004,2008,2009,2011 by Alois Schloegl <alois.schloegl@gmail.com>
+%       Copyright (C) 2014 Dynare Team
+%       This function is part of the NaN-toolbox
+%       http://pub.ist.ac.at/~schloegl/matlab/NaN/
+
+%    This program 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.
+%
+%    This program 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 this program.  If not, see <http://www.gnu.org/licenses/>.
+
+% Features:
+% + handles missing values (encoded as NaN's)
+%       + pairwise deletion of missing data
+%       + checks independence of missing values (NaNs)
+% + parametric and non-parametric (rank) correlation
+%       + Pearson's correlation
+%       + Spearman's rank correlation
+%       + Rank correlation (non-parametric, Spearman rank correlation with proper handling of ties)
+% + is fast, using an efficient algorithm O(n.log(n)) for calculating the ranks
+% + significance test for null-hypthesis: r=0
+% + confidence interval included
+% - rank correlation works for cell arrays, too (no check for missing values).
+% + compatible with Octave and Matlab
+
+global FLAG_NANS_OCCURED;
+
+NARG = nargout;	% needed because nargout is not reentrant in Octave, and corrcoef is recursive
+mode = [];
+
+if nargin==1
+        Y = [];
+        Mode='Pearson';
+elseif nargin==0
+        fprintf(2,'Error CORRCOEF: Missing argument(s)\n');
+elseif nargin>1
+        if ischar(Y)
+                varg = [Y,varargin];
+                Y=[];
+        else
+                varg = varargin;
+        end;
+
+        if length(varg)<1,
+                Mode = 'Pearson';
+        elseif length(varg)==1,
+                Mode = varg{1};
+        else
+                for k = 2:2:length(varg),
+                        mode = setfield(mode,lower(varg{k-1}),varg{k});
+                end;
+                if isfield(mode,'mode')
+                        Mode = mode.mode;
+                end;
+        end;
+end;
+if isempty(Mode) Mode='pearson'; end;
+Mode=[Mode,'        '];
+
+
+
+FLAG_WARNING = warning;		% save warning status
+warning('off');
+
+[r1,c1]=size(X);
+if ~isempty(Y)
+        [r2,c2]=size(Y);
+        if r1~=r2,
+                fprintf(2,'Error CORRCOEF: X and Y must have the same number of observations (rows).\n');
+                return;
+        end;
+        NN = real(~isnan(X)')*real(~isnan(Y));
+else
+        [r2,c2]=size(X);
+        NN = real(~isnan(X)')*real(~isnan(X));
+end;
+
+%%%%% generate combinations using indices for pairwise calculation of the correlation
+YESNAN = any(isnan(X(:))) | any(isnan(Y(:)));
+if YESNAN,
+    FLAG_NANS_OCCURED=(1==1);
+    if isfield(mode,'rows')
+        if strcmp(mode.rows,'complete')
+            ix = ~any([X,Y],2);
+            X = X(ix,:);
+            if ~isempty(Y)
+                Y = Y(ix,:);
+            end;
+            YESNAN = 0;
+            NN = size(X,1);
+        elseif strcmp(mode.rows,'all')
+            fprintf(1,'Warning: data contains NaNs, rows=pairwise is used.');
+            %%NN(NN < size(X,1)) = NaN;
+        elseif strcmp(mode.rows,'pairwise')
+            %%% default
+        end;
+    end;
+end;
+if isempty(Y),
+        IX = ones(c1)-diag(ones(c1,1));
+        [jx, jy ] = find(IX);
+        [jxo,jyo] = find(IX);
+    R = eye(c1);
+else
+        IX = sparse([],[],[],c1+c2,c1+c2,c1*c2);
+        IX(1:c1,c1+(1:c2)) = 1;
+        [jx,jy] = find(IX);
+
+        IX = ones(c1,c2);
+        [jxo,jyo] = find(IX);
+    R = zeros(c1,c2);
+end;
+
+if strcmp(lower(Mode(1:7)),'pearson');
+        % see http://mathworld.wolfram.com/CorrelationCoefficient.html
+    if ~YESNAN,
+                [S,N,SSQ] = sumskipnan(X,1);
+                if ~isempty(Y),
+                    [S2,N2,SSQ2] = sumskipnan(Y,1);
+                        CC = X'*Y;
+                        M1 = S./N;
+                        M2 = S2./N2;
+                        cc = CC./NN - M1'*M2;
+                        R  = cc./sqrt((SSQ./N-M1.*M1)'*(SSQ2./N2-M2.*M2));
+                else
+                        CC = X'*X;
+                        M  = S./N;
+                        cc = CC./NN - M'*M;
+                        v  = SSQ./N - M.*M; %max(N-1,0);
+                        R  = cc./sqrt(v'*v);
+                end;
+        else
+                if ~isempty(Y),
+                        X  = [X,Y];
+                end;
+                for k = 1:length(jx),
+                        %ik = ~any(isnan(X(:,[jx(k),jy(k)])),2);
+                        ik = ~isnan(X(:,jx(k))) & ~isnan(X(:,jy(k)));
+                        [s,n,s2] = sumskipnan(X(ik,[jx(k),jy(k)]),1);
+                        v  = (s2-s.*s./n)./n;
+                        cc = X(ik,jx(k))'*X(ik,jy(k));
+                        cc = cc/n(1) - prod(s./n);
+                        %r(k) = cc./sqrt(prod(v));
+                        R(jxo(k),jyo(k)) = cc./sqrt(prod(v));
+                end;
+    end
+
+elseif strcmp(lower(Mode(1:4)),'rank');
+        % see [ 6] http://mathworld.wolfram.com/SpearmanRankCorrelationCoefficient.html
+    if ~YESNAN,
+                if isempty(Y)
+                    R = corrcoef(ranks(X));
+                else
+                        R = corrcoef(ranks(X),ranks(Y));
+                end;
+        else
+                if ~isempty(Y),
+                        X = [X,Y];
+                end;
+                for k = 1:length(jx),
+                        %ik = ~any(isnan(X(:,[jx(k),jy(k)])),2);
+                        ik = ~isnan(X(:,jx(k))) & ~isnan(X(:,jy(k)));
+                        il = ranks(X(ik,[jx(k),jy(k)]));
+                        R(jxo(k),jyo(k)) = corrcoef(il(:,1),il(:,2));
+                end;
+        X = ranks(X);
+    end;
+
+elseif strcmp(lower(Mode(1:8)),'spearman');
+        % see [ 6] http://mathworld.wolfram.com/SpearmanRankCorrelationCoefficient.html
+        if ~isempty(Y),
+                X = [X,Y];
+        end;
+
+        n = repmat(nan,c1,c2);
+
+        if ~YESNAN,
+                iy = ranks(X);	%  calculates ranks;
+
+                for k = 1:length(jx),
+                        [R(jxo(k),jyo(k)),n(jxo(k),jyo(k))] = sumskipnan((iy(:,jx(k)) - iy(:,jy(k))).^2);	% NN is the number of non-missing values
+                end;
+        else
+                for k = 1:length(jx),
+                        %ik = ~any(isnan(X(:,[jx(k),jy(k)])),2);
+                        ik = ~isnan(X(:,jx(k))) & ~isnan(X(:,jy(k)));
+                        il = ranks(X(ik,[jx(k),jy(k)]));
+                        % NN is the number of non-missing values
+                        [R(jxo(k),jyo(k)),n(jxo(k),jyo(k))] = sumskipnan((il(:,1) - il(:,2)).^2);
+                end;
+        X = ranks(X);
+        end;
+        R = 1 - 6 * R ./ (n.*(n.*n-1));
+
+elseif strcmp(lower(Mode(1:7)),'partial');
+        fprintf(2,'Error CORRCOEF: use PARTCORRCOEF \n',Mode);
+
+        return;
+
+elseif strcmp(lower(Mode(1:7)),'kendall');
+        fprintf(2,'Error CORRCOEF: mode ''%s'' not implemented yet.\n',Mode);
+
+        return;
+else
+        fprintf(2,'Error CORRCOEF: unknown mode ''%s''\n',Mode);
+end;
+
+if (NARG<2),
+        warning(FLAG_WARNING);  % restore warning status
+        return;
+end;
+
+
+% CONFIDENCE INTERVAL
+if isfield(mode,'alpha')
+    alpha = mode.alpha;
+elseif exist('flag_implicit_significance','file'),
+        alpha = flag_implicit_significance;
+else
+    alpha = 0.01;
+end;
+% fprintf(1,'CORRCOEF: confidence interval is based on alpha=%f\n',alpha);
+
+
+% SIGNIFICANCE TEST
+R(isnan(R))=0;
+tmp = 1 - R.*R;
+tmp(tmp<0) = 0;		% prevent tmp<0 i.e. imag(t)~=0
+t   = R.*sqrt(max(NN-2,0)./tmp);
+
+if exist('t_cdf','file');
+        sig = t_cdf(t,NN-2);
+elseif exist('tcdf','file')>1;
+        sig = tcdf(t,NN-2);
+else
+        fprintf('CORRCOEF: significance test not completed because of missing TCDF-function\n')
+        sig = repmat(nan,size(R));
+end;
+sig  = 2 * min(sig,1 - sig);
+
+
+if NARG<3,
+    warning(FLAG_WARNING);  % restore warning status
+        return;
+end;
+
+
+tmp = R;
+%tmp(ix1 | ix2) = nan;		% avoid division-by-zero warning
+z   = log((1+tmp)./(1-tmp))/2;  % Fisher transformation [21]
+%sz = 1./sqrt(NN-3);		% standard error of z
+sz  = sqrt(2)*erfinv(1-alpha)./sqrt(NN-3);	% confidence interval for alpha of z
+
+ci1 = tanh(z-sz);
+ci2 = tanh(z+sz);
+
+%ci1(isnan(ci1))=R(isnan(ci1));	% in case of isnan(ci), the interval limits are exactly the R value
+%ci2(isnan(ci2))=R(isnan(ci2));
+
+if (NARG<5) || ~YESNAN,
+    nan_sig = repmat(NaN,size(R));
+    warning(FLAG_WARNING);  % restore warning status
+    return;
+end;
+
+%%%%% ----- check independence of NaNs (missing values) -----
+[nan_R, nan_sig] = corrcoef(X,double(isnan(X)));
+
+% remove diagonal elements, because these have not any meaning %
+nan_sig(isnan(nan_R)) = nan;
+% remove diagonal elements, because these have not any meaning %
+nan_R(isnan(nan_R)) = 0;
+
+if 0, any(nan_sig(:) < alpha),
+        tmp = nan_sig(:);			% Hack to skip NaN's in MIN(X)
+        min_sig = min(tmp(~isnan(tmp)));    % Necessary, because Octave returns NaN rather than min(X) for min(NaN,X)
+        fprintf(1,'CORRCOFF Warning: Missing Values (i.e. NaNs) are not independent of data (p-value=%f)\n', min_sig);
+        fprintf(1,'   Its recommended to remove all samples (i.e. rows) with any missing value (NaN).\n');
+        fprintf(1,'   The null-hypotheses (NaNs are uncorrelated) is rejected for the following parameter pair(s).\n');
+        [ix,iy] = find(nan_sig < alpha);
+        disp([ix,iy])
+end;
+
+%%%%% ----- end of independence check ------
+
+warning(FLAG_WARNING);  % restore warning status
+return;
+
diff --git a/matlab/missing/corrcoef/flag_implicit_skip_nan.m b/matlab/missing/corrcoef/flag_implicit_skip_nan.m
new file mode 100644
index 0000000000000000000000000000000000000000..409b9f69648ea224f956bdcbb1b968b8f3bcc652
--- /dev/null
+++ b/matlab/missing/corrcoef/flag_implicit_skip_nan.m
@@ -0,0 +1,66 @@
+function FLAG = flag_implicit_skip_nan(i)
+% FLAG_IMPLICIT_SKIP_NAN sets and gets default mode for handling NaNs
+%	1 skips NaN's (the default mode if no mode is set)
+%   0 NaNs are propagated; input NaN's give NaN's at the output
+%
+% FLAG = flag_implicit_skip_nan()
+%   gets current mode
+%
+% flag_implicit_skip_nan(FLAG)    % sets mode
+%
+% prevFLAG = flag_implicit_skip_nan(nextFLAG)
+%	gets previous set FLAG and sets FLAG for the future
+% flag_implicit_skip_nan(prevFLAG)
+%	resets FLAG to previous mode
+%
+% It is used in:
+%	SUMSKIPNAN, MEDIAN, QUANTILES, TRIMEAN
+% and affects many other functions like:
+%	CENTER, KURTOSIS, MAD, MEAN, MOMENT, RMS, SEM, SKEWNESS,
+%	STATISTIC, STD, VAR, ZSCORE etc.
+%
+% The mode is stored in the global variable FLAG_implicit_skip_nan
+% It is recommended to use flag_implicit_skip_nan(1) as default and
+% flag_implicit_skip_nan(0) should be used for exceptional cases only.
+% This feature might disappear without further notice, so you should really not
+% rely on it.
+
+
+%    This program 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.
+%
+%    This program 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 this program; if not, write to the Free Software
+%    Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301  USA
+
+%	$Id: flag_implicit_skip_nan.m 8351 2011-06-24 17:35:07Z carandraug $
+%   Copyright (C) 2001-2003,2009 by Alois Schloegl <alois.schloegl@gmail.com>
+%   Copyright (C) 2014 Dynare Team
+%       This function is part of the NaN-toolbox
+%       http://pub.ist.ac.at/~schloegl/matlab/NaN/
+
+
+persistent FLAG_implicit_skip_nan;
+
+%% if strcmp(version,'3.6'), FLAG_implicit_skip_nan=(1==1); end;	%% hack for the use with Freemat3.6
+
+%%% set DEFAULT value of FLAG
+if isempty(FLAG_implicit_skip_nan),
+    FLAG_implicit_skip_nan = (1==1); %logical(1); % logical.m not available on 2.0.16
+end;
+
+FLAG = FLAG_implicit_skip_nan;
+if nargin>0,
+    FLAG_implicit_skip_nan = (i~=0); %logical(i); %logical.m not available in 2.0.16
+    if (~i)
+        warning('flag_implicit_skipnan(0): You are warned!!! You have turned off skipping NaN in sumskipnan. This is not recommended. Make sure you really know what you do.')
+    end;
+end;
+
diff --git a/matlab/missing/corrcoef/sumskipnan.m b/matlab/missing/corrcoef/sumskipnan.m
new file mode 100644
index 0000000000000000000000000000000000000000..78f8ecbc1e40854d7c96083f11d7315b5947b6c1
--- /dev/null
+++ b/matlab/missing/corrcoef/sumskipnan.m
@@ -0,0 +1,194 @@
+function [o,count,SSQ] = sumskipnan(x, DIM, W)
+% SUMSKIPNAN adds all non-NaN values.
+%
+% All NaN's are skipped; NaN's are considered as missing values.
+% SUMSKIPNAN of NaN's only  gives O; and the number of valid elements is return.
+% SUMSKIPNAN is also the elementary function for calculating
+% various statistics (e.g. MEAN, STD, VAR, RMS, MEANSQ, SKEWNESS,
+% KURTOSIS, MOMENT, STATISTIC etc.) from data with missing values.
+% SUMSKIPNAN implements the DIMENSION-argument for data with missing values.
+% Also the second output argument return the number of valid elements (not NaNs)
+%
+% Y = sumskipnan(x [,DIM])
+% [Y,N,SSQ] = sumskipnan(x [,DIM])
+% [...] = sumskipnan(x, DIM, W)
+%
+% x	input data
+% DIM	dimension (default: [])
+%	empty DIM sets DIM to first non singleton dimension
+% W	weight vector for weighted sum, numel(W) must fit size(x,DIM)
+% Y	resulting sum
+% N	number of valid (not missing) elements
+% SSQ	sum of squares
+%
+% the function FLAG_NANS_OCCURED() returns whether any value in x
+%  is a not-a-number (NaN)
+%
+% features:
+% - can deal with NaN's (missing values)
+% - implements dimension argument.
+% - computes weighted sum
+% - compatible with Matlab and Octave
+%
+% see also: FLAG_NANS_OCCURED, SUM, NANSUM, MEAN, STD, VAR, RMS, MEANSQ,
+%      SSQ, MOMENT, SKEWNESS, KURTOSIS, SEM
+
+
+%    This program 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.
+%
+%    This program 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 this program; If not, see <http://www.gnu.org/licenses/>.
+
+%	$Id: sumskipnan.m 9033 2011-11-08 20:58:07Z schloegl $
+%       Copyright (C) 2000-2005,2009,2011 by Alois Schloegl <alois.schloegl@gmail.com>
+%       Copyright (C) 2014 Dynare Team
+%       This function is part of the NaN-toolbox
+%       http://pub.ist.ac.at/~schloegl/matlab/NaN/
+
+
+global FLAG_NANS_OCCURED;
+
+if nargin<2,
+        DIM = [];
+end;
+if nargin<3,
+        W = [];
+end;
+
+% an efficient implementation in C of the following lines
+% could significantly increase performance
+% only one loop and only one check for isnan is needed
+% An MEX-Implementation is available in sumskipnan.cpp
+%
+% Outline of the algorithm:
+% for { k=1,o=0,count=0; k++; k<N}
+%   if ~isnan(i(k))
+%   {   o     += x(k);
+%               count += 1;
+%		tmp    = x(k)*x(k)
+%		o2    += tmp;
+%		o3    += tmp.*tmp;
+%       };
+
+if isempty(DIM),
+        DIM = find(size(x)>1,1);
+        if isempty(DIM), DIM = 1; end;
+end
+if (DIM<1), DIM = 1; end; %% Hack, because min([])=0 for FreeMat v3.5
+
+%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+% non-float data
+%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+if  (isempty(W) && (~(isa(x,'float') || isa(x,'double')))) || ~flag_implicit_skip_nan(), %%% skip always NaN's
+    if ~isempty(W)
+        error('SUMSKIPNAN: weighted sum of integers not supported, yet');
+    end;
+    x = double(x);
+    o = sum(x,DIM);
+    if nargout>1
+        sz = size(x);
+        N  = sz(DIM);
+        sz(DIM) = 1;
+        count = repmat(N,sz);
+        if nargout>2
+            x = x.*x;
+            SSQ = sum(x,DIM);
+        end;
+    end;
+    return;
+end;
+
+if (length(size(x))<DIM)
+    error('SUMSKIPNAN: DIM argument larger than number of dimensions of x');
+elseif ~isempty(W) && (size(x,DIM)~=numel(W))
+    error('SUMSKIPNAN: size of weight vector does not match size(x,DIM)');
+end;
+
+%% mex and oct files expect double
+x = double(x);
+
+%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+% use Matlab-MEX function when available
+%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+%if 1,
+try
+
+    %% using sumskipnan_mex.mex
+
+    %% !!! hack: FLAG_NANS_OCCURED is an output argument, reserve memory !!!
+    if isempty(FLAG_NANS_OCCURED),
+        FLAG_NANS_OCCURED = logical(0);  % default value
+    end;
+
+    if (nargout<2),
+        o = sumskipnan_mex(real(x),DIM,FLAG_NANS_OCCURED,W);
+        if (~isreal(x))
+            io = sumskipnan_mex(imag(x),DIM,FLAG_NANS_OCCURED,W);
+            o  = o + i*io;
+        end;
+        return;
+    elseif (nargout==2),
+        [o,count] = sumskipnan_mex(real(x),DIM,FLAG_NANS_OCCURED,W);
+        if (~isreal(x))
+            [io,icount] = sumskipnan_mex(imag(x),DIM,FLAG_NANS_OCCURED,W);
+            if any(count(:)-icount(:))
+                error('Number of NaNs differ for REAL and IMAG part');
+            else
+                o  = o+i*io;
+            end;
+        end;
+        return;
+    elseif (nargout>=3),
+        [o,count,SSQ] = sumskipnan_mex(real(x),DIM,FLAG_NANS_OCCURED,W);
+        if (~isreal(x))
+            [io,icount,iSSQ] = sumskipnan_mex(imag(x),DIM,FLAG_NANS_OCCURED,W);
+            if any(count(:)-icount(:))
+                error('Number of NaNs differ for REAL and IMAG part');
+            else
+                o  = o+i*io;
+                SSQ = SSQ+iSSQ;
+            end;
+        end;
+        return;
+    end;
+end;
+
+if ~isempty(W)
+    error('weighted sumskipnan requires sumskipnan_mex');
+end;
+
+%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+% count non-NaN's
+%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+if nargout>1,
+        count = sum(x==x,DIM);
+    FLAG_NANS_OCCURED = any(count(:)<size(x,DIM));
+end;
+
+%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+% replace NaN's with zero
+%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+x(x~=x) = 0;
+o = sum(x,DIM);
+
+if nargout>2,
+        x = real(x).^2 + imag(x).^2;
+        SSQ = sum(x,DIM);
+end;
+
+%!assert(sumskipnan([1,2],1),[1,2])
+%!assert(sumskipnan([1,NaN],2),1)
+%!assert(sumskipnan([1,NaN],2),1)
+%!assert(sumskipnan([nan,1,4,5]),10)
+%!assert(sumskipnan([nan,1,4,5]',1,[3;2;1;0]),6)
+
+
+
diff --git a/matlab/missing/corrcoef/tcdf.m b/matlab/missing/corrcoef/tcdf.m
new file mode 100644
index 0000000000000000000000000000000000000000..c282e0a1745c80b660f4a56425d08898f55ecbfb
--- /dev/null
+++ b/matlab/missing/corrcoef/tcdf.m
@@ -0,0 +1,62 @@
+function p = tcdf(x,n)
+% TCDF returns student cumulative distribtion function
+%
+% cdf = tcdf(x,DF);
+%
+% Computes the CDF of the students distribution
+%    with DF degrees of freedom
+% x,DF must be matrices of same size, or any one can be a scalar.
+%
+% see also: NORMCDF, TPDF, TINV
+
+% Reference(s):
+
+%	$Id: tcdf.m 9033 2011-11-08 20:58:07Z schloegl $
+%	Copyright (C) 2000-2003,2009 by Alois Schloegl <alois.schloegl@gmail.com>
+%   Copyright (C) 2014 Dynare Team
+%       This is part of the NaN-toolbox. For more details see
+%       http://pub.ist.ac.at/~schloegl/matlab/NaN/
+
+%    This program 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.
+%
+%    This program 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 this program; If not, see <http://www.gnu.org/licenses/>.
+
+
+% check size of arguments
+if all(size(x)==1)
+    x = repmat(x,size(n));
+elseif all(size(n)==1)
+    n = repmat(n,size(x));
+elseif all(size(x)==size(n))
+    ;	%% OK, do nothing
+else
+    error('size of input arguments must be equal or scalar')
+end;
+
+% allocate memory
+p = zeros(size(x));
+p((x==Inf) & (n>0)) = 1;
+
+% workaround for invalid arguments in BETAINC
+ix   = isnan(x) | ~(n>0);
+p(ix)= NaN;
+
+ix    = (x > -Inf) & (x < Inf) & (n > 0);
+p(ix) = betainc (n(ix) ./ (n(ix) + x(ix).^2), n(ix)/2, 1/2) / 2;
+
+ix    = find(x>0);
+p(ix) = 1 - p(ix);
+
+% shape output
+p = reshape(p,size(x));
+
+%!assert(tcdf(NaN,4),NaN)
diff --git a/matlab/mode_check.m b/matlab/mode_check.m
index 2fa6f4a9d145b1d8bcbd35fd8e538fab02f25e00..fd80782d7a123fd95d5102f50a535bac03466aed 100644
--- a/matlab/mode_check.m
+++ b/matlab/mode_check.m
@@ -1,4 +1,4 @@
-function mode_check(fun,x,hessian,DynareDataset,DatasetInfo,DynareOptions,Model,EstimatedParameters,BayesInfo,DynareResults)
+function mode_check(fun,x,hessian,DynareDataset,DatasetInfo,DynareOptions,Model,EstimatedParameters,BayesInfo,BoundsInfo,DynareResults)
 % Checks the estimated ML mode or Posterior mode.
 
 %@info:
@@ -62,7 +62,7 @@ if ~isempty(hessian);
     [ s_min, k ] = min(diag(hessian));
 end
 
-fval = feval(fun,x,DynareDataset,DatasetInfo,DynareOptions,Model,EstimatedParameters,BayesInfo,DynareResults);
+fval = feval(fun,x,DynareDataset,DatasetInfo,DynareOptions,Model,EstimatedParameters,BayesInfo,BoundsInfo,DynareResults);
 
 if ~isempty(hessian);
     skipline()
@@ -109,23 +109,23 @@ for plt = 1:nbplt,
             end
         end
         xx = x;
-        l1 = max(BayesInfo.lb(kk),(1-sign(x(kk))*ll)*x(kk)); m1 = 0; %lower bound
-        l2 = min(BayesInfo.ub(kk),(1+sign(x(kk))*ll)*x(kk)); %upper bound
+        l1 = max(BoundsInfo.lb(kk),(1-sign(x(kk))*ll)*x(kk)); m1 = 0; %lower bound
+        l2 = min(BoundsInfo.ub(kk),(1+sign(x(kk))*ll)*x(kk)); %upper bound
         binding_lower_bound=0;
         binding_upper_bound=0;
-        if isequal(x(kk),BayesInfo.lb(kk))
+        if isequal(x(kk),BoundsInfo.lb(kk))
             binding_lower_bound=1;
-            bound_value=BayesInfo.lb(kk);
-        elseif isequal(x(kk),BayesInfo.ub(kk))
+            bound_value=BoundsInfo.lb(kk);
+        elseif isequal(x(kk),BoundsInfo.ub(kk))
             binding_upper_bound=1;
-            bound_value=BayesInfo.ub(kk);           
+            bound_value=BoundsInfo.ub(kk);
         end      
         if DynareOptions.mode_check.symmetric_plots && ~binding_lower_bound && ~binding_upper_bound
             if l2<(1+ll)*x(kk) %test whether upper bound is too small due to prior binding
                 l1 = x(kk) - (l2-x(kk)); %adjust lower bound to become closer
                 m1 = 1;
             end
-            if ~m1 && (l1>(1-ll)*x(kk)) && (x(kk)+(x(kk)-l1)<BayesInfo.ub(kk)) % if lower bound was truncated and using difference from lower bound does not violate upper bound
+            if ~m1 && (l1>(1-ll)*x(kk)) && (x(kk)+(x(kk)-l1)<BoundsInfo.ub(kk)) % if lower bound was truncated and using difference from lower bound does not violate upper bound
                 l2 = x(kk) + (x(kk)-l1); %set upper bound to same distance as lower bound
             end
         end
@@ -138,7 +138,7 @@ for plt = 1:nbplt,
         end
         for i=1:length(z)
             xx(kk) = z(i);
-            [fval, junk1, junk2, exit_flag] = feval(fun,xx,DynareDataset,DatasetInfo,DynareOptions,Model,EstimatedParameters,BayesInfo,DynareResults);
+            [fval, junk1, junk2, exit_flag] = feval(fun,xx,DynareDataset,DatasetInfo,DynareOptions,Model,EstimatedParameters,BayesInfo,BoundsInfo,DynareResults);
             if exit_flag
                 y(i,1) = fval;
             else
diff --git a/matlab/model_diagnostics.m b/matlab/model_diagnostics.m
index 29b56b318f8f83f31ec7e8c524b28efdf29b67e0..62ec92054e666ab69cd9b41ce1837de78e408647 100644
--- a/matlab/model_diagnostics.m
+++ b/matlab/model_diagnostics.m
@@ -169,6 +169,18 @@ for b=1:nb
 end
     
 if singularity_problem 
+    try
+        options_check=options;
+        options_check.noprint=1;
+        [eigenvalues_] = check(M, options_check, oo);
+        if any((abs(eigenvalues_)-1)<1e-6)
+            fprintf('MODEL_DIAGNOSTICS:  The singularity seems to be (partly) caused by the presence of a unit root\n')
+            fprintf('MODEL_DIAGNOSTICS:  as the absolute value of one eigenvalue is in the range of +-1e-6 to 1.\n')
+            fprintf('MODEL_DIAGNOSTICS:  If the model is actually supposed to feature unit root behavior, such a warning is expected,\n')
+            fprintf('MODEL_DIAGNOSTICS:  but you should nevertheless check whether there is an additional singularity problem.\n')
+        end
+    catch
+    end
     fprintf('MODEL_DIAGNOSTICS:  The presence of a singularity problem typically indicates that there is one\n')
     fprintf('MODEL_DIAGNOSTICS:  redundant equation entered in the model block, while another non-redundant equation\n')
     fprintf('MODEL_DIAGNOSTICS:  is missing. The problem often derives from Walras Law.\n')
@@ -192,7 +204,7 @@ if options.order == 1
         [junk,jacobia_] = feval([M.fname '_dynamic'],z(iyr0),exo_simul, ...
                             M.params, dr.ys, it_);
     end;
-elseif options.order == 2
+elseif options.order >= 2
     if (options.bytecode)
         [chck, junk, loc_dr] = bytecode('dynamic','evaluate', z,exo_simul, ...
                             M.params, dr.ys, 1);
diff --git a/matlab/modules/dates b/matlab/modules/dates
new file mode 160000
index 0000000000000000000000000000000000000000..6374a597d9cb4e24f2083229d58ba4e15642779d
--- /dev/null
+++ b/matlab/modules/dates
@@ -0,0 +1 @@
+Subproject commit 6374a597d9cb4e24f2083229d58ba4e15642779d
diff --git a/matlab/modules/dseries b/matlab/modules/dseries
new file mode 160000
index 0000000000000000000000000000000000000000..e42b73475856b1f3a63acfee0dbf3bfb1a6a11df
--- /dev/null
+++ b/matlab/modules/dseries
@@ -0,0 +1 @@
+Subproject commit e42b73475856b1f3a63acfee0dbf3bfb1a6a11df
diff --git a/matlab/mr_hessian.m b/matlab/mr_hessian.m
index 1cdbb05b1736ca95f885e1d228044a13317f3dbd..109c0147cf302b00c0844e08b2c921e516ece44d 100644
--- a/matlab/mr_hessian.m
+++ b/matlab/mr_hessian.m
@@ -28,7 +28,8 @@ function [hessian_mat, gg, htol1, ihh, hh_mat0, hh1] = mr_hessian(init,x,func,hf
 %  varargin{4} --> Model
 %  varargin{5} --> EstimatedParameters
 %  varargin{6} --> BayesInfo
-%  varargin{1} --> DynareResults
+%  varargin{7} --> BayesInfo
+%  varargin{8} --> DynareResults
 
 
 
@@ -60,9 +61,9 @@ if init
 end
 
 [f0, ff0]=feval(func,x,varargin{:});
-h2=varargin{6}.ub-varargin{6}.lb;
-hmax=varargin{6}.ub-x;
-hmax=min(hmax,x-varargin{6}.lb);
+h2=varargin{7}.ub-varargin{7}.lb;
+hmax=varargin{7}.ub-x;
+hmax=min(hmax,x-varargin{7}.lb);
 if isempty(ff0),
     outer_product_gradient=0;
 else
diff --git a/matlab/non_linear_dsge_likelihood.m b/matlab/non_linear_dsge_likelihood.m
index 4ea45c814d85a2a6c31a7a624bd30486c37e2b5e..f3122ec739a76926ecb3f199e92280ffc94b2c4e 100644
--- a/matlab/non_linear_dsge_likelihood.m
+++ b/matlab/non_linear_dsge_likelihood.m
@@ -1,4 +1,4 @@
-function [fval,ys,trend_coeff,exit_flag,info,Model,DynareOptions,BayesInfo,DynareResults] = non_linear_dsge_likelihood(xparam1,DynareDataset,DynareOptions,Model,EstimatedParameters,BayesInfo,DynareResults)
+function [fval,ys,trend_coeff,exit_flag,info,Model,DynareOptions,BayesInfo,DynareResults] = non_linear_dsge_likelihood(xparam1,DynareDataset,DatasetInfo,DynareOptions,Model,EstimatedParameters,BayesInfo,BoundsInfo,DynareResults)
 % Evaluates the posterior kernel of a dsge model using a non linear filter.
 
 %@info:
@@ -138,26 +138,23 @@ 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;
-
 %------------------------------------------------------------------------------
 % 1. Get the structural parameters & define penalties
 %------------------------------------------------------------------------------
 
 % Return, with endogenous penalty, if some parameters are smaller than the lower bound of the prior domain.
-if (DynareOptions.mode_compute~=1) && any(xparam1<BayesInfo.lb)
-    k = find(xparam1(:) < BayesInfo.lb);
-    fval = objective_function_penalty_base+sum((BayesInfo.lb(k)-xparam1(k)).^2);
+if (DynareOptions.mode_compute~=1) && any(xparam1<BoundsInfo.lb)
+    k = find(xparam1(:) < BoundsInfo.lb);
+    fval = objective_function_penalty_base+sum((BoundsInfo.lb(k)-xparam1(k)).^2);
     exit_flag = 0;
     info = 41;
     return
 end
 
 % Return, with endogenous penalty, if some parameters are greater than the upper bound of the prior domain.
-if (DynareOptions.mode_compute~=1) && any(xparam1>BayesInfo.ub)
-    k = find(xparam1(:)>BayesInfo.ub);
-    fval = objective_function_penalty_base+sum((xparam1(k)-BayesInfo.ub(k)).^2);
+if (DynareOptions.mode_compute~=1) && any(xparam1>BoundsInfo.ub)
+    k = find(xparam1(:)>BoundsInfo.ub);
+    fval = objective_function_penalty_base+sum((xparam1(k)-BoundsInfo.ub(k)).^2);
     exit_flag = 0;
     info = 42;
     return
@@ -217,7 +214,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 || info(1) == 25
+if info(1) == 1 || info(1) == 2 || info(1) == 5 || info(1) == 25 || info(1) == 10
     fval = objective_function_penalty_base+1;
     exit_flag = 0;
     return
@@ -232,30 +229,30 @@ BayesInfo.mf = BayesInfo.mf1;
 
 % Define the deterministic linear trend of the measurement equation.
 if DynareOptions.noconstant
-    constant = zeros(nvobs,1);
+    constant = zeros(DynareDataset.vobs,1);
 else
     constant = SteadyState(BayesInfo.mfys);
 end
 
 % Define the deterministic linear trend of the measurement equation.
 if BayesInfo.with_trend
-    trend_coeff = zeros(DynareDataset.info.nvobs,1);
+    trend_coeff = zeros(DynareDataset.vobs,1);
     t = DynareOptions.trend_coeffs;
     for i=1:length(t)
         if ~isempty(t{i})
             trend_coeff(i) = evalin('base',t{i});
         end
     end
-    trend = repmat(constant,1,DynareDataset.info.ntobs)+trend_coeff*[1:DynareDataset.info.ntobs];
+    trend = repmat(constant,1,DynareDataset.nobs)+trend_coeff*[1:DynareDataset.nobs];
 else
-    trend = repmat(constant,1,DynareDataset.info.ntobs);
+    trend = repmat(constant,1,DynareDataset.nobs);
 end
 
 % Get needed informations for kalman filter routines.
 start = DynareOptions.presample+1;
 np    = size(T,1);
 mf    = BayesInfo.mf;
-Y     = transpose(DynareDataset.rawdata);
+Y     = transpose(DynareDataset.data)-trend;
 
 %------------------------------------------------------------------------------
 % 3. Initial condition of the Kalman filter
@@ -295,7 +292,7 @@ ReducedForm.mf1 = mf1;
 switch DynareOptions.particle.initialization
   case 1% Initial state vector covariance is the ergodic variance associated to the first order Taylor-approximation of the model.
     StateVectorMean = ReducedForm.constant(mf0);
-    StateVectorVariance = lyapunov_symm(ReducedForm.ghx(mf0,:),ReducedForm.ghu(mf0,:)*ReducedForm.Q*ReducedForm.ghu(mf0,:)',1e-12,1e-12);
+    StateVectorVariance = lyapunov_symm(ReducedForm.ghx(mf0,:),ReducedForm.ghu(mf0,:)*ReducedForm.Q*ReducedForm.ghu(mf0,:)',1e-12,1e-12,[],[],DynareOptions.debug);
   case 2% Initial state vector covariance is a monte-carlo based estimate of the ergodic variance (consistent with a k-order Taylor-approximation of the model).
     StateVectorMean = ReducedForm.constant(mf0);
     old_DynareOptionsperiods = DynareOptions.periods;
diff --git a/matlab/osr1.m b/matlab/osr1.m
index a8d3931488fec6d9404d0ad59da51dbd1068ea81..eb23312ffe499556b3bcd583a7014db3e1a6a8a2 100644
--- a/matlab/osr1.m
+++ b/matlab/osr1.m
@@ -76,8 +76,9 @@ inv_order_var = oo_.dr.inv_order_var;
 H0 = 1e-4*eye(np);
 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
@@ -96,6 +97,7 @@ end
 [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));
 osr_res.objective_function = f;
+M_.params(i_params)=p; %make sure optimal parameters are set (and not the last draw used in csminwel)
 for i=1:length(i_params)
     osr_res.optim_params.(deblank(M_.param_names(i_params(i),:))) = p(i);
 end
diff --git a/matlab/osr_obj.m b/matlab/osr_obj.m
index 431a941f7fb9030b9acb6b90bd8c2d328139bf2c..378d2b06ed0b50362aa14018eb3d07c3c86f741e 100644
--- a/matlab/osr_obj.m
+++ b/matlab/osr_obj.m
@@ -86,4 +86,4 @@ switch info(1)
 end
 
 vx = get_variance_of_endogenous_variables(dr,i_var);
-loss = weights(:)'*vx(:);
+loss = full(weights(:)'*vx(:));
diff --git a/matlab/particle/conditional_filter_proposal.m b/matlab/particle/conditional_filter_proposal.m
index 1a25244cca38d3be36bb00ac9d5c2410c2bd61e4..aa82a449a4a29f8328a7be4a5a5edd5a4b5120ec 100644
--- a/matlab/particle/conditional_filter_proposal.m
+++ b/matlab/particle/conditional_filter_proposal.m
@@ -1,8 +1,8 @@
-function [ProposalStateVector,Weights] = conditional_filter_proposal(ReducedForm,obs,StateVectors,SampleWeights,Q_lower_triangular_cholesky,H_lower_triangular_cholesky,H,DynareOptions,normconst2) 
+function [ProposalStateVector,Weights] = conditional_filter_proposal(ReducedForm,obs,StateVectors,SampleWeights,Q_lower_triangular_cholesky,H_lower_triangular_cholesky,H,DynareOptions,normconst2)
+%
+% Computes the proposal for each past particle using Gaussian approximations
+% for the state errors and the Kalman filter
 %
-% Computes the proposal for each past particle using Gaussian approximations 
-% for the state errors and the Kalman filter 
-% 
 % INPUTS
 %    reduced_form_model     [structure] Matlab's structure describing the reduced form model.
 %                                       reduced_form_model.measurement.H   [double]   (pp x pp) variance matrix of measurement errors.
@@ -39,8 +39,8 @@ function [ProposalStateVector,Weights] = conditional_filter_proposal(ReducedForm
 %           stephane DOT adjemian AT univ DASH lemans DOT fr
 
 persistent init_flag2 mf0 mf1
-persistent number_of_state_variables number_of_observed_variables 
-persistent number_of_structural_innovations 
+persistent number_of_state_variables number_of_observed_variables
+persistent number_of_structural_innovations
 
 % Set local state space model (first-order approximation).
 ghx  = ReducedForm.ghx;
@@ -73,16 +73,13 @@ if isempty(init_flag2)
     init_flag2 = 1;
 end
 
-if strcmpi(DynareOptions.particle.IS_approximation_method,'cubature') || strcmpi(DynareOptions.particle.IS_approximation_method,'monte-carlo')
-    [nodes,weights] = spherical_radial_sigma_points(number_of_structural_innovations) ; 
-    weights_c = weights ;
-end    
-if strcmpi(DynareOptions.particle.IS_approximation_method,'quadrature')
-    [nodes,weights] = nwspgr('GQN',number_of_structural_innovations,DynareOptions.particle.smolyak_accuracy) ;
+if DynareOptions.particle.proposal_approximation.cubature || DynareOptions.particle.proposal_approximation.montecarlo
+    [nodes,weights] = spherical_radial_sigma_points(number_of_structural_innovations);
     weights_c = weights ;
-end    
-if strcmpi(DynareOptions.particle.IS_approximation_method,'unscented')
-    [nodes,weights,weights_c] = unscented_sigma_points(number_of_structural_innovations,DynareOptions) ; 
+elseif DynareOptions.particle.proposal_approximation.unscented
+    [nodes,weights,weights_c] = unscented_sigma_points(number_of_structural_innovations,DynareOptions);
+else
+    error('Estimation: This approximation for the proposal is not implemented or unknown!')
 end
 
 epsilon = Q_lower_triangular_cholesky*(nodes') ;
@@ -93,38 +90,34 @@ tmp = local_state_space_iteration_2(yhat,epsilon,ghx,ghu,constant,ghxx,ghuu,ghxu
 PredictedStateMean = tmp(mf0,:)*weights ;
 PredictedObservedMean = tmp(mf1,:)*weights;
 
-if strcmpi(DynareOptions.particle.IS_approximation_method,'cubature') || ...
-   strcmpi(DynareOptions.particle.IS_approximation_method,'monte-carlo')
+if DynareOptions.particle.proposal_approximation.cubature || DynareOptions.particle.proposal_approximation.montecarlo
     PredictedStateMean = sum(PredictedStateMean,2) ;
     PredictedObservedMean = sum(PredictedObservedMean,2) ;
     dState = bsxfun(@minus,tmp(mf0,:),PredictedStateMean)'.*sqrt(weights) ;
     dObserved = bsxfun(@minus,tmp(mf1,:),PredictedObservedMean)'.*sqrt(weights);
-    big_mat = [dObserved  dState ; [H_lower_triangular_cholesky zeros(number_of_observed_variables,number_of_state_variables)] ] ;
-    [mat1,mat] = qr2(big_mat,0) ;
-    mat = mat' ; 
+    big_mat = [dObserved  dState; [H_lower_triangular_cholesky zeros(number_of_observed_variables,number_of_state_variables)] ];
+    [mat1,mat] = qr2(big_mat,0);
+    mat = mat';
     clear('mat1');
-    PredictedObservedVarianceSquareRoot = mat(1:number_of_observed_variables,1:number_of_observed_variables) ;
-    CovarianceObservedStateSquareRoot = mat(number_of_observed_variables+(1:number_of_state_variables),1:number_of_observed_variables) ;
-    StateVectorVarianceSquareRoot = mat(number_of_observed_variables+(1:number_of_state_variables),number_of_observed_variables+(1:number_of_state_variables)) ;
-    StateVectorMean = PredictedStateMean + (CovarianceObservedStateSquareRoot/PredictedObservedVarianceSquareRoot)*(obs - PredictedObservedMean) ; 
-end 
-if strcmpi(DynareOptions.particle.IS_approximation_method,'quadrature') || ... 
-   strcmpi(DynareOptions.particle.IS_approximation_method,'unscented') 
+    PredictedObservedVarianceSquareRoot = mat(1:number_of_observed_variables,1:number_of_observed_variables);
+    CovarianceObservedStateSquareRoot = mat(number_of_observed_variables+(1:number_of_state_variables),1:number_of_observed_variables);
+    StateVectorVarianceSquareRoot = mat(number_of_observed_variables+(1:number_of_state_variables),number_of_observed_variables+(1:number_of_state_variables));
+    StateVectorMean = PredictedStateMean + (CovarianceObservedStateSquareRoot/PredictedObservedVarianceSquareRoot)*(obs - PredictedObservedMean);
+else
     dState = bsxfun(@minus,tmp(mf0,:),PredictedStateMean);
     dObserved = bsxfun(@minus,tmp(mf1,:),PredictedObservedMean);
     PredictedStateVariance = dState*diag(weights_c)*dState';
     PredictedObservedVariance = dObserved*diag(weights_c)*dObserved' + H;
     PredictedStateAndObservedCovariance = dState*diag(weights_c)*dObserved';
-    KalmanFilterGain = PredictedStateAndObservedCovariance/PredictedObservedVariance ; 
+    KalmanFilterGain = PredictedStateAndObservedCovariance/PredictedObservedVariance ;
     StateVectorMean = PredictedStateMean + KalmanFilterGain*(obs - PredictedObservedMean);
     StateVectorVariance = PredictedStateVariance - KalmanFilterGain*PredictedObservedVariance*KalmanFilterGain';
     StateVectorVariance = .5*(StateVectorVariance+StateVectorVariance');
-    StateVectorVarianceSquareRoot = reduced_rank_cholesky(StateVectorVariance)'; 
-end 
-    
+    StateVectorVarianceSquareRoot = reduced_rank_cholesky(StateVectorVariance)';
+end
+
 ProposalStateVector = StateVectorVarianceSquareRoot*randn(size(StateVectorVarianceSquareRoot,2),1)+StateVectorMean ;
 ypred = measurement_equations(ProposalStateVector,ReducedForm,DynareOptions) ;
 foo = H_lower_triangular_cholesky \ (obs - ypred) ;
-likelihood = exp(-0.5*(foo)'*foo)/normconst2 + 1e-99 ;			
-Weights = SampleWeights.*likelihood ;	
-
+likelihood = exp(-0.5*(foo)'*foo)/normconst2 + 1e-99 ;
+Weights = SampleWeights.*likelihood;
diff --git a/matlab/particle/conditional_particle_filter.m b/matlab/particle/conditional_particle_filter.m
index 941e01331ecd2c3f625607a509a8b2ed6d1af9b6..3f365f85c10d23e04ec9b223fda2ed1c71dbc73e 100644
--- a/matlab/particle/conditional_particle_filter.m
+++ b/matlab/particle/conditional_particle_filter.m
@@ -113,8 +113,7 @@ for t=1:sample_size
     SumSampleWeights = sum(SampleWeights) ;
     lik(t) = log(SumSampleWeights) ; 
     SampleWeights = SampleWeights./SumSampleWeights ;		
-    if (strcmp(DynareOptions.particle.resampling.status,'generic') && neff(SampleWeights)<DynareOptions.particle.resampling.neff_threshold*sample_size ) || ...
-        strcmp(DynareOptions.particle.resampling.status,'systematic')
+    if (DynareOptions.particle.resampling.status.generic && neff(SampleWeights)<DynareOptions.particle.resampling.threshold*sample_size) || DynareOptions.particle.resampling.status.systematic
         ks = ks + 1 ;
         StateParticles = resample(StateParticles',SampleWeights',DynareOptions)';
         SampleWeights = ones(1,number_of_particles)/number_of_particles ;
diff --git a/matlab/particle/gaussian_filter.m b/matlab/particle/gaussian_filter.m
index ebe2b1d31aa6bb333dae703490c43fa1324a7078..da3840c74f2908f85a47cc8d5fae05ee77b9740d 100644
--- a/matlab/particle/gaussian_filter.m
+++ b/matlab/particle/gaussian_filter.m
@@ -1,21 +1,21 @@
 function [LIK,lik] = gaussian_filter(ReducedForm,Y,start,DynareOptions)
-% Evaluates the likelihood of a non-linear model approximating the 
-% predictive (prior) and filtered (posterior) densities for state variables 
-% by gaussian distributions. 
-% Gaussian approximation is done by:  
-% - a Kronrod-Paterson gaussian quadrature with a limited number of nodes. 
-% Multidimensional quadrature is obtained by the Smolyak operator (ref: Winschel & Kratzig, 2010). 
+% Evaluates the likelihood of a non-linear model approximating the
+% predictive (prior) and filtered (posterior) densities for state variables
+% by gaussian distributions.
+% Gaussian approximation is done by:
+% - a Kronrod-Paterson gaussian quadrature with a limited number of nodes.
+% Multidimensional quadrature is obtained by the Smolyak operator (ref: Winschel & Kratzig, 2010).
 % - a spherical-radial cubature (ref: Arasaratnam & Haykin, 2008,2009).
 % - a scaled unscented transform cubature (ref: )
-% - Monte-Carlo draws from a multivariate gaussian distribution. 
-% First and second moments of prior and posterior state densities are computed 
-% from the resulting nodes/particles and allows to generate new distributions at the 
-% following observation. 
-% => The use of nodes is much faster than Monte-Carlo Gaussian particle and standard particles 
-% filters since it treats a lesser number of particles and there is no need 
+% - Monte-Carlo draws from a multivariate gaussian distribution.
+% First and second moments of prior and posterior state densities are computed
+% from the resulting nodes/particles and allows to generate new distributions at the
+% following observation.
+% => The use of nodes is much faster than Monte-Carlo Gaussian particle and standard particles
+% filters since it treats a lesser number of particles and there is no need
 % of resampling.
-% However, estimations may reveal biaised if the model is truly non-gaussian 
-% since predictive and filtered densities are unimodal. 
+% However, estimations may reveal biaised if the model is truly non-gaussian
+% since predictive and filtered densities are unimodal.
 %
 % INPUTS
 %    reduced_form_model     [structure] Matlab's structure describing the reduced form model.
@@ -53,9 +53,7 @@ function [LIK,lik] = gaussian_filter(ReducedForm,Y,start,DynareOptions)
 
 persistent init_flag mf0 mf1
 persistent nodes2 weights2 weights_c2 number_of_particles
-persistent sample_size number_of_state_variables number_of_observed_variables 
-
-verbose = 1;
+persistent sample_size number_of_state_variables number_of_observed_variables
 
 % Set default
 if isempty(start)
@@ -72,21 +70,24 @@ if isempty(init_flag)
     number_of_particles = DynareOptions.particle.number_of_particles;
     init_flag = 1;
 end
+
 % compute gaussian quadrature nodes and weights on states and shocks
-if isempty(nodes2) && strcmpi(DynareOptions.particle.approximation_method,'quadrature') 
-    [nodes2,weights2] = nwspgr('GQN',number_of_state_variables,DynareOptions.particle.smolyak_accuracy) ;
-    weights_c2 = weights2 ; 
+if isempty(nodes2)
+    if DynareOptions.particle.distribution_approximation.cubature
+        [nodes2,weights2] = spherical_radial_sigma_points(number_of_state_variables);
+        weights_c2 = weights2;
+    elseif DynareOptions.particle.distribution_approximation.unscented
+        [nodes2,weights2,weights_c2] = unscented_sigma_points(number_of_state_variables,DynareOptions);
+    else
+        if ~DynareOptions.particle.distribution_approximation.montecarlo
+            error('Estimation: This approximation for the proposal is not implemented or unknown!')
+        end
+    end
 end
-if isempty(nodes2) && strcmpi(DynareOptions.particle.approximation_method,'cubature')
-    [nodes2,weights2] = spherical_radial_sigma_points(number_of_state_variables) ;
-    weights_c2 = weights2 ; 
+
+if DynareOptions.particle.distribution_approximation.montecarlo
+    set_dynare_seed('default');
 end
-if isempty(nodes2) && strcmpi(DynareOptions.particle.approximation_method,'unscented')
-    [nodes2,weights2,weights_c2] = unscented_sigma_points(number_of_state_variables,DynareOptions) ;    
-end    
-if isempty(nodes2) && strcmpi(DynareOptions.particle.approximation_method,'monte-carlo')
- 	set_dynare_seed('default');
-end 
 
 % Get covariance matrices
 Q = ReducedForm.Q;
@@ -114,46 +115,43 @@ ks = 0 ;
 %Estimate = zeros(number_of_state_variables,sample_size) ;
 %V_Estimate = zeros(number_of_state_variables,number_of_state_variables,sample_size) ;
 for t=1:sample_size
-    % build the proposal 
+    % build the proposal
     [PredictedStateMean,PredictedStateVarianceSquareRoot,StateVectorMean,StateVectorVarianceSquareRoot] = ...
         gaussian_filter_bank(ReducedForm,Y(:,t),StateVectorMean,StateVectorVarianceSquareRoot,Q_lower_triangular_cholesky,H_lower_triangular_cholesky,H,DynareOptions) ;
     %Estimate(:,t) = PredictedStateMean ;
     %V_Estimate(:,:,t) = PredictedStateVarianceSquareRoot ;
-    if strcmpi(DynareOptions.particle.approximation_method,'quadrature') || ... % sparse grids approximations 
-       strcmpi(DynareOptions.particle.approximation_method,'cubature') || ...
-       strcmpi(DynareOptions.particle.approximation_method,'unscented')
-        StateParticles = bsxfun(@plus,StateVectorMean,StateVectorVarianceSquareRoot*nodes2') ;    
+    if DynareOptions.particle.distribution_approximation.cubature || DynareOptions.particle.distribution_approximation.unscented
+        StateParticles = bsxfun(@plus,StateVectorMean,StateVectorVarianceSquareRoot*nodes2') ;
         IncrementalWeights = ...
                     gaussian_densities(Y(:,t),StateVectorMean,...
                                         StateVectorVarianceSquareRoot,PredictedStateMean,...
                                         PredictedStateVarianceSquareRoot,StateParticles,H,const_lik,...
-                                        weights2,weights_c2,ReducedForm,DynareOptions) ;  
-        SampleWeights = weights2.*IncrementalWeights ;			
+                                        weights2,weights_c2,ReducedForm,DynareOptions) ;
+        SampleWeights = weights2.*IncrementalWeights ;
         SumSampleWeights = sum(SampleWeights) ;
         lik(t) = log(SumSampleWeights) ;
-        SampleWeights = SampleWeights./SumSampleWeights ;		
+        SampleWeights = SampleWeights./SumSampleWeights ;
     else % Monte-Carlo draws
         StateParticles = bsxfun(@plus,StateVectorVarianceSquareRoot*randn(state_variance_rank,number_of_particles),StateVectorMean) ;
         IncrementalWeights = ...
                     gaussian_densities(Y(:,t),StateVectorMean,...
                                         StateVectorVarianceSquareRoot,PredictedStateMean,...
                                         PredictedStateVarianceSquareRoot,StateParticles,H,const_lik,...
-                                        1/number_of_particles,1/number_of_particles,ReducedForm,DynareOptions) ;  
-        SampleWeights = SampleWeights.*IncrementalWeights ;			
+                                        1/number_of_particles,1/number_of_particles,ReducedForm,DynareOptions) ;
+        SampleWeights = SampleWeights.*IncrementalWeights ;
         SumSampleWeights = sum(SampleWeights) ;
         %VarSampleWeights = IncrementalWeights-SumSampleWeights ;
         %VarSampleWeights = VarSampleWeights*VarSampleWeights'/(number_of_particles-1) ;
-        lik(t) = log(SumSampleWeights) ; %+ .5*VarSampleWeights/(number_of_particles*(SumSampleWeights*SumSampleWeights)) ; 
-        SampleWeights = SampleWeights./SumSampleWeights ;		
+        lik(t) = log(SumSampleWeights) ; %+ .5*VarSampleWeights/(number_of_particles*(SumSampleWeights*SumSampleWeights)) ;
+        SampleWeights = SampleWeights./SumSampleWeights ;
         Neff = 1/sum(bsxfun(@power,SampleWeights,2)) ;
-        if (Neff<.5*sample_size && strcmpi(DynareOptions.particle.resampling.status,'generic')) || ... 
-                                   strcmpi(DynareOptions.particle.resampling.status,'systematic')
+        if (Neff<.5*sample_size && DynareOptions.particle.resampling.status.generic) || DynareOptions.particle.resampling.status.systematic
             ks = ks + 1 ;
-            StateParticles = resample(StateParticles',SampleWeights,DynareOptions)' ; 
+            StateParticles = resample(StateParticles',SampleWeights,DynareOptions)' ;
             StateVectorMean = mean(StateParticles,2) ;
             StateVectorVarianceSquareRoot = reduced_rank_cholesky( (StateParticles*StateParticles')/(number_of_particles-1) - StateVectorMean*(StateVectorMean') )';
             SampleWeights = 1/number_of_particles ;
-        elseif strcmpi(DynareOptions.particle.resampling.status,'none')
+        elseif DynareOptions.particle.resampling.status.none
             StateVectorMean = (sampleWeights*StateParticles)' ;
             temp = sqrt(SampleWeights').*StateParticles ;
             StateVectorVarianceSquareRoot = reduced_rank_cholesky( temp'*temp - StateVectorMean*(StateVectorMean') )';
@@ -162,4 +160,3 @@ for t=1:sample_size
 end
 
 LIK = -sum(lik(start:end));
-
diff --git a/matlab/particle/gaussian_filter_bank.m b/matlab/particle/gaussian_filter_bank.m
index 41cd6aa021cf628532d0505ef21ab5e7760afc97..6094dbcf1583b0c646a246acfeca07388c2d94d6 100644
--- a/matlab/particle/gaussian_filter_bank.m
+++ b/matlab/particle/gaussian_filter_bank.m
@@ -1,8 +1,8 @@
-function [PredictedStateMean,PredictedStateVarianceSquareRoot,StateVectorMean,StateVectorVarianceSquareRoot] = gaussian_filter_bank(ReducedForm,obs,StateVectorMean,StateVectorVarianceSquareRoot,Q_lower_triangular_cholesky,H_lower_triangular_cholesky,H,DynareOptions) 
+function [PredictedStateMean,PredictedStateVarianceSquareRoot,StateVectorMean,StateVectorVarianceSquareRoot] = gaussian_filter_bank(ReducedForm,obs,StateVectorMean,StateVectorVarianceSquareRoot,Q_lower_triangular_cholesky,H_lower_triangular_cholesky,H,DynareOptions)
 %
 % Computes the proposal with a gaussian approximation for importance
-% sampling 
-% This proposal is a gaussian distribution calculated à la Kalman 
+% sampling
+% This proposal is a gaussian distribution calculated à la Kalman
 %
 % INPUTS
 %    reduced_form_model     [structure] Matlab's structure describing the reduced form model.
@@ -37,8 +37,8 @@ function [PredictedStateMean,PredictedStateVarianceSquareRoot,StateVectorMean,St
 % along with Dynare.  If not, see <http://www.gnu.org/licenses/>.
 
 persistent init_flag2 mf0 mf1
-persistent number_of_state_variables number_of_observed_variables 
-persistent number_of_structural_innovations 
+persistent number_of_state_variables number_of_observed_variables
+persistent number_of_structural_innovations
 
 % Set local state space model (first-order approximation).
 ghx  = ReducedForm.ghx;
@@ -71,45 +71,42 @@ if isempty(init_flag2)
     init_flag2 = 1;
 end
 
-if strcmpi(DynareOptions.particle.IS_approximation_method,'cubature') || strcmpi(DynareOptions.particle.IS_approximation_method,'monte-carlo')
-    [nodes,weights] = spherical_radial_sigma_points(number_of_state_variables+number_of_structural_innovations) ; 
+if DynareOptions.particle.proposal_approximation.cubature || DynareOptions.particle.proposal_approximation.montecarlo
+    [nodes,weights] = spherical_radial_sigma_points(number_of_state_variables+number_of_structural_innovations) ;
     weights_c = weights ;
-end    
-if strcmpi(DynareOptions.particle.IS_approximation_method,'quadrature')
-    [nodes,weights] = nwspgr('GQN',number_of_state_variables+number_of_structural_innovations,DynareOptions.particle.smolyak_accuracy) ;
-    weights_c = weights ;
-end    
-if strcmpi(DynareOptions.particle.IS_approximation_method,'unscented')
-    [nodes,weights,weights_c] = unscented_sigma_points(number_of_state_variables+number_of_structural_innovations,DynareOptions) ; 
+elseif DynareOptions.particle.proposal_approximation.unscented
+    [nodes,weights,weights_c] = unscented_sigma_points(number_of_state_variables+number_of_structural_innovations,DynareOptions);
+else
+    error('Estimation: This approximation for the proposal is not implemented or unknown!')
 end
 
 xbar = [StateVectorMean ; zeros(number_of_structural_innovations,1) ] ;
-sqr_Px = [ [ StateVectorVarianceSquareRoot zeros(number_of_state_variables,number_of_structural_innovations) ] ; 
-           [ zeros(number_of_structural_innovations,number_of_state_variables) Q_lower_triangular_cholesky ] ] ;
-sigma_points = bsxfun(@plus,xbar,sqr_Px*(nodes')) ;
-StateVectors = sigma_points(1:number_of_state_variables,:) ; 
-epsilon = sigma_points(number_of_state_variables+1:number_of_state_variables+number_of_structural_innovations,:) ; 
+sqr_Px = [ [ StateVectorVarianceSquareRoot zeros(number_of_state_variables,number_of_structural_innovations) ] ;
+           [ zeros(number_of_structural_innovations,number_of_state_variables) Q_lower_triangular_cholesky ] ];
+sigma_points = bsxfun(@plus,xbar,sqr_Px*(nodes'));
+StateVectors = sigma_points(1:number_of_state_variables,:);
+epsilon = sigma_points(number_of_state_variables+1:number_of_state_variables+number_of_structural_innovations,:);
 yhat = bsxfun(@minus,StateVectors,state_variables_steady_state);
 tmp = local_state_space_iteration_2(yhat,epsilon,ghx,ghu,constant,ghxx,ghuu,ghxu,DynareOptions.threads.local_state_space_iteration_2);
 PredictedStateMean = tmp(mf0,:)*weights ;
 PredictedObservedMean = tmp(mf1,:)*weights;
-if strcmpi(DynareOptions.particle.IS_approximation_method,'cubature') || strcmpi(DynareOptions.particle.IS_approximation_method,'monte-carlo')
-    PredictedStateMean = sum(PredictedStateMean,2) ;
-    PredictedObservedMean = sum(PredictedObservedMean,2) ;
-    dState = bsxfun(@minus,tmp(mf0,:),PredictedStateMean)'.*sqrt(weights) ;
+
+if DynareOptions.particle.proposal_approximation.cubature || DynareOptions.particle.proposal_approximation.montecarlo
+    PredictedStateMean = sum(PredictedStateMean,2);
+    PredictedObservedMean = sum(PredictedObservedMean,2);
+    dState = bsxfun(@minus,tmp(mf0,:),PredictedStateMean)'.*sqrt(weights);
     dObserved = bsxfun(@minus,tmp(mf1,:),PredictedObservedMean)'.*sqrt(weights);
     PredictedStateVarianceSquareRoot = chol(dState'*dState)';
-    big_mat = [dObserved  dState ; [H_lower_triangular_cholesky zeros(number_of_observed_variables,number_of_state_variables)] ] ;
-    [mat1,mat] = qr2(big_mat,0) ;
-    mat = mat' ; 
+    big_mat = [dObserved  dState ; [H_lower_triangular_cholesky zeros(number_of_observed_variables,number_of_state_variables)] ];
+    [mat1,mat] = qr2(big_mat,0);
+    mat = mat';
     clear('mat1');
-    PredictedObservedVarianceSquareRoot = mat(1:number_of_observed_variables,1:number_of_observed_variables) ;
-    CovarianceObservedStateSquareRoot = mat(number_of_observed_variables+(1:number_of_state_variables),1:number_of_observed_variables) ;
-    StateVectorVarianceSquareRoot = mat(number_of_observed_variables+(1:number_of_state_variables),number_of_observed_variables+(1:number_of_state_variables)) ;
-    PredictionError = obs - PredictedObservedMean ;
-    StateVectorMean = PredictedStateMean + (CovarianceObservedStateSquareRoot/PredictedObservedVarianceSquareRoot)*PredictionError ; 
-end 
-if strcmpi(DynareOptions.particle.IS_approximation_method,'quadrature') || strcmpi(DynareOptions.particle.IS_approximation_method,'unscented') 
+    PredictedObservedVarianceSquareRoot = mat(1:number_of_observed_variables,1:number_of_observed_variables);
+    CovarianceObservedStateSquareRoot = mat(number_of_observed_variables+(1:number_of_state_variables),1:number_of_observed_variables);
+    StateVectorVarianceSquareRoot = mat(number_of_observed_variables+(1:number_of_state_variables),number_of_observed_variables+(1:number_of_state_variables));
+    PredictionError = obs - PredictedObservedMean;
+    StateVectorMean = PredictedStateMean + (CovarianceObservedStateSquareRoot/PredictedObservedVarianceSquareRoot)*PredictionError;
+else
     dState = bsxfun(@minus,tmp(mf0,:),PredictedStateMean);
     dObserved = bsxfun(@minus,tmp(mf1,:),PredictedObservedMean);
     PredictedStateVariance = dState*diag(weights_c)*dState';
@@ -117,10 +114,9 @@ if strcmpi(DynareOptions.particle.IS_approximation_method,'quadrature') || strcm
     PredictedStateAndObservedCovariance = dState*diag(weights_c)*dObserved';
     PredictedStateVarianceSquareRoot = chol(PredictedStateVariance)';
     PredictionError = obs - PredictedObservedMean;
-    KalmanFilterGain = PredictedStateAndObservedCovariance/PredictedObservedVariance ; 
+    KalmanFilterGain = PredictedStateAndObservedCovariance/PredictedObservedVariance;
     StateVectorMean = PredictedStateMean + KalmanFilterGain*PredictionError;
     StateVectorVariance = PredictedStateVariance - KalmanFilterGain*PredictedObservedVariance*KalmanFilterGain';
     StateVectorVariance = .5*(StateVectorVariance+StateVectorVariance');
-    StateVectorVarianceSquareRoot = reduced_rank_cholesky(StateVectorVariance)'; 
-end 
-    
+    StateVectorVarianceSquareRoot = reduced_rank_cholesky(StateVectorVariance)';
+end
\ No newline at end of file
diff --git a/matlab/particle/gaussian_mixture_filter.m b/matlab/particle/gaussian_mixture_filter.m
index 8f05ea390c6f1d1c32a427b46cf1ff643172e5fe..5c60a81fb9b3a590b1ffd9acd9b56cb23d5c7441 100644
--- a/matlab/particle/gaussian_mixture_filter.m
+++ b/matlab/particle/gaussian_mixture_filter.m
@@ -1,18 +1,18 @@
 function [LIK,lik] = gaussian_mixture_filter(ReducedForm,Y,start,DynareOptions)
 % Evaluates the likelihood of a non-linear model approximating the state
-% variables distributions with gaussian mixtures. Gaussian Mixture allows reproducing 
-% a wide variety of generalized distributions (when multimodal for instance). 
+% variables distributions with gaussian mixtures. Gaussian Mixture allows reproducing
+% a wide variety of generalized distributions (when multimodal for instance).
 % Each gaussian distribution is obtained whether
-%   - with a Smolyak quadrature à la Kronrod & Paterson (Heiss & Winschel 2010, Winschel & Kratzig 2010). 
-%   - with a radial-spherical cubature 
+%   - with a Smolyak quadrature à la Kronrod & Paterson (Heiss & Winschel 2010, Winschel & Kratzig 2010).
+%   - with a radial-spherical cubature
 %   - with scaled unscented sigma-points
-% A Sparse grid Kalman Filter is implemented on each component of the mixture, 
-% which confers it a weight about current information. 
-% Information on the current observables is then embodied in the proposal 
-% distribution in which we draw particles, which allows 
-%   - reaching a greater precision relatively to a standard particle filter, 
-%   - reducing the number of particles needed, 
-%   - still being faster. 
+% A Sparse grid Kalman Filter is implemented on each component of the mixture,
+% which confers it a weight about current information.
+% Information on the current observables is then embodied in the proposal
+% distribution in which we draw particles, which allows
+%   - reaching a greater precision relatively to a standard particle filter,
+%   - reducing the number of particles needed,
+%   - still being faster.
 %
 %
 % INPUTS
@@ -30,9 +30,9 @@ function [LIK,lik] = gaussian_mixture_filter(ReducedForm,Y,start,DynareOptions)
 % REFERENCES
 %
 % Van der Meerwe & Wan, Gaussian Mixture Sigma-Point Particle Filters for Sequential
-% Probabilistic Inference in Dynamic State-Space Models.  
-% Heiss & Winschel, 2010, Journal of Applied Economics. 
-% Winschel & Kratzig, 2010, Econometrica. 
+% Probabilistic Inference in Dynamic State-Space Models.
+% Heiss & Winschel, 2010, Journal of Applied Economics.
+% Winschel & Kratzig, 2010, Econometrica.
 %
 % NOTES
 %   The vector "lik" is used to evaluate the jacobian of the likelihood.
@@ -53,7 +53,7 @@ function [LIK,lik] = gaussian_mixture_filter(ReducedForm,Y,start,DynareOptions)
 % You should have received a copy of the GNU General Public License
 % along with Dynare.  If not, see <http://www.gnu.org/licenses/>.
 
-  
+
 persistent init_flag mf0 mf1 Gprime Gsecond
 persistent nodes weights weights_c I J G number_of_particles
 persistent sample_size number_of_state_variables number_of_observed_variables number_of_structural_innovations
@@ -71,9 +71,9 @@ if isempty(init_flag)
   number_of_state_variables = length(mf0);
   number_of_observed_variables = length(mf1);
   number_of_structural_innovations = length(ReducedForm.Q);
-  G = DynareOptions.particle.mixture_state_variables;           % number of GM components in state 
+  G = DynareOptions.particle.mixture_state_variables;           % number of GM components in state
   I = DynareOptions.particle.mixture_structural_shocks ;        % number of GM components in structural noise
-  J = DynareOptions.particle.mixture_measurement_shocks ;       % number of GM components in observation noise 
+  J = DynareOptions.particle.mixture_measurement_shocks ;       % number of GM components in observation noise
   Gprime = G*I ;
   Gsecond = G*I*J ;
   number_of_particles = DynareOptions.particle.number_of_particles;
@@ -81,20 +81,25 @@ if isempty(init_flag)
 end
 
 SampleWeights = ones(Gsecond,1)/Gsecond ;
+
 % compute gaussian quadrature nodes and weights on states and shocks
-if isempty(nodes) && strcmpi(DynareOptions.particle.approximation_method,'quadrature') 
-    [nodes,weights] = nwspgr('GQN',number_of_state_variables,DynareOptions.particle.smolyak_accuracy) ;
-    weights_c = weights ;
-elseif isempty(nodes) && strcmpi(DynareOptions.particle.approximation_method,'cubature')
-    [nodes,weights] = spherical_radial_sigma_points(number_of_state_variables) ;
-    weights_c = weights ;
-elseif isempty(nodes) && strcmpi(DynareOptions.particle.approximation_method,'unscented')
-    [nodes,weights,weights_c] = unscented_sigma_points(number_of_state_variables,DynareOptions) ;    
-else 
-    % Set seed for randn().
+if isempty(nodes)
+    if DynareOptions.particle.distribution_approximation.cubature
+        [nodes,weights] = spherical_radial_sigma_points(number_of_state_variables);
+        weights_c = weights;
+    elseif DynareOptions.particle.distribution_approximation.unscented
+        [nodes,weights,weights_c] = unscented_sigma_points(number_of_state_variables,DynareOptions);
+    else
+        if ~DynareOptions.particle.distribution_approximation.montecarlo
+            error('Estimation: This approximation for the proposal is not implemented or unknown!')
+        end
+    end
+end
+
+if DynareOptions.particle.distribution_approximation.montecarlo
     set_dynare_seed('default');
     SampleWeights = 1/number_of_particles ;
-end 
+end
 
 % Get covariance matrices
 Q = ReducedForm.Q;
@@ -107,24 +112,24 @@ else
 end
 Q_lower_triangular_cholesky = reduced_rank_cholesky(Q)';
 
-% Initialize all matrices 
+% Initialize all matrices
 StateWeights = ones(1,G)/G ;
 StateMu = ReducedForm.StateVectorMean*ones(1,G) ;
 StateSqrtP = zeros(number_of_state_variables,number_of_state_variables,G) ;
 for g=1:G
   StateSqrtP(:,:,g) = reduced_rank_cholesky(ReducedForm.StateVectorVariance)' ;
-end  
+end
 
-StructuralShocksWeights = ones(1,I)/I ; 
+StructuralShocksWeights = ones(1,I)/I ;
 StructuralShocksMu = zeros(number_of_structural_innovations,I) ;
-StructuralShocksSqrtP = zeros(number_of_structural_innovations,number_of_structural_innovations,I) ;			
+StructuralShocksSqrtP = zeros(number_of_structural_innovations,number_of_structural_innovations,I) ;
 for i=1:I
   StructuralShocksSqrtP(:,:,i) = Q_lower_triangular_cholesky ;
-end  
+end
 
-ObservationShocksWeights  = ones(1,J)/J ; 
+ObservationShocksWeights  = ones(1,J)/J ;
 ObservationShocksMu = zeros(number_of_observed_variables,J) ;
-ObservationShocksSqrtP = zeros(number_of_observed_variables,number_of_observed_variables,J) ;			
+ObservationShocksSqrtP = zeros(number_of_observed_variables,number_of_observed_variables,J) ;
 for j=1:J
   ObservationShocksSqrtP(:,:,j) = H_lower_triangular_cholesky ;
 end
@@ -134,8 +139,8 @@ StateMuPrior = zeros(number_of_state_variables,Gprime) ;
 StateSqrtPPrior = zeros(number_of_state_variables,number_of_state_variables,Gprime) ;
 
 StateWeightsPost = zeros(1,Gsecond) ;
-StateMuPost = zeros(number_of_state_variables,Gsecond) ;			
-StateSqrtPPost = zeros(number_of_state_variables,number_of_state_variables,Gsecond) ;			
+StateMuPost = zeros(number_of_state_variables,Gsecond) ;
+StateSqrtPPost = zeros(number_of_state_variables,number_of_state_variables,Gsecond) ;
 
 %estimate = zeros(sample_size,number_of_state_variables,3) ;
 const_lik = (2*pi)^(.5*number_of_observed_variables) ;
@@ -145,70 +150,68 @@ lik  = NaN(sample_size,1);
 LIK  = NaN;
 for t=1:sample_size
     % Build the proposal joint quadratures of Gaussian on states, structural
-    % shocks and observation shocks based on each combination of mixtures 
-    for i=1:I 
-        for j=1:J 
+    % shocks and observation shocks based on each combination of mixtures
+    for i=1:I
+        for j=1:J
             for g=1:G ;
                 a = g + (j-1)*G ;
-                b = a + (i-1)*Gprime ;		
+                b = a + (i-1)*Gprime ;
                 [StateMuPrior(:,a),StateSqrtPPrior(:,:,a),StateWeightsPrior(1,a),...
                  StateMuPost(:,b),StateSqrtPPost(:,:,b),StateWeightsPost(1,b)] =...
                  gaussian_mixture_filter_bank(ReducedForm,Y(:,t),StateMu(:,g),StateSqrtP(:,:,g),StateWeights(1,g),...
                                                                  StructuralShocksMu(:,i),StructuralShocksSqrtP(:,:,i),StructuralShocksWeights(1,i),...
                                                                  ObservationShocksMu(:,j),ObservationShocksSqrtP(:,:,j),ObservationShocksWeights(1,j),...
                                                                  H,H_lower_triangular_cholesky,const_lik,DynareOptions) ;
-            end 
+            end
         end
     end
-    
-    % Normalize weights 
-    StateWeightsPrior = StateWeightsPrior/sum(StateWeightsPrior,2) ;			
-    StateWeightsPost = StateWeightsPost/sum(StateWeightsPost,2) ;		
-    
-    if strcmpi(DynareOptions.particle.approximation_method,'quadrature') || ... % sparse grids approximations 
-       strcmpi(DynareOptions.particle.approximation_method,'cubature') || ...
-       strcmpi(DynareOptions.particle.approximation_method,'unscented')
-        for i=1:Gsecond 
-            StateParticles = bsxfun(@plus,StateMuPost(:,i),StateSqrtPPost(:,:,i)*nodes') ;    
+
+    % Normalize weights
+    StateWeightsPrior = StateWeightsPrior/sum(StateWeightsPrior,2) ;
+    StateWeightsPost = StateWeightsPost/sum(StateWeightsPost,2) ;
+
+    if DynareOptions.particle.distribution_approximation.cubature || DynareOptions.particle.distribution_approximation.unscented
+        for i=1:Gsecond
+            StateParticles = bsxfun(@plus,StateMuPost(:,i),StateSqrtPPost(:,:,i)*nodes') ;
             IncrementalWeights = gaussian_mixture_densities(Y(:,t),StateMuPrior,StateSqrtPPrior,StateWeightsPrior,...
                                                                    StateMuPost,StateSqrtPPost,StateWeightsPost,...
                                                                    StateParticles,H,const_lik,weights,weights_c,ReducedForm,DynareOptions) ;
             SampleWeights(i) = sum(StateWeightsPost(i)*weights.*IncrementalWeights) ;
-        end 
+        end
         SumSampleWeights = sum(SampleWeights) ;
         lik(t) = log(SumSampleWeights) ;
-        SampleWeights = SampleWeights./SumSampleWeights ;			
-        [ras,SortedRandomIndx] = sort(rand(1,Gsecond));        
+        SampleWeights = SampleWeights./SumSampleWeights ;
+        [ras,SortedRandomIndx] = sort(rand(1,Gsecond));
         SortedRandomIndx = SortedRandomIndx(1:G);
         indx = index_resample(0,SampleWeights,DynareOptions) ;
         indx = indx(SortedRandomIndx) ;
         StateMu = StateMuPost(:,indx);
         StateSqrtP = StateSqrtPPost(:,:,indx);
         StateWeights = ones(1,G)/G ;
-    else 
+    else
         % Sample particle in the proposal distribution, ie the posterior state GM
-        StateParticles = importance_sampling(StateMuPost,StateSqrtPPost,StateWeightsPost',number_of_particles) ;	
-        % Compute prior, proposal and likelihood of particles 
+        StateParticles = importance_sampling(StateMuPost,StateSqrtPPost,StateWeightsPost',number_of_particles) ;
+        % Compute prior, proposal and likelihood of particles
         IncrementalWeights = gaussian_mixture_densities(Y(:,t),StateMuPrior,StateSqrtPPrior,StateWeightsPrior,...
                                                                StateMuPost,StateSqrtPPost,StateWeightsPost,...
                                                                StateParticles,H,const_lik,1/number_of_particles,...
                                                                1/number_of_particles,ReducedForm,DynareOptions) ;
-        % calculate importance weights of particles 			
-        SampleWeights = SampleWeights.*IncrementalWeights ;			
+        % calculate importance weights of particles
+        SampleWeights = SampleWeights.*IncrementalWeights ;
         SumSampleWeights = sum(SampleWeights,1) ;
-        SampleWeights = SampleWeights./SumSampleWeights ;			
+        SampleWeights = SampleWeights./SumSampleWeights ;
         lik(t) = log(SumSampleWeights) ;
         % First possible state point estimates
         %estimate(t,:,1) = SampleWeights*StateParticles' ;
-        % Resampling if needed of required 
+        % Resampling if needed of required
         Neff = 1/sum(bsxfun(@power,SampleWeights,2)) ;
-        if (Neff<.5*sample_size && strcmpi(DynareOptions.particle.resampling.status,'generic')) || strcmpi(DynareOptions.particle.resampling.status,'systematic')
+        if (DynareOptions.particle.resampling.status.generic && Neff<.5*sample_size) || DynareOptions.particle.resampling.status.systematic
             ks = ks + 1 ;
-            StateParticles = resample(StateParticles',SampleWeights,DynareOptions)' ; 
+            StateParticles = resample(StateParticles',SampleWeights,DynareOptions)' ;
             StateVectorMean = mean(StateParticles,2) ;
             StateVectorVarianceSquareRoot = reduced_rank_cholesky( (StateParticles*StateParticles')/number_of_particles - StateVectorMean*(StateVectorMean') )';
             SampleWeights = 1/number_of_particles ;
-        elseif strcmpi(DynareOptions.particle.resampling.status,'none')
+        elseif DynareOptions.particle.resampling.status.none
             StateVectorMean = StateParticles*sampleWeights ;
             temp = sqrt(SampleWeights').*StateParticles ;
             StateVectorVarianceSquareRoot = reduced_rank_cholesky( temp*temp' - StateVectorMean*(StateVectorMean') )';
diff --git a/matlab/particle/gaussian_mixture_filter_bank.m b/matlab/particle/gaussian_mixture_filter_bank.m
index 9d931f1290e60642249b1bfe154ff6740c2ea053..3a3caa776a546c7c3a3ebb35861273ea49dd1120 100644
--- a/matlab/particle/gaussian_mixture_filter_bank.m
+++ b/matlab/particle/gaussian_mixture_filter_bank.m
@@ -79,48 +79,41 @@ end
 
 numb = number_of_state_variables+number_of_structural_innovations ;
 
-if strcmpi(DynareOptions.particle.IS_approximation_method,'quadrature') 
-    [nodes3,weights3] = nwspgr('GQN',numb,DynareOptions.particle.smolyak_accuracy) ;
-    weights_c3 = weights3 ;
-end
-if strcmpi(DynareOptions.particle.IS_approximation_method,'cubature')
-    [nodes3,weights3] = spherical_radial_sigma_points(numb) ;
-    weights_c3 = weights3 ;
-end
-if strcmpi(DynareOptions.particle.IS_approximation_method,'unscented')
-    [nodes3,weights3,weights_c3] = unscented_sigma_points(numb,DynareOptions) ;    
+if DynareOptions.particle.proposal_approximation.cubature
+    [nodes3,weights3] = spherical_radial_sigma_points(numb);
+    weights_c3 = weights3;
+elseif DynareOptions.particle.proposal_approximation.unscented
+    [nodes3,weights3,weights_c3] = unscented_sigma_points(numb,DynareOptions);
+else
+    error('Estimation: This approximation for the proposal is not implemented or unknown!')
 end
 
 epsilon =  bsxfun(@plus,StructuralShocksSqrtP*nodes3(:,number_of_state_variables+1:number_of_state_variables+number_of_structural_innovations)',StructuralShocksMu) ;
 StateVectors = bsxfun(@plus,StateSqrtP*nodes3(:,1:number_of_state_variables)',StateMu);
-%ObservationShocks = bsxfun(@plus,ObservationShocksSqrtP*nodes3(:,1+number_of_state_variables+number_of_structural_innovations:number_of_state_variables+number_of_structural_innovations+number_of_observed_variables)',ObservationShocksMu)  ; 
-
-yhat = bsxfun(@minus,StateVectors,state_variables_steady_state) ;
+yhat = bsxfun(@minus,StateVectors,state_variables_steady_state);
 tmp = local_state_space_iteration_2(yhat,epsilon,ghx,ghu,constant,ghxx,ghuu,ghxu,DynareOptions.threads.local_state_space_iteration_2);
 PredictedStateMean = tmp(mf0,:)*weights3;
 PredictedObservedMean = tmp(mf1,:)*weights3;
 
-if strcmpi(DynareOptions.particle.IS_approximation_method,'cubature')
-    PredictedStateMean = sum(PredictedStateMean,2) ;
-    PredictedObservedMean = sum(PredictedObservedMean,2) ;
-    dState = (bsxfun(@minus,tmp(mf0,:),PredictedStateMean)').*sqrt(weights3) ;
+if DynareOptions.particle.proposal_approximation.cubature
+    PredictedStateMean = sum(PredictedStateMean,2);
+    PredictedObservedMean = sum(PredictedObservedMean,2);
+    dState = (bsxfun(@minus,tmp(mf0,:),PredictedStateMean)').*sqrt(weights3);
     dObserved = (bsxfun(@minus,tmp(mf1,:),PredictedObservedMean)').*sqrt(weights3);
     PredictedStateVariance = dState'*dState;
-    big_mat = [dObserved  dState ; [H_lower_triangular_cholesky zeros(number_of_observed_variables,number_of_state_variables)] ] ;
-    [mat1,mat] = qr2(big_mat,0) ;
-    mat = mat' ; 
+    big_mat = [dObserved  dState ; [H_lower_triangular_cholesky zeros(number_of_observed_variables,number_of_state_variables)] ];
+    [mat1,mat] = qr2(big_mat,0);
+    mat = mat';
     clear('mat1');
-    PredictedObservedVarianceSquareRoot = mat(1:number_of_observed_variables,1:number_of_observed_variables) ;
-    CovarianceObservedStateSquareRoot = mat(number_of_observed_variables+(1:number_of_state_variables),1:number_of_observed_variables) ;
-    StateVectorVarianceSquareRoot = mat(number_of_observed_variables+(1:number_of_state_variables),number_of_observed_variables+(1:number_of_state_variables)) ;
+    PredictedObservedVarianceSquareRoot = mat(1:number_of_observed_variables,1:number_of_observed_variables);
+    CovarianceObservedStateSquareRoot = mat(number_of_observed_variables+(1:number_of_state_variables),1:number_of_observed_variables);
+    StateVectorVarianceSquareRoot = mat(number_of_observed_variables+(1:number_of_state_variables),number_of_observed_variables+(1:number_of_state_variables));
     iPredictedObservedVarianceSquareRoot = inv(PredictedObservedVarianceSquareRoot);
-    iPredictedObservedVariance = iPredictedObservedVarianceSquareRoot'*iPredictedObservedVarianceSquareRoot ;
-    sqrdet = 1/sqrt(det(iPredictedObservedVariance)) ;
-    PredictionError = obs - PredictedObservedMean ;
+    iPredictedObservedVariance = iPredictedObservedVarianceSquareRoot'*iPredictedObservedVarianceSquareRoot;
+    sqrdet = 1/sqrt(det(iPredictedObservedVariance));
+    PredictionError = obs - PredictedObservedMean;
     StateVectorMean = PredictedStateMean + CovarianceObservedStateSquareRoot*iPredictedObservedVarianceSquareRoot*PredictionError;
-end 
-if strcmpi(DynareOptions.particle.IS_approximation_method,'quadrature') || ...
-   strcmpi(DynareOptions.particle.IS_approximation_method,'unscented') 
+else
     dState = bsxfun(@minus,tmp(mf0,:),PredictedStateMean);
     dObserved = bsxfun(@minus,tmp(mf1,:),PredictedObservedMean);
     PredictedStateVariance = dState*diag(weights_c3)*dState';
@@ -133,13 +126,13 @@ if strcmpi(DynareOptions.particle.IS_approximation_method,'quadrature') || ...
     StateVectorMean = PredictedStateMean + KalmanFilterGain*PredictionError;
     StateVectorVariance = PredictedStateVariance - KalmanFilterGain*PredictedObservedVariance*KalmanFilterGain';
     StateVectorVariance = .5*(StateVectorVariance+StateVectorVariance');
-    StateVectorVarianceSquareRoot = reduced_rank_cholesky(StateVectorVariance)'; 
-end 
+    StateVectorVarianceSquareRoot = reduced_rank_cholesky(StateVectorVariance)';
+end
 
-data_lik_GM_g = exp(-0.5*PredictionError'*iPredictedObservedVariance*PredictionError)/abs(normfactO*sqrdet) + 1e-99;			
+data_lik_GM_g = exp(-0.5*PredictionError'*iPredictedObservedVariance*PredictionError)/abs(normfactO*sqrdet) + 1e-99;
 StateMuPrior = PredictedStateMean ;
-StateSqrtPPrior = reduced_rank_cholesky(PredictedStateVariance)' ;
-StateWeightsPrior = StateWeights*StructuralShocksWeights ;			
-StateMuPost = StateVectorMean ;
-StateSqrtPPost = StateVectorVarianceSquareRoot ;
-StateWeightsPost = StateWeightsPrior*ObservationShocksWeights*data_lik_GM_g ;			
+StateSqrtPPrior = reduced_rank_cholesky(PredictedStateVariance)';
+StateWeightsPrior = StateWeights*StructuralShocksWeights;
+StateMuPost = StateVectorMean;
+StateSqrtPPost = StateVectorVarianceSquareRoot;
+StateWeightsPost = StateWeightsPrior*ObservationShocksWeights*data_lik_GM_g ;
diff --git a/matlab/particle/index_resample.m b/matlab/particle/index_resample.m
index 7587ca483309e0541a2a19ba8e299a1b1e155bb7..e916456054ae0261f988b34bc41d8cc263e1dd39 100644
--- a/matlab/particle/index_resample.m
+++ b/matlab/particle/index_resample.m
@@ -51,26 +51,22 @@ function resampling_index = index_resample(particles,weights,DynareOptions)
 % You should have received a copy of the GNU General Public License
 % along with Dynare.  If not, see <http://www.gnu.org/licenses/>.
 
-% AUTHOR(S) frederic DOT karame AT univ DASH evry DOT fr
-%           stephane DOT adjemian AT univ DASH lemans DOT fr
+defaultmethod = 1; % For residual based method set this variable equal to 0.
 
-switch DynareOptions.particle.resampling.method1
-  case 'residual'
-    if strcmpi(DynareOptions.particle.resampling.method2,'kitagawa')
-        resampling_index = residual_resampling(particles,weights,rand);
-    elseif strcmpi(DynareOptions.particle.resampling.method2,'stratified')
-        resampling_index = residual_resampling(particles,weights,rand(size(weights)));
-    else
-        error('particle::resample: Unknown method!')
-    end
-  case 'traditional'
-    if strcmpi(DynareOptions.particle.resampling.method2,'kitagawa')
+if defaultmethod
+    if DynareOptions.particle.resampling.method.kitagawa
         resampling_index = traditional_resampling(particles,weights,rand);
-    elseif strcmpi(DynareOptions.particle.resampling.method2,'stratified')
+    elseif DynareOptions.particle.resampling.method.stratified
         resampling_index = traditional_resampling(particles,weights,rand(size(weights)));
     else
-        error('particle::resample: Unknown method!')
+        error('Unknow sampling method!')
+    end
+else
+    if DynareOptions.particle.resampling.method.kitagawa
+        resampled_particles = residual_resampling(particles,weights,rand);
+    elseif DynareOptions.particle.resampling.method.stratified
+        resampled_particles = residual_resampling(particles,weights,rand(size(weights)));
+    else
+        error('Unknown sampling method!')
     end
-  otherwise
-    error('particle::resample: Unknown method!')
 end
\ No newline at end of file
diff --git a/matlab/particle/local_state_space_iteration/local_state_space_iteration_2.m b/matlab/particle/local_state_space_iteration/local_state_space_iteration_2.m
index bc205d1803497df5910a92423c8e8450a03edabb..0c6a52d071a74c84dfcd2c69cd16cce9233084b5 100644
--- a/matlab/particle/local_state_space_iteration/local_state_space_iteration_2.m
+++ b/matlab/particle/local_state_space_iteration/local_state_space_iteration_2.m
@@ -135,9 +135,9 @@ end
 %$ end
 %$
 %$ % Check the results.
-%$ t(1) = dyn_assert(y1,ones(n,1));
-%$ t(2) = dyn_assert(y2,ones(n,1));
-%$ t(3) = dyn_assert(y2_,ones(n,1));
+%$ t(1) = dassert(y1,ones(n,1));
+%$ t(2) = dassert(y2,ones(n,1));
+%$ t(3) = dassert(y2_,ones(n,1));
 %$ T = all(t);
 %@eof:1
 
@@ -218,9 +218,9 @@ end
 %$     cd(where_am_i_coming_from);
 %$     dynare_config([],0);
 %$     % Check the results.
-%$     t(1) = dyn_assert(y1a,y1b);
-%$     t(2) = dyn_assert(y2a,y2b);
-%$     t(3) = dyn_assert(y2a_,y2b_);
+%$     t(1) = dassert(y1a,y1b);
+%$     t(2) = dassert(y2a,y2b);
+%$     t(3) = dassert(y2a_,y2b_);
 %$     T = all(t);
 %$ else
 %$     t(1) = 1;
@@ -258,13 +258,13 @@ end
 %$ t1 = toc;
 %$ tic, for i=1:10, y2 = local_state_space_iteration_2(yhat,epsilon,ghx,ghu,constant,ghxx,ghuu,ghxu,2); end
 %$ t2 = toc;
-%$ t(1) = dyn_assert(y1,y2,1e-15); clear('y1');
+%$ t(1) = dassert(y1,y2,1e-15); clear('y1');
 %$ tic, for i=1:10, y3 = local_state_space_iteration_2(yhat,epsilon,ghx,ghu,constant,ghxx,ghuu,ghxu,3); end
 %$ t3 = toc;
-%$ t(2) = dyn_assert(y2,y3,1e-15); clear('y2');
+%$ t(2) = dassert(y2,y3,1e-15); clear('y2');
 %$ tic, for i=1:10, y4 = local_state_space_iteration_2(yhat,epsilon,ghx,ghu,constant,ghxx,ghuu,ghxu,4); end
 %$ t4 = toc;
-%$ t(3) = dyn_assert(y4,y3,1e-15); clear('y3','y4');
+%$ t(3) = dassert(y4,y3,1e-15); clear('y3','y4');
 %$ t(4) = (t1>t2) && (t2>t3) && (t3>t4);
 %$ if ~t(4)
 %$     disp('Timmings:')
diff --git a/matlab/particle/online_auxiliary_filter.m b/matlab/particle/online_auxiliary_filter.m
index 7089a9038977a3b7d1ccde357b8ca68cde94dbe1..1edcb66b9f7750a1745a2bba40493d95cce6e2ab 100644
--- a/matlab/particle/online_auxiliary_filter.m
+++ b/matlab/particle/online_auxiliary_filter.m
@@ -85,8 +85,8 @@ small_a = sqrt(1-h_square) ;
 
 % Initialization of parameter particles 
 xparam = zeros(number_of_parameters,number_of_particles) ;
-stderr = sqrt(bsxfun(@power,bounds(:,2)+bounds(:,1),2)/12)/100 ;
-stderr = sqrt(bsxfun(@power,bounds(:,2)+bounds(:,1),2)/12)/50 ;
+%stderr = sqrt(bsxfun(@power,bounds(:,2)+bounds(:,1),2)/12)/100 ;
+stderr = sqrt(bsxfun(@power,bounds(:,2)+bounds(:,1),2)/12)/10 ;
 i = 1 ;
 while i<=number_of_particles
     %candidate = start_param + .001*liu_west_chol_sigma_bar*randn(number_of_parameters,1) ;
@@ -110,7 +110,10 @@ std_xparam = zeros(number_of_parameters,sample_size) ;
 lb95_xparam = zeros(number_of_parameters,sample_size) ;
 ub95_xparam = zeros(number_of_parameters,sample_size) ;
 
-%% The Online filter 
+disp(0) 
+disp(start_param)
+    
+    %% The Online filter 
 for t=1:sample_size
     disp(t)
     % Moments of parameters particles distribution 
@@ -206,7 +209,7 @@ for t=1:sample_size
     wtilde = lnw./wtilde ;
     % normalization 
     weights = wtilde/sum(wtilde);
-    if (variance_update==1) && (neff(weights)<DynareOptions.particle.resampling.neff_threshold*sample_size)
+    if (variance_update==1) && (neff(weights)<DynareOptions.particle.resampling.threshold*sample_size)
         variance_update = 0 ;
     end
     % final resampling (advised)
diff --git a/matlab/particle/resample.m b/matlab/particle/resample.m
index 05e5f033fc906c531c9c35f35369da69000222e3..a72894428262efd98b685fb5438cccdad33e159c 100644
--- a/matlab/particle/resample.m
+++ b/matlab/particle/resample.m
@@ -51,29 +51,24 @@ function resampled_particles = resample(particles,weights,DynareOptions)
 % You should have received a copy of the GNU General Public License
 % along with Dynare.  If not, see <http://www.gnu.org/licenses/>.
 
-% AUTHOR(S) frederic DOT karame AT univ DASH evry DOT fr
-%           stephane DOT adjemian AT univ DASH lemans DOT fr
+defaultmethod = 1; % For residual based method set this variable equal to 0.
 
-
-switch DynareOptions.particle.resampling.method1
-  case 'residual'
-    if strcmpi(DynareOptions.particle.resampling.method2,'kitagawa')
-        resampled_particles = residual_resampling(particles,weights,rand);
-    elseif strcmpi(DynareOptions.particle.resampling.method2,'stratified')
-        resampled_particles = residual_resampling(particles,weights,rand(size(weights)));
-    else
-        error('particle::resample: Unknown method!')
-    end
-  case 'traditional'
-    if strcmpi(DynareOptions.particle.resampling.method2,'kitagawa')
+if defaultmethod
+    if DynareOptions.particle.resampling.method.kitagawa
         resampled_particles = traditional_resampling(particles,weights,rand);
-    elseif strcmpi(DynareOptions.particle.resampling.method2,'stratified')
+    elseif DynareOptions.particle.resampling.method.stratified
         resampled_particles = traditional_resampling(particles,weights,rand(size(weights)));
+    elseif DynareOptions.particle.resampling.method.smooth
+        resampled_particles = multivariate_smooth_resampling(particles,weights);
+    else
+        error('Unknow sampling method!')
+    end
+else
+    if DynareOptions.particle.resampling.method.kitagawa
+        resampled_particles = residual_resampling(particles,weights,rand);
+    elseif DynareOptions.particle.resampling.method.stratified
+        resampled_particles = residual_resampling(particles,weights,rand(size(weights)));
     else
-        error('particle::resample: Unknown method!')
+        error('Unknown sampling method!')
     end
-  case 'smooth'
-    resampled_particles = multivariate_smooth_resampling(particles,weights) ;
-  otherwise
-    error('particle::resample: Unknown method!')
 end
diff --git a/matlab/particle/sequential_importance_particle_filter.m b/matlab/particle/sequential_importance_particle_filter.m
index 6474f6cdab7ce2d8215c81eb97e7305db8f9a91d..eadaeba41f85d381072bfd01c03d04f68b70e29d 100644
--- a/matlab/particle/sequential_importance_particle_filter.m
+++ b/matlab/particle/sequential_importance_particle_filter.m
@@ -158,8 +158,7 @@ for t=1:sample_size
     wtilde = weights.*exp(lnw-dfac);
     lik(t) = log(sum(wtilde))+dfac;
     weights = wtilde/sum(wtilde);
-    if (strcmp(DynareOptions.particle.resampling.status,'generic') && neff(weights)<DynareOptions.particle.resampling.neff_threshold*sample_size ) || ...
-        strcmp(DynareOptions.particle.resampling.status,'systematic')
+    if (DynareOptions.particle.resampling.status.generic && neff(weights)<DynareOptions.particle.resampling.threshold*sample_size) || DynareOptions.particle.resampling.status.systematic
         if pruning
             temp = resample([tmp(mf0,:)' tmp_(mf0,:)'],weights',DynareOptions);
             StateVectors = temp(:,1:number_of_state_variables)';
@@ -168,7 +167,7 @@ for t=1:sample_size
             StateVectors = resample(tmp(mf0,:)',weights',DynareOptions)';
         end
         weights = ones(1,number_of_particles)/number_of_particles;
-    elseif strcmp(DynareOptions.particle.resampling.status,'none')
+    elseif DynareOptions.particle.resampling.status.none
         StateVectors = tmp(mf0,:);
         if pruning
             StateVectors_ = tmp_(mf0,:);
diff --git a/matlab/particle/solve_model_for_online_filter.m b/matlab/particle/solve_model_for_online_filter.m
index bdcf5b12a63a36bfaaa37c10038137a5b1dc531e..31fb7f7e69960c27c4a2cb5173a0290385ac9349 100644
--- a/matlab/particle/solve_model_for_online_filter.m
+++ b/matlab/particle/solve_model_for_online_filter.m
@@ -307,11 +307,18 @@ end
 
 ReducedForm.ghx  = dr.ghx(restrict_variables_idx,:);
 ReducedForm.ghu  = dr.ghu(restrict_variables_idx,:);
-ReducedForm.ghxx = dr.ghxx(restrict_variables_idx,:);
-ReducedForm.ghuu = dr.ghuu(restrict_variables_idx,:);
-ReducedForm.ghxu = dr.ghxu(restrict_variables_idx,:);
 ReducedForm.steadystate = dr.ys(dr.order_var(restrict_variables_idx));
-ReducedForm.constant = ReducedForm.steadystate + .5*dr.ghs2(restrict_variables_idx);
+if DynareOptions.order>1
+    ReducedForm.ghxx = dr.ghxx(restrict_variables_idx,:);
+    ReducedForm.ghuu = dr.ghuu(restrict_variables_idx,:);
+    ReducedForm.ghxu = dr.ghxu(restrict_variables_idx,:);
+    ReducedForm.constant = ReducedForm.steadystate + .5*dr.ghs2(restrict_variables_idx);
+else 
+    ReducedForm.ghxx = zeros(size(restrict_variables_idx,1),size(dr.kstate,2));
+    ReducedForm.ghuu = zeros(size(restrict_variables_idx,1),size(dr.ghu,2));
+    ReducedForm.ghxu = zeros(size(restrict_variables_idx,1),size(dr.ghx,2));
+    ReducedForm.constant = ReducedForm.steadystate ;
+end
 ReducedForm.state_variables_steady_state = dr.ys(dr.order_var(state_variables_idx));
 ReducedForm.Q = Q;
 ReducedForm.H = H;
@@ -323,7 +330,7 @@ if observation_number==1
     switch DynareOptions.particle.initialization
       case 1% Initial state vector covariance is the ergodic variance associated to the first order Taylor-approximation of the model.
         StateVectorMean = ReducedForm.constant(mf0);
-        StateVectorVariance = lyapunov_symm(ReducedForm.ghx(mf0,:),ReducedForm.ghu(mf0,:)*ReducedForm.Q*ReducedForm.ghu(mf0,:)',1e-12,1e-12);
+        StateVectorVariance = lyapunov_symm(ReducedForm.ghx(mf0,:),ReducedForm.ghu(mf0,:)*ReducedForm.Q*ReducedForm.ghu(mf0,:)',1e-12,1e-12,[],[],DynareOptions.debug);
       case 2% Initial state vector covariance is a monte-carlo based estimate of the ergodic variance (consistent with a k-order Taylor-approximation of the model).
         StateVectorMean = ReducedForm.constant(mf0);
         old_DynareOptionsperiods = DynareOptions.periods;
diff --git a/matlab/particle/traditional_resampling.m b/matlab/particle/traditional_resampling.m
index 6c7b70ed0b8087cbee52cff03e1942ebb6013e1c..a9d86eb36e1705d95b50adfa21279a74ccabf937 100644
--- a/matlab/particle/traditional_resampling.m
+++ b/matlab/particle/traditional_resampling.m
@@ -231,7 +231,7 @@ end
 %$ end
 %$
 %$ % Check results.
-%$ t(1) = dyn_assert(indx1,indx1_);
-%$ t(2) = dyn_assert(indx2,indx2_);
+%$ t(1) = dassert(indx1,indx1_);
+%$ t(2) = dassert(indx2,indx2_);
 %$ T = all(t);
 %@eof:3
\ No newline at end of file
diff --git a/matlab/perfect_foresight_solver.m b/matlab/perfect_foresight_solver.m
index ec88ab319312cf0df65070763c90273e7403baad..bfeb16e4f309ef2e33dcb4953923df7d03a12f53 100644
--- a/matlab/perfect_foresight_solver.m
+++ b/matlab/perfect_foresight_solver.m
@@ -141,7 +141,7 @@ end
 if oo_.deterministic_simulation.status == 1
     disp('Perfect foresight solution found.')
 else
-    disp('Failed to solve perfect foresight model')
+    warning('Failed to solve perfect foresight model')
 end
 
 dyn2vec;
diff --git a/matlab/pm3.m b/matlab/pm3.m
index 9e34bf1c045538a3f2d2839ad4918d22c768455b..583cd6ff04ebee6b038ac0b168a260870639c966 100644
--- a/matlab/pm3.m
+++ b/matlab/pm3.m
@@ -1,10 +1,31 @@
 function pm3(n1,n2,ifil,B,tit1,tit2,tit3,tit_tex,names1,names2,name3,DirectoryName,var_type)
+% pm3(n1,n2,ifil,B,tit1,tit2,tit3,tit_tex,names1,names2,name3,DirectoryName,var_type)
+% Computes, stores and plots the posterior moment statistics.
+%
+% Inputs:
+%  n1           [scalar] size of first dimension of moment matrix
+%  n2           [scalar] size of second dimension of moment matrix
+%  ifil         [scalar] number of moment files to load
+%  B         [scalar] number of subdraws
+%  tit1         [string] Figure title 
+%  tit2         [string] not used
+%  tit3         [string] Save name for figure
+%  tit_tex      [cell array] TeX-Names for Variables
+%  name1        [cell array] Names of variables subset selected for moments
+%  name2            [cell array] Names of all variables in the moment matrix from
+%                       which names1 is selected
+%  name3        [string] Name of the field in oo_ structure to be set
+%  name3        [string] Name of the field in oo_ structure to be set
+%  DirectoryName [string] Name of the directory in which to save and from
+%                       where to read
+%  var_type     [string] suffix of the filename from which to load moment
+%                   matrix
 
 % PARALLEL CONTEXT
 % See also the comment in random_walk_metropolis_hastings.m funtion.
 
 
-% Copyright (C) 2007-2013 Dynare Team
+% Copyright (C) 2007-2014 Dynare Team
 %
 % This file is part of Dynare.
 %
@@ -40,9 +61,8 @@ else
     end
 end
 if options_.TeX
-    % needs to be fixed
     if isempty(tit_tex),
-        tit_tex=M_.endo_names_tex;
+        tit_tex=names1;
     end
         
     varlist_TeX = [];
@@ -126,8 +146,8 @@ for i = 1:nvar
     eval(['oo_.' name3 '.Median.' name ' = Median(:,i);']);
     eval(['oo_.' name3 '.Var.' name ' = Var(:,i);']);
     eval(['oo_.' name3 '.deciles.' name ' = Distrib(:,:,i);']);
-    eval(['oo_.' name3 '.HPDinf.' name ' = HPD(1,:,i);']);
-    eval(['oo_.' name3 '.HPDsup.' name ' = HPD(2,:,i);']);
+    eval(['oo_.' name3 '.HPDinf.' name ' = HPD(1,:,i)'';']);
+    eval(['oo_.' name3 '.HPDsup.' name ' = HPD(2,:,i)'';']);
     if filter_step_ahead_indicator
         for K_step = 1:length(options_.filter_step_ahead)
             name4=['Filtered_Variables_',num2str(K_step),'_step_ahead'];
diff --git a/matlab/print_info.m b/matlab/print_info.m
index 2aded2e6b98398ef3ac5142450a864d3a1c074c1..0ec5e378884827ee3e9790ad901c4fb9c1db2e3f 100644
--- a/matlab/print_info.m
+++ b/matlab/print_info.m
@@ -65,9 +65,13 @@ if ~noprint
           error(['The Jacobian contains NaNs. For more information, use options_.debug.'])
         end
       case 9
-        error(['k_order_pert was unable to compute the solution']) 
+        error(['k_order_pert was unable to compute the solution'])
       case 10
-        error(['The Jacobian or the dynamic model contains Inf. For more information, use options_.debug.'])         
+        error(['The Jacobian of the dynamic model contains Inf. For more information, use options_.debug.'])
+      case 11
+        error('The Hessian of the dynamic model used for second order solutions must not contain Inf')
+      case 12
+        error('The Hessian of the dynamic model used for second order solutions must not contain NaN')
       case 19
         error('The steadystate file did not compute the steady state')
       case 20
@@ -120,6 +124,18 @@ if ~noprint
       case 72
         error(['Calibrated covariance of the measurement errors implies correlation larger than  +-1.']);
         % Aim Code Conversions by convertAimCodeToInfo.m
+      case 81
+        error(['Ramsey: The solution to the static first order conditions for optimal policy could not be found. Either the model' ...
+               ' doesn''t have a steady state, there are an infinity of steady states, ' ...
+               ' or the guess values are too far from the solution']);
+      case 82
+        error(['Ramsey: The steady state computation resulted in NaN in the static first order conditions for optimal policy']);
+      case 83
+        error(['Ramsey: The steady state computation resulted in NaN in the auxiliary equations for optimal policy']);
+      case 84
+        error(['Ramsey: The steady state file computation for the Ramsey problem resulted in NaNs at the initial values of the instruments']);
+      case 85
+        error(['Ramsey: The steady state file does not solve the static first order conditions conditional on the instruments.']);
       case 102
         error('Aim: roots not correctly computed by real_schur');
       case 103
diff --git a/matlab/prior_bounds.m b/matlab/prior_bounds.m
index 4eb290e57ddcd9597d34f2360542eef6f22d5970..a224c69a0a184e774e8ca4bd2ba9a21144750947 100644
--- a/matlab/prior_bounds.m
+++ b/matlab/prior_bounds.m
@@ -21,8 +21,7 @@ function bounds = prior_bounds(bayestopt,options)
 %! @sp 1
 %! @table @ @var
 %! @item bounds
-%! p*2 matrix of doubles, where p is the number of estimated parameters. The first and second columns report
-%! respectively the lower and upper bounds.
+%! A structure with two fields lb and up (p*1 vectors of doubles, where p is the number of estimated parameters) for the lower and upper bounds.
 %! @end table
 %! @sp 2
 %! @strong{This function is called by:}
@@ -43,7 +42,7 @@ function bounds = prior_bounds(bayestopt,options)
 %    bayestopt  [structure]  characterizing priors (shape, mean, p1..p4)
 %    
 % OUTPUTS
-%    bounds     [double]      matrix specifying prior bounds (row= parameter, column=lower&upper bound)
+%    bounds     [double]      structure specifying prior bounds (lb and ub fields)
 %    
 % SPECIAL REQUIREMENTS
 %    none
@@ -72,27 +71,27 @@ p6 = bayestopt.p6;
 p7 = bayestopt.p7;
 prior_trunc = options.prior_trunc;
 
-bounds = zeros(length(p6),2);
+bounds.lb = zeros(length(p6),1);
+bounds.ub = zeros(length(p6),1);
 
 for i=1:length(p6)
     switch pshape(i)
       case 1
         if prior_trunc == 0
-            bounds(i,1) = p3(i);
-            bounds(i,2) = p4(i);
+            bounds.lb(i) = p3(i);
+            bounds.ub(i) = p4(i);
         else
-            bounds(i,1) = betainv(prior_trunc,p6(i),p7(i))*(p4(i)-p3(i))+p3(i);
-            bounds(i,2) = betainv(1-prior_trunc,p6(i),p7(i))* ...
-                (p4(i)-p3(i))+p3(i);
+            bounds.lb(i) = betainv(prior_trunc,p6(i),p7(i))*(p4(i)-p3(i))+p3(i);
+            bounds.ub(i) = betainv(1-prior_trunc,p6(i),p7(i))*(p4(i)-p3(i))+p3(i);
         end
       case 2
         if prior_trunc == 0
-            bounds(i,1) = p3(i);
-            bounds(i,2) = Inf;
+            bounds.lb(i) = p3(i);
+            bounds.ub(i) = Inf;
         else
             try
-                bounds(i,1) = gaminv(prior_trunc,p6(i),p7(i))+p3(i);
-                bounds(i,2) = gaminv(1-prior_trunc,p6(i),p7(i))+p3(i);
+                bounds.lb(i) = gaminv(prior_trunc,p6(i),p7(i))+p3(i);
+                bounds.ub(i) = gaminv(1-prior_trunc,p6(i),p7(i))+p3(i);
             catch
                 % Workaround for ticket #161
                 if isoctave
@@ -104,21 +103,20 @@ for i=1:length(p6)
         end
       case 3
         if prior_trunc == 0
-            bounds(i,1) = -Inf;
-            bounds(i,2) = Inf;
+            bounds.lb(i) = -Inf;
+            bounds.ub(i) = Inf;
         else
-            bounds(i,1) = norminv(prior_trunc,p6(i),p7(i));
-            bounds(i,2) = norminv(1-prior_trunc,p6(i),p7(i));
+            bounds.lb(i) = norminv(prior_trunc,p6(i),p7(i));
+            bounds.ub(i) = norminv(1-prior_trunc,p6(i),p7(i));
         end
       case 4
         if prior_trunc == 0
-            bounds(i,1) = p3(i);
-            bounds(i,2) = Inf;
+            bounds.lb(i) = p3(i);
+            bounds.ub(i) = Inf;
         else
             try
-                bounds(i,1) = 1/sqrt(gaminv(1-prior_trunc, p7(i)/2, 2/p6(i)))+p3(i);
-                bounds(i,2) = 1/sqrt(gaminv(prior_trunc, p7(i)/2, ...
-                                            2/p6(i)))+p3(i);
+                bounds.lb(i) = 1/sqrt(gaminv(1-prior_trunc, p7(i)/2, 2/p6(i)))+p3(i);
+                bounds.ub(i) = 1/sqrt(gaminv(prior_trunc, p7(i)/2, 2/p6(i)))+p3(i);
             catch
                 % Workaround for ticket #161
                 if isoctave
@@ -130,20 +128,20 @@ for i=1:length(p6)
         end
       case 5
         if prior_trunc == 0
-            bounds(i,1) = p6(i);
-            bounds(i,2) = p7(i);
+            bounds.lb(i) = p6(i);
+            bounds.ub(i) = p7(i);
         else
-            bounds(i,1) = p6(i)+(p7(i)-p6(i))*prior_trunc;
-            bounds(i,2) = p7(i)-(p7(i)-p6(i))*prior_trunc;
+            bounds.lb(i) = p6(i)+(p7(i)-p6(i))*prior_trunc;
+            bounds.ub(i) = p7(i)-(p7(i)-p6(i))*prior_trunc;
         end
       case 6
         if prior_trunc == 0
-            bounds(i,1) = p3(i);
-            bounds(i,2) = Inf;
+            bounds.lb(i) = p3(i);
+            bounds.ub(i) = Inf;
         else
             try
-                bounds(i,1) = 1/gaminv(1-prior_trunc, p7(i)/2, 2/p6(i))+p3(i);
-                bounds(i,2) = 1/gaminv(prior_trunc, p7(i)/2, 2/p6(i))+ p3(i);
+                bounds.lb(i) = 1/gaminv(1-prior_trunc, p7(i)/2, 2/p6(i))+p3(i);
+                bounds.ub(i) = 1/gaminv(prior_trunc, p7(i)/2, 2/p6(i))+ p3(i);
             catch
                 % Workaround for ticket #161
                 if isoctave
diff --git a/matlab/prior_draw.m b/matlab/prior_draw.m
index 8edf9954e3088e231f051d524349a0db779cc4e1..8923be87c531441714f3445a028f8438d9831200 100644
--- a/matlab/prior_draw.m
+++ b/matlab/prior_draw.m
@@ -42,8 +42,9 @@ if nargin>0 && init
     p7 = evalin('base', 'bayestopt_.p7');
     p3 = evalin('base', 'bayestopt_.p3');
     p4 = evalin('base', 'bayestopt_.p4');
-    lb = evalin('base', 'bayestopt_.lb');
-    ub = evalin('base', 'bayestopt_.ub');
+    bounds = evalin('base', 'prior_bounds(bayestopt_,options_)');
+    lb = bounds.lb;
+    ub = bounds.ub;
     number_of_estimated_parameters = length(p6);
     if nargin>1 && uniform
         prior_shape = repmat(5,number_of_estimated_parameters,1);
diff --git a/matlab/prior_posterior_statistics.m b/matlab/prior_posterior_statistics.m
index f06e0d433ea024755cd1d0069a03c935d2269685..35a0b481f682cc8841b2d7bf7ea665d3f472f0ea 100644
--- a/matlab/prior_posterior_statistics.m
+++ b/matlab/prior_posterior_statistics.m
@@ -58,6 +58,7 @@ naK = length(options_.filter_step_ahead);
 MaxNumberOfBytes=options_.MaxNumberOfBytes;
 endo_nbr=M_.endo_nbr;
 exo_nbr=M_.exo_nbr;
+meas_err_nbr=length(M_.Correlation_matrix_ME);
 nvobs     = length(options_.varobs);
 iendo = 1:endo_nbr;
 horizon = options_.forecast;
@@ -102,8 +103,8 @@ if naK
 end
 
 if horizon
-    MAX_nforc1 = min(B,ceil(MaxNumberOfBytes/((endo_nbr)*(horizon+maxlag))/8));
-    MAX_nforc2 = min(B,ceil(MaxNumberOfBytes/((endo_nbr)*(horizon+maxlag))/ ...
+    MAX_nforc1 = min(B,ceil(MaxNumberOfBytes/((endo_nbr)*horizon)/8));
+    MAX_nforc2 = min(B,ceil(MaxNumberOfBytes/((endo_nbr)*horizon)/ ...
                             8));
     IdObs    = bayestopt_.mfys;
 
@@ -144,8 +145,8 @@ if options_.filter_step_ahead
     run_smoother = 1;
 end
 if options_.forecast
-    stock_forcst_mean = zeros(endo_nbr,horizon+maxlag,MAX_nforc1);
-    stock_forcst_point = zeros(endo_nbr,horizon+maxlag,MAX_nforc2);
+    stock_forcst_mean = zeros(endo_nbr,horizon,MAX_nforc1);
+    stock_forcst_point = zeros(endo_nbr,horizon,MAX_nforc2);
     run_smoother = 1;
 end
 
@@ -268,10 +269,15 @@ if options_.smoother
         '',M_.exo_names,M_.exo_names_tex,M_.exo_names,...
         M_.exo_names,'SmoothedShocks',DirectoryName,'_inno');
     if nvn
-        % needs to  be fixed
-        %        pm3(endo_nbr,gend,ifil(3),B,'Smoothed measurement errors',...
-        %            M_.endo_names(SelecVariables),M_.endo_names,'tit_tex',M_.endo_names,...
-        %            'names2','smooth_errors',[M_.fname '/metropolis'],'_error')
+        for obs_iter=1:length(options_.varobs)        
+            meas_error_names{obs_iter,1}=['SE_EOBS_' M_.endo_names(strmatch(options_.varobs{obs_iter},M_.endo_names,'exact'),:)];
+            texnames{obs_iter,1}=['SE_EOBS_' M_.endo_names_tex(strmatch(options_.varobs{obs_iter},M_.endo_names,'exact'),:)];
+        end
+        meas_error_names=char(meas_error_names);
+        texnames=char(texnames);
+        pm3(meas_err_nbr,gend,ifil(3),B,'Smoothed measurement errors',...
+           '',meas_error_names,texnames,meas_error_names,...
+           meas_error_names,'SmoothedMeasurementErrors',DirectoryName,'_error')
     end
 end
 
@@ -286,10 +292,10 @@ if options_.filtered_vars
 end
 
 if options_.forecast
-    pm3(endo_nbr,horizon+maxlag,ifil(6),B,'Forecasted variables (mean)',...
+    pm3(endo_nbr,horizon,ifil(6),B,'Forecasted variables (mean)',...
         '',varlist,M_.endo_names_tex,M_.endo_names,...
         varlist,'MeanForecast',DirectoryName,'_forc_mean');
-    pm3(endo_nbr,horizon+maxlag,ifil(6),B,'Forecasted variables (point)',...
+    pm3(endo_nbr,horizon,ifil(6),B,'Forecasted variables (point)',...
         '',varlist,M_.endo_names_tex,M_.endo_names,...
         varlist,'PointForecast',DirectoryName,'_forc_point');
 end
diff --git a/matlab/prior_posterior_statistics_core.m b/matlab/prior_posterior_statistics_core.m
index 63443a6ae12bb054cd793df6e51bc64a110ac97e..ef8328c3577d132692e078cff232214cf21e1271 100644
--- a/matlab/prior_posterior_statistics_core.m
+++ b/matlab/prior_posterior_statistics_core.m
@@ -135,8 +135,8 @@ if run_smoother
   stock_update=NaN(endo_nbr,gend,MAX_nsmoo);
   stock_innov=NaN(M_.exo_nbr,gend,MAX_ninno);
   if horizon
-      stock_forcst_mean= NaN(endo_nbr,horizon+maxlag,MAX_nforc1);
-      stock_forcst_point = NaN(endo_nbr,horizon+maxlag,MAX_nforc2);
+      stock_forcst_mean= NaN(endo_nbr,horizon,MAX_nforc1);
+      stock_forcst_point = NaN(endo_nbr,horizon,MAX_nforc2);
   end
 end
 if nvn
@@ -214,8 +214,8 @@ for b=fpar:B
                 yf1 = yf1 + repmat(SteadyState',[horizon+maxlag,1,1]);
             end
 
-            stock_forcst_mean(:,:,irun(6)) = yf';
-            stock_forcst_point(:,:,irun(7)) = yf1';
+            stock_forcst_mean(:,:,irun(6)) = yf(maxlag+1:end,:)';
+            stock_forcst_point(:,:,irun(7)) = yf1(maxlag+1:end,:)';
         end
     else
         [T,R,SteadyState,info,M_,options_,oo_] = dynare_resolve(M_,options_,oo_);
diff --git a/matlab/qmc_sequence.m b/matlab/qmc_sequence.m
index bfbb15dff4dcb2a5c1867769674b25ae2bdd8508..aa26ae2d3cc962b05f59e46ceeaf47c72ceb9b29 100644
--- a/matlab/qmc_sequence.m
+++ b/matlab/qmc_sequence.m
@@ -111,9 +111,9 @@
 %$ [draws2, Q] = qmc_sequence(d,S,0,n);
 %$ [draws3, P] = qmc_sequence(d,s,0,2*n);
 %$
-%$ t(1) = dyn_assert(s,int64(0));
-%$ t(2) = dyn_assert(P,Q);
-%$ t(3) = dyn_assert([draws1,draws2],draws3);
+%$ t(1) = dassert(s,int64(0));
+%$ t(2) = dassert(P,Q);
+%$ t(3) = dassert([draws1,draws2],draws3);
 %$ T = all(t);
 %@eof:2
 
@@ -129,8 +129,8 @@
 %$ draws3 = draws2;
 %$ draws3(1,:) = 2*draws2(1,:);
 %$ draws3(2,:) = 3*draws2(2,:)-1;
-%$ t(1) = dyn_assert(S,Q);
-%$ t(2) = dyn_assert(draws1,draws3);
+%$ t(1) = dassert(S,Q);
+%$ t(2) = dassert(draws1,draws3);
 %$ T = all(t);
 %@eof:3
 
@@ -143,15 +143,15 @@
 %$
 %$ [draws, S] = qmc_sequence(d,s,2,n,radius);
 %$
-%$ t(1) = dyn_assert(sqrt(draws(:,3)'*draws(:,3)),radius,1e-14);
-%$ t(2) = dyn_assert(sqrt(draws(:,5)'*draws(:,5)),radius,1e-14);
-%$ t(3) = dyn_assert(sqrt(draws(:,7)'*draws(:,7)),radius,1e-14);
-%$ t(4) = dyn_assert(sqrt(draws(:,11)'*draws(:,11)),radius,1e-14);
-%$ t(5) = dyn_assert(sqrt(draws(:,13)'*draws(:,13)),radius,1e-14);
-%$ t(6) = dyn_assert(sqrt(draws(:,17)'*draws(:,17)),radius,1e-14);
-%$ t(7) = dyn_assert(sqrt(draws(:,19)'*draws(:,19)),radius,1e-14);
-%$ t(8) = dyn_assert(sqrt(draws(:,23)'*draws(:,23)),radius,1e-14);
-%$ t(9) = dyn_assert(sqrt(draws(:,29)'*draws(:,29)),radius,1e-14);
+%$ t(1) = dassert(sqrt(draws(:,3)'*draws(:,3)),radius,1e-14);
+%$ t(2) = dassert(sqrt(draws(:,5)'*draws(:,5)),radius,1e-14);
+%$ t(3) = dassert(sqrt(draws(:,7)'*draws(:,7)),radius,1e-14);
+%$ t(4) = dassert(sqrt(draws(:,11)'*draws(:,11)),radius,1e-14);
+%$ t(5) = dassert(sqrt(draws(:,13)'*draws(:,13)),radius,1e-14);
+%$ t(6) = dassert(sqrt(draws(:,17)'*draws(:,17)),radius,1e-14);
+%$ t(7) = dassert(sqrt(draws(:,19)'*draws(:,19)),radius,1e-14);
+%$ t(8) = dassert(sqrt(draws(:,23)'*draws(:,23)),radius,1e-14);
+%$ t(9) = dassert(sqrt(draws(:,29)'*draws(:,29)),radius,1e-14);
 %$ T = all(t);
 %@eof:4
 
@@ -174,6 +174,6 @@
 %$
 %$ COVARIANCE = draws*draws'/(b*n);
 %$
-%$ t(1) = dyn_assert(covariance,COVARIANCE,1e-6);
+%$ t(1) = dassert(covariance,COVARIANCE,1e-6);
 %$ T = all(t);
 %@eof:5
\ No newline at end of file
diff --git a/matlab/quadratic_matrix_equation_solver.m b/matlab/quadratic_matrix_equation_solver.m
index 146dc9aee91a36661773ce04e3a4ce9f64ebe28e..f222df843f9aa5cf76bf61ef401d269f23a9ec31 100644
--- a/matlab/quadratic_matrix_equation_solver.m
+++ b/matlab/quadratic_matrix_equation_solver.m
@@ -152,7 +152,7 @@ function t = line_search(A,H,F)
 %$ tic, X2 = quadratic_matrix_equation_solver(A,B,C,1e-16,100,1,zeros(n)); toc
 %$
 %$ % Check the results.
-%$ t(1) = dyn_assert(X1,X2,1e-12);
+%$ t(1) = dassert(X1,X2,1e-12);
 %$
 %$ T = all(t);
 %@eof:1
\ No newline at end of file
diff --git a/matlab/random_walk_metropolis_hastings_core.m b/matlab/random_walk_metropolis_hastings_core.m
index 62e1728eb9790d3bbe01b00fdc069ec74c867948..90c89e871d91aaf7fdbe76dc78fa55b82b9a562b 100644
--- a/matlab/random_walk_metropolis_hastings_core.m
+++ b/matlab/random_walk_metropolis_hastings_core.m
@@ -163,9 +163,9 @@ for b = fblck:nblck,
     j = 1;
     while j <= nruns(b)
         par = feval(ProposalFun, ix2(b,:), proposal_covariance_Cholesky_decomposition, n);
-        if all( par(:) > mh_bounds(:,1) ) && all( par(:) < mh_bounds(:,2) )
+        if all( par(:) > mh_bounds.lb ) && all( par(:) < mh_bounds.ub )
             try
-                logpost = - feval(TargetFun, par(:),dataset_,dataset_info,options_,M_,estim_params_,bayestopt_,oo_);
+                logpost = - feval(TargetFun, par(:),dataset_,dataset_info,options_,M_,estim_params_,bayestopt_,mh_bounds,oo_);
             catch
                 logpost = -inf;
             end
diff --git a/matlab/reduced_rank_cholesky.m b/matlab/reduced_rank_cholesky.m
index af16453b396710593b2da656746fa8764e1dd6fc..1af9ec6090e2838d9f9131275d22b90975885032 100644
--- a/matlab/reduced_rank_cholesky.m
+++ b/matlab/reduced_rank_cholesky.m
@@ -92,6 +92,6 @@ end
 %$
 %$
 %$ % Check the results.
-%$ t(2) = dyn_assert(T,chol(X),1e-16);
+%$ t(2) = dassert(T,chol(X),1e-16);
 %$ T = all(t);
 %@eof:1
\ No newline at end of file
diff --git a/matlab/replace_object_in_a_one_dimensional_cell_array.m b/matlab/replace_object_in_a_one_dimensional_cell_array.m
index dd717454fb244d520be40765450d73523c096045..9f3c03a25146aeaa85e7ce5e777256d5f5705c39 100644
--- a/matlab/replace_object_in_a_one_dimensional_cell_array.m
+++ b/matlab/replace_object_in_a_one_dimensional_cell_array.m
@@ -74,7 +74,7 @@ end
 %$ end
 %$
 %$ if t(1)
-%$   t(2) = dyn_assert(C,[B; A(2:3)]);
+%$   t(2) = dassert(C,[B; A(2:3)]);
 %$ end
 %$ T = all(t);
 %@eof:1
@@ -91,7 +91,7 @@ end
 %$ 
 %$ D = {'A1';'B1';'A4'};
 %$ if t(1)
-%$   t(2) = dyn_assert(C,D);
+%$   t(2) = dassert(C,D);
 %$ end
 %$ T = all(t);
 %@eof:2
\ No newline at end of file
diff --git a/matlab/reports/@graph/graph.m b/matlab/reports/@graph/graph.m
index 7aa052514a9e85d3bf84c8fd24d128e07f6ab49f..4d73da534628a657db480721dcd9d9c058374cd9 100644
--- a/matlab/reports/@graph/graph.m
+++ b/matlab/reports/@graph/graph.m
@@ -85,6 +85,8 @@ o.height = 4.5;
 o.miscTikzPictureOptions = '';
 o.miscTikzAxisOptions = '';
 
+o.writeCSV = false;
+
 if nargin == 1
     assert(isa(varargin{1}, 'graph'),['@graph.graph: with one arg you ' ...
                         'must pass a graph object']);
@@ -139,7 +141,7 @@ assert(isint(o.yTickLabelPrecision), '@graph.graph: o.yTickLabelPrecision must b
 assert(islogical(o.yTickLabelFixed), '@graph.graph: yTickLabelFixed must be either true or false');
 assert(islogical(o.yTickLabelZeroFill), '@graph.graph: yTickLabelZeroFill must be either true or false');
 assert(islogical(o.yTickLabelScaled), '@graph.graph: yTickLabelScaled must be either true or false');
-
+assert(islogical(o.writeCSV), '@graph.graph: writeCSV must be either true or false');
 assert(ischar(o.shadeColor), '@graph.graph: shadeColor must be a string');
 assert(ischar(o.zeroLineColor), '@graph.graph: zeroLineColor must be a string');
 assert(any(strcmp(o.axisShape, {'box', 'L'})), ['@graph.graph: axisShape ' ...
diff --git a/matlab/reports/@graph/writeGraphFile.m b/matlab/reports/@graph/writeGraphFile.m
index bd820c9e9117519e2e22c2801465c767c4e8c109..85b09d41d3c2b8b3efc923d8758132e9f495e76d 100644
--- a/matlab/reports/@graph/writeGraphFile.m
+++ b/matlab/reports/@graph/writeGraphFile.m
@@ -231,8 +231,25 @@ if o.showZeroline
         o.zeroLineColor, dd.ndat);
 end
 
+if o.writeCSV
+    csvseries = dseries();
+end
 for i=1:ne
     o.series{i}.writeSeriesForGraph(fid, dd);
+    if o.writeCSV
+        csvseries = [csvseries ...
+            o.series{i}.data(dd).set_names([...
+            o.series{i}.data.name{:} '_' ...
+            o.series{i}.graphLegendName '_' ...
+            o.series{i}.graphLineColor '_' ...
+            o.series{i}.graphLineStyle '_' ...
+            num2str(o.series{i}.graphLineWidth) '_' ...
+            o.series{i}.graphMarker '_' ...
+            o.series{i}.graphMarkerEdgeColor '_' ...
+            o.series{i}.graphMarkerFaceColor '_' ...
+            num2str(o.series{i}.graphMarkerSize)]) ...
+            ];
+    end
     if o.showLegend
         le = o.series{i}.getNameForLegend();
         if ~isempty(le)
@@ -240,6 +257,9 @@ for i=1:ne
         end
     end
 end
+if o.writeCSV
+    csvseries.save(strrep(o.graphName, '.tex', ''), 'csv');
+end
 fprintf(fid, '\\end{axis}\n\\end{tikzpicture}%%');
 if fclose(fid) == -1
     error('@graph.writeGraphFile: closing %s\n', o.filename);
diff --git a/matlab/reports/@report_series/writeSeriesForTable.m b/matlab/reports/@report_series/writeSeriesForTable.m
index bd4f70b672df50796faa4583fd55f50c9d543402..77bc82a3b1704944a5394b7b777fdf4ceba66078 100644
--- a/matlab/reports/@report_series/writeSeriesForTable.m
+++ b/matlab/reports/@report_series/writeSeriesForTable.m
@@ -1,5 +1,5 @@
-function o = writeSeriesForTable(o, fid, dates, precision, ncols)
-%function o = writeSeriesForTable(o, fid, dates, precision, ncols)
+function o = writeSeriesForTable(o, fid, dates, precision, ncols, rowcolor)
+%function o = writeSeriesForTable(o, fid, dates, precision, ncols, rowcolor)
 % Write Table Row
 %
 % INPUTS
@@ -8,6 +8,7 @@ function o = writeSeriesForTable(o, fid, dates, precision, ncols)
 %   dates        [dates]            dates for report_series slice
 %   precision    [float]            precision with which to print the data
 %   ncols        [int]              total number of columns in table
+%   rowcolor     [string]           string to color this row
 %
 %
 % OUTPUTS
@@ -65,7 +66,11 @@ assert(isfloat(o.tableMarkerLimit), '@report_series.writeSeriesForTable: tableMa
 
 %% Write Output
 fprintf(fid, '%% Table Row (report_series)\n');
-if ~isempty(o.tableRowColor)
+if ~isempty(o.tableRowColor) && ~strcmpi(o.tableRowColor, 'white')
+    fprintf(fid, '\\rowcolor{%s}', o.tableRowColor);
+elseif ~isempty(rowcolor)
+    fprintf(fid, '\\rowcolor{%s}', rowcolor);
+else
     fprintf(fid, '\\rowcolor{%s}', o.tableRowColor);
 end
 if ~isempty(o.tableSubSectionHeader)
diff --git a/matlab/reports/@report_table/report_table.m b/matlab/reports/@report_table/report_table.m
index 84b0d2f9d9f2d657f223acf63899bcdec2d73297..effd07e517b97963cdcee638c0351ce40c486cd7 100644
--- a/matlab/reports/@report_table/report_table.m
+++ b/matlab/reports/@report_table/report_table.m
@@ -49,6 +49,9 @@ o.data = '';
 o.seriesToUse = '';
 o.range = {};
 o.precision = 1;
+o.writeCSV = false;
+
+o.highlightRows = {''};
 
 if nargin == 1
     assert(isa(varargin{1}, 'report_table'),['With one arg to Report_Table constructor, ' ...
@@ -115,6 +118,8 @@ assert(iscellstr(o.titleFormat), ...
        '@report_table.report_table: titleFormat must be a cell array of string(s)');
 assert(ischar(o.tableName), '@report_table.report_table: tableName must be a string');
 assert(ischar(o.tableDirName), '@report_table.report_table: tableDirName must be a string');
+assert(islogical(o.writeCSV), '@report_table.report_table: writeCSV must be either true or false');
+assert(iscellstr(o.highlightRows), '@report_table.report_table: highlightRowsmust be a cell string');
 
 % using o.seriesToUse, create series objects and put them in o.series
 if ~isempty(o.data)
diff --git a/matlab/reports/@report_table/writeTableFile.m b/matlab/reports/@report_table/writeTableFile.m
index 575402ea1e37b86580f91d69b90488af1f0d1228..01e04adaa58fa4417a43be9d5408ec1a885e98a5 100644
--- a/matlab/reports/@report_table/writeTableFile.m
+++ b/matlab/reports/@report_table/writeTableFile.m
@@ -40,6 +40,8 @@ end
 
 if isempty(o.tableName)
     o.tableName = sprintf('%s/table_pg%d_sec%d_row%d_col%d.tex', o.tableDirName, pg, sec, row, col);
+else
+    o.tableName = [o.tableDirName '/' o.tableName];
 end
 
 [fid, msg] = fopen(o.tableName, 'w');
@@ -169,13 +171,26 @@ fprintf(fid, '\\hline%%\n');
 fprintf(fid, '%%\n');
 
 % Write Report_Table Data
+if o.writeCSV
+    csvseries = dseries();
+end
 for i=1:ne
-    o.series{i}.writeSeriesForTable(fid, o.range, o.precision, ncols);
+    o.series{i}.writeSeriesForTable(fid, o.range, o.precision, ncols, o.highlightRows{mod(i,length(o.highlightRows))+1});
+    if o.writeCSV
+        if isempty(o.series{i}.tableSubSectionHeader)
+            csvseries = [csvseries ...
+                o.series{i}.data(dates).set_names([...
+                num2str(i) '_' ...
+                o.series{i}.data.name{:}])];
+        end
+    end
     if o.showHlines
         fprintf(fid, '\\hline\n');
     end
 end
-
+if o.writeCSV
+    csvseries.save(strrep(o.tableName, '.tex', ''), 'csv');
+end
 fprintf(fid, '\\bottomrule\n');
 fprintf(fid, '\\end{tabular}\\setlength{\\parindent}{0pt}\n \\par \\medskip\n\n');
 fprintf(fid, '%% End Report_Table Object\n');
diff --git a/matlab/resol.m b/matlab/resol.m
index cae7a1a49cbdad4ef95548f4f05d301bb94725ac..92c775806782913052368174b1042aa847fc1eca 100644
--- a/matlab/resol.m
+++ b/matlab/resol.m
@@ -116,18 +116,18 @@ if options.loglinear
         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)))
+            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.')
+            fprintf('You should check that the priors and/or bounds over the deep parameters are such\n')
+            fprintf('that the steady state levels of all the variables are strictly positive, or consider\n')
+            fprintf('a linearization of the model instead of a log linearization.\n')
         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.')
+            fprintf('You should check that the calibration of the deep parameters is such that the\n')
+            fprintf('steady state levels of all the variables are strictly positive, or consider\n')
+            fprintf('a linearization of the model instead of a log linearization.\n')
         end
-        error('stoch_simul::resol: The loglinearization of the model cannot be performed because the steady state is not strictly positive!')
+        error('stoch_simul::resol: The loglinearization of the model cannot be performed, because the steady state is not strictly positive!')
     end
 end
 
diff --git a/matlab/rplot.m b/matlab/rplot.m
index df7712535fed2406d8bc3dee9b0ca2ccbf3c77c8..3878170188c8776f18277a04b447d7bfd2cdc1a3 100644
--- a/matlab/rplot.m
+++ b/matlab/rplot.m
@@ -35,13 +35,17 @@ global M_ oo_ options_
 
 rplottype = options_.rplottype;
 
+if isempty(oo_.endo_simul)
+    error('rplot: oo_.endo_simul is empty.')
+end
+
 col = ['y','c','r','g','b','w','m'] ;
 ix = [1 - M_.maximum_lag:size(oo_.endo_simul,2)-M_.maximum_lag]' ;
 
 y = [];
 for k=1:size(s1,1)
     if isempty(strmatch(s1(k,:),M_.endo_names,'exact'))
-        error (['One of the variable specified does not exist']) ;
+        error (['rplot: One of the variables specified does not exist']) ;
     end
 
     y = [y; oo_.endo_simul(strmatch(s1(k,:),M_.endo_names,'exact'),:)] ;
diff --git a/matlab/set_prior.m b/matlab/set_prior.m
index 253b51c242f6b0102c001304d09856b25f8a6175..9fcbd10b3e99aefdd90812b545598862538c3da4 100644
--- a/matlab/set_prior.m
+++ b/matlab/set_prior.m
@@ -48,8 +48,8 @@ estim_params_.ncn = ncn; % correlation between endogenous variables, i.e. measur
 estim_params_.np = np;   % other parameters of the model
 
 xparam1 = [];
-ub = [];
-lb = [];
+ub = []; % Upper bound imposed for optimization.
+lb = []; % Lower bound imposed for optimization.
 bayestopt_.pshape = [];
 bayestopt_.p1 = []; % prior mean
 bayestopt_.p2 = []; % prior standard deviation
@@ -63,7 +63,7 @@ bayestopt_.jscale = [];
 bayestopt_.name = {};
 if nvx
     xparam1 = estim_params_.var_exo(:,2);
-    ub = estim_params_.var_exo(:,4); 
+    ub = estim_params_.var_exo(:,4);
     lb = estim_params_.var_exo(:,3); 
     bayestopt_.pshape =  estim_params_.var_exo(:,5);
     bayestopt_.p1 =  estim_params_.var_exo(:,6);
@@ -152,9 +152,6 @@ if np
     bayestopt_.name = [bayestopt_.name; cellstr(M_.param_names(estim_params_.param_vals(:,1),:))];
 end
 
-bayestopt_.ub = ub;
-bayestopt_.lb = lb;
-
 bayestopt_.p6 = NaN(size(bayestopt_.p1)) ;
 bayestopt_.p7 = bayestopt_.p6 ;
 
diff --git a/matlab/sim1.m b/matlab/sim1.m
index 87517461af3fd04107b89d7732e87c36d85ad2b3..bbf41d1936cae674da9d6569200dff1a9a519b5b 100644
--- a/matlab/sim1.m
+++ b/matlab/sim1.m
@@ -136,6 +136,9 @@ for iter = 1:options_.simul.maxit
         if any(isnan(res)) || any(isinf(res)) || any(isnan(Y)) || any(isinf(Y))
             fprintf('\nWARNING: NaN or Inf detected in the residuals or endogenous variables.\n');    
         end
+        if ~isreal(res) || ~isreal(Y)
+            fprintf('\nWARNING: Imaginary parts detected in the residuals or endogenous variables.\n');    
+        end        
         skipline()
     end
     
@@ -162,7 +165,7 @@ end
 
 
 if stop
-    if any(isnan(res)) || any(isinf(res)) || any(isnan(Y)) || any(isinf(Y))
+    if any(isnan(res)) || any(isinf(res)) || any(isnan(Y)) || any(isinf(Y)) || ~isreal(res) || ~isreal(Y)
         oo_.deterministic_simulation.status = 0;% NaN or Inf occurred
         oo_.deterministic_simulation.error = err;
         oo_.deterministic_simulation.iterations = iter;
@@ -171,7 +174,12 @@ if stop
         skipline();
         fprintf('\nSimulation terminated after %d iterations.\n',iter);
         fprintf('Total time of simulation: %16.13f\n',etime(clock,h1));
-        fprintf('WARNING: Simulation terminated with NaN or Inf in the residuals or endogenous variables. There is most likely something wrong with your model.\n');
+        if ~isreal(res) || ~isreal(Y)
+            fprintf('WARNING: Simulation terminated with imaginary parts in the residuals or endogenous variables.\n');
+        else
+            fprintf('WARNING: Simulation terminated with NaN or Inf in the residuals or endogenous variables.\n');
+        end
+        fprintf('WARNING: There is most likely something wrong with your model. Try model_diagnostics.\n');
     else
         skipline();
         fprintf('\nSimulation concluded successfully after %d iterations.\n',iter);
diff --git a/matlab/simplex_optimization_routine.m b/matlab/simplex_optimization_routine.m
index 9d60b5774ead3d38ad97b9b3576f2271a37aa517..33843cf0d589caef3391eef246f5a3fc39cbdc9c 100644
--- a/matlab/simplex_optimization_routine.m
+++ b/matlab/simplex_optimization_routine.m
@@ -1,4 +1,4 @@
-function [x,fval,exitflag] = simplex_optimization_routine(objective_function,x,options,varargin)
+function [x,fval,exitflag] = simplex_optimization_routine(objective_function,x,options,var_names,varargin)
 
 % Nelder-Mead like optimization routine (see http://en.wikipedia.org/wiki/Nelder-Mead_method)
 %
@@ -11,6 +11,8 @@ function [x,fval,exitflag] = simplex_optimization_routine(objective_function,x,o
 %  o objective_function     [string]                  Name of the objective function to be minimized.
 %  o x                      [double]                  n*1 vector, starting guess of the optimization routine.
 %  o options                [structure]               Options of this implementation of the simplex algorithm.
+%  o var_names              [cell]                    Names of parameters
+%                                                       for verbose output
 %  o varargin               [cell of structures]      Structures to be passed to the objective function.
 %
 %     varargin{1} --> DynareDataset
@@ -45,14 +47,16 @@ function [x,fval,exitflag] = simplex_optimization_routine(objective_function,x,o
 % along with Dynare.  If not, see <http://www.gnu.org/licenses/>.
 
 % Set verbose mode
-verbose = 2;
+verbose = options.verbosity;
 
 % Set number of control variables.
 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.
@@ -153,8 +157,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
@@ -194,7 +198,7 @@ else
         disp(['Current parameter values: '])
         fprintf(1,'%s: \t\t\t %s \t\t\t %s \t\t\t %s \t\t\t %s \t\t\t %s \n','Names','Best point', 'Worst point', 'Mean values', 'Min values', 'Max values');
         for i=1:number_of_variables
-            fprintf(1,'%s: \t\t\t %+8.6f \t\t\t %+8.6f \t\t\t %+8.6f \t\t\t %+8.6f \t\t\t %+8.6f \n',varargin{6}.name{i},v(i,1), v(i,end), mean(v(i,:),2), min(v(i,:),[],2), max(v(i,:),[],2));
+            fprintf(1,'%s: \t\t\t %+8.6f \t\t\t %+8.6f \t\t\t %+8.6f \t\t\t %+8.6f \t\t\t %+8.6f \n',var_names{i},v(i,1), v(i,end), mean(v(i,:),2), min(v(i,:),[],2), max(v(i,:),[],2));
         end
         skipline()
     end
@@ -406,7 +410,7 @@ while (func_count < max_func_calls) && (iter_count < max_iterations) && (simplex
         disp(['Current parameter values: '])
         fprintf(1,'%s: \t\t\t %s \t\t\t %s \t\t\t %s \t\t\t %s \t\t\t %s \n','Names','Best point', 'Worst point', 'Mean values', 'Min values', 'Max values');
         for i=1:number_of_variables
-            fprintf(1,'%s: \t\t\t %+8.6f \t\t\t %+8.6f \t\t\t %+8.6f \t\t\t %+8.6f \t\t\t %+8.6f \n',varargin{6}.name{i}, v(i,1), v(i,end), mean(v(i,:),2), min(v(i,:),[],2), max(v(i,:),[],2));
+            fprintf(1,'%s: \t\t\t %+8.6f \t\t\t %+8.6f \t\t\t %+8.6f \t\t\t %+8.6f \t\t\t %+8.6f \n',var_names{i}, v(i,1), v(i,end), mean(v(i,:),2), min(v(i,:),[],2), max(v(i,:),[],2));
         end
         skipline()
     end
@@ -432,7 +436,7 @@ while (func_count < max_func_calls) && (iter_count < max_iterations) && (simplex
                 disp(['values for the control variables. '])
                 disp(['New value of delta (size of the new simplex) is: '])
                 for i=1:number_of_variables
-                    fprintf(1,'%s: \t\t\t %+8.6f \n',varargin{6}.name{i}, delta(i));
+                    fprintf(1,'%s: \t\t\t %+8.6f \n',var_names{i}, delta(i));
                 end
             end
             % Reset counters
@@ -479,7 +483,7 @@ while (func_count < max_func_calls) && (iter_count < max_iterations) && (simplex
                 disp(['values for the control variables. '])
                 disp(['New value of delta (size of the new simplex) is: '])
                 for i=1:number_of_variables
-                    fprintf(1,'%s: \t\t\t %+8.6f \n',varargin{6}.name{i}, delta(i));
+                    fprintf(1,'%s: \t\t\t %+8.6f \n',var_names{i}, delta(i));
                 end
             end
             % Reset counters
@@ -499,7 +503,7 @@ while (func_count < max_func_calls) && (iter_count < max_iterations) && (simplex
 end% while loop.
 
 x(:) = v(:,1);
-fval = fv(:,1);
+fval = fv(1);
 exitflag = 1;
 
 if func_count>= max_func_calls
diff --git a/matlab/skipline.m b/matlab/skipline.m
index feb5bd83fde2b7c98177d764cdb7d863fa1e3766..6eadae93a57b1305430e7a9b810b79a7b65f0be3 100644
--- a/matlab/skipline.m
+++ b/matlab/skipline.m
@@ -1,6 +1,17 @@
-function skipline(n,fid)
-    
-% Copyright (C) 2013 Dynare Team
+function skipline(n, fid)
+% function skipline(n, fid)
+% This function prints n newlines to fid
+%
+% INPUTS 
+%
+%   n        [integer]    Number of newlines to print
+%   fid      [integer]    file id returned by fopen
+%    
+% OUTPUTS 
+%   None
+%
+
+% Copyright (C) 2013-2014 Dynare Team
 %
 % This file is part of Dynare.
 %
@@ -17,18 +28,14 @@ function skipline(n,fid)
 % You should have received a copy of the GNU General Public License
 % along with Dynare.  If not, see <http://www.gnu.org/licenses/>.    
 
-if nargin<2
-    fid = 1;
+if nargin < 2
+	fid = 1;
+	if nargin < 1
+		n = 1;
+	end
 end
 
-if nargin<1
-    fid = 1;
+for i=1:n
+	fprintf(fid,'\n');
 end
-    
-if ~nargin || isequal(n,1)
-    fprintf(fid,'\n');
-else
-    for i=1:n
-        fprintf(fid,'\n');
-    end
 end
\ No newline at end of file
diff --git a/matlab/smoother2histval.m b/matlab/smoother2histval.m
index e6cc27585de96977e3d36ef98293fb1e459eff56..6996af36591edb193c1062d0bf94f377f11cf884 100644
--- a/matlab/smoother2histval.m
+++ b/matlab/smoother2histval.m
@@ -49,6 +49,7 @@ if ~isfield(opts, 'infile')
     end
     smoothedvars = oo_.SmoothedVariables;
     smoothedshocks = oo_.SmoothedShocks;
+    steady_state = oo_.steady_state;
 else
     S = load(opts.infile);
     if ~isfield(S, 'oo_') || ~isfield(S.oo_, 'SmoothedVariables')
@@ -56,6 +57,7 @@ else
     end
     smoothedvars = S.oo_.SmoothedVariables;
     smoothedshocks = S.oo_.SmoothedShocks;
+    steady_state = S.oo_.steady_state;
 end
 
 % Hack to determine if oo_.SmoothedVariables was computed after a Metropolis
@@ -71,6 +73,7 @@ if isempty(options_.parameter_set)
     if post_metropolis
         smoothedvars = smoothedvars.Mean;
         smoothedshocks = smoothedshocks.Mean;
+        steady_state = zeros(size(steady_state));
     end
 else
     switch options_.parameter_set
@@ -88,12 +91,14 @@ else
         end
         smoothedvars = smoothedvars.Mean;
         smoothedshocks = smoothedshocks.Mean;
+        steady_state = zeros(size(steady_state));
       case 'posterior_median'
         if ~post_metropolis
             error('Option parameter_set=posterior_median is not consistent with computed smoothed values.')
         end
         smoothedvars = smoothedvars.Median;
         smoothedshocks = smoothedshocks.Median;
+        steady_state = zeros(size(steady_state));
       otherwise
         error([ 'Option parameter_set=' options_.parameter_set ' unsupported.' ])
     end
@@ -156,7 +161,8 @@ for i = 1:length(invars)
         continue
     end
     s = getfield(smoothedvars, invars{i});
-    v = s((period-M_.maximum_endo_lag+1):period);
+    j = strmatch(invars{i}, M_.endo_names, 'exact');
+    v = s((period-M_.maximum_endo_lag+1):period) + steady_state(j);
     if ~isfield(opts, 'outfile')
         j = strmatch(outvars{i}, M_.endo_names, 'exact');
         if isempty(j)
@@ -193,9 +199,9 @@ for i = 1:length(M_.aux_vars)
         if period-M_.maximum_endo_lag+1+l < 1
             error('The period that you indicated is too small to construct initial conditions')
         end
-        v = s((period-M_.maximum_endo_lag+1+l):(period+l));
+        j = M_.aux_vars(i).endo_index;
+        v = s((period-M_.maximum_endo_lag+1+l):(period+l))+steady_state(j);
         if ~isfield(opts, 'outfile')
-            j = M_.aux_vars(i).endo_index;
             M_.endo_histval(j, :) = v;
         else
             % When saving to a file, x(-2) is in the variable called "x_l2"
diff --git a/matlab/solve1.m b/matlab/solve1.m
index 17bb0a3ab7e4c3e74f8c6df49146f498e4527374..5fecdd35643c4b6cddd06022064a825c241c259c 100644
--- a/matlab/solve1.m
+++ b/matlab/solve1.m
@@ -101,7 +101,7 @@ for its = 1:maxit
     end
     if 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
diff --git a/matlab/stochastic_solvers.m b/matlab/stochastic_solvers.m
index 2738afc292185c2eee9e08cc99a806c0ead5ee2c..64b9b2c810933f2239c54e60f163334703f582c9 100644
--- a/matlab/stochastic_solvers.m
+++ b/matlab/stochastic_solvers.m
@@ -113,6 +113,30 @@ elseif options_.order == 2
         hessian1 = sparse(hessian1(:,1), hessian1(:,2), hessian1(:,3), ...
                           size(jacobia_, 1), size(jacobia_, 2)*size(jacobia_, 2));
     end
+    [infrow,infcol]=find(isinf(hessian1));
+    if options_.debug
+        if ~isempty(infrow)     
+        fprintf('\nSTOCHASTIC_SOLVER: The Hessian of the dynamic model contains Inf.\n')
+        fprintf('STOCHASTIC_SOLVER: Try running model_diagnostics to find the source of the problem.\n')
+        save([M_.fname '_debug.mat'],'hessian1')
+        end
+    end
+    if ~isempty(infrow)
+        info(1)=11;
+        return
+    end
+    [nanrow,nancol]=find(isnan(hessian1));
+    if options_.debug
+        if ~isempty(nanrow)     
+            fprintf('\nSTOCHASTIC_SOLVER: The Hessian of the dynamic model contains NaN.\n')
+            fprintf('STOCHASTIC_SOLVER: Try running model_diagnostics to find the source of the problem.\n')
+            save([M_.fname '_debug.mat'],'hessian1')
+        end
+    end
+    if ~isempty(nanrow)
+        info(1)=12;
+        return
+    end    
 end
 
 [infrow,infcol]=find(isinf(jacobia_));
@@ -217,9 +241,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;
diff --git a/matlab/test_for_deep_parameters_calibration.m b/matlab/test_for_deep_parameters_calibration.m
index c5b88b40fb1790852aba625f8ef772a5ffe908b7..b45ad399bdd5b3b41f98b7f567a78ebfb0e00cb3 100644
--- a/matlab/test_for_deep_parameters_calibration.m
+++ b/matlab/test_for_deep_parameters_calibration.m
@@ -42,7 +42,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);
     if strmatch('optimal_policy_discount_factor',plist,'exact')
diff --git a/matlab/th_autocovariances.m b/matlab/th_autocovariances.m
index e257b4ee62c65b201e4a7df5fa667cb6c6fd964f..39967de93dc5a31fa104e443db0423c92f943d11 100644
--- a/matlab/th_autocovariances.m
+++ b/matlab/th_autocovariances.m
@@ -129,7 +129,7 @@ end;
 % and compute 2nd order mean correction on stationary variables (in case of
 % HP filtering, this mean correction is computed *before* filtering)
 if options_.order == 2 || options_.hp_filter == 0
-    [vx, u] =  lyapunov_symm(A,B*M_.Sigma_e*B',options_.qz_criterium,options_.lyapunov_complex_threshold);
+    [vx, u] =  lyapunov_symm(A,B*M_.Sigma_e*B',options_.qz_criterium,options_.lyapunov_complex_threshold,[],[],options_.debug);
     if options_.block == 0
         iky = inv_order_var(ivar);
     else
@@ -177,30 +177,34 @@ if options_.hp_filter == 0
         end
     end
     % variance decomposition
-    if ~nodecomposition && M_.exo_nbr > 1 && size(stationary_vars, 1) > 0
-        Gamma_y{nar+2} = zeros(nvar,M_.exo_nbr);
-        SS(exo_names_orig_ord,exo_names_orig_ord)=M_.Sigma_e+1e-14*eye(M_.exo_nbr);
-        cs = chol(SS)';
-        b1(:,exo_names_orig_ord) = ghu1;
-        b1 = b1*cs;
-        b2(:,exo_names_orig_ord) = ghu(iky,:);
-        b2 = b2*cs;
-        vx  = lyapunov_symm(A,b1*b1',options_.qz_criterium,options_.lyapunov_complex_threshold,1);
-        vv = diag(aa*vx*aa'+b2*b2');
-        vv2 = 0;
-        for i=1:M_.exo_nbr
-            vx1 = lyapunov_symm(A,b1(:,i)*b1(:,i)',options_.qz_criterium,options_.lyapunov_complex_threshold,2);
-            vx2 = abs(diag(aa*vx1*aa'+b2(:,i)*b2(:,i)'));
-            Gamma_y{nar+2}(stationary_vars,i) = vx2;
-            vv2 = vv2 +vx2;
-        end
-        if max(abs(vv2-vv)./vv) > 1e-4
-            warning(['Aggregate variance and sum of variances by shocks ' ...
-                     'differ by more than 0.01 %'])
-        end
-        for i=1:M_.exo_nbr
-            Gamma_y{nar+2}(stationary_vars,i) = Gamma_y{nar+ ...
-                                2}(stationary_vars,i)./vv2;
+    if ~nodecomposition && M_.exo_nbr > 0 && size(stationary_vars, 1) > 0
+        if M_.exo_nbr == 1
+            Gamma_y{nar+2} = ones(nvar,1);
+        else
+            Gamma_y{nar+2} = zeros(nvar,M_.exo_nbr);
+            SS(exo_names_orig_ord,exo_names_orig_ord)=M_.Sigma_e+1e-14*eye(M_.exo_nbr);
+            cs = chol(SS)';
+            b1(:,exo_names_orig_ord) = ghu1;
+            b1 = b1*cs;
+            b2(:,exo_names_orig_ord) = ghu(iky,:);
+            b2 = b2*cs;
+            vx  = lyapunov_symm(A,b1*b1',options_.qz_criterium,options_.lyapunov_complex_threshold,1,[],options_.debug);
+            vv = diag(aa*vx*aa'+b2*b2');
+            vv2 = 0;
+            for i=1:M_.exo_nbr
+                vx1 = lyapunov_symm(A,b1(:,i)*b1(:,i)',options_.qz_criterium,options_.lyapunov_complex_threshold,2,[],options_.debug);
+                vx2 = abs(diag(aa*vx1*aa'+b2(:,i)*b2(:,i)'));
+                Gamma_y{nar+2}(stationary_vars,i) = vx2;
+                vv2 = vv2 +vx2;
+            end
+            if max(abs(vv2-vv)./vv) > 1e-4
+                warning(['Aggregate variance and sum of variances by shocks ' ...
+                         'differ by more than 0.01 %'])
+            end
+            for i=1:M_.exo_nbr
+                Gamma_y{nar+2}(stationary_vars,i) = Gamma_y{nar+ ...
+                                    2}(stationary_vars,i)./vv2;
+            end
         end
     end
 else% ==> Theoretical HP filter.
@@ -224,8 +228,8 @@ else% ==> Theoretical HP filter.
             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
+                                   *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
@@ -244,49 +248,53 @@ else% ==> Theoretical HP filter.
         end
     end
     % Variance decomposition
-    if ~nodecomposition && M_.exo_nbr > 1
-        Gamma_y{nar+2} = zeros(nvar,M_.exo_nbr);
-        SS(exo_names_orig_ord,exo_names_orig_ord) = M_.Sigma_e+1e-14*eye(M_.exo_nbr);
-        cs = chol(SS)';
-        SS = cs*cs';
-        b1(:,exo_names_orig_ord) = ghu1;
-        b2(:,exo_names_orig_ord) = ghu(iky,:);
-        mathp_col = [];
-        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;  
-        imathp_col = real(ifft(mathp_col))*(2*pi);
-        vv = diag(reshape(imathp_col(1,:),nvar,nvar));
-        for i=1:M_.exo_nbr
+    if ~nodecomposition && M_.exo_nbr > 0
+        if M_.exo_nbr == 1
+            Gamma_y{nar+2} = ones(nvar,1);
+        else
+            Gamma_y{nar+2} = zeros(nvar,M_.exo_nbr);
+            SS(exo_names_orig_ord,exo_names_orig_ord) = M_.Sigma_e+1e-14*eye(M_.exo_nbr);
+            cs = chol(SS)';
+            SS = cs*cs';
+            b1(:,exo_names_orig_ord) = ghu1;
+            b2(:,exo_names_orig_ord) = ghu(iky,:);
             mathp_col = [];
-            SSi = cs(:,i)*cs(:,i)';
+            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]...
-                        *SSi*[b1'*inv(IA-A'*tpos(ig)) ...
-                        IE]); % state variables
+                                           *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;
+                                                         % for ifft
+            end;  
             imathp_col = real(ifft(mathp_col))*(2*pi);
-            Gamma_y{nar+2}(:,i) = abs(diag(reshape(imathp_col(1,:),nvar,nvar)))./vv;
+            vv = diag(reshape(imathp_col(1,:),nvar,nvar));
+            for i=1:M_.exo_nbr
+                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;
+                imathp_col = real(ifft(mathp_col))*(2*pi);
+                Gamma_y{nar+2}(:,i) = abs(diag(reshape(imathp_col(1,:),nvar,nvar)))./vv;
+            end
         end
     end
 end
diff --git a/matlab/thet2tau.m b/matlab/thet2tau.m
index b3db2c68362c175223ad0399d511cc2c5f2f122c..9a321434422bbed22cda7fa677060cdd3847b293 100644
--- a/matlab/thet2tau.m
+++ b/matlab/thet2tau.m
@@ -51,7 +51,7 @@ elseif flagmoments==-1
     tau=[oo_.dr.ys(oo_.dr.order_var); g1(:)];
 
 else
-    GAM =  lyapunov_symm(A,B*M_.Sigma_e*B',options_.qz_criterium,options_.lyapunov_complex_threshold);
+    GAM =  lyapunov_symm(A,B*M_.Sigma_e*B',options_.qz_criterium,options_.lyapunov_complex_threshold,[],[],options_.debug);
     k = find(abs(GAM) < 1e-12);
     GAM(k) = 0;
     if useautocorr,
diff --git a/matlab/utilities/dataset/describe_missing_data.m b/matlab/utilities/dataset/describe_missing_data.m
index 69589933ee0cdadd7e57b93344f11d04edb36445..f13bb6c7aaeb6621bdbf945faff6c96e0e37a2e2 100644
--- a/matlab/utilities/dataset/describe_missing_data.m
+++ b/matlab/utilities/dataset/describe_missing_data.m
@@ -121,9 +121,9 @@ end
 %$ [B,C,D,E] = describe_missing_data(transpose(A));
 %$
 %$ % Check the results.
-%$ t(1) = dyn_assert(B,eB);
-%$ t(2) = dyn_assert(C,eC);
-%$ t(3) = dyn_assert(D,eD);
-%$ t(4) = dyn_assert(E,eE);
+%$ t(1) = dassert(B,eB);
+%$ t(2) = dassert(C,eC);
+%$ t(3) = dassert(D,eD);
+%$ t(4) = dassert(E,eE);
 %$ T = all(t);
 %@eof:1
\ No newline at end of file
diff --git a/matlab/utilities/dataset/makedataset.m b/matlab/utilities/dataset/makedataset.m
index 4c679f50396d9e855af75cc1abd3e1824c55f49c..86f40df100f51748e6fd02721cfbb59757b94a41 100644
--- a/matlab/utilities/dataset/makedataset.m
+++ b/matlab/utilities/dataset/makedataset.m
@@ -36,7 +36,9 @@ end
 if isempty(DynareOptions.datafile) && isempty(DynareOptions.dataset.file) && isempty(DynareOptions.dataset.series)
     if gsa_flag
         DynareDataset = dseries();
-        DatasetInfo = [];
+        DatasetInfo = struct('missing', struct('state', 0, 'aindex', [], 'vindex', [], 'number_of_observations', NaN, 'no_more_missing_observations', NaN), ...
+                     'descriptive', struct('mean', [], 'covariance', [], 'correlation', [], 'autocovariance', []));
+        newdatainterface=0;
         return
     else
         error('makedataset: datafile option is missing!')
@@ -61,9 +63,9 @@ elseif ~isempty(DynareOptions.datafile) && isempty(DynareOptions.dataset.file)
     datafile = DynareOptions.datafile;
     newdatainterface = 0;
 elseif isempty(DynareOptions.datafile) && ~isempty(DynareOptions.dataset.file)
-    error('You cannot use simultaneously the data command and the datafile option (in the estimation command)!')
+    error('makedataset: You cannot simultaneously use the data command and the datafile option (in the estimation command)!')
 else
-    error('You have to specify the datafile!')
+    error('makedataset: You have to specify the datafile!')
 end
 
 % Check extension.
@@ -79,12 +81,12 @@ if ~isempty(datafile)
             end
         end
         if isempty(available_extensions)
-            error(['I can''t find a datafile (with allowed extension)!'])
+            error(['makedataset: I can''t find a datafile (with allowed extension m, mat, csv, xls or xlsx)!'])
         end
         if length(available_extensions)>1
-            error(sprintf(['You did not specify an extension for the datafile, but more than one candidate ' ...
-                           'are available in the designed folder!\nPlease, add an extension to the datafile ' ...
-                           '(m, mat, csv, xls or xlsx are legal extensions).']));
+            error(sprintf(['makedataset: You did not specify an extension for the datafile, but more than one candidate ' ...
+                           'is available in the designated folder!\nPlease, add an extension to the datafile ' ...
+                           '(m, mat, csv, xls or xlsx are permitted extensions).']));
         end
         datafile = [datafile '.' available_extensions{1}];
     end
@@ -92,7 +94,12 @@ end
 
 % Load the data in a dseries object.
 if ~isempty(datafile)
-    DynareDataset = dseries(datafile);
+    if ~( newdatainterface==0 && strcmp(datafile(end-1:end),'.m'))
+        DynareDataset = dseries(datafile);
+    else
+        % Load an m file with the old interface.
+        DynareDataset = load_m_file_data_legacy(datafile, DynareOptions.varobs);
+    end
 else
     DynareDataset = dseriesobjectforuserdataset;
     clear('dseriesobjectforuserdataset');
@@ -135,7 +142,7 @@ end
 if ~set_time_default_initial_period && ~dataset_default_initial_period
     % Check if dataset.init and options_.initial_period are identical.
     if DynareOptions.initial_period<DynareDataset.init
-        error('The date as defined by the set_time command is not consistent with the initial period in the database!')
+        error('makedataset: The date as defined by the set_time command is not consistent with the initial period in the database!')
     end
 end
 
@@ -165,7 +172,7 @@ if newdatainterface
         else
             % last_obs and nobs were used in the data command. Check that they are consistent (with firstobs).
             if ~isequal(lastobs,firstobs+(nobs-1))
-                error(sprintf('Options last_obs (%s), first_obs (%s) and nobs (%s) are not consistent!',char(lastobs),char(firstobs),num2str(nobs)));
+                error(sprintf('makedataset: Options last_obs (%s), first_obs (%s) and nobs (%s) are not consistent!',char(lastobs),char(firstobs),num2str(nobs)));
             end
         end
     end
@@ -189,23 +196,23 @@ FIRSTOBS = firstobs-initialconditions;
 
 % Check that firstobs belongs to DynareDataset.dates
 if firstobs<DynareDataset.init
-    error(sprintf('first_obs (%s) cannot be less than the first date in the dataset (%s)!',char(firstobs),char(DynareDataset.init)))
+    error(sprintf('makedataset: first_obs (%s) cannot be less than the first date in the dataset (%s)!',char(firstobs),char(DynareDataset.init)))
 end
 
 % Check that FIRSTOBS belongs to DynareDataset.dates
 if initialconditions && FIRSTOBS<DynareDataset.init
-    error(sprintf('first_obs (%s) - %i cannot be less than the first date in the dataset (%s)!\nReduce the number of lags in the VAR model or increase the value of first_obs.', char(firstobs), initialconditions, char(DynareDataset.init)));
+    error(sprintf('makedataset: first_obs (%s) - %i cannot be less than the first date in the dataset (%s)!\nReduce the number of lags in the VAR model or increase the value of first_obs\nto at least first_obs=%i.', char(firstobs), initialconditions, char(DynareDataset.init),initialconditions+1));
 end
 
 % Check that lastobs belongs to DynareDataset.dates...
 if newdatainterface
     if lastobs>DynareDataset.dates(end)
-        error(sprintf('last_obs (%s) cannot be greater than the last date in the dataset (%s)!',char(lastobs),char(DynareDataset.dates(end))))
+        error(sprintf('makedataset: last_obs (%s) cannot be greater than the last date in the dataset (%s)!',char(lastobs),char(DynareDataset.dates(end))))
     end
 else
     % ...  or check that nobs is smaller than the number of observations in DynareDataset.
     if nobs>DynareDataset.nobs
-        error(sprintf('nobs (%s) cannot be greater than the last date in the dataset (%s)!', num2str(nobs), num2str(nobs)))
+        error(sprintf('makedataset: nobs (%s) cannot be greater than the last date in the dataset (%s)!', num2str(nobs), num2str(DynareDataset.nobs)))
     end
 end
 
diff --git a/matlab/utilities/dates/add_periods_to_array_of_dates.m b/matlab/utilities/dates/add_periods_to_array_of_dates.m
deleted file mode 100644
index 48a371739a22767f65bd1e2215c1ae71a704a7e6..0000000000000000000000000000000000000000
--- a/matlab/utilities/dates/add_periods_to_array_of_dates.m
+++ /dev/null
@@ -1,83 +0,0 @@
-function time = add_periods_to_array_of_dates(time, freq, p)  % --*-- Unitary tests --*--
-
-% Adds a p periods (p can be negative) to a date (or a set of dates) characterized by array time and frequency freq.
-    
-% Copyright (C) 2013 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 isequal(rows(time),1) && length(p)>1
-    time = repmat(time,length(p),1);
-end
-
-time(:,1) = time(:,1) + fix(p/freq);
-time(:,2) = time(:,2) + rem(p,freq);
-
-id1 = find(time(:,2)>freq);
-if ~isempty(id1)
-    time(id1,1) = time(id1,1) + 1;
-    time(id1,2) = time(id1,2) - freq;
-end
-
-id2 = find(time(:,2)<1);
-if ~isempty(id2)
-    time(id2,1) = time(id2,1) - 1;
-    time(id2,2) = time(id2,2) + freq;
-end
-
-%@test:1
-%$ t(1) = dyn_assert(add_periods_to_array_of_dates([1950 1], 4, 1),[1950 2]);
-%$ t(2) = dyn_assert(add_periods_to_array_of_dates([1950 1], 4, 2),[1950 3]);
-%$ t(3) = dyn_assert(add_periods_to_array_of_dates([1950 1], 4, 3),[1950 4]);
-%$ t(4) = dyn_assert(add_periods_to_array_of_dates([1950 1], 4, 4),[1951 1]);
-%$ t(5) = dyn_assert(add_periods_to_array_of_dates([1950 1], 4, 5),[1951 2]);
-%$ t(6) = dyn_assert(add_periods_to_array_of_dates([1950 1], 4, 6),[1951 3]);
-%$ t(7) = dyn_assert(add_periods_to_array_of_dates([1950 1], 4, 7),[1951 4]);
-%$ t(8) = dyn_assert(add_periods_to_array_of_dates([1950 1], 4, 8),[1952 1]);
-%$ T = all(t);
-%@eof:1
-
-%@test:2
-%$ t(1) = dyn_assert(add_periods_to_array_of_dates(repmat([1950 1],8,1), 4, transpose(1:8)),[1950 2; 1950 3; 1950 4; 1951 1; 1951 2; 1951 3; 1951 4; 1952 1]);
-%$ T = all(t);
-%@eof:2
-
-%@test:3
-%$ t(1) = dyn_assert(add_periods_to_array_of_dates([1950 1], 1, 1),[1951 1]);
-%$ T = all(t);
-%@eof:3
-
-%@test:4
-%$ t(1) = dyn_assert(add_periods_to_array_of_dates([1950 1; 1950 2; 1950 3; 1950 4], 4, 1),[1950 2; 1950 3; 1950 4; 1951 1]);
-%$ T = all(t);
-%@eof:4
-
-%@test:5
-%$ t(1) = dyn_assert(add_periods_to_array_of_dates([1950 1], 4, transpose(1:8)),[1950 2; 1950 3; 1950 4; 1951 1; 1951 2; 1951 3; 1951 4; 1952 1]);
-%$ T = all(t);
-%@eof:5
-
-%@test:6
-%$ t(1) = dyn_assert(add_periods_to_array_of_dates([1950 1], 4, -1),[1949 4]);
-%$ t(2) = dyn_assert(add_periods_to_array_of_dates([1950 1], 4, -2),[1949 3]);
-%$ t(3) = dyn_assert(add_periods_to_array_of_dates([1950 1], 4, -3),[1949 2]);
-%$ t(4) = dyn_assert(add_periods_to_array_of_dates([1950 1], 4, -4),[1949 1]);
-%$ t(5) = dyn_assert(add_periods_to_array_of_dates([1950 1], 4, -5),[1948 4]);
-%$ t(6) = dyn_assert(add_periods_to_array_of_dates([1950 1], 4, -6),[1948 3]);
-%$ t(7) = dyn_assert(add_periods_to_array_of_dates([1950 1], 4, -7),[1948 2]);
-%$ t(8) = dyn_assert(add_periods_to_array_of_dates([1950 1], 4, -8),[1948 1]);
-%$ T = all(t);
-%@eof:6
\ No newline at end of file
diff --git a/matlab/utilities/dates/add_periods_to_date.m b/matlab/utilities/dates/add_periods_to_date.m
deleted file mode 100644
index 22ff62c5d109c7b65cb4b5e7a157c4ce3e16e7ef..0000000000000000000000000000000000000000
--- a/matlab/utilities/dates/add_periods_to_date.m
+++ /dev/null
@@ -1,57 +0,0 @@
-function time = add_periods_to_date(time, freq, p)  % --*-- Unitary tests --*--
-
-% Adds a p periods (p can be negative) to a date (or a set of dates) characterized by array time and frequency freq.
-    
-% Copyright (C) 2013 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/>.
-
-time(1) = time(1) + fix(p/freq);
-time(2) = time(2) + rem(p,freq);
-
-if time(2)>freq
-    time(1) = time(1) + 1;
-    time(2) = time(2) - freq;
-end
-
-if time(2)<1
-    time(1) = time(1) - 1;
-    time(2) = time(2) + freq;
-end
-
-%@test:1
-%$ t(1) = dyn_assert(add_periods_to_date([1950 1], 4, 1),[1950 2]);
-%$ t(2) = dyn_assert(add_periods_to_date([1950 1], 4, 2),[1950 3]);
-%$ t(3) = dyn_assert(add_periods_to_date([1950 1], 4, 3),[1950 4]);
-%$ t(4) = dyn_assert(add_periods_to_date([1950 1], 4, 4),[1951 1]);
-%$ t(5) = dyn_assert(add_periods_to_date([1950 1], 4, 5),[1951 2]);
-%$ t(6) = dyn_assert(add_periods_to_date([1950 1], 4, 6),[1951 3]);
-%$ t(7) = dyn_assert(add_periods_to_date([1950 1], 4, 7),[1951 4]);
-%$ t(8) = dyn_assert(add_periods_to_date([1950 1], 4, 8),[1952 1]);
-%$ T = all(t);
-%@eof:1
-
-%@test:2
-%$ t(1) = dyn_assert(add_periods_to_date([1950 1], 4, -1),[1949 4]);
-%$ t(2) = dyn_assert(add_periods_to_date([1950 1], 4, -2),[1949 3]);
-%$ t(3) = dyn_assert(add_periods_to_date([1950 1], 4, -3),[1949 2]);
-%$ t(4) = dyn_assert(add_periods_to_date([1950 1], 4, -4),[1949 1]);
-%$ t(5) = dyn_assert(add_periods_to_date([1950 1], 4, -5),[1948 4]);
-%$ t(6) = dyn_assert(add_periods_to_date([1950 1], 4, -6),[1948 3]);
-%$ t(7) = dyn_assert(add_periods_to_date([1950 1], 4, -7),[1948 2]);
-%$ t(8) = dyn_assert(add_periods_to_date([1950 1], 4, -8),[1948 1]);
-%$ T = all(t);
-%@eof:2
\ No newline at end of file
diff --git a/matlab/utilities/dates/date2string.m b/matlab/utilities/dates/date2string.m
deleted file mode 100644
index 26358ee23fc2060372421b542bb2bd846232df6a..0000000000000000000000000000000000000000
--- a/matlab/utilities/dates/date2string.m
+++ /dev/null
@@ -1,51 +0,0 @@
-function s = date2string(varargin)
- 
-% Returns date as a string.
-%
-% INPUTS 
-%  o varargin{1}     + dates object with one element, if nargin==1.
-%                    + 1*2 vector of integers (first element is the year, second element is the subperiod), if nargin==2.
-%  o varargin{2}     integer scalar equal to 1, 4, 12 or 52 (frequency).
-%
-% OUTPUTS 
-%  o s               string.
-    
-% Copyright (C) 2013 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 isequal(nargin,1) 
-    if ~(isa(varargin{1},'dates') && isequal(length(varargin{1}),1))
-        error(['dates::format: Input argument ' inputname(1) ' has to be a dates object with one element!'])
-    else
-        time = varargin{1}.time;
-        freq = varargin{1}.freq;
-    end
-end
-
-if isequal(nargin,2)
-    if ~(isvector(varargin{1}) && isequal(length(varargin{1}),2) && all(isint(varargin{1})) && isscalar(varargin{2} && ismember(varargin{2},[1 4 12 52])))
-        error(['dates::format: First input must be a 1*2 vector of integers and second input must be a scalar integer (1, 4, 12 or 52)!'])
-    else
-        time = varargin{1};
-        freq = varargin{2};
-    end
-end
-
-s = [num2str(time(1)) freq2string(freq)];
-if freq>1
-    s = strcat(s, num2str(time(2)));
-end
\ No newline at end of file
diff --git a/matlab/utilities/dates/freq2string.m b/matlab/utilities/dates/freq2string.m
deleted file mode 100644
index 2d12f8def073acc9e2d260b25a32a5c82eb346a3..0000000000000000000000000000000000000000
--- a/matlab/utilities/dates/freq2string.m
+++ /dev/null
@@ -1,37 +0,0 @@
-function s = freq2string(freq)
-
-% INPUTS 
-%  o freq     scalar integer,  equal to 1, 4, 12 or 52 (resp. annual, quaterly, monthly or weekly)
-%
-% OUTPUTS 
-%  o s        character, equal to Y, Q, M or W (resp. annual, quaterly, monthly or weekly)
-    
-% Copyright (C) 2013 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/>.
-
-switch freq
-  case 1
-    s = 'Y';
-  case 4
-    s = 'Q';
-  case 12
-    s = 'M';
-  case 52
-    s = 'W';
-  otherwise
-    error('dates::freq2string: Unknown frequency!')
-end
\ No newline at end of file
diff --git a/matlab/utilities/dates/isdate.m b/matlab/utilities/dates/isdate.m
deleted file mode 100644
index 726e5e47980429e27458391a5f2c1aedb5fa2e19..0000000000000000000000000000000000000000
--- a/matlab/utilities/dates/isdate.m
+++ /dev/null
@@ -1,55 +0,0 @@
-function b = isdate(str)  % --*-- Unitary tests --*--
-
-% Tests if the input string can be interpreted as a date.
-%
-% INPUTS 
-%  o str     string.
-%
-% OUTPUTS 
-%  o b       integer scalar, equal to 1 if str can be interpreted as a date or 0 otherwise.
-
-% Copyright (C) 2013 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(str) && isscalar(str)
-    b = 1;
-    return
-end
-
-b = isstringdate(str);
-
-%@test:1
-%$
-%$ date_1 = 1950;
-%$ date_2 = '1950m2';
-%$ date_3 = '-1950m2';
-%$ date_4 = '1950m52';
-%$ date_5 = ' 1950';
-%$ date_6 = '1950Y';
-%$ date_7 = '-1950a';
-%$ date_8 = '1950m ';
-%$
-%$ t(1) = dyn_assert(isdate(date_1),1);
-%$ t(2) = dyn_assert(isdate(date_2),1);
-%$ t(3) = dyn_assert(isdate(date_3),1);
-%$ t(4) = dyn_assert(isdate(date_4),0);
-%$ t(5) = dyn_assert(isdate(date_5),0);
-%$ t(6) = dyn_assert(isdate(date_6),1);
-%$ t(7) = dyn_assert(isdate(date_7),1);
-%$ t(8) = dyn_assert(isdate(date_8),0);
-%$ T = all(t);
-%@eof:1
\ No newline at end of file
diff --git a/matlab/utilities/dates/isdates.m b/matlab/utilities/dates/isdates.m
deleted file mode 100644
index 33b679020bb4b539593495456d17f504fc3c57b2..0000000000000000000000000000000000000000
--- a/matlab/utilities/dates/isdates.m
+++ /dev/null
@@ -1,22 +0,0 @@
-function B = isdates(A)
-
-% Tests if the input A is a dates object.
-
-% Copyright (C) 2013 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/>.
-
-B = isa(A,'dates');
\ No newline at end of file
diff --git a/matlab/utilities/dates/isfreq.m b/matlab/utilities/dates/isfreq.m
deleted file mode 100644
index 79ba42c5395ab9484bff5e18f10a69ffb37b79d0..0000000000000000000000000000000000000000
--- a/matlab/utilities/dates/isfreq.m
+++ /dev/null
@@ -1,39 +0,0 @@
-function B = isfreq(A)
-
-% Tests if A can be interpreted as a frequency.
-%
-% INPUTS 
-%  o A     scalar integer or character.
-%
-% OUTPUTS 
-%  o B     scalar integer equal to one if A can be interpreted as a frequency, zero otherwise.
-
-% Copyright (C) 2013 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/>.
-
-B = 0;
-
-if ischar(A)
-    if isequal(length(A),1) && ismember(upper(A),{'Y','A','Q','M','W'})
-        B = 1;
-        return
-    end
-end
-
-if isnumeric(A) && isequal(length(A),1) && ismember(A,[1 4 12 52])
-    B = 1;
-end
\ No newline at end of file
diff --git a/matlab/utilities/dates/ismonthly.m b/matlab/utilities/dates/ismonthly.m
deleted file mode 100644
index a66d06e695f1f411ad09127f14a767d20caaa178..0000000000000000000000000000000000000000
--- a/matlab/utilities/dates/ismonthly.m
+++ /dev/null
@@ -1,58 +0,0 @@
-function b = ismonthly(str)  % --*-- Unitary tests --*--
-
-% Tests if the input can be interpreted as a monthly date.
-%
-% INPUTS 
-%  o str     string.
-%
-% OUTPUTS 
-%  o b       integer scalar, equal to 1 if str can be interpreted as a monthly date or 0 otherwise.
-
-% Copyright (C) 2012-2013 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 ischar(str)
-    if isempty(regexp(str,'^-?[0-9]*[Mm]([1-9]|1[0-2])$','once'))
-        b = 0;
-    else
-        b = 1;
-    end
-else
-    b = 0;
-end
-
-%@test:1
-%$
-%$ date_1 = '1950M2';
-%$ date_2 = '1950m2';
-%$ date_3 = '-1950m2';
-%$ date_4 = '1950m12';
-%$ date_5 = '1950 azd ';
-%$ date_6 = '1950Y';
-%$ date_7 = '1950Q3';
-%$ date_8 = '1950m24';
-%$
-%$ t(1) = dyn_assert(ismonthly(date_1),1);
-%$ t(2) = dyn_assert(ismonthly(date_2),1);
-%$ t(3) = dyn_assert(ismonthly(date_3),1);
-%$ t(4) = dyn_assert(ismonthly(date_4),1);
-%$ t(5) = dyn_assert(ismonthly(date_5),0);
-%$ t(6) = dyn_assert(ismonthly(date_6),0);
-%$ t(7) = dyn_assert(ismonthly(date_7),0);
-%$ t(8) = dyn_assert(ismonthly(date_8),0);
-%$ T = all(t);
-%@eof:1
\ No newline at end of file
diff --git a/matlab/utilities/dates/isquaterly.m b/matlab/utilities/dates/isquaterly.m
deleted file mode 100644
index 2b154ef3c5f403a296b5c95c00ef79b8202862f1..0000000000000000000000000000000000000000
--- a/matlab/utilities/dates/isquaterly.m
+++ /dev/null
@@ -1,56 +0,0 @@
-function b = isquaterly(str)  % --*-- Unitary tests --*--
-
-% Tests if the input can be interpreted as a quaterly date.
-%
-% INPUTS 
-%  o str     string.
-%
-% OUTPUTS 
-%  o b       integer scalar, equal to 1 if str can be interpreted as a quaterly date or 0 otherwise.
-
-% Copyright (C) 2012-2013 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 ischar(str)
-    if isempty(regexp(str,'^-?[0-9]*[Qq][1-4]$','once'))
-        b = 0;
-    else
-        b = 1;
-    end
-else
-    b = 0;
-end
-
-%@test:1
-%$
-%$ date_1 = '1950Q2';
-%$ date_2 = '1950q2';
-%$ date_3 = '-1950q2';
-%$ date_4 = '1950q12';
-%$ date_5 = '1950 azd ';
-%$ date_6 = '1950Y';
-%$ date_7 = '1950m24';
-%$
-%$ t(1) = dyn_assert(isquaterly(date_1),1);
-%$ t(2) = dyn_assert(isquaterly(date_2),1);
-%$ t(3) = dyn_assert(isquaterly(date_3),1);
-%$ t(4) = dyn_assert(isquaterly(date_4),0);
-%$ t(5) = dyn_assert(isquaterly(date_5),0);
-%$ t(6) = dyn_assert(isquaterly(date_6),0);
-%$ t(7) = dyn_assert(isquaterly(date_7),0);
-%$ T = all(t);
-%@eof:1
\ No newline at end of file
diff --git a/matlab/utilities/dates/isstringdate.m b/matlab/utilities/dates/isstringdate.m
deleted file mode 100644
index fbac8b0072e54c596fc5549445664f689f8c9ee2..0000000000000000000000000000000000000000
--- a/matlab/utilities/dates/isstringdate.m
+++ /dev/null
@@ -1,54 +0,0 @@
-function b = isstringdate(str)  % --*-- Unitary tests --*--
-
-% Tests if the input string can be interpreted as a date.
-%
-% INPUTS 
-%  o str     string.
-%
-% OUTPUTS 
-%  o b       integer scalar, equal to 1 if str can be interpreted as a date or 0 otherwise.
-
-% Copyright (C) 2013 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 ischar(str)
-    b = isquaterly(str) || isyearly(str) || ismonthly(str) || isweekly(str);
-else
-    b = 0;
-end
-
-%@test:1
-%$
-%$ date_1 = '1950M2';
-%$ date_2 = '1950m2';
-%$ date_3 = '-1950m2';
-%$ date_4 = '1950m52';
-%$ date_5 = ' 1950';
-%$ date_6 = '1950Y';
-%$ date_7 = '-1950a';
-%$ date_8 = '1950m ';
-%$
-%$ t(1) = dyn_assert(isstringdate(date_1),1);
-%$ t(2) = dyn_assert(isstringdate(date_2),1);
-%$ t(3) = dyn_assert(isstringdate(date_3),1);
-%$ t(4) = dyn_assert(isstringdate(date_4),0);
-%$ t(5) = dyn_assert(isstringdate(date_5),0);
-%$ t(6) = dyn_assert(isstringdate(date_6),1);
-%$ t(7) = dyn_assert(isstringdate(date_7),1);
-%$ t(8) = dyn_assert(isstringdate(date_8),0);
-%$ T = all(t);
-%@eof:1
\ No newline at end of file
diff --git a/matlab/utilities/dates/issubperiod.m b/matlab/utilities/dates/issubperiod.m
deleted file mode 100644
index 5f7a7560bcc7202a0712152a4c8f362334507e83..0000000000000000000000000000000000000000
--- a/matlab/utilities/dates/issubperiod.m
+++ /dev/null
@@ -1,24 +0,0 @@
-function C = issubperiod(A,B)
-
-% Copyright (C) 2013 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 isfreq(B)
-    C = all(isint(A)) && all(A>=1) && all(A<=B);
-else
-    error('issubperiod:: Second input argument must be equal to 1, 4, 12 or 52 (frequency)!')
-end
\ No newline at end of file
diff --git a/matlab/utilities/dates/isweekly.m b/matlab/utilities/dates/isweekly.m
deleted file mode 100644
index d9988f5253bd865d83d04e8cb18e59a441fd836a..0000000000000000000000000000000000000000
--- a/matlab/utilities/dates/isweekly.m
+++ /dev/null
@@ -1,58 +0,0 @@
-function b = isweekly(str)  % --*-- Unitary tests --*--
-
-% Tests if the input can be interpreted as a weekly date.
-%
-% INPUTS 
-%  o str     string.
-%
-% OUTPUTS 
-%  o b       integer scalar, equal to 1 if str can be interpreted as a weekly date or 0 otherwise.
-
-% Copyright (C) 2012-2013 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 ischar(str)
-    if isempty(regexp(str,'^-?[0-9]*[Ww]([1-9]|[1-4][0-9]|5[0-2])$','once'))
-        b = 0;
-    else
-        b = 1;
-    end
-else
-    b = 0;
-end
-
-%@test:1
-%$
-%$ date_1 = '1950W2';
-%$ date_2 = '1950w2';
-%$ date_3 = '-1950w2';
-%$ date_4 = '1950w22';
-%$ date_5 = '1950 azd ';
-%$ date_6 = '1950Y';
-%$ date_7 = '1950Q3';
-%$ date_8 = '1950m54';
-%$
-%$ t(1) = dyn_assert(isweekly(date_1),1);
-%$ t(2) = dyn_assert(isweekly(date_2),1);
-%$ t(3) = dyn_assert(isweekly(date_3),1);
-%$ t(4) = dyn_assert(isweekly(date_4),1);
-%$ t(5) = dyn_assert(isweekly(date_5),0);
-%$ t(6) = dyn_assert(isweekly(date_6),0);
-%$ t(7) = dyn_assert(isweekly(date_7),0);
-%$ t(8) = dyn_assert(isweekly(date_8),0);
-%$ T = all(t);
-%@eof:1
\ No newline at end of file
diff --git a/matlab/utilities/dates/isyearly.m b/matlab/utilities/dates/isyearly.m
deleted file mode 100644
index d1345a0a185eed4ea79ccfe69d7ca9d1239a5231..0000000000000000000000000000000000000000
--- a/matlab/utilities/dates/isyearly.m
+++ /dev/null
@@ -1,58 +0,0 @@
-function b = isyearly(str)  % --*-- Unitary tests --*--
-
-% Tests if the input can be interpreted as a yearly date.
-%
-% INPUTS 
-%  o str     string.
-%
-% OUTPUTS 
-%  o b       integer scalar, equal to 1 if str can be interpreted as a yearly date or 0 otherwise.
-
-% Copyright (C) 2012-2013 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 ischar(str)
-    if isempty(regexp(str,'^-?[0-9]*[YyAa]$','once'))
-        b = 0;
-    else
-        b = 1;
-    end
-else
-    b = 0;
-end
-
-%@test:1
-%$
-%$ date_1 = '1950M2';
-%$ date_2 = '1950m2';
-%$ date_3 = '-1950m2';
-%$ date_4 = '1950m12';
-%$ date_5 = '1950 azd ';
-%$ date_6 = '1950Y';
-%$ date_7 = '-1950a';
-%$ date_8 = '1950m24';
-%$
-%$ t(1) = dyn_assert(isyearly(date_1),0);
-%$ t(2) = dyn_assert(isyearly(date_2),0);
-%$ t(3) = dyn_assert(isyearly(date_3),0);
-%$ t(4) = dyn_assert(isyearly(date_4),0);
-%$ t(5) = dyn_assert(isyearly(date_5),0);
-%$ t(6) = dyn_assert(isyearly(date_6),1);
-%$ t(7) = dyn_assert(isyearly(date_7),1);
-%$ t(8) = dyn_assert(isyearly(date_8),0);
-%$ T = all(t);
-%@eof:1
\ No newline at end of file
diff --git a/matlab/utilities/dates/string2date.m b/matlab/utilities/dates/string2date.m
deleted file mode 100644
index bb91a05fb3b693c196576f842e8a16b6d698129d..0000000000000000000000000000000000000000
--- a/matlab/utilities/dates/string2date.m
+++ /dev/null
@@ -1,109 +0,0 @@
-function date = string2date(a) % --*-- Unitary tests --*--
-    
-% Copyright (C) 2013 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/>.
-
-date = struct('freq', NaN, 'time', NaN(1,2));
-
-if ~ischar(a) || ~isdate(a)
-    error('dates::string2date: Input must be a string that can be interpreted as a date!');
-end
-
-if isyearly(a)
-    year = 1:(regexp(a,'[AaYy]')-1);
-    date.freq = 1;
-    date.time = write_time_field_y(a, year);
-    return
-end
-
-if isquaterly(a)
-    year = 1:(regexp(a,'[Qq]')-1);
-    date.freq = 4;
-    date.time = write_time_field(a, year);
-    return
-end
-
-if ismonthly(a)
-    year = 1:(regexp(a,'[Mm]')-1);
-    date.freq = 12;
-    date.time = write_time_field(a, year);
-    return
-end
-
-if isweekly(a)
-    year = 1:(regexp(a,'[Ww]')-1);
-    date.freq = 52;
-    date.time = write_time_field(a, year);
-    return
-end
-
-
-function b = write_time_field(c, d)
-    b(1) = str2double(c(d));
-    b(2) = str2double(c(d(end)+2:end));
-
-function b = write_time_field_y(c, d)
-    b(1) = str2double(c(d));
-    b(2) = 1;
-
-%@test:1
-%$
-%$ % Define some dates
-%$ date_1 = '1950Q2';
-%$ date_2 = '1950m10';
-%$ date_3 = '1950w50';
-%$ date_4 = '1950a';
-%$ date_5 = '1967y';
-%$ date_6 = '2009A';
-%$
-%$ % Define expected results.
-%$ e_date_1 = [1950 2];
-%$ e_freq_1 = 4;
-%$ e_date_2 = [1950 10];
-%$ e_freq_2 = 12;
-%$ e_date_3 = [1950 50];
-%$ e_freq_3 = 52;
-%$ e_date_4 = [1950 1];
-%$ e_freq_4 = 1;
-%$ e_date_5 = [1967 1];
-%$ e_freq_5 = 1;
-%$ e_date_6 = [2009 1];
-%$ e_freq_6 = 1;
-%$
-%$ % Call the tested routine.
-%$ d1 = string2date(date_1);
-%$ d2 = string2date(date_2);
-%$ d3 = string2date(date_3);
-%$ d4 = string2date(date_4);
-%$ d5 = string2date(date_5);
-%$ d6 = string2date(date_6);
-%$
-%$ % Check the results.
-%$ t(1) = dyn_assert(d1.time,e_date_1);
-%$ t(2) = dyn_assert(d2.time,e_date_2);
-%$ t(3) = dyn_assert(d3.time,e_date_3);
-%$ t(4) = dyn_assert(d4.time,e_date_4);
-%$ t(5) = dyn_assert(d5.time,e_date_5);
-%$ t(6) = dyn_assert(d6.time,e_date_6);
-%$ t(7) = dyn_assert(d1.freq,e_freq_1);
-%$ t(8) = dyn_assert(d2.freq,e_freq_2);
-%$ t(9) = dyn_assert(d3.freq,e_freq_3);
-%$ t(10) = dyn_assert(d4.freq,e_freq_4);
-%$ t(11)= dyn_assert(d5.freq,e_freq_5);
-%$ t(12)= dyn_assert(d6.freq,e_freq_6);
-%$ T = all(t);
-%@eof:1
\ No newline at end of file
diff --git a/matlab/utilities/dates/string2freq.m b/matlab/utilities/dates/string2freq.m
deleted file mode 100644
index ea04c39649e27a0f3555163d6e44ad612cc2009f..0000000000000000000000000000000000000000
--- a/matlab/utilities/dates/string2freq.m
+++ /dev/null
@@ -1,37 +0,0 @@
-function freq = string2freq(s)
-
-% INPUTS 
-%  o s        character, equal to Y, Q, M or W (resp. annual, quaterly, monthly or weekly)
-%
-% OUTPUTS 
-%  o freq     scalar integer,  equal to 1, 4, 12 or 52 (resp. annual, quaterly, monthly or weekly)
-    
-% Copyright (C) 2013 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/>.
-
-switch upper(s)
-  case {'Y','A'}
-    freq = 1;
-  case 'Q'
-    freq = 4;
-  case 'M'
-    freq = 12;
-  case 'W'
-    freq = 52;
-  otherwise
-    error('dates::freq2string: Unknown frequency!')
-end
\ No newline at end of file
diff --git a/matlab/utilities/dseries/from.m b/matlab/utilities/dseries/from.m
deleted file mode 100644
index 81fd5bc1621a1af14cd6d239b3f6123c6f70c4d7..0000000000000000000000000000000000000000
--- a/matlab/utilities/dseries/from.m
+++ /dev/null
@@ -1,494 +0,0 @@
-function from(varargin)   % --*-- 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/>.
-
-lvarargin = lower(varargin);
-
-to_id = strmatch('to',lvarargin);
-do_id = strmatch('do',lvarargin);
-
-if isempty(to_id) || isempty(do_id)
-    error(get_error_message_0())
-end
-
-if do_id<to_id
-    msg = sprinf('dseries::from: Wrong syntax! The TO keyword must preceed the DO keyword.\n');
-    error(get_error_message_0(msg))
-end
-
-if ~isdate(varargin{1})
-    % The first argument is not a string formatted date. Test if this argument refers to a dates object
-    % in the caller workspace.
-    try
-        d1 = evalin('caller', varargin{1});
-        if ~isdates(d1)
-            error(['dseries::from: Variable ' varargin{1} ' is not a dates object!'])
-        end
-    catch
-        error(['dseries::from: Variable ' varargin{1} ' is unknown!'])
-    end
-    if ~exist('d1')
-        msg = sprintf('dseries::from: Wrong syntax! The FROM statement must be followed by a string formatted date.\n');
-        error(get_error_message_0(msg))
-    end
-else
-    d1 = dates(varargin{1}); % First date
-end
-
-if ~isequal(to_id,2)
-    msg = sprintf('dseries::from: Wrong syntax! The first dates object must be immediately followed by the TO keyword.\n');
-    error(get_error_message_0(msg))
-end
-
-if ~isdate(varargin{3})
-    % The third argument is not a string formatted date. Test if this argument refers to a dates object
-    % in the caller workspace.
-    try
-        d2 = evalin('caller', varargin{3});
-        if ~isdates(d2)
-            error(['dseries::from: Variable ' varargin{3} ' is not a dates object!'])
-        end
-    catch
-        error(['dseries::from: Variable ' varargin{3} ' is unknown!'])
-    end
-    if ~exist('d2')
-        msg = sprintf('dseries::from: Wrong syntax! The TO keyword must be followed by a second dates object.\n');
-        error(get_error_message_0(msg))
-    end
-else
-    d2 = dates(varargin{3}); % Last date
-end
-
-if d1>d2
-    error('dseries::from: The first date must preceed the second one!')
-end
-
-if ~isequal(do_id,4)
-    msg = sprintf('dseries::from: Wrong syntax! The second dates object must be immediately followed by the DO keyword.\n');
-    error(get_error_message_0(msg))
-end
-
-% Build the recursive expression.
-EXPRESSION = char([varargin{5:end}]);
-
-% Check that the expression is an assignment
-equal_id = strfind(EXPRESSION,'=');
-if isempty(equal_id)
-    error('dseries::from: Wrong syntax! The expression following the DO keyword must be an assignment (missing equal symbol).')
-end
-
-% Issue ann error message if the user attempts to do more than one assignment.
-if ~isequal(length(equal_id),1)
-    error('dseries::from: Not yet implemented! Only one assignment is allowed in the FROM-TO-DO statement.')
-end
-
-% Get all the variables involved in the recursive expression.
-variables = unique(regexpi(EXPRESSION, '\w*\(t\)|\w*\(t\-\d\)|\w*\(t\+\d\)|\w*\.\w*\(t\)|\w*\.\w*\(t\-\d\)|\w*\.\w*\(t\+\d\)','match'));
-
-% Copy EXPRESSION in expression. In the next loop we will remove all indexed variables from expression.
-expression = EXPRESSION;
-
-% Build an incidence table (max lag/lead for each variable)
-%
-% Column 1: Name of the variable.
-% Column 2: Maximum lag order.
-% Column 3: Equal to 1 if the variable appears at the current period, 0 otherwise.
-% Column 4: Maximum lead order.
-% Column 5: Vector of effective lag orders.
-% Column 6: Vector of effective lead orders.
-%
-% Initialization.
-leadlagtable = cell(0,6);
-% Loop over the variables (dseries objects).
-for i=1:length(variables)
-    expression = strrep(expression,variables{i},'');
-    current = ~isempty(regexpi(variables{i},'\(t\)'));
-    lag = ~isempty(regexpi(variables{i},'\(t\-\d\)'));
-    lead = ~isempty(regexpi(variables{i},'\(t\+\d\)'));
-    start = regexpi(variables{i},'\(t\)|\(t\-\d\)|\(t\+\d\)');
-    index = variables{i}(start:end);
-    variables(i) = {variables{i}(1:start-1)};
-    if isempty(leadlagtable)
-        leadlagtable(1,1) = {variables{i}};
-        if current
-            leadlagtable(1,3) = {1};
-        else
-            leadlagtable(1,3) = {0};
-        end
-        if lag
-            tmp = regexpi(index,'\d','match');
-            leadlagtable(1,2) = {str2double(tmp{1})};
-            leadlagtable(1,5) = {str2double(tmp{1})};
-        else
-            leadlagtable(1,2) = {0};
-            leadlagtable(1,5) = {[]};
-        end
-        if lead
-            tmp = regexpi(index,'\d','match');
-            leadlagtable(1,4) = {str2double(tmp{1})};
-            leadlagtable(1,6) = {str2double(tmp{1})};
-        else
-            leadlagtable(1,4) = {0};
-            leadlagtable(1,6) = {[]};
-        end
-    else
-        linea = strmatch(variables{i},leadlagtable(:,1));
-        if isempty(linea)
-            % This is a new variable!
-            linea = size(leadlagtable,1)+1;
-            leadlagtable(linea,1) = {variables{i}};
-            leadlagtable(linea,2) = {0};
-            leadlagtable(linea,3) = {0};
-            leadlagtable(linea,4) = {0};
-            leadlagtable(linea,5) = {[]};
-            leadlagtable(linea,6) = {[]};
-        end
-        if current
-            leadlagtable(linea,3) = {1};
-        end
-        if lag
-            tmp = regexpi(index,'\d','match');
-            leadlagtable(linea,2) = {max(str2double(tmp{1}),leadlagtable{linea,2})};
-            leadlagtable(linea,5) = {sortrows([leadlagtable{linea,5}; str2double(tmp{1})])};
-        end
-        if lead
-            tmp = regexpi(index,'\d','match');
-            leadlagtable(linea,4) = {max(str2double(tmp{1}),leadlagtable{linea,4})};
-            leadlagtable(linea,6) = {sortrows([leadlagtable{linea,6}; str2double(tmp{1})])};
-        end
-    end
-end
-
-% Set the number of variables
-number_of_variables = size(leadlagtable,1);
-
-% Initialize a cell array containing the names of the variables.
-variable_names = cell(1);
-
-% Test that all the involved variables are available dseries objects. Also check that
-% these time series are defined over the time range given by d1 and d2 (taking care of
-% the lags and leads) and check that each object is a singleton
-for i=1:number_of_variables
-    current_variable = leadlagtable{i,1};
-    idvar = strfind(current_variable,'.');
-    if isempty(idvar)
-        idvar = 0;
-    end
-    if idvar
-        current_variable_0 = current_variable(1:idvar-1);
-    else
-        current_variable_0 = current_variable;
-    end
-    try
-        var = evalin('caller',current_variable_0);
-    catch
-        error(['dseries::from: Variable ' current_variable_0 ' is unknown!'])
-    end
-    if idvar
-        try
-            eval(sprintf('var = var.%s;',current_variable(idvar+1:end)))
-        catch
-            error(sprintf('dseries::from: Variable %s is not a member of dseries oject %s!', current_variable(idvar+1:end), current_variable_0))
-        end
-    end
-    if ~isdseries(var)
-        error(['dseries::from: Variable ' current_variable ' is not a dseries object!'])
-    else
-        if ~var.vobs
-            msg = sprintf('dseries::from: Object %s must not be empty!\n',current_variable);
-            error(msg)
-        end
-        if var.vobs>1
-            msg = sprintf('dseries::from: Object %s must contain only one variable!\n',current_variable);
-            error(msg)
-        end
-        if i>1
-            if ismember(var.name,variable_names)
-                % Locally change variable name.
-                var = var.rename(var.name{1},get_random_string(20));
-            end
-            variable_names(i) = {var.name{1}};
-        else
-            variable_names(i) = {var.name{1}};
-        end
-        if d1<var.dates(1)+leadlagtable{i,2}
-            msg = sprintf('dseries::from: Initial date of the loop (%s) is inconsistent with %s''s range!\n',char(d1),current_variable);
-            msg = [msg, sprintf('               Initial date should be greater than or equal to %s.',char(var.dates(1)+leadlagtable{i,2}))];
-            error(msg)
-        end
-        if d2>var.dates(end)-leadlagtable{i,4}
-            % The first variable should be the assigned variable (will be tested later)
-            if ~isassignedvariable(leadlagtable{i,1},EXPRESSION)
-                msg = sprintf('dseries::from: Last date of the loop (%s) is inconsistent with %s''s range!\n',char(d2),current_variable);
-                msg = [msg, sprintf('               Last date should be less than or equal to %s.',char(var.dates(end)-leadlagtable{i,4}))];
-                error(msg)
-            else
-                var = [var; dseries(NaN((d2-var.dates(end)),1),var.dates(end)+1:d2,var.name)];
-            end
-        end
-        eval(sprintf('%s = var;',current_variable));
-    end
-end
-
-% Get the name of the assigned variable (with time index)
-assignedvariablename = regexpi(EXPRESSION(1:equal_id-1), '\w*\(t\)|\w*\(t\-\d\)|\w*\(t\+\d\)|\w*\.\w*\(t\)|\w*\.\w*\(t\-\d\)|\w*\.\w*\(t\+\d\)','match');
-if isempty(assignedvariablename)
-    error('dseries::from: Wrong syntax! The expression following the DO keyword must be an assignment (missing variable before the equal symbol).')
-end
-if length(assignedvariablename)>1
-    error('dseries::from: No more than one variable can be assigned!')
-end
-% Check if the model is static
-start = regexpi(assignedvariablename{1},'\(t\)|\(t\-\d\)|\(t\+\d\)');
-index = assignedvariablename{1}(start:end);
-assignedvariablename = assignedvariablename{1}(1:start-1);
-indva = strmatch(assignedvariablename, leadlagtable(:,1));
-dynamicmodel = ~isempty(regexpi(EXPRESSION(equal_id:end), ...
-                                sprintf('%s\\(t\\)|%s\\(t\\-\\d\\)|%s\\(t\\+\\d\\)',assignedvariablename,assignedvariablename,assignedvariablename),'match'));
-% Check that the dynamic model for the endogenous variable is not forward looking.
-if dynamicmodel
-    indum = index2num(index);
-    if indum<leadlagtable{indva,4}
-        error('dseries::from: It is not possible to simulate a forward looking model!')
-    end
-end
-% Check that the assigned variable does not depend on itself (the assigned variable can depend on its past level but not on the current level).
-if dynamicmodel
-    tmp = regexpi(EXPRESSION(equal_id+1:end), ...
-                  sprintf('%s\\(t\\)|%s\\(t\\-\\d\\)|%s\\(t\\+\\d\\)',assignedvariablename,assignedvariablename,assignedvariablename),'match');
-    tmp = cellfun(@extractindex, tmp);
-    tmp = cellfun(@index2num, tmp);
-    if ~all(tmp(:)<indum)
-        error(sprintf('dseries::from: On the righthand side, the endogenous variable, %s, must be indexed by %s at most.',assignedvariablename,num2index(indum-1)))
-    end
-end
-
-% Put all the variables in a unique dseries object.
-list_of_variables = leadlagtable{1,1};
-for i=2:number_of_variables
-   list_of_variables = [list_of_variables, ',' leadlagtable{i,1}];
-end
-eval(sprintf('tmp = [%s];', list_of_variables));
-
-% Get base time index
-t1 = find(d1==tmp.dates);
-t2 = find(d2==tmp.dates);
-
-% Get data
-data = tmp.data;
-
-% Isolate the (potential) parameters in the expression to be evaluated
-TMP314 = regexp(expression, '([0-9]*\.[0-9]*|\w*)', 'match');
-% Here I remove the numbers (TMP314 -> TMP314159).
-TMP3141 = regexp(TMP314,'(([0-9]*\.[0-9]*)|([0-9]*))','match');
-TMP31415 = find(cellfun(@isempty,TMP3141));
-TMP314159 = TMP314(TMP31415);
-
-if dynamicmodel
-    % Transform EXPRESSION by replacing calls to the dseries objects by references to data.
-    for i=1:number_of_variables
-        EXPRESSION = regexprep(EXPRESSION,sprintf('%s\\(t\\)',leadlagtable{i,1}),sprintf('data(t,%s)',num2str(i)));
-        for j=1:length(leadlagtable{i,5})
-            lag = leadlagtable{i,5}(j);
-            EXPRESSION = regexprep(EXPRESSION,sprintf('%s\\(t-%s\\)',leadlagtable{i,1},num2str(lag)), ...
-                                   sprintf('data(t-%s,%s)',num2str(lag),num2str(i)));
-        end
-        for j=1:length(leadlagtable{i,6})
-            lead = leadlagtable{i,6}(j);
-            EXPRESSION = regexprep(EXPRESSION,sprintf('%s\\(t+%s\\)',leadlagtable{i,1},num2str(lead)), ...
-                                   sprintf('data(t+%s,%s)',num2str(lead),num2str(i)));
-        end
-    end
-    % Get values for the parameters (if any)
-    if ~isempty(TMP314159)
-        for i=1:length(TMP314159)
-            wordcandidate = TMP314159{i};
-            try % If succesful, word is a reference to a variable in the caller function/script.
-                thiswordisaparameter = evalin('caller', wordcandidate);
-                eval(sprintf('%s = thiswordisaparameter;',wordcandidate));
-            catch
-                % I assume that word is a reference to a function.
-            end
-        end
-    end
-    % Do the job. Evaluate the recursion.
-    eval(sprintf('for t=%s:%s, %s; end',num2str(t1),num2str(t2),EXPRESSION));
-else
-    % Transform EXPRESSION by replacing calls to the dseries objects by references to data.
-    for i=1:number_of_variables
-        EXPRESSION = regexprep(EXPRESSION,sprintf('%s\\(t\\)',leadlagtable{i,1}), ...
-                               sprintf('data(%s:%s,%s)',num2str(t1),num2str(t2),num2str(i)));
-        for j=1:length(leadlagtable{i,5})
-            lag = leadlagtable{i,5}(j);
-            EXPRESSION = regexprep(EXPRESSION,sprintf('%s\\(t-%s\\)',leadlagtable{i,1},num2str(lag)), ...
-                                   sprintf('data(%s:%s,%s)',num2str(t1-lag),num2str(t2-lag),num2str(i)));
-        end
-        for j=1:length(leadlagtable{i,6})
-            lead = leadlagtable{i,6}(j);
-            EXPRESSION = regexprep(EXPRESSION,sprintf('%s\\(t+%s\\)',leadlagtable{i,1},num2str(lead)), ...
-                                   sprintf('data(%s:%s,%s)',num2str(t1-lead),num2str(t2-lead),num2str(i)));
-        end
-    end
-    % Transform some operators (^ -> .^, / -> ./ and * -> .*)
-    EXPRESSION = strrep(EXPRESSION,'^','.^');
-    EXPRESSION = strrep(EXPRESSION,'*','.*');
-    EXPRESSION = strrep(EXPRESSION,'/','./');
-    % Get values for the parameters (if any)
-    if ~isempty(TMP314159)
-        for i=1:length(TMP314159)
-            wordcandidate = TMP314159{i};
-            try % If succesful, word is a reference to a variable in the caller function/script.
-                thiswordisaparameter = evalin('caller', wordcandidate);
-                eval(sprintf('%s = thiswordisaparameter;',wordcandidate));
-            catch
-                % I assume that word is a reference to a function.
-            end
-        end
-    end
-    % Do the job. Evaluate the static expression.
-    eval(sprintf('%s;',EXPRESSION));
-end
-
-% Put assigned variable back in the caller workspace...
-if isempty(strfind(assignedvariablename,'.'))
-    eval(sprintf('assignin(''caller'', ''%s'', dseries(data(:,indva),%s.init,%s.name,%s.tex));', ...
-                 assignedvariablename,assignedvariablename,assignedvariablename,assignedvariablename))
-else
-    DATA = num2cell(data(:,indva));
-    strdata = sprintf('%f ', DATA{:});
-    evalin('caller',sprintf('%s = dseries(transpose([%s]),%s.init,%s.name,%s.tex);', ...
-                            assignedvariablename,strdata,assignedvariablename,assignedvariablename,assignedvariablename))
-end
-
-function msg = get_error_message_0(msg)
-    if ~nargin
-        msg = sprintf('Wrong syntax! The correct syntax is:\n\n');
-    else
-        msg = [msg, sprintf('The correct syntax is:\n\n')];
-    end
-    msg = [msg, sprintf('    from d1 to d2 do SOMETHING\n\n')];
-    msg = [msg, sprintf('where d1<d2 are dates objects, and SOMETHING is a recursive expression involving dseries objects.')];
-
-
-function index = extractindex(str)
-    index = regexpi(str,'\(t\)|\(t\-\d\)|\(t\+\d\)','match');
-
-
-function i = index2num(id)
-    if isequal('(t)',id)
-        i = 0;
-        return
-    end
-    if isequal('-',id(3))
-        i = - str2num(id(4:end-1));
-    else
-        i = str2num(id(4:end-1));
-    end
-
-
-function id = num2index(i)
-    if isequal(i,0)
-        id = '(t)';
-        return
-    end
-    if i<0
-        id = ['(t-' int2str(abs(i)) ')'];
-    else
-        id = ['(t+' int2str(i) ')'];
-    end
-
-function i = isassignedvariable(var,expr)
-    idv = strfind(expr,var);
-    idq = strfind(expr,'=');
-    if ~isempty(idv)
-        if idv(1)<idq
-            i = 1;
-            return
-        end
-    end
-    i = 0;
-
-%@test:1
-%$ try
-%$     y = dseries(zeros(400,1),dates('1950Q1')) ;
-%$     v = dseries(randn(400,1),dates('1950Q1')) ;
-%$     u = dseries(randn(400,1),dates('1950Q1')) ;
-%$     from 1950Q2 to 2049Q4 do y(t) = (1+.01*u(t))*y(t-1) + v(t)
-%$     t(1) = 1;
-%$ catch
-%$     t(1) = 0;
-%$ end
-%$
-%$ T = all(t);
-%@eof:1
-
-%@test:2
-%$ try
-%$     y = dseries(zeros(400,1),dates('1950Q1')) ;
-%$     v = dseries(randn(400,1),dates('1950Q1')) ;
-%$     u = dseries(randn(400,1),dates('1950Q1')) ;
-%$     from 1950Q2 to 2049Q3 do y(t) = (1+.01*u(t))*y(t+1) + v(t)
-%$     t(1) = 0;
-%$ catch
-%$     t(1) = 1;
-%$ end
-%$
-%$ T = all(t);
-%@eof:2
-
-%@test:3
-%$ try
-%$     y = dseries(zeros(400,1),dates('1950Q1')) ;
-%$     v = dseries(randn(400,1),dates('1950Q1')) ;
-%$     u = dseries(randn(400,1),dates('1950Q1')) ;
-%$     from 1950Q2 to 2049Q4 do y(t) = v(t) -.5*v(t-1);
-%$     t(1) = 1;
-%$ catch
-%$     t(1) = 0;
-%$ end
-%$
-%$ T = all(t);
-%@eof:3
-
-%@test:4
-%$ try
-%$     y = dseries(zeros(400,1),dates('1950Q1')) ;
-%$     v = dseries(randn(400,1),dates('1950Q1')) ;
-%$     u = dseries(randn(400,1),dates('1950Q1')) ;
-%$     from 1950Q2 to 2049Q4 do y(t) = 2*((v(t) -.5*v(t-1))>0)-1;
-%$     t(1) = 1;
-%$ catch
-%$     t(1) = 0;
-%$ end
-%$
-%$ T = all(t);
-%@eof:4
-
-%@test:5
-%$ try
-%$     y = dseries(zeros(4000,1),dates('1950Q1')) ;
-%$     v = dseries(randn(4000,1),dates('1950Q1')) ;
-%$     u = dseries(randn(4000,1),dates('1950Q1')) ;
-%$     from 1950Q2 to 2949Q4 do y(t) = y(t-1)*(2*((v(t) -.5*v(t-1))>u(t))-1)+u(t); %plot(y)
-%$     t(1) = 1;
-%$ catch
-%$     t(1) = 0;
-%$ end
-%$
-%$ T = all(t);
-%@eof:5
diff --git a/matlab/utilities/dseries/isdseries.m b/matlab/utilities/dseries/isdseries.m
deleted file mode 100644
index 9d2c7d2497887f75a8b336f097fedc07a2791ce3..0000000000000000000000000000000000000000
--- a/matlab/utilities/dseries/isdseries.m
+++ /dev/null
@@ -1,20 +0,0 @@
-function B = isdseries(A)
-
-% Copyright (C) 2011-2013 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/>.
-
-B = isa(A,'dseries');
\ No newline at end of file
diff --git a/matlab/utilities/general/compare_vectors.m b/matlab/utilities/general/compare_vectors.m
index 07dca457279aead5d487e3f0c51594737c8f38f2..97e916c7573cee000345a042880d70d8d4acc71e 100644
--- a/matlab/utilities/general/compare_vectors.m
+++ b/matlab/utilities/general/compare_vectors.m
@@ -77,18 +77,18 @@ else
 end
 
 %@test:1
-%$ t(1) = dyn_assert(compare_vectors(@lt, [1990 3], [1991 3]), 1);
-%$ t(2) = dyn_assert(compare_vectors(@lt, [1990 3], [1990 3]), 0);
-%$ t(3) = dyn_assert(compare_vectors(@le, [1990 3], [1990 3]), 1);
-%$ t(4) = dyn_assert(compare_vectors(@lt, [1990 3], [1990 4]), 1);
-%$ t(5) = dyn_assert(compare_vectors(@le, [1990 3], [1990 4]), 1);
-%$ t(6) = dyn_assert(compare_vectors(@gt, [1990 3], [1991 3]), 0);
-%$ t(7) = dyn_assert(compare_vectors(@gt, [1990 3], [1990 3]), 0);
-%$ t(8) = dyn_assert(compare_vectors(@ge, [1990 3], [1990 3]), 1);
-%$ t(9) = dyn_assert(compare_vectors(@gt, [1990 3], [1990 4]), 0);
-%$ t(10) = dyn_assert(compare_vectors(@ge, [1990 3], [1990 4]), 0);
-%$ t(11) = dyn_assert(compare_vectors(@le, [1991 3], [1990 4]), 0);
-%$ t(12) = dyn_assert(compare_vectors(@le, [1991 3], [1990 2]), 0);
-%$ t(13) = dyn_assert(compare_vectors(@le, [1945 2], [1950, 1]),1);
+%$ t(1) = dassert(compare_vectors(@lt, [1990 3], [1991 3]), 1);
+%$ t(2) = dassert(compare_vectors(@lt, [1990 3], [1990 3]), 0);
+%$ t(3) = dassert(compare_vectors(@le, [1990 3], [1990 3]), 1);
+%$ t(4) = dassert(compare_vectors(@lt, [1990 3], [1990 4]), 1);
+%$ t(5) = dassert(compare_vectors(@le, [1990 3], [1990 4]), 1);
+%$ t(6) = dassert(compare_vectors(@gt, [1990 3], [1991 3]), 0);
+%$ t(7) = dassert(compare_vectors(@gt, [1990 3], [1990 3]), 0);
+%$ t(8) = dassert(compare_vectors(@ge, [1990 3], [1990 3]), 1);
+%$ t(9) = dassert(compare_vectors(@gt, [1990 3], [1990 4]), 0);
+%$ t(10) = dassert(compare_vectors(@ge, [1990 3], [1990 4]), 0);
+%$ t(11) = dassert(compare_vectors(@le, [1991 3], [1990 4]), 0);
+%$ t(12) = dassert(compare_vectors(@le, [1991 3], [1990 2]), 0);
+%$ t(13) = dassert(compare_vectors(@le, [1945 2], [1950, 1]),1);
 %$ T = all(t);
 %@eof:1
\ No newline at end of file
diff --git a/matlab/utilities/general/name2tex.m b/matlab/utilities/general/name2tex.m
index 0bf02a2cb91f8eb08c2a25886a8e4b504d075875..33c0513b41f2071963603282251a1d43b54fcbd6 100644
--- a/matlab/utilities/general/name2tex.m
+++ b/matlab/utilities/general/name2tex.m
@@ -96,22 +96,22 @@ end
 %$ t17 = name2tex('_azert_uiop_qsdfg',1);
 %$ t18 = name2tex('_azert_uiop_qsdfg_',1);
 %$
-%$ t(1) = dyn_assert(strcmp(t1,'\\_azert'),1);
-%$ t(2) = dyn_assert(strcmp(t2,'azert\\_'),1);
-%$ t(3) = dyn_assert(strcmp(t3,'\\_azert\\_'),1);
-%$ t(4) = dyn_assert(strcmp(t4,'azert\\_uiop'),1);
-%$ t(5) = dyn_assert(strcmp(t5,'azert\\_uiop\\_qsdfg'),1);
-%$ t(6) = dyn_assert(strcmp(t6,'azert\\_uiop\\_qsdfg\\_'),1);
-%$ t(7) = dyn_assert(strcmp(t7,'\\_azert\\_uiop\\_qsdfg'),1);
-%$ t(8) = dyn_assert(strcmp(t8,'\\_azert\\_uiop\\_qsdfg\\_'),1);
-%$ t(9) = dyn_assert(strcmp(t11,'\\_azert'),1);
-%$ t(10) = dyn_assert(strcmp(t12,'azert\\_'),1);
-%$ t(11) = dyn_assert(strcmp(t13,'\\_azert\\_'),1);
-%$ t(12) = dyn_assert(strcmp(t14,'azert_{uiop}'),1);
-%$ t(13) = dyn_assert(strcmp(t15,'azert\\_uiop_{qsdfg}'),1);
-%$ t(14) = dyn_assert(strcmp(t16,'azert\\_uiop_{qsdfg\\_}'),1);
-%$ t(15) = dyn_assert(strcmp(t17,'\\_azert\\_uiop_{qsdfg}'),1);
-%$ t(16) = dyn_assert(strcmp(t18,'\\_azert\\_uiop_{qsdfg\\_}'),1);
+%$ t(1) = dassert(strcmp(t1,'\\_azert'),true);
+%$ t(2) = dassert(strcmp(t2,'azert\\_'),true);
+%$ t(3) = dassert(strcmp(t3,'\\_azert\\_'),true);
+%$ t(4) = dassert(strcmp(t4,'azert\\_uiop'),true);
+%$ t(5) = dassert(strcmp(t5,'azert\\_uiop\\_qsdfg'),true);
+%$ t(6) = dassert(strcmp(t6,'azert\\_uiop\\_qsdfg\\_'),true);
+%$ t(7) = dassert(strcmp(t7,'\\_azert\\_uiop\\_qsdfg'),true);
+%$ t(8) = dassert(strcmp(t8,'\\_azert\\_uiop\\_qsdfg\\_'),true);
+%$ t(9) = dassert(strcmp(t11,'\\_azert'),true);
+%$ t(10) = dassert(strcmp(t12,'azert\\_'),true);
+%$ t(11) = dassert(strcmp(t13,'\\_azert\\_'),true);
+%$ t(12) = dassert(strcmp(t14,'azert_{uiop}'),true);
+%$ t(13) = dassert(strcmp(t15,'azert\\_uiop_{qsdfg}'),true);
+%$ t(14) = dassert(strcmp(t16,'azert\\_uiop_{qsdfg\\_}'),true);
+%$ t(15) = dassert(strcmp(t17,'\\_azert\\_uiop_{qsdfg}'),true);
+%$ t(16) = dassert(strcmp(t18,'\\_azert\\_uiop_{qsdfg\\_}'),true);
 %$
 %$ T = all(t);
 %@eof:1
@@ -135,22 +135,22 @@ end
 %$ t17 = name2tex({'_azert_uiop_qsdfg'},1);
 %$ t18 = name2tex({'_azert_uiop_qsdfg_'},1);
 %$
-%$ t(1) = dyn_assert(t1,{'\\_azert'});
-%$ t(2) = dyn_assert(t2,{'azert\\_'});
-%$ t(3) = dyn_assert(t3,{'\\_azert\\_'});
-%$ t(4) = dyn_assert(t4,{'azert\\_uiop'});
-%$ t(5) = dyn_assert(t5,{'azert\\_uiop\\_qsdfg'});
-%$ t(6) = dyn_assert(t6,{'azert\\_uiop\\_qsdfg\\_'});
-%$ t(7) = dyn_assert(t7,{'\\_azert\\_uiop\\_qsdfg'});
-%$ t(8) = dyn_assert(t8,{'\\_azert\\_uiop\\_qsdfg\\_'});
-%$ t(9) = dyn_assert(t11,{'\\_azert'});
-%$ t(10) = dyn_assert(t12,{'azert\\_'});
-%$ t(11) = dyn_assert(t13,{'\\_azert\\_'});
-%$ t(12) = dyn_assert(t14,{'azert_{uiop}'});
-%$ t(13) = dyn_assert(t15,{'azert\\_uiop_{qsdfg}'});
-%$ t(14) = dyn_assert(t16,{'azert\\_uiop_{qsdfg\\_}'});
-%$ t(15) = dyn_assert(t17,{'\\_azert\\_uiop_{qsdfg}'});
-%$ t(16) = dyn_assert(t18,{'\\_azert\\_uiop_{qsdfg\\_}'});
+%$ t(1) = dassert(t1,{'\\_azert'});
+%$ t(2) = dassert(t2,{'azert\\_'});
+%$ t(3) = dassert(t3,{'\\_azert\\_'});
+%$ t(4) = dassert(t4,{'azert\\_uiop'});
+%$ t(5) = dassert(t5,{'azert\\_uiop\\_qsdfg'});
+%$ t(6) = dassert(t6,{'azert\\_uiop\\_qsdfg\\_'});
+%$ t(7) = dassert(t7,{'\\_azert\\_uiop\\_qsdfg'});
+%$ t(8) = dassert(t8,{'\\_azert\\_uiop\\_qsdfg\\_'});
+%$ t(9) = dassert(t11,{'\\_azert'});
+%$ t(10) = dassert(t12,{'azert\\_'});
+%$ t(11) = dassert(t13,{'\\_azert\\_'});
+%$ t(12) = dassert(t14,{'azert_{uiop}'});
+%$ t(13) = dassert(t15,{'azert\\_uiop_{qsdfg}'});
+%$ t(14) = dassert(t16,{'azert\\_uiop_{qsdfg\\_}'});
+%$ t(15) = dassert(t17,{'\\_azert\\_uiop_{qsdfg}'});
+%$ t(16) = dassert(t18,{'\\_azert\\_uiop_{qsdfg\\_}'});
 %$
 %$ T = all(t);
 %@eof:2
@@ -174,11 +174,11 @@ end
 %$ end
 %$
 %$ if t(1)
-%$     t(3) = dyn_assert(t1,{'\\_azert';'azert\\_';'\\_azert\\_';'azert\\_uiop';'azert\\_uiop\\_qsdfg';'azert\\_uiop\\_qsdfg\\_'});
+%$     t(3) = dassert(t1,{'\\_azert';'azert\\_';'\\_azert\\_';'azert\\_uiop';'azert\\_uiop\\_qsdfg';'azert\\_uiop\\_qsdfg\\_'});
 %$ end
 %$
 %$ if t(2)
-%$     t(4) = dyn_assert(t2,{'\\_azert';'azert\\_';'\\_azert\\_';'azert_{uiop}';'azert\\_uiop_{qsdfg}';'azert\\_uiop_{qsdfg\\_}'});
+%$     t(4) = dassert(t2,{'\\_azert';'azert\\_';'\\_azert\\_';'azert_{uiop}';'azert\\_uiop_{qsdfg}';'azert\\_uiop_{qsdfg\\_}'});
 %$ end
 %$
 %$ T = all(t);
diff --git a/matlab/utilities/tests b/matlab/utilities/tests
new file mode 160000
index 0000000000000000000000000000000000000000..4eba56c2fa3daa05e67349fb41c60a7e1101ca00
--- /dev/null
+++ b/matlab/utilities/tests
@@ -0,0 +1 @@
+Subproject commit 4eba56c2fa3daa05e67349fb41c60a7e1101ca00
diff --git a/matlab/utilities/tests/build_report_summary.m b/matlab/utilities/tests/build_report_summary.m
deleted file mode 100644
index b4a1dcd20ba344b455fc44f1e886cd9ac2bf3c83..0000000000000000000000000000000000000000
--- a/matlab/utilities/tests/build_report_summary.m
+++ /dev/null
@@ -1,101 +0,0 @@
-function str = build_report_summary(reportfile, printonscreen, mailreport)
-
-% Copyright (C) 2013 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 isequal(nargin,1)
-    printonscreen = 1;
-    mailreport = 0;
-end
-
-if nargin<3
-    mailreport = 0;
-else
-    if ischar(mailreport)
-        mailto = mailreport;
-        mailreport = 1;
-        fid = fopen('~/.matlab-send-report');
-        server = fgetl(fid);
-        fclose(fid);
-        fprintf('\n\n');
-        disp('Send report...')
-        system(['scp ' reportfile ' ' server]);
-        system(['scp ' reportfile(1:end-3) 'log ' server]);
-    else
-        if ~isequal(mailreport,0)
-            error('build_report_summary:: Third argument must be an adress email!')
-        end
-    end
-end
-
-reportfilecontent = load(reportfile);
-reportcell = reportfilecontent.report;
-gitinfo = reportfilecontent.gitinfo;
-gitlastcommithash = reportfilecontent.gitlastcommithash;
-
-str = 'Hi,';
-str = char(str,'');
-str = char(str,'This is a summary report for the unitary tests in Dynare. Full report can be found at:');
-str = char(str,'');
-str = char(str,'');
-str = char(str,['http://www.dynare.org/stepan/dynare/tests/' reportfile]);
-str = char(str,'');
-str = char(str,['http://www.dynare.org/stepan/dynare/tests/' reportfile(1:end-3) 'log']);
-str = char(str,'');
-str = char(str,gitinfo(1,:));
-str = char(str,gitinfo(2,:));
-str = char(str,'');
-str = char(str,'');
-str = char(str,['===========================']);
-str = char(str,'DYNARE/MATLAB UNITARY TESTS');
-str = char(str,'===========================');
-str = char(str,['| TOTAL: ' int2str(size(reportcell,1))]);
-str = char(str,['|  PASS: ' int2str(length(find(cell2mat(reportcell(:,3)))))]);
-str = char(str,['|  FAIL: ' int2str(length(find(~cell2mat(reportcell(:,3)))))]);
-str = char(str,'|');
-str = char(str,'| LIST OF FAILED TESTS:');
-for i=1:size(reportcell,1)
-    if ~reportcell{i,3}
-        str = char(str,['|    * ' reportcell{i,1} ' (test #'  int2str(reportcell{i,2}) '{' strrep(int2str(transpose(find(~reportcell{i,4}))),' ',',') '})']);
-    end
-end
-
-if printonscreen
-    skipline(2);
-    disp(str)
-    skipline(2);
-end
-
-if mailreport
-    if exist('~/.matlab-send-mail-info','file')
-        fid = fopen('~/.matlab-send-mail-info','r');
-    else
-       disp(['build_report_summary:: I Cannot send the report to ' mailto ' because the sender and the smtp server are not defined!'])
-       disp(['                       You probably need to add a ''.matlab-send-mail-info'' in your root directory...'])
-       return
-    end
-    setpref('Internet','SMTP_Server',fgetl(fid));
-    setpref('Internet','SMTP_Username',fgetl(fid));
-    setpref('Internet','E_mail',fgetl(fid));
-    setpref('Internet','SMTP_Passeword',fgetl(fid));
-    fclose(fid);
-    STR = [deblank(str(1,:))];
-    for i=2:size(str,1)
-        STR = [STR 10 deblank(str(i,:)) ];
-    end
-    sendmail(mailto,'Dynare/Matlab unitary tests',STR); 
-end
\ No newline at end of file
diff --git a/matlab/utilities/tests/dynTest.m b/matlab/utilities/tests/dynTest.m
deleted file mode 100644
index 8dd2fc01702e49e273092db3c782a11ea988f198..0000000000000000000000000000000000000000
--- a/matlab/utilities/tests/dynTest.m
+++ /dev/null
@@ -1,84 +0,0 @@
-function dynTest(fun,dynare_path)
-
-%@info:
-%! @deftypefn {Function File} dynTest (@var{fun})
-%! @anchor{dynTest}
-%! @sp 1
-%! Tests matlab/octave routine @var{fun}.m.
-%! @sp 2
-%!
-%! @strong{Inputs}
-%! @sp 1
-%! @table @ @var
-%! @item fun
-%! string, name of the matlab/octave routine to be tested.
-%! @end table
-%! @sp 2
-%!
-%! @strong{Outputs}
-%! @sp 1
-%! None
-%! @sp 2
-%!
-%! @strong{This function is called by:}
-%! @sp 1
-%! @ref{internals}, @ref{mroutines}
-%! @sp 2
-%!
-%! @strong{This function calls:}
-%! @sp 1
-%! @ref{mtest}
-%!
-%! @end deftypefn
-%@eod:
-
-% Copyright (C) 2011-2012 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/>.
-
-% Original author: stephane DOT adjemian AT univ DASH lemans DOT fr
-
-original_directory = pwd();
-
-[pathstr1, name1, ext1] = fileparts(fun);
-
-pathstr1 = [original_directory filesep pathstr1];
-
-cd([dynare_path filesep '..' filesep 'tests']);
-
-mex_flag = 0;
-if exist(name1)==3
-    mex_flag = 1;
-end
-
-class_flag = 0;
-if ~isempty(strfind(fun,'@')) || ~isempty(strfind(which(name1),'@'))
-    class_flag = 1;
-end
-
-check = mtest(name1,pathstr1);
-
-if check
-    if mex_flag
-        disp(['Succesfull test(s) for ' name1 ' mex file!'])
-    elseif class_flag
-        disp(['Succesfull test(s) for ' name1 ' method!'])
-    else
-        disp(['Succesfull test(s) for ' name1 ' routine!'])
-    end
-end
-
-cd(original_directory);
\ No newline at end of file
diff --git a/matlab/utilities/tests/dyn_assert.m b/matlab/utilities/tests/dyn_assert.m
deleted file mode 100644
index 5311631396f3bc054fd0945fa68000e4cbb7f734..0000000000000000000000000000000000000000
--- a/matlab/utilities/tests/dyn_assert.m
+++ /dev/null
@@ -1,63 +0,0 @@
-function t = dyn_assert(A,B,tol)
-% This function tests the equality of two objects.
-
-% Copyright (C) 2011-2012 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/>.
-
-% Original author: stephane DOT adjemian AT univ DASH lemans DOT fr
-
-if ( (nargin<3) || isempty(tol) )
-    use_isequal_matlab_builtin = 1;
-else
-    use_isequal_matlab_builtin = 0;
-end
-
-[nA,mA] = size(A);
-[nB,mB] = size(B);
-
-if nA-nB
-    error('assert:: Dimensions of compared objects A and B don''t match!')
-end
-
-if mA-mB
-    error('assert:: Dimensions of compared objects A and B don''t match!')
-end
-
-if isstruct(B) && ~isstruct(A)
-    error('assert:: Compared objects are not of the same type!')
-end
-
-if iscell(B) && ~iscell(A)
-    error('assert:: Compared objects are not of the same type!')
-end
-
-if use_isequal_matlab_builtin
-    t = isequal(A,B);
-    if ~t
-        t = isequalwithequalnans(A,B);
-    end
-else
-    t = 1;
-    if ~(isstruct(B) || iscell(B))
-        if max(abs(A(:)-B(:)))>tol
-            t = 0;
-        end
-    else
-        % not yet implemented
-        t = NaN;
-    end
-end
\ No newline at end of file
diff --git a/matlab/utilities/tests/get_directory_description.m b/matlab/utilities/tests/get_directory_description.m
deleted file mode 100644
index 3be45da11da0847da76fa9406d97c1b4d1027111..0000000000000000000000000000000000000000
--- a/matlab/utilities/tests/get_directory_description.m
+++ /dev/null
@@ -1,34 +0,0 @@
-function flist = get_directory_description(basedir)
-
-% Copyright (C) 2013 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/>.
-
-dd = dir(basedir);
-flist = {};
-file = 1;
-
-for f=1:length(dd)
-    if ~(isequal(dd(f).name,'.') || isequal(dd(f).name,'..'))
-        if dd(f).isdir
-            r = get_directory_description([ basedir filesep dd(f).name]);
-            flist = { flist{:} r{:} };
-        else
-            flist{length(flist)+1} = [basedir filesep dd(f).name];
-        end
-        file = file + 1; 
-    end
-end
diff --git a/matlab/utilities/tests/is_unitary_test_available.m b/matlab/utilities/tests/is_unitary_test_available.m
deleted file mode 100644
index 80a3bc240c6df90ab2116a296698c90fdbd0273b..0000000000000000000000000000000000000000
--- a/matlab/utilities/tests/is_unitary_test_available.m
+++ /dev/null
@@ -1,51 +0,0 @@
-function info = is_unitary_test_available(fun)
-
-%@info:
-%! @deftypefn {Function File} {@var{info} =} is_unitary_test_available (@var{fun})
-%! @anchor{is_unitary_test_available}
-%! @sp 1
-%! Tests if matlab/octave routine @var{fun} has unitary tests.
-%! @sp 2
-%! @strong{Inputs}
-%! @sp 1
-%! @table @ @var
-%! @item fun
-%! string, name of the matlab/octave routine to be tested.
-%! @end table
-%! @sp 2
-%! @strong{Outputs}
-%! @sp 1
-%! @table @ @var
-%! @item info
-%! Integer scalar equal to one if unitary tests are available, zero otherwise.
-%! @end table
-%! @sp 2
-%! @end deftypefn
-%@eod:
-
-% Copyright (C) 2013 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/>.
-    
-info = 0;
-
-fid = fopen(fun,'r');
-first_line = fgetl(fid);
-fclose(fid);
-
-if strfind(first_line,'% --*-- Unitary tests --*--')
-    info = 1;
-end
\ No newline at end of file
diff --git a/matlab/utilities/tests/mtest.m b/matlab/utilities/tests/mtest.m
deleted file mode 100644
index 29f771613b48c54517f08868e8338309aca8f37f..0000000000000000000000000000000000000000
--- a/matlab/utilities/tests/mtest.m
+++ /dev/null
@@ -1,137 +0,0 @@
-function [check, info] = mtest(fname, fpath)
-% Extract test sections from matlab's routine executes the test and report errors.
-
-% Copyright (C) 2011-2013 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/>.
-
-% Original author: stephane DOT adjemian AT univ DASH lemans DOT fr
-
-% Default answer (no problem).
-check = 1;
-
-% Open the matlab file.
-if nargin<2 || isempty(fpath)
-    if nargout<2
-        error('mtest:: Wrong calling sequence!')
-    end
-    % The full path to the matlab routine (with extension) is given.
-    fid = fopen(fname,'r');
-    [junk, FNAME, vessel] = fileparts(fname);
-else
-    fid = fopen([fpath '/' fname '.m'],'r');
-    FNAME = fname;
-end
-
-% Read the matlab file.
-file = textscan(fid,'%s','delimiter','\n');
-file = file{1};
-
-% Close the matlab file.
-fclose(fid);
-
-% Locate the test blocks.
-b1 = find(strncmp(file,'%@test:',7))+1;
-b2 = find(strncmp(file,'%@eof:',6))-1;
-nn = length(b2);
-
-if length(b1)-length(b2)
-    error('test:: There is a problem with the test blocks definition!')
-end
-
-% Initialize the second output if necessary.
-if nargout>1
-    % First column   name of the tested routine.
-    % Second column  number of the unitary test.
-    % Third column   status of the unitary test (0 if the test fails, 1 otherwise)
-    % Fourth column  details about the failure (vector of integers)
-    % Fifth column   elapsed time in seconds (cpu time).
-    info = cell(nn,5);
-end
-
-% Perform the tests.
-for i=1:nn
-    if nargout>1
-        info(i,1) = {fname};
-        info(i,2) = {i};
-    end
-    % Write the temporary test routine.
-    tid = fopen([FNAME '_test_' int2str(i) '.m'],'w');
-    fprintf(tid,['function [T,t,LOG] = ' FNAME '_test_' int2str(i) '()\n']);
-    fprintf(tid,['try\n']);
-    for j=b1(i):b2(i)
-        str = sprintf('%s \n',file{j}(4:end));
-        str = regexprep(str, '%', '%%');
-        fprintf(tid,str);
-    end
-    fprintf(tid,['LOG = NaN;\n']);
-    if isoctave
-        fprintf(tid,'catch\n');
-        fprintf(tid,'exception = lasterror;\n');
-        fprintf(tid, 'LOG = ''%s'';\n','The Log output is not available with Octave!');
-    else
-        fprintf(tid,'catch exception\n');
-        fprintf(tid,['LOG = getReport(exception,''extended'');\n']);
-    end
-    fprintf(tid,['T = NaN;\n']);
-    fprintf(tid,['t = NaN;\n']);
-    fprintf(tid,['end\n']);
-    fclose(tid);
-    % Call the temporary test routine.
-    init = cputime;
-    [TestFlag,TestDetails,LOG] = feval([FNAME '_test_' int2str(i)]);
-    time = cputime-init;
-    if isnan(TestFlag)
-        fprintf(['\n'])
-        fprintf(['Call to ' FNAME ' test routine n°' int2str(i) ' failed (' datestr(now) ')!\n'])
-        fprintf(['\n'])
-        if ~isoctave
-            disp(LOG)
-        end
-        check = 0;
-        if nargout>1
-            info(i,3) = {0};
-        end
-        continue
-    end
-    if ~TestFlag
-        if nargout>1
-            info(i,3) = {0};
-            tmp = ones(length(TestDetails),1);
-        end
-        fprintf(['Test n°' int2str(i) ' for routine ' FNAME ' failed (' datestr(now) ')!\n']);
-        for j=1:length(TestDetails)
-            if ~TestDetails(j)
-                if nargout>1
-                    tmp(j) = 0;
-                end
-                fprintf(['Output argument n°' int2str(j) ' didn''t give the expected result.\n']);
-            end
-        end
-        if nargout>1
-            info(i,4) = {tmp};
-            info(i,5) = {NaN};
-        end
-        check = 0;
-    else
-        if nargout>1
-            info(i,3) = {1};
-            info(i,4) = {ones(length(TestDetails),1)};
-            info(i,5) = {time};
-        end
-        delete([FNAME '_test_' int2str(i) '.m'])
-    end
-end
\ No newline at end of file
diff --git a/matlab/utilities/tests/run_unitary_tests.m b/matlab/utilities/tests/run_unitary_tests.m
deleted file mode 100644
index b20d6c959b4a89c0631de4d2c5c89b33a50c49d3..0000000000000000000000000000000000000000
--- a/matlab/utilities/tests/run_unitary_tests.m
+++ /dev/null
@@ -1,36 +0,0 @@
-function [report, time] = run_unitary_tests(listoffiles)
-    
-% Copyright (C) 2013 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/>.
-
-report = {};
-    
-for f=1:length(listoffiles)
-    if isequal(listoffiles{f}(end-1:end),'.m') && isempty(strfind(listoffiles{f},'.#'))
-        if is_unitary_test_available(listoffiles{f})
-            disp(['***** Process unitary tests in      ' listoffiles{f}])
-            [check, info] = mtest(listoffiles{f});
-            report = [report; info];
-        else
-            disp(['Booh! No unitary tests available in ' listoffiles{f}])
-        end
-    end
-end
-
-if nargout>1
-    time = clock;
-end
diff --git a/matlab/utilities/tests/run_unitary_tests_in_directory.m b/matlab/utilities/tests/run_unitary_tests_in_directory.m
deleted file mode 100644
index ef2499eb54277b75414861517b7d4b5a8c4beb62..0000000000000000000000000000000000000000
--- a/matlab/utilities/tests/run_unitary_tests_in_directory.m
+++ /dev/null
@@ -1,47 +0,0 @@
-function report = run_unitary_tests_in_directory(dirname,savereport,printreport,sendreport)
-
-% Copyright (C) 2013 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/>.
-
-system('git show --pretty=format:"Last commit %H by %an, %ar %n-> %s" HEAD > git.info');
-system('git rev-parse HEAD > git.last-commit-hash');
-
-fid = fopen('git.info');
-gitinfo = fgetl(fid);
-gitinfo = char(gitinfo,fgetl(fid));
-fclose(fid);
-
-fid = fopen('git.last-commit-hash');
-gitlastcommithash = fgetl(fid);
-fclose(fid);
-
-matlabverion = version;
-platform = computer;
-
-listoffiles = get_directory_description(dirname);
-
-diary(['report-' gitlastcommithash '.log'] )
-[report, time] = run_unitary_tests(listoffiles)
-diary off
-
-if nargin>1 && savereport>0
-    save(['report-' gitlastcommithash '.mat'],'report','time','gitinfo','gitlastcommithash','matlabverion','platform');
-end
-
-if nargin>2
-    build_report_summary(['report-' gitlastcommithash '.mat'], printreport, sendreport);
-end
\ No newline at end of file
diff --git a/osx/createOsxFolderForPkg.sh b/osx/createOsxFolderForPkg.sh
index c9bd8cde294b79f5b57ed45d1e838e4794f5e5f6..6841202652255f4cfcc93a5016c333e83dadd462 100755
--- a/osx/createOsxFolderForPkg.sh
+++ b/osx/createOsxFolderForPkg.sh
@@ -1,37 +1,34 @@
 #!/bin/bash
 set -ex
 
+VERSION=4.4.3
 TOP_DIR=/Users/Houtan/Documents/DYNARE/PACKAGES
-TOP_DYN_DIR=$TOP_DIR/dynare
+TOP_DYN_DIR=$TOP_DIR/dynare-$VERSION
 
-VERSION=4.3
 INSTALLDIRNAME=dynare-$VERSION-osx
-INSTALLDIR=$TOP_DIR/$INSTALLDIRNAME
+rm -rf $INSTALLDIRNAME
 mkdir $INSTALLDIRNAME
-
+INSTALLDIR=$TOP_DIR/$INSTALLDIRNAME
 
 ########################
 # UPDATE DYNARE SOURCE #
 ########################
 cd $TOP_DYN_DIR
-autoreconf -si
-
 
 ########################
 # BEGIN MAKING PACKAGE #
 ########################
 # create directories
 mkdir "$INSTALLDIR/scripts"
+mkdir "$INSTALLDIR/dynare++"
 mkdir -p "$INSTALLDIR/doc/dynare++"
 mkdir "$INSTALLDIR/doc/dynare.html"
-mkdir "$INSTALLDIR/dynare++"
 mkdir -p "$INSTALLDIR/contrib/ms-sbvar/TZcode"
 mkdir -p "$INSTALLDIR/mex/octave"
 mkdir -p "$INSTALLDIR/mex/matlab/osx64"
 mkdir "$INSTALLDIR/mex/matlab/osx32-7.4"
 mkdir "$INSTALLDIR/mex/matlab/osx32-7.5-7.11"
 
-
 # top level
 cp $TOP_DYN_DIR/scripts/dynare.el                                $INSTALLDIR/scripts
 cp $TOP_DYN_DIR/license.txt                                      $INSTALLDIR
@@ -43,17 +40,15 @@ cp -r $TOP_DYN_DIR/contrib/ms-sbvar/TZcode/MatlabFiles           $INSTALLDIR/con
 # examples
 cp -r $TOP_DYN_DIR/examples                                      $INSTALLDIR
 
-
 ##########################################################
 # FIRST BUILD 32 BIT EVERYTHING, 32 BIT MATLAB < 7.5 MEX #
 ##########################################################
-./configure FFLAGS='-isysroot /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.6.sdk -mmacosx-version-min=10.6 -arch i386' CPPFLAGS='-isysroot /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.6.sdk -mmacosx-version-min=10.6 -arch i386' LDFLAGS='-isysroot /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.6.sdk -mmacosx-version-min=10.6 -arch i386' --with-matlab=/Applications/MATLAB_OLD/R2007a MATLAB_VERSION=7.4 --with-slicot=/usr/local32 --disable-octave --with-matio=/usr/localStatic --with-gsl=/usr/localStatic
+./configure FFLAGS='-isysroot /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.6.sdk -mmacosx-version-min=10.6 -arch i386' CPPFLAGS='-isysroot /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.6.sdk -mmacosx-version-min=10.6 -arch i386' LDFLAGS='-isysroot /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.6.sdk -mmacosx-version-min=10.6 -arch i386' --disable-octave --with-matlab=/Applications/MATLAB_OLD/R2007a MATLAB_VERSION=7.4 --with-gsl=/usr/local32 --with-slicot=/usr/local32 --with-matio=/usr/local32
 cd $TOP_DYN_DIR/doc
 texi2dvi --pdf --batch --build-dir=dynare.t2p dynare.texi
 
 cd $TOP_DYN_DIR
 make pdf
-make html
 
 cd $TOP_DYN_DIR/preprocessor
 make
@@ -64,7 +59,6 @@ make
 cd $TOP_DYN_DIR/mex/build/matlab
 make
 
-
 # Matlab
 # Must come after configure because matlab/dynare_version.m is created by configure script
 cp -r $TOP_DYN_DIR/matlab                                        $INSTALLDIR
@@ -75,19 +69,8 @@ cp -r $TOP_DYN_DIR/matlab                                        $INSTALLDIR
 # compiled preprocessor
 cp $TOP_DYN_DIR/preprocessor/dynare_m                            $INSTALLDIR/matlab
 
-# Matlab
-cp $TOP_DYN_DIR/mex/build/matlab/block_kalman_filter/*.mexmaci                      $INSTALLDIR/mex/matlab/osx32-7.4
-cp $TOP_DYN_DIR/mex/build/matlab/bytecode/*.mexmaci                                 $INSTALLDIR/mex/matlab/osx32-7.4
-cp $TOP_DYN_DIR/mex/build/matlab/dynare_simul_/*.mexmaci                            $INSTALLDIR/mex/matlab/osx32-7.4
-cp $TOP_DYN_DIR/mex/build/matlab/estimation/*.mexmaci                               $INSTALLDIR/mex/matlab/osx32-7.4
-cp $TOP_DYN_DIR/mex/build/matlab/gensylv/*.mexmaci                                  $INSTALLDIR/mex/matlab/osx32-7.4
-cp $TOP_DYN_DIR/mex/build/matlab/k_order_perturbation/*.mexmaci                     $INSTALLDIR/mex/matlab/osx32-7.4
-cp $TOP_DYN_DIR/mex/build/matlab/kalman_steady_state/*.mexmaci                      $INSTALLDIR/mex/matlab/osx32-7.4
-cp $TOP_DYN_DIR/mex/build/matlab/kronecker/*.mexmaci                                $INSTALLDIR/mex/matlab/osx32-7.4
-cp $TOP_DYN_DIR/mex/build/matlab/local_state_space_iterations/*.mexmaci             $INSTALLDIR/mex/matlab/osx32-7.4
-cp $TOP_DYN_DIR/mex/build/matlab/mjdgges/*.mexmaci                                  $INSTALLDIR/mex/matlab/osx32-7.4
-cp $TOP_DYN_DIR/mex/build/matlab/ms_sbvar/*.mexmaci                                 $INSTALLDIR/mex/matlab/osx32-7.4
-cp $TOP_DYN_DIR/mex/build/matlab/sobol/*.mexmaci                                    $INSTALLDIR/mex/matlab/osx32-7.4
+# Matlab Mex
+cp $TOP_DYN_DIR/mex/matlab/*                                     $INSTALLDIR/mex/matlab/osx32-7.4
 
 # dynare++
 cp $TOP_DYN_DIR/dynare++/src/dynare++                                               $INSTALLDIR/dynare++
@@ -116,77 +99,27 @@ cp $TOP_DYN_DIR/dynare++/kord/kord.pdf
 ##############################################
 # RETURN TO BUILD 32 BIT MATLAB 7.5 & UP MEX #
 ##############################################
-make clean
 cd $TOP_DYN_DIR/mex/build/matlab
-./configure FFLAGS='-isysroot /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.6.sdk -mmacosx-version-min=10.6 -arch i386' CPPFLAGS='-isysroot /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.6.sdk -mmacosx-version-min=10.6 -arch i386' LDFLAGS='-isysroot /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.6.sdk -mmacosx-version-min=10.6 -arch i386' --with-matlab=/Applications/MATLAB_OLD/MATLAB_R2009b_32bit/MATLAB_R2009b.app MATLAB_VERSION=7.9 MEXEXT='mexmaci' --with-slicot=/usr/local32 --with-matio=/usr/localStatic --with-gsl=/usr/localStatic
+make clean
+./configure FFLAGS='-isysroot /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.6.sdk -mmacosx-version-min=10.6 -arch i386' CPPFLAGS='-isysroot /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.6.sdk -mmacosx-version-min=10.6 -arch i386' LDFLAGS='-isysroot /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.6.sdk -mmacosx-version-min=10.6 -arch i386' --with-matlab=/Applications/MATLAB_OLD/MATLAB_R2009b_32bit/MATLAB_R2009b.app MATLAB_VERSION=7.9 MEXEXT='mexmaci' --with-slicot=/usr/local32 --with-matio=/usr/local32 --with-gsl=/usr/local32
 make
 
-# Matlab
-cp $TOP_DYN_DIR/mex/build/matlab/block_kalman_filter/*.mexmaci                      $INSTALLDIR/mex/matlab/osx32-7.5-7.11
-cp $TOP_DYN_DIR/mex/build/matlab/bytecode/*.mexmaci                                 $INSTALLDIR/mex/matlab/osx32-7.5-7.11
-cp $TOP_DYN_DIR/mex/build/matlab/dynare_simul_/*.mexmaci                            $INSTALLDIR/mex/matlab/osx32-7.5-7.11
-cp $TOP_DYN_DIR/mex/build/matlab/estimation/*.mexmaci                               $INSTALLDIR/mex/matlab/osx32-7.5-7.11
-cp $TOP_DYN_DIR/mex/build/matlab/gensylv/*.mexmaci                                  $INSTALLDIR/mex/matlab/osx32-7.5-7.11
-cp $TOP_DYN_DIR/mex/build/matlab/k_order_perturbation/*.mexmaci                     $INSTALLDIR/mex/matlab/osx32-7.5-7.11
-cp $TOP_DYN_DIR/mex/build/matlab/kalman_steady_state/*.mexmaci                      $INSTALLDIR/mex/matlab/osx32-7.5-7.11
-cp $TOP_DYN_DIR/mex/build/matlab/kronecker/*.mexmaci                                $INSTALLDIR/mex/matlab/osx32-7.5-7.11
-cp $TOP_DYN_DIR/mex/build/matlab/local_state_space_iterations/*.mexmaci             $INSTALLDIR/mex/matlab/osx32-7.5-7.11
-cp $TOP_DYN_DIR/mex/build/matlab/mjdgges/*.mexmaci                                  $INSTALLDIR/mex/matlab/osx32-7.5-7.11
-cp $TOP_DYN_DIR/mex/build/matlab/ms_sbvar/*.mexmaci                                 $INSTALLDIR/mex/matlab/osx32-7.5-7.11
-cp $TOP_DYN_DIR/mex/build/matlab/sobol/*.mexmaci                                    $INSTALLDIR/mex/matlab/osx32-7.5-7.11
-
+# Matlab Mex
+cp $TOP_DYN_DIR/mex/matlab/*                                                         $INSTALLDIR/mex/matlab/osx32-7.5-7.11
 
 #####################################
 # RETURN TO BUILD 64 BIT MATLAB MEX #
 #####################################
-make clean
 cd $TOP_DYN_DIR/mex/build/matlab
-./configure --with-matlab=/Applications/MATLAB_OLD/MATLAB_R2009b.app MATLAB_VERSION=7.9 MEXEXT=mexmaci64 --with-matio=/usr/localStatic --with-gsl=/usr/localStatic
-make
-
-# Matlab
-cp $TOP_DYN_DIR/mex/build/matlab/block_kalman_filter/*.mexmaci64                      $INSTALLDIR/mex/matlab/osx64
-cp $TOP_DYN_DIR/mex/build/matlab/bytecode/*.mexmaci64                                 $INSTALLDIR/mex/matlab/osx64
-cp $TOP_DYN_DIR/mex/build/matlab/dynare_simul_/*.mexmaci64                            $INSTALLDIR/mex/matlab/osx64
-cp $TOP_DYN_DIR/mex/build/matlab/estimation/*.mexmaci64                               $INSTALLDIR/mex/matlab/osx64
-cp $TOP_DYN_DIR/mex/build/matlab/gensylv/*.mexmaci64                                  $INSTALLDIR/mex/matlab/osx64
-cp $TOP_DYN_DIR/mex/build/matlab/k_order_perturbation/*.mexmaci64                     $INSTALLDIR/mex/matlab/osx64
-cp $TOP_DYN_DIR/mex/build/matlab/kalman_steady_state/*.mexmaci64                      $INSTALLDIR/mex/matlab/osx64
-cp $TOP_DYN_DIR/mex/build/matlab/kronecker/*.mexmaci64                                $INSTALLDIR/mex/matlab/osx64
-cp $TOP_DYN_DIR/mex/build/matlab/local_state_space_iterations/*.mexmaci64             $INSTALLDIR/mex/matlab/osx64
-cp $TOP_DYN_DIR/mex/build/matlab/mjdgges/*.mexmaci64                                  $INSTALLDIR/mex/matlab/osx64
-cp $TOP_DYN_DIR/mex/build/matlab/ms_sbvar/*.mexmaci64                                 $INSTALLDIR/mex/matlab/osx64
-cp $TOP_DYN_DIR/mex/build/matlab/sobol/*.mexmaci64                                    $INSTALLDIR/mex/matlab/osx64
-
-#####################################
-# RETURN TO BUILD 64 BIT OCTAVE MEX #
-#####################################
 make clean
-cd $TOP_DYN_DIR/mex/build/octave
-./configure CC="gcc" CXX="g++" --with-matio=/usr/localStatic --with-gsl=/usr/localStatic
+./configure --with-matlab=/Applications/MATLAB_OLD/MATLAB_R2009b.app MATLAB_VERSION=7.9 MEXEXT=mexmaci64 --with-matio=/usr/localStatic --with-gsl=/usr/localStatic
 make
 
-# Octave
-cp $TOP_DYN_DIR/mex/build/octave/block_kalman_filter/*.mex                          $INSTALLDIR/mex/octave
-cp $TOP_DYN_DIR/mex/build/octave/bytecode/*.mex                                     $INSTALLDIR/mex/octave
-cp $TOP_DYN_DIR/mex/build/octave/dynare_simul_/*.mex                                $INSTALLDIR/mex/octave
-cp $TOP_DYN_DIR/mex/build/octave/estimation/*.mex                                   $INSTALLDIR/mex/octave
-cp $TOP_DYN_DIR/mex/build/octave/gensylv/*.mex                                      $INSTALLDIR/mex/octave
-cp $TOP_DYN_DIR/mex/build/octave/k_order_perturbation/*.mex                         $INSTALLDIR/mex/octave
-cp $TOP_DYN_DIR/mex/build/octave/kalman_steady_state/*.mex                          $INSTALLDIR/mex/octave
-cp $TOP_DYN_DIR/mex/build/octave/kronecker/*.mex                                    $INSTALLDIR/mex/octave
-cp $TOP_DYN_DIR/mex/build/octave/linsolve/*.oct                                     $INSTALLDIR/mex/octave
-cp $TOP_DYN_DIR/mex/build/octave/local_state_space_iterations/*.mex                 $INSTALLDIR/mex/octave
-cp $TOP_DYN_DIR/mex/build/octave/mjdgges/*.mex                                      $INSTALLDIR/mex/octave
-cp $TOP_DYN_DIR/mex/build/octave/ms_sbvar/*.mex                                     $INSTALLDIR/mex/octave
-cp $TOP_DYN_DIR/mex/build/octave/ordschur/*.oct                                     $INSTALLDIR/mex/octave
-cp $TOP_DYN_DIR/mex/build/octave/qzcomplex/*.oct                                    $INSTALLDIR/mex/octave
-cp $TOP_DYN_DIR/mex/build/octave/sobol/*.mex                                        $INSTALLDIR/mex/octave
-
+# Matlab Mex
+cp $TOP_DYN_DIR/mex/matlab/*                                                           $INSTALLDIR/mex/matlab/osx64
 
 # clean everything
 cd $TOP_DYN_DIR
-make distclean
 
 # remove .DS_Store files
 cd $INSTALLDIR
@@ -196,3 +129,5 @@ find . -name *.DS_Store -type f -exec rm {} \;
 chmod -R g+w $INSTALLDIR
 
 echo DONE
+# NEED TO BUILD DYNARE.HTML DOCUMENTION ON DEBIAN
+# AND INCLUDE IN DISTRIBUTION BY HAND
diff --git a/others/cpp/tests/test1.cc b/others/cpp/tests/test1.cc
index 0e72ee74d043a2c7ac127e3f7228a7cfb6fba14c..9e2c1304d8d8770f6edf34a2ef6aacda15931026 100644
--- a/others/cpp/tests/test1.cc
+++ b/others/cpp/tests/test1.cc
@@ -32,20 +32,29 @@ main(int argc, char **argv)
   int nback = zeta_back.size();
   int nmixed = zeta_mixed.size();
   int nstatic = zeta_static.size();
+  int sdyn = nfwrd + nback + 2*nmixed;
 
-  int jacob_cols = zeta_back.size()+zeta_fwrd.size()+zeta_mixed.size()+exo_nbr;
+  int jacob_cols = sdyn + endo_nbr + exo_nbr;
 
   double *exo_steady_state = new double[exo_nbr];
   double *jacob_data = new double[endo_nbr*jacob_cols];
 
+  std::cout << endo_nbr << " " << jacob_cols << endl;
+
   FirstDerivatives(steady_state, exo_steady_state, 0, params, steady_state, 1, NULL, jacob_data, NULL, NULL);
 
+  std::cout << "g1[44] = " << jacob_data[44] << endl;
+
   DecisionRules dr(endo_nbr, exo_nbr, zeta_fwrd, zeta_back, zeta_mixed,
                    zeta_static, qz_criterium);
 
-  int sdyn = nfwrd + nback + 2*nmixed;
+  std::cout << "g1[44] = " << jacob_data[44] << endl;
+
   int jacobian_col_nbr = sdyn + endo_nbr + exo_nbr;
+  std::cout << "g1[44] = " << jacob_data[44] << endl;
   MatrixView jacob_tmp(jacob_data, endo_nbr, jacobian_col_nbr, endo_nbr);
+  std::cout << "g1[44] = " << jacob_data[44] << endl;
+  std::cout << "jacob_tmp(2,7) = "<< jacob_tmp(2,7) << endl;
 
   Matrix jacobian(endo_nbr, jacobian_col_nbr), g_y(endo_nbr, nback+nmixed), g_u(endo_nbr, exo_nbr);
   jacobian = jacob_tmp;
diff --git a/preprocessor/ComputingTasks.cc b/preprocessor/ComputingTasks.cc
index c23908a0d519eea2aecf9f6d09326eb62d529637..e22f157725a7e3c1a93a0c9d5cca4b36e0cec1f9 100644
--- a/preprocessor/ComputingTasks.cc
+++ b/preprocessor/ComputingTasks.cc
@@ -233,7 +233,9 @@ RamseyModelStatement::writeOutput(ostream &output, const string &basename) const
   // options_.ramsey_policy indicates that a Ramsey model is present in the *.mod file
   // this affects the computation of the steady state that uses a special algorithm
   // It should probably rather be a M_ field, but we leave it in options_ for historical reason
+
   output << "options_.ramsey_policy = 1;\n";
+  options_list.writeOutput(output);
 }
 
 RamseyPolicyStatement::RamseyPolicyStatement(const SymbolList &symbol_list_arg,
diff --git a/preprocessor/DataTree.cc b/preprocessor/DataTree.cc
index f95ab9ca2b8acb996c141b0282737650f8a15b98..3f90a44f87b3180c25abf406b55f59ccf278db17 100644
--- a/preprocessor/DataTree.cc
+++ b/preprocessor/DataTree.cc
@@ -168,7 +168,7 @@ DataTree::AddTimes(expr_t iArg1, expr_t iArg2)
 }
 
 expr_t
-DataTree::AddDivide(expr_t iArg1, expr_t iArg2)
+DataTree::AddDivide(expr_t iArg1, expr_t iArg2) throw (DivisionByZeroException)
 {
   if (iArg2 == One)
     return iArg1;
@@ -177,7 +177,7 @@ DataTree::AddDivide(expr_t iArg1, expr_t iArg2)
   if (iArg2 == Zero)
     {
       cerr << "ERROR: Division by zero!" << endl;
-      exit(EXIT_FAILURE);
+      throw DivisionByZeroException();
     }
 
   if (iArg1 == Zero)
diff --git a/preprocessor/DataTree.hh b/preprocessor/DataTree.hh
index 19712e9bfdad98b9f422cc115d5dc7ec12b4469a..d7c53645d5d74cc88833d042c45c3c8e98f917a6 100644
--- a/preprocessor/DataTree.hh
+++ b/preprocessor/DataTree.hh
@@ -117,6 +117,10 @@ public:
     }
   };
 
+  class DivisionByZeroException
+  {
+  };
+
   //! Adds a non-negative numerical constant (possibly Inf or NaN)
   expr_t AddNonNegativeConstant(const string &value);
   //! Adds a variable
@@ -131,7 +135,7 @@ public:
   //! Adds "arg1*arg2" to model tree
   expr_t AddTimes(expr_t iArg1, expr_t iArg2);
   //! Adds "arg1/arg2" to model tree
-  expr_t AddDivide(expr_t iArg1, expr_t iArg2);
+  expr_t AddDivide(expr_t iArg1, expr_t iArg2) throw (DivisionByZeroException);
   //! Adds "arg1<arg2" to model tree
   expr_t AddLess(expr_t iArg1, expr_t iArg2);
   //! Adds "arg1>arg2" to model tree
diff --git a/preprocessor/DynamicModel.cc b/preprocessor/DynamicModel.cc
index ca2051329bebde550ebc46e832fac0301ae5cbbb..0043b76d77f098205ea3401e19ff810c336f7252 100644
--- a/preprocessor/DynamicModel.cc
+++ b/preprocessor/DynamicModel.cc
@@ -1523,7 +1523,8 @@ DynamicModel::writeDynamicMFile(const string &dynamic_basename) const
                     << "%" << endl
                     << "% Outputs:" << endl
                     << "%   residual  [M_.endo_nbr by 1] double    vector of residuals of the dynamic model equations in order of " << endl
-                    << "%                                          declaration of the equations" << endl
+                    << "%                                          declaration of the equations." << endl
+					<< "%                                          Dynare may prepend auxiliary equations, see M_.aux_vars" << endl
                     << "%   g1        [M_.endo_nbr by #dynamic variables] double    Jacobian matrix of the dynamic model equations;" << endl
                     << "%                                                           rows: equations in order of declaration" << endl
                     << "%                                                           columns: variables in order stored in M_.lead_lag_incidence" << endl
@@ -1746,7 +1747,6 @@ DynamicModel::writeSparseDynamicMFile(const string &dynamic_basename, const stri
   string sp;
   ofstream mDynamicModelFile;
   ostringstream tmp, tmp1, tmp_eq;
-  int prev_Simulation_Type;
   bool OK;
   chdir(basename.c_str());
   string filename = dynamic_basename + ".m";
@@ -1764,7 +1764,7 @@ DynamicModel::writeSparseDynamicMFile(const string &dynamic_basename, const stri
   mDynamicModelFile << "%/\n";
 
   int Nb_SGE = 0;
-  bool skip_head, open_par = false;
+  bool open_par = false;
 
   mDynamicModelFile << "function [varargout] = " << dynamic_basename << "(varargin)\n";
   mDynamicModelFile << "  global oo_ options_ M_ ;\n";
@@ -1810,7 +1810,6 @@ DynamicModel::writeSparseDynamicMFile(const string &dynamic_basename, const stri
                     << "    Per_u_=0;" << endl
                     << "    Per_y_=it_*y_size;" << endl
                     << "    ys=y(it_,:);" << endl;
-  prev_Simulation_Type = -1;
   tmp.str("");
   tmp_eq.str("");
   unsigned int nb_blocks = getNbBlocks();
@@ -1901,7 +1900,6 @@ DynamicModel::writeSparseDynamicMFile(const string &dynamic_basename, const stri
                     << "  y=oo_.endo_simul';" << endl
                     << "  x=oo_.exo_simul;" << endl;
 
-  prev_Simulation_Type = -1;
   mDynamicModelFile << "  params=M_.params;\n";
   mDynamicModelFile << "  steady_state=oo_.steady_state;\n";
   mDynamicModelFile << "  oo_.deterministic_simulation.status = 0;\n";
@@ -1912,66 +1910,55 @@ DynamicModel::writeSparseDynamicMFile(const string &dynamic_basename, const stri
       unsigned int block_recursive = block_size - block_mfs;
       BlockSimulationType simulation_type = getBlockSimulationType(block);
 
-      if (BlockSim(prev_Simulation_Type) == BlockSim(simulation_type)
-          && (simulation_type == EVALUATE_FORWARD || simulation_type == EVALUATE_BACKWARD))
-        skip_head = true;
-      else
-        skip_head = false;
       if ((simulation_type == EVALUATE_FORWARD) && (block_size))
         {
-          if (!skip_head)
+          if (open_par)
             {
-              if (open_par)
-                {
-                  mDynamicModelFile << "  end\n";
-                }
-              mDynamicModelFile << "  oo_.deterministic_simulation.status = 1;\n";
-              mDynamicModelFile << "  oo_.deterministic_simulation.error = 0;\n";
-              mDynamicModelFile << "  oo_.deterministic_simulation.iterations = 0;\n";
-              mDynamicModelFile << "  if(isfield(oo_.deterministic_simulation,'block'))\n";
-              mDynamicModelFile << "    blck_num = length(oo_.deterministic_simulation.block)+1;\n";
-              mDynamicModelFile << "  else\n";
-              mDynamicModelFile << "    blck_num = 1;\n";
-              mDynamicModelFile << "  end;\n";
-              mDynamicModelFile << "  oo_.deterministic_simulation.block(blck_num).status = 1;\n";
-              mDynamicModelFile << "  oo_.deterministic_simulation.block(blck_num).error = 0;\n";
-              mDynamicModelFile << "  oo_.deterministic_simulation.block(blck_num).iterations = 0;\n";
-              mDynamicModelFile << "  g1=[];g2=[];g3=[];\n";
-              mDynamicModelFile << "  y=" << dynamic_basename << "_" << block + 1 << "(y, x, params, steady_state, 0, y_kmin, periods);\n";
-              mDynamicModelFile << "  tmp = y(:,M_.block_structure.block(" << block + 1 << ").variable);\n";
-              mDynamicModelFile << "  if any(isnan(tmp) | isinf(tmp))\n";
-              mDynamicModelFile << "    disp(['Inf or Nan value during the evaluation of block " << block <<"']);\n";
-              mDynamicModelFile << "    return;\n";
-              mDynamicModelFile << "  end;\n";
+              mDynamicModelFile << "  end\n";
             }
+          mDynamicModelFile << "  oo_.deterministic_simulation.status = 1;\n";
+          mDynamicModelFile << "  oo_.deterministic_simulation.error = 0;\n";
+          mDynamicModelFile << "  oo_.deterministic_simulation.iterations = 0;\n";
+          mDynamicModelFile << "  if(isfield(oo_.deterministic_simulation,'block'))\n";
+          mDynamicModelFile << "    blck_num = length(oo_.deterministic_simulation.block)+1;\n";
+          mDynamicModelFile << "  else\n";
+          mDynamicModelFile << "    blck_num = 1;\n";
+          mDynamicModelFile << "  end;\n";
+          mDynamicModelFile << "  oo_.deterministic_simulation.block(blck_num).status = 1;\n";
+          mDynamicModelFile << "  oo_.deterministic_simulation.block(blck_num).error = 0;\n";
+          mDynamicModelFile << "  oo_.deterministic_simulation.block(blck_num).iterations = 0;\n";
+          mDynamicModelFile << "  g1=[];g2=[];g3=[];\n";
+          mDynamicModelFile << "  y=" << dynamic_basename << "_" << block + 1 << "(y, x, params, steady_state, 0, y_kmin, periods);\n";
+          mDynamicModelFile << "  tmp = y(:,M_.block_structure.block(" << block + 1 << ").variable);\n";
+          mDynamicModelFile << "  if any(isnan(tmp) | isinf(tmp))\n";
+          mDynamicModelFile << "    disp(['Inf or Nan value during the evaluation of block " << block <<"']);\n";
+          mDynamicModelFile << "    return;\n";
+          mDynamicModelFile << "  end;\n";
         }
       else if ((simulation_type == EVALUATE_BACKWARD) && (block_size))
         {
-          if (!skip_head)
+          if (open_par)
             {
-              if (open_par)
-                {
-                  mDynamicModelFile << "  end\n";
-                }
-              mDynamicModelFile << "  oo_.deterministic_simulation.status = 1;\n";
-              mDynamicModelFile << "  oo_.deterministic_simulation.error = 0;\n";
-              mDynamicModelFile << "  oo_.deterministic_simulation.iterations = 0;\n";
-              mDynamicModelFile << "  if(isfield(oo_.deterministic_simulation,'block'))\n";
-              mDynamicModelFile << "    blck_num = length(oo_.deterministic_simulation.block)+1;\n";
-              mDynamicModelFile << "  else\n";
-              mDynamicModelFile << "    blck_num = 1;\n";
-              mDynamicModelFile << "  end;\n";
-              mDynamicModelFile << "  oo_.deterministic_simulation.block(blck_num).status = 1;\n";
-              mDynamicModelFile << "  oo_.deterministic_simulation.block(blck_num).error = 0;\n";
-              mDynamicModelFile << "  oo_.deterministic_simulation.block(blck_num).iterations = 0;\n";
-              mDynamicModelFile << "  g1=[];g2=[];g3=[];\n";
-              mDynamicModelFile << "  " << dynamic_basename << "_" << block + 1 << "(y, x, params, steady_state, 0, y_kmin, periods);\n";
-              mDynamicModelFile << "  tmp = y(:,M_.block_structure.block(" << block + 1 << ").variable);\n";
-              mDynamicModelFile << "  if any(isnan(tmp) | isinf(tmp))\n";
-              mDynamicModelFile << "    disp(['Inf or Nan value during the evaluation of block " << block <<"']);\n";
-              mDynamicModelFile << "    return;\n";
-              mDynamicModelFile << "  end;\n";
+              mDynamicModelFile << "  end\n";
             }
+          mDynamicModelFile << "  oo_.deterministic_simulation.status = 1;\n";
+          mDynamicModelFile << "  oo_.deterministic_simulation.error = 0;\n";
+          mDynamicModelFile << "  oo_.deterministic_simulation.iterations = 0;\n";
+          mDynamicModelFile << "  if(isfield(oo_.deterministic_simulation,'block'))\n";
+          mDynamicModelFile << "    blck_num = length(oo_.deterministic_simulation.block)+1;\n";
+          mDynamicModelFile << "  else\n";
+          mDynamicModelFile << "    blck_num = 1;\n";
+          mDynamicModelFile << "  end;\n";
+          mDynamicModelFile << "  oo_.deterministic_simulation.block(blck_num).status = 1;\n";
+          mDynamicModelFile << "  oo_.deterministic_simulation.block(blck_num).error = 0;\n";
+          mDynamicModelFile << "  oo_.deterministic_simulation.block(blck_num).iterations = 0;\n";
+          mDynamicModelFile << "  g1=[];g2=[];g3=[];\n";
+          mDynamicModelFile << "  " << dynamic_basename << "_" << block + 1 << "(y, x, params, steady_state, 0, y_kmin, periods);\n";
+          mDynamicModelFile << "  tmp = y(:,M_.block_structure.block(" << block + 1 << ").variable);\n";
+          mDynamicModelFile << "  if any(isnan(tmp) | isinf(tmp))\n";
+          mDynamicModelFile << "    disp(['Inf or Nan value during the evaluation of block " << block <<"']);\n";
+          mDynamicModelFile << "    return;\n";
+          mDynamicModelFile << "  end;\n";
         }
       else if ((simulation_type == SOLVE_FORWARD_COMPLETE || simulation_type == SOLVE_FORWARD_SIMPLE) && (block_size))
         {
@@ -2062,7 +2049,6 @@ DynamicModel::writeSparseDynamicMFile(const string &dynamic_basename, const stri
           mDynamicModelFile << "    return;\n";
           mDynamicModelFile << "  end;\n";
         }
-      prev_Simulation_Type = simulation_type;
     }
   if (open_par)
     mDynamicModelFile << "  end;\n";
@@ -3555,14 +3541,22 @@ DynamicModel::toStatic(StaticModel &static_model) const
             break;
           }
 
-      // If yes, replace it by an equation marked [static]
-      if (is_dynamic_only)
+      try
+        {
+          // If yes, replace it by an equation marked [static]
+          if (is_dynamic_only)
+            {
+              static_model.addEquation(static_only_equations[static_only_index]->toStatic(static_model), static_only_equations_lineno[static_only_index]);
+              static_only_index++;
+            }
+          else
+            static_model.addEquation(equations[i]->toStatic(static_model), equations_lineno[i]);
+        }
+      catch (DataTree::DivisionByZeroException)
         {
-          static_model.addEquation(static_only_equations[static_only_index]->toStatic(static_model), static_only_equations_lineno[static_only_index]);
-          static_only_index++;
+          cerr << "...division by zero error encountred when converting equation " << i << " to static" << endl;
+          exit(EXIT_FAILURE);
         }
-      else
-        static_model.addEquation(equations[i]->toStatic(static_model), equations_lineno[i]);
     }
 
   // Convert auxiliary equations
diff --git a/preprocessor/DynareBison.yy b/preprocessor/DynareBison.yy
index 0c754a4bc06edef53640eedf800aec4df12c14d7..a92801207b30fbe9414955f65fae44061c49096f 100644
--- a/preprocessor/DynareBison.yy
+++ b/preprocessor/DynareBison.yy
@@ -84,7 +84,7 @@ class ParsingDriver;
 
 %token AIM_SOLVER ANALYTIC_DERIVATION AR AUTOCORR
 %token BAYESIAN_IRF BETA_PDF BLOCK USE_CALIBRATION
-%token BVAR_DENSITY BVAR_FORECAST
+%token BVAR_DENSITY BVAR_FORECAST NODECOMPOSITION
 %token BVAR_PRIOR_DECAY BVAR_PRIOR_FLAT BVAR_PRIOR_LAMBDA
 %token BVAR_PRIOR_MU BVAR_PRIOR_OMEGA BVAR_PRIOR_TAU BVAR_PRIOR_TRAIN
 %token BVAR_REPLIC BYTECODE ALL_VALUES_REQUIRED
@@ -94,7 +94,7 @@ class ParsingDriver;
 %token END ENDVAL EQUAL ESTIMATION ESTIMATED_PARAMS ESTIMATED_PARAMS_BOUNDS ESTIMATED_PARAMS_INIT EXTENDED_PATH ENDOGENOUS_PRIOR
 %token FILENAME FILTER_STEP_AHEAD FILTERED_VARS FIRST_OBS LAST_OBS SET_TIME
 %token <string_val> FLOAT_NUMBER DATES
-%token DEFAULT FIXED_POINT
+%token DEFAULT FIXED_POINT OPT_ALGO
 %token FORECAST K_ORDER_SOLVER INSTRUMENTS SHIFT MEAN STDEV VARIANCE MODE INTERVAL SHAPE DOMAINN
 %token GAMMA_PDF GRAPH GRAPH_FORMAT CONDITIONAL_VARIANCE_DECOMPOSITION NOCHECK STD
 %token HISTVAL HISTVAL_FILE HOMOTOPY_SETUP HOMOTOPY_MODE HOMOTOPY_STEPS HOMOTOPY_FORCE_CONTINUE HP_FILTER HP_NGRID HYBRID
@@ -107,6 +107,8 @@ class ParsingDriver;
 %token MFS MH_CONF_SIG MH_DROP MH_INIT_SCALE MH_JSCALE MH_MODE MH_NBLOCKS MH_REPLIC MH_RECOVER POSTERIOR_MAX_SUBSAMPLE_DRAWS MIN MINIMAL_SOLVING_PERIODS
 %token MODE_CHECK MODE_CHECK_NEIGHBOURHOOD_SIZE MODE_CHECK_SYMMETRIC_PLOTS MODE_CHECK_NUMBER_OF_POINTS MODE_COMPUTE MODE_FILE MODEL MODEL_COMPARISON MODEL_INFO MSHOCKS ABS SIGN
 %token MODEL_DIAGNOSTICS MODIFIEDHARMONICMEAN MOMENTS_VARENDO DIFFUSE_FILTER SUB_DRAWS TAPER_STEPS GEWEKE_INTERVAL MCMC_JUMPING_COVARIANCE MOMENT_CALIBRATION
+%token NUMBER_OF_PARTICLES RESAMPLING SYSTEMATIC GENERIC RESAMPLING_THRESHOLD RESAMPLING_METHOD KITAGAWA STRATIFIED SMOOTH
+%token FILTER_ALGORITHM SIS APF GF GMF CPF PROPOSAL_APPROXIMATION CUBATURE UNSCENTED MONTECARLO DISTRIBUTION_APPROXIMATION
 %token <string_val> NAME
 %token NAN_CONSTANT NO_STATIC NOBS NOCONSTANT NODISPLAY NOCORR NODIAGNOSTIC NOFUNCTIONS NO_HOMOTOPY
 %token NOGRAPH NOMOMENTS NOPRINT NORMAL_PDF SAVE_DRAWS
@@ -1094,6 +1096,7 @@ stoch_simul_primary_options : o_dr_algo
 
 stoch_simul_options : stoch_simul_primary_options
                     | o_loglinear
+                    | o_nodecomposition
                     ;
 
 symbol_list : symbol_list symbol
@@ -1623,7 +1626,8 @@ estimation_options : o_datafile
                    | o_mh_nblocks
                    | o_load_mh_file
                    | o_loglinear
-		   | o_logdata
+                   | o_logdata
+                   | o_nodecomposition
                    | o_nodiagnostic
                    | o_bayesian_irf
                    | o_dsge_var
@@ -1676,6 +1680,13 @@ estimation_options : o_datafile
                    | o_posterior_max_subsample_draws
                    | o_consider_all_endogenous
                    | o_consider_only_observed
+		   | o_number_of_particles
+		   | o_resampling
+		   | o_resampling_threshold
+		   | o_resampling_method
+		   | o_filter_algorithm
+		   | o_proposal_approximation
+		   | o_distribution_approximation
                    ;
 
 list_optim_option : QUOTED_STRING COMMA QUOTED_STRING
@@ -1730,6 +1741,8 @@ osr_options_list : osr_options_list COMMA osr_options
 osr_options : stoch_simul_primary_options
             | o_osr_maxit
             | o_osr_tolf
+            | o_opt_algo
+            | o_optim
             ;
 
 osr : OSR ';'
@@ -1788,6 +1801,8 @@ identification_option : o_ar
                       | o_nograph
                       | o_nodisplay
                       | o_graph_format
+                      | o_diffuse_filter
+                      | o_prior_trunc
                       ;
 
 model_comparison : MODEL_COMPARISON mc_filename_list ';'
@@ -2351,6 +2366,9 @@ calib_smoother_options_list : calib_smoother_option COMMA calib_smoother_options
 calib_smoother_option : o_filtered_vars
                       | o_filter_step_ahead
                       | o_datafile
+                      | o_prefilter
+                      | o_loglinear
+                      | o_first_obs
                       ;
 
 extended_path : EXTENDED_PATH ';'
@@ -2484,6 +2502,9 @@ o_simul_maxit : MAXIT EQUAL INT_NUMBER { driver.option_num("simul.maxit", $3); }
 o_dp_maxit : MAXIT EQUAL INT_NUMBER { driver.option_num("dp.maxit", $3); };
 o_osr_maxit : MAXIT EQUAL INT_NUMBER { driver.option_num("osr.maxit", $3); };
 o_osr_tolf : TOLF EQUAL non_negative_number { driver.option_num("osr.tolf", $3); };
+o_opt_algo : OPT_ALGO EQUAL INT_NUMBER { driver.option_num("osr.opt_algo", $3); }
+           | OPT_ALGO EQUAL filename { driver.option_str("osr.opt_algo", $3); }
+           ;
 o_cutoff : CUTOFF EQUAL non_negative_number { driver.cutoff($3); };
 o_markowitz : MARKOWITZ EQUAL non_negative_number { driver.option_num("markowitz", $3); };
 o_minimal_solving_periods : MINIMAL_SOLVING_PERIODS EQUAL non_negative_number { driver.option_num("minimal_solving_periods", $3); };
@@ -2638,6 +2659,27 @@ o_bvar_prior_flat : BVAR_PRIOR_FLAT { driver.option_num("bvar_prior_flat", "1");
 o_bvar_prior_train : BVAR_PRIOR_TRAIN EQUAL INT_NUMBER { driver.option_num("bvar_prior_train", $3); };
 o_bvar_replic : BVAR_REPLIC EQUAL INT_NUMBER { driver.option_num("bvar_replic", $3); };
 
+o_number_of_particles : NUMBER_OF_PARTICLES EQUAL INT_NUMBER { driver.option_num("particle.number_of_particles", $3); };
+o_resampling : RESAMPLING EQUAL SYSTEMATIC
+              | RESAMPLING EQUAL NONE {driver.option_num("particle.resampling.status.systematic", "0"); driver.option_num("particle.resampling.status.none", "1"); }
+              | RESAMPLING EQUAL GENERIC {driver.option_num("particle.resampling.status.systematic", "0"); driver.option_num("particle.resampling.status.generic", "1"); };
+o_resampling_threshold : RESAMPLING_THRESHOLD EQUAL non_negative_number { driver.option_num("particle.resampling.threshold", $3); };
+o_resampling_method : RESAMPLING_METHOD EQUAL KITAGAWA {driver.option_num("particle.resampling.method.kitagawa", "1"); driver.option_num("particle.resampling.method.smooth", "0"); driver.option_num("particle.resampling.smethod.stratified", "0"); }
+              | RESAMPLING_METHOD EQUAL SMOOTH {driver.option_num("particle.resampling.method.kitagawa", "0"); driver.option_num("particle.resampling.method.smooth", "1"); driver.option_num("particle.resampling.smethod.stratified", "0"); }
+              | RESAMPLING_METHOD EQUAL STRATIFIED {driver.option_num("particle.resampling.method.kitagawa", "0"); driver.option_num("particle.resampling.method.smooth", "0"); driver.option_num("particle.resampling.method.stratified", "1"); };
+o_filter_algorithm : FILTER_ALGORITHM EQUAL SIS {driver.option_num("particle.filter_algorithm.sis", "1"); driver.option_num("particle.filter_algorithm.apf", "0"); driver.option_num("particle.filter_algorithm.gf", "0"); driver.option_num("particle.filter_algorithm.gmf", "0");driver.option_num("particle.filter_algorithm.cpf", "0");}
+		   | FILTER_ALGORITHM EQUAL APF {driver.option_num("particle.filter_algorithm.sis", "0"); driver.option_num("particle.filter_algorithm.apf", "1"); driver.option_num("particle.filter_algorithm.gf", "0"); driver.option_num("particle.filter_algorithm.gmf", "0"); driver.option_num("particle.filter_algorithm.cpf", "0");}
+		   | FILTER_ALGORITHM EQUAL GF {driver.option_num("particle.filter_algorithm.sis", "0"); driver.option_num("particle.filter_algorithm.apf", "0"); driver.option_num("particle.filter_algorithm.gf", "1");  driver.option_num("particle.filter_algorithm.gmf", "0"); driver.option_num("particle.filter_algorithm.cpf", "0");}
+		   | FILTER_ALGORITHM EQUAL GMF {driver.option_num("particle.filter_algorithm.sis", "0"); driver.option_num("particle.filter_algorithm.apf", "0"); driver.option_num("particle.filter_algorithm.gf", "0"); driver.option_num("particle.filter_algorithm.gmf", "1"); driver.option_num("particle.filter_algorithm.cpf", "0");}
+		   | FILTER_ALGORITHM EQUAL CPF {driver.option_num("particle.filter_algorithm.sis", "0"); driver.option_num("particle.filter_algorithm.apf", "0"); driver.option_num("particle.filter_algorithm.gf", "0"); driver.option_num("particle.filter_algorithm.gmf", "0"); driver.option_num("particle.filter_algorithm.cpf", "1");} ;
+o_proposal_approximation : PROPOSAL_APPROXIMATION EQUAL CUBATURE {driver.option_num("particle.proposal_approximation.cubature", "1"); driver.option_num("particle.proposal_approximation.unscented", "0"); driver.option_num("particle.proposal_approximation.montecarlo", "0");}
+		| PROPOSAL_APPROXIMATION EQUAL UNSCENTED {driver.option_num("particle.proposal_approximation.cubature", "0"); driver.option_num("particle.proposal_approximation.unscented", "1"); driver.option_num("particle.proposal_approximation.montecarlo", "0");}
+		| PROPOSAL_APPROXIMATION EQUAL MONTECARLO {driver.option_num("particle.proposal_approximation.cubature", "0"); driver.option_num("particle.proposal_approximation.unscented", "0"); driver.option_num("particle.proposal_approximation.montecarlo", "1");} ;
+o_distribution_approximation : DISTRIBUTION_APPROXIMATION EQUAL CUBATURE {driver.option_num("particle.distribution_approximation.cubature", "1"); driver.option_num("particle.distribution_approximation.unscented", "0"); driver.option_num("particle.distribution_approximation.montecarlo", "0");}
+		| DISTRIBUTION_APPROXIMATION EQUAL UNSCENTED {driver.option_num("particle.distribution_approximation.cubature", "0"); driver.option_num("particle.distribution_approximation.unscented", "1"); driver.option_num("particle.distribution_approximation.montecarlo", "0");}
+		| DISTRIBUTION_APPROXIMATION EQUAL MONTECARLO {driver.option_num("particle.distribution_approximation.cubature", "0"); driver.option_num("particle.distribution_approximation.unscented", "0"); driver.option_num("particle.distribution_approximation.montecarlo", "1");} ;
+
+
 o_gsa_identification : IDENTIFICATION EQUAL INT_NUMBER { driver.option_num("identification", $3); }; /*not in doc */
 o_gsa_morris : MORRIS EQUAL INT_NUMBER { driver.option_num("morris", $3); };
 o_gsa_stab : STAB  EQUAL INT_NUMBER { driver.option_num("stab", $3); };
@@ -2701,6 +2743,7 @@ o_parameter_set : PARAMETER_SET EQUAL PRIOR_MODE
                 | PARAMETER_SET EQUAL CALIBRATION
                   { driver.option_str("parameter_set", "calibration"); }
                 ;
+o_nodecomposition : NODECOMPOSITION { driver.option_num("nodecomposition", "1"); };
 o_ms_drop : DROP EQUAL INT_NUMBER { driver.option_num("ms.drop", $3); };
 o_ms_mh_replic : MH_REPLIC EQUAL INT_NUMBER { driver.option_num("ms.mh_replic", $3); };
 o_freq : FREQ EQUAL INT_NUMBER
diff --git a/preprocessor/DynareFlex.ll b/preprocessor/DynareFlex.ll
index a552f19973237dd2298e4a5c11e466c30c2b1f17..9052a1027dad845da6378e740c5e5bdd292fc486 100644
--- a/preprocessor/DynareFlex.ll
+++ b/preprocessor/DynareFlex.ll
@@ -352,6 +352,28 @@ DATE -?[0-9]+([YyAa]|[Mm]([1-9]|1[0-2])|[Qq][1-4]|[Ww]([1-9]{1}|[1-4][0-9]|5[0-2
 <DYNARE_STATEMENT>use_univariate_filters_if_singularity_is_detected {return token::USE_UNIVARIATE_FILTERS_IF_SINGULARITY_IS_DETECTED;}
 <DYNARE_STATEMENT>hybrid {return token::HYBRID;}
 <DYNARE_STATEMENT>default {return token::DEFAULT;}
+
+<DYNARE_STATEMENT>number_of_particles {return token::NUMBER_OF_PARTICLES;}
+<DYNARE_STATEMENT>resampling {return token::RESAMPLING;}
+<DYNARE_STATEMENT>systematic {return token::SYSTEMATIC;}
+<DYNARE_STATEMENT>generic {return token::GENERIC;}
+<DYNARE_STATEMENT>resampling_threshold {return token::RESAMPLING_THRESHOLD;}
+<DYNARE_STATEMENT>resampling_method {return token::RESAMPLING_METHOD;}
+<DYNARE_STATEMENT>kitagawa {return token::KITAGAWA;}
+<DYNARE_STATEMENT>smooth {return token::SMOOTH;}
+<DYNARE_STATEMENT>stratified {return token::STRATIFIED;}
+<DYNARE_STATEMENT>filter_algorithm {return token::FILTER_ALGORITHM;}
+<DYNARE_STATEMENT>sis {return token::SIS;}
+<DYNARE_STATEMENT>apf {return token::APF;}
+<DYNARE_STATEMENT>gf {return token::GF;}
+<DYNARE_STATEMENT>gmf {return token::GMF;}
+<DYNARE_STATEMENT>cpf {return token::CPF;}
+<DYNARE_STATEMENT>proposal_approximation {return token::PROPOSAL_APPROXIMATION;}
+<DYNARE_STATEMENT>cubature {return token::CUBATURE;}
+<DYNARE_STATEMENT>unscented {return token::UNSCENTED;}
+<DYNARE_STATEMENT>montecarlo {return token::MONTECARLO;}
+<DYNARE_STATEMENT>distribution_approximation {return token::DISTRIBUTION_APPROXIMATION;}
+
 <DYNARE_STATEMENT>alpha {
   yylval->string_val = new string(yytext);
   return token::ALPHA;
@@ -431,6 +453,7 @@ DATE -?[0-9]+([YyAa]|[Mm]([1-9]|1[0-2])|[Qq][1-4]|[Ww]([1-9]{1}|[1-4][0-9]|5[0-2
   yylval->string_val = new string(yytext);
   return token::CNUM;
 }
+<DYNARE_STATEMENT>nodecomposition {return token::NODECOMPOSITION;};
 <DYNARE_STATEMENT>banact {return token::BANACT;}
 <DYNARE_BLOCK>use_calibration {return token::USE_CALIBRATION;}
 <DYNARE_STATEMENT>output_file_tag {return token::OUTPUT_FILE_TAG;}
@@ -475,6 +498,7 @@ DATE -?[0-9]+([YyAa]|[Mm]([1-9]|1[0-2])|[Qq][1-4]|[Ww]([1-9]{1}|[1-4][0-9]|5[0-2
 <DYNARE_STATEMENT>random_function_convergence_criterion {return token::RANDOM_FUNCTION_CONVERGENCE_CRITERION;}
 <DYNARE_STATEMENT>random_parameter_convergence_criterion {return token::RANDOM_PARAMETER_CONVERGENCE_CRITERION;}
 <DYNARE_STATEMENT>tolf {return token::TOLF;}
+<DYNARE_STATEMENT>opt_algo {return token::OPT_ALGO;}
 <DYNARE_STATEMENT>instruments {return token::INSTRUMENTS;}
 <DYNARE_STATEMENT>hessian  {
   yylval->string_val = new string(yytext);
diff --git a/preprocessor/ExprNode.cc b/preprocessor/ExprNode.cc
index d7f7bd4dc026b3302cccb562f30b80d02bb98d72..d4121b72924600e3e2663709300afab1edd0f2b0 100644
--- a/preprocessor/ExprNode.cc
+++ b/preprocessor/ExprNode.cc
@@ -621,7 +621,9 @@ VariableNode::writeOutput(ostream &output, ExprNodeOutputType output_type,
       break;
 
     case eModelLocalVariable:
-      if (output_type == oMatlabDynamicModelSparse || output_type == oMatlabStaticModelSparse)
+      if (output_type == oMatlabDynamicModelSparse || output_type == oMatlabStaticModelSparse
+          || output_type == oMatlabDynamicSteadyStateOperator || output_type == oMatlabDynamicSparseSteadyStateOperator
+          || output_type == oCDynamicSteadyStateOperator)
         {
           output << "(";
           datatree.local_variables_table[symb_id]->writeOutput(output, output_type, temporary_terms, tef_terms);
diff --git a/preprocessor/ModFile.cc b/preprocessor/ModFile.cc
index 89161214635ceb549df7c9f78f80c4f618645250..554901776c5937822b7ace9f134407bcafa8bcbf 100644
--- a/preprocessor/ModFile.cc
+++ b/preprocessor/ModFile.cc
@@ -39,7 +39,7 @@ ModFile::ModFile(WarningConsolidation &warnings_arg)
     steady_state_model(symbol_table, num_constants, external_functions_table, static_model),
     linear(false), block(false), byte_code(false), use_dll(false), no_static(false), 
     differentiate_forward_vars(false),
-    nonstationary_variables(false), ramsey_model_orig_eqn_nbr(0),
+    nonstationary_variables(false), orig_eqn_nbr(0), ramsey_eqn_nbr(0),
     warnings(warnings_arg)
 {
 }
@@ -330,6 +330,7 @@ ModFile::transformPass(bool nostrict)
       dynamic_model.removeTrendVariableFromEquations();
     }
 
+  orig_eqn_nbr = dynamic_model.equation_number();
   if (mod_file_struct.ramsey_model_present)
     {
       StaticModel *planner_objective = NULL;
@@ -340,7 +341,6 @@ ModFile::transformPass(bool nostrict)
             planner_objective = pos->getPlannerObjective();
         }
       assert(planner_objective != NULL);
-      ramsey_model_orig_eqn_nbr = dynamic_model.equation_number();
 
       /*
         clone the model then clone the new equations back to the original because
@@ -349,6 +349,7 @@ ModFile::transformPass(bool nostrict)
       dynamic_model.cloneDynamic(ramsey_FOC_equations_dynamic_model);
       ramsey_FOC_equations_dynamic_model.computeRamseyPolicyFOCs(*planner_objective);
       ramsey_FOC_equations_dynamic_model.replaceMyEquations(dynamic_model);
+      ramsey_eqn_nbr = dynamic_model.equation_number() - orig_eqn_nbr;
     }
 
   if (mod_file_struct.stoch_simul_present
@@ -419,11 +420,17 @@ ModFile::transformPass(bool nostrict)
       exit(EXIT_FAILURE);
     }
 
+  if (mod_file_struct.identification_present && symbol_table.exo_det_nbr() > 0)
+    {
+      cerr << "ERROR: identification is incompatible with deterministic exogenous variables" << endl;
+      exit(EXIT_FAILURE);
+    }
+
   if (!mod_file_struct.ramsey_model_present)
     cout << "Found " << dynamic_model.equation_number() << " equation(s)." << endl;
   else
     {
-      cout << "Found " << ramsey_model_orig_eqn_nbr  << " equation(s)." << endl;
+      cout << "Found " << orig_eqn_nbr  << " equation(s)." << endl;
       cout << "Found " << dynamic_model.equation_number() << " FOC equation(s) for Ramsey Problem." << endl;
     }
 
@@ -734,8 +741,9 @@ ModFile::writeOutputFiles(const string &basename, bool clear_all, bool no_log, b
   if (block && !byte_code)
     mOutputFile << "addpath " << basename << ";" << endl;
 
-  if (mod_file_struct.ramsey_model_present)
-    mOutputFile << "M_.orig_eq_nbr = " << ramsey_model_orig_eqn_nbr << ";" << endl;
+  mOutputFile << "M_.orig_eq_nbr = " << orig_eqn_nbr << ";" << endl
+              << "M_.eq_nbr = " << dynamic_model.equation_number() << ";" << endl
+              << "M_.ramsey_eq_nbr = " << ramsey_eqn_nbr << ";" << endl;
 
   if (dynamic_model.equation_number() > 0)
     {
diff --git a/preprocessor/ModFile.hh b/preprocessor/ModFile.hh
index a561af08efea45f58dade4bbbeb261a5f3a2ad57..d8b042a73ed55c6749140b7ec603b9e407decec8 100644
--- a/preprocessor/ModFile.hh
+++ b/preprocessor/ModFile.hh
@@ -93,7 +93,10 @@ public:
   eval_context_t global_eval_context;
 
   //! Stores the original number of equations in the model_block
-  int ramsey_model_orig_eqn_nbr;
+  int orig_eqn_nbr;
+
+  //! Stores the number of equations added to the Ramsey model
+  int ramsey_eqn_nbr;
 
   //! Stores the list of extra files to be transefered during a parallel run
   /*! (i.e. option parallel_local_files of model block) */
diff --git a/preprocessor/ParsingDriver.cc b/preprocessor/ParsingDriver.cc
index ac58da0c4a5ab33452e6bc69750c999c40a252ab..c7f6b2574e07da1a109a9a2da8d79f753f66f2ad 100644
--- a/preprocessor/ParsingDriver.cc
+++ b/preprocessor/ParsingDriver.cc
@@ -2125,7 +2125,15 @@ ParsingDriver::add_times(expr_t arg1, expr_t arg2)
 expr_t
 ParsingDriver::add_divide(expr_t arg1, expr_t arg2)
 {
-  return data_tree->AddDivide(arg1, arg2);
+  try
+    {
+      return data_tree->AddDivide(arg1, arg2);
+    }
+  catch (DataTree::DivisionByZeroException)
+    {
+      cerr << "...division by zero error encountred when reading model from .mod file" << endl;
+      exit(EXIT_FAILURE);
+    }
 }
 
 expr_t
diff --git a/preprocessor/Statement.cc b/preprocessor/Statement.cc
index db02db9392fe89d54d592b7b37ddf01c32c9b3b4..d4d522e7b7e5f98202a07275c235fab6f0387c60 100644
--- a/preprocessor/Statement.cc
+++ b/preprocessor/Statement.cc
@@ -139,16 +139,12 @@ OptionsList::writeOutput(ostream &output, const string &option_group) const
   unsigned idx = option_group.find_last_of(".");
   if (idx<UINT_MAX)
     {
-      output << option_group << endl;
-      output << idx << endl;
       output << "if ~isfield(" << option_group.substr(0,idx) << ",'" << option_group.substr(idx+1) << "')" << endl;
       output << "    " << option_group << " = struct();" << endl;
       output << "end" << endl;
     }
   else
-    {
-      output << option_group << " = struct();" << endl;
-    }
+    output << option_group << " = struct();" << endl;
 
   for (num_options_t::const_iterator it = num_options.begin();
        it != num_options.end(); it++)
diff --git a/preprocessor/StaticModel.cc b/preprocessor/StaticModel.cc
index 18be48f11eafb94a826a96acd7c7477f24a1f9c2..09fb9261b06593004b1fc7244c6e5b20ab09014d 100644
--- a/preprocessor/StaticModel.cc
+++ b/preprocessor/StaticModel.cc
@@ -1159,7 +1159,8 @@ StaticModel::writeStaticMFile(const string &func_name) const
          << "%" << endl
          << "% Outputs:" << endl
          << "%   residual  [M_.endo_nbr by 1] double    vector of residuals of the static model equations " << endl
-         << "%                                          in order of declaration of the equations" << endl
+         << "%                                          in order of declaration of the equations." << endl
+         << "%                                          Dynare may prepend auxiliary equations, see M_.aux_vars" << endl
          << "%   g1        [M_.endo_nbr by M_.endo_nbr] double    Jacobian matrix of the static model equations;" << endl
          << "%                                                       columns: variables in declaration order" << endl
          << "%                                                       rows: equations in order of declaration" << endl
diff --git a/preprocessor/macro/MacroValue.cc b/preprocessor/macro/MacroValue.cc
index 65b3fc39ddb80de222b28a007fdefd329f4df971..3dfab32331afdf9c654f44acb364443584ec6438 100644
--- a/preprocessor/macro/MacroValue.cc
+++ b/preprocessor/macro/MacroValue.cc
@@ -387,7 +387,7 @@ StringMV::operator[](const MacroValue &mv) const throw (TypeError, OutOfBoundsEr
       if (*it < 1 || *it > (int) value.length())
         throw OutOfBoundsError();
       char c = value.at(*it - 1);
-      result.append(&c);
+      result.append(1, c);
     }
   return new StringMV(driver, result);
 }
diff --git a/scripts/fix-copyright-years b/scripts/fix-copyright-years
new file mode 100755
index 0000000000000000000000000000000000000000..86eceb7bdd63e7d24da38443e4454dec312f12af
--- /dev/null
+++ b/scripts/fix-copyright-years
@@ -0,0 +1,62 @@
+#!/bin/sh
+
+# This scripts updates all the "Copyright" lines in source files with the
+# correct most recent modification years.
+#
+# It must be given a file in argument. A typical usage can be to run it on all
+# code source files:
+#
+# find \( -name '*.m' -or -name '*.cc' -or -name '*.hh' -or -name '*.c' -or -name '*.h' -or -name '*.f' \) -exec fix-copyright-years '{}' ';'
+#
+# The LAST_UPDATE_COMMIT variable must be updated to contain the number of the
+# last commit in which such a copyright update has been done.
+#
+# Note that the script does not understand some unusual copyright notices: it
+# will display a message in that case.
+
+LAST_UPDATE_COMMIT=61485ab809d9a33484abf6136f05abd84da2be1b
+
+if [ -z "$1" ]; then
+    echo "Give a filename in argument"
+    exit 1
+fi
+
+if [ ! -f "$1" ]; then
+    echo "$1: Unknown file"
+    exit 1
+fi
+
+GITYEAR=$(git log $LAST_UPDATE_COMMIT.. --date=short --pretty=format:%cd -n 1 $1 | sed "s/\([0-9]\{4\}\)-[0-9]\{2\}-[0-9]\{2\}/\1/")
+
+if [ -z "$GITYEAR" ]; then
+    # Not in git
+    exit 0
+fi
+
+COPYLINES=$(grep -c Copyright $1)
+
+if [ $COPYLINES -eq 0 ]; then
+    echo "$1: File has no copyright line"
+    exit 1
+fi
+
+if [ $COPYLINES -ge 2 ]; then
+    COPYLINES=$(grep Copyright $1)
+    echo "$1: File has too many copyright lines (Git year: $GITYEAR): $COPYLINES"
+    exit 1
+fi
+
+COPYLINE=$(grep -o -E "Copyright \(C\) ([[:digit:]]{4}-)?[[:digit:]]{4} Dynare Team" $1)
+
+if [ -z "$COPYLINE" ]; then
+    COPYLINE=$(grep Copyright $1)
+    echo "$1: Unsupported copyright notice (Git year: $GITYEAR): $COPYLINE"
+    exit 1
+fi
+
+ACTUALYEAR=$(echo $COPYLINE | sed "s/Copyright (C) \([0-9]\{4\}-\)\?\([0-9]\{4\}\) Dynare Team/\2/")
+
+if [ $GITYEAR -gt $ACTUALYEAR ]; then
+    sed -i "s/Copyright (C) \([0-9]\{4\}\)\(-[0-9]\{4\}\)\? Dynare Team/Copyright (C) \1-$GITYEAR Dynare Team/" $1
+    echo "$1: Updating to $GITYEAR"
+fi
diff --git a/scripts/indent-c++ b/scripts/indent-c++
new file mode 100755
index 0000000000000000000000000000000000000000..db299d518d27f32abfc913674edc50b88db3eaf0
--- /dev/null
+++ b/scripts/indent-c++
@@ -0,0 +1,15 @@
+#!/bin/sh
+
+# Reindents the C++ source code file given in argument.
+
+if [ -z "$1" ]; then
+    echo "Give a filename in argument"
+    exit 1
+fi
+
+SCRIPTS_DIR=$(pwd)/$(dirname $0)
+
+uncrustify -l CPP --replace -c ${SCRIPTS_DIR}/uncrustify.cfg $1
+
+cd $(dirname $1)
+emacs -batch $(basename $1) -l ${SCRIPTS_DIR}/indent-c++.el
diff --git a/scripts/indent-c++.el b/scripts/indent-c++.el
new file mode 100644
index 0000000000000000000000000000000000000000..17ab26ba54b11c97927abbe718dc2868bc741e4f
--- /dev/null
+++ b/scripts/indent-c++.el
@@ -0,0 +1,5 @@
+(c++-mode)
+(setq indent-tabs-mode nil)
+(indent-region (point-min) (point-max))
+(set-buffer-file-coding-system 'unix)
+(save-buffer)
diff --git a/scripts/indent-matlab b/scripts/indent-matlab
new file mode 100755
index 0000000000000000000000000000000000000000..77772bd9a45c64e993ff93e30c1275132d0ee5e7
--- /dev/null
+++ b/scripts/indent-matlab
@@ -0,0 +1,13 @@
+#!/bin/sh
+
+# Reindents the MATLAB source code file given in argument.
+
+if [ -z "$1" ]; then
+    echo "Give a filename in argument"
+    exit 1
+fi
+
+SCRIPTS_DIR=$(pwd)/$(dirname $0)
+
+cd $(dirname $1)
+emacs -batch $(basename $1) -l ${SCRIPTS_DIR}/indent-matlab.el
diff --git a/scripts/indent-matlab.el b/scripts/indent-matlab.el
new file mode 100644
index 0000000000000000000000000000000000000000..76861b258056e241b7eefe6cfa8f050931d077e5
--- /dev/null
+++ b/scripts/indent-matlab.el
@@ -0,0 +1,7 @@
+(matlab-mode)
+(setq matlab-indent-level 4)
+(setq matlab-indent-function-body nil)
+(untabify (point-min) (point-max))
+(indent-region (point-min) (point-max))
+(set-buffer-file-coding-system 'unix)
+(save-buffer)
diff --git a/tests/Makefile.am b/tests/Makefile.am
index 257af1500e99dae2eeb9a2a41e4b2e4137609bd7..b133708533968acc5b62c914a8fb57adb70cac27 100644
--- a/tests/Makefile.am
+++ b/tests/Makefile.am
@@ -19,6 +19,8 @@ MODFILES = \
 	example1_macroif.mod \
 	t_sgu_ex1.mod \
 	optimal_policy/osr_example.mod \
+	optimal_policy/osr_example_objective_correctness.mod \
+	optimal_policy/osr_example_obj_corr_non_stat_vars.mod \
 	optimal_policy/ramsey.mod \
 	optimal_policy/nk_ramsey.mod \
 	optimal_policy/nk_ramsey_model.mod \
@@ -26,6 +28,10 @@ MODFILES = \
 	optimal_policy/nk_ramsey_expectation.mod \
 	optimal_policy/nk_ramsey_expectation_a.mod \
 	optimal_policy/mult_elimination_test.mod \
+	optimal_policy/Ramsey/ramsey_ex_initval.mod \
+	optimal_policy/Ramsey/ramsey_ex.mod \
+	optimal_policy/Ramsey/ramsey_ex_initval_AR2.mod \
+	optimal_policy/Ramsey/ramsey_ex_aux.mod \
 	discretionary_policy/dennis_1.mod \
 	ramst_initval_file.mod \
 	ramst_normcdf_and_friends.mod \
@@ -116,6 +122,9 @@ MODFILES = \
 	identification/kim/kim2.mod \
 	identification/as2007/as2007.mod \
 	simul/example1.mod \
+	simul/Solow_no_varexo.mod \
+	simul/simul_ZLB_purely_forward.mod \
+	simul/simul_ZLB_purely_forward_no_solution.mod \
 	conditional_forecasts/fs2000_cal.mod \
 	conditional_forecasts/fs2000_est.mod \
 	recursive/ls2003.mod \
@@ -130,6 +139,7 @@ MODFILES = \
 	ms-sbvar/test_ms_variances.mod \
 	ms-sbvar/test_ms_variances_repeated_runs.mod \
 	ms-dsge/test_ms_dsge.mod \
+	kalman/lyapunov/fs2000_lyap.mod \
 	kalman_filter_smoother/gen_data.mod \
 	kalman_filter_smoother/algo1.mod \
 	kalman_filter_smoother/algo2.mod \
@@ -144,6 +154,8 @@ MODFILES = \
 	kalman_filter_smoother/fs2000_1.mod \
 	kalman_filter_smoother/fs2000_2.mod \
 	kalman_filter_smoother/fs2000a.mod \
+	kalman_filter_smoother/check_variable_dimensions/fs2000.mod \
+	kalman_filter_smoother/check_variable_dimensions/fs2000_ML.mod \
 	second_order/burnside_1.mod \
 	second_order/ds1.mod \
 	second_order/ds2.mod \
@@ -170,6 +182,7 @@ MODFILES = \
 	shock_decomposition/fs2000_est_varlist.mod \
 	stochastic_purely_forward/stochastic_purely_forward.mod \
 	stochastic_purely_forward/stochastic_purely_forward_with_static.mod \
+	forecast/Hansen_exo_det_forecast.mod \
 	gradient/fs2000_numgrad_13.mod \
 	gradient/fs2000_numgrad_15.mod \
 	gradient/fs2000_numgrad_2.mod \
@@ -184,7 +197,8 @@ MODFILES = \
 	reporting/example1.mod
 
 XFAIL_MODFILES = ramst_xfail.mod \
-	estim_param_in_shock_value.mod
+	estim_param_in_shock_value.mod \
+	optimal_policy/Ramsey/ramsey_ex_wrong_ss_file.mod
 
 # Dependencies
 example1_use_dll.m.trs: example1.m.trs
@@ -346,7 +360,9 @@ EXTRA_DIST = \
 	filter_step_ahead/fs2000_filter_step_ahead_bayesian_steadystate.m \
 	filter_step_ahead/fs2000_filter_step_ahead_ML_steadystate.m \
 	loglinear/results_exp.mat \
-	smoother2histval/fsdat_simul.m
+	smoother2histval/fsdat_simul.m \
+	optimal_policy/Ramsey/find_c.m \
+	optimal_policy/Ramsey/oo_ramsey_policy_initval.mat 
 
 TARGETS =
 
diff --git a/tests/forecast/Hansen_exo_det_forecast.mod b/tests/forecast/Hansen_exo_det_forecast.mod
new file mode 100644
index 0000000000000000000000000000000000000000..22744908a5c8534855ef981ea5e2ce0f3c658677
--- /dev/null
+++ b/tests/forecast/Hansen_exo_det_forecast.mod
@@ -0,0 +1,95 @@
+/*
+* The Hansen model following McCandless, George T. (2008): The ABCs of RBCs, Hardvard University Press, Chapter 6
+*
+* This mod-file tests the correctness of forecasting with exogenous deterministic variables.
+* A forecast starting at the steady state in t=0, where the only shock is a perfectly 
+* anticipated shock in t=8, is equal to the IRF to a 7 period anticipated news shock.
+* Note the timing difference due to the fact that in forecasting. the agent starts at the 
+* steady state at time 0 and has the first endogenous reaction period at t=1 so that the shock at 
+* t=8 is only 7 period anticipated
+
+* This implementation was written by Johannes Pfeifer. Please note that the
+* following copyright notice only applies to this Dynare implementation of the
+* model.
+*/
+
+/*
+ * Copyright (C) 2014 Johannes Pfeifer
+ *
+ * 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/>.
+ */
+
+
+
+var c r y h k a;
+varexo eps_a_surp eps_a_antic;
+varexo_det e_det;
+
+parameters beta delta theta rho_a A_disutil;
+
+beta = 0.99;
+delta = 0.025;
+theta = 0.36;
+rho_a = 0.35;
+A_disutil = 2;
+
+model;
+1/c = beta*((1/c(+1))*(r(+1) +(1-delta)));
+(1-h)*(1-theta)*(y/h) = A_disutil*c;
+c = y +(1-delta)*k(-1) - k;
+y = a*k(-1)^(theta)*h^(1-theta);
+r = theta*(y/k(-1));
+log(a)=rho_a*log(a(-1))+eps_a_surp+eps_a_antic(-7)+e_det;
+end;
+
+steady_state_model;
+a = 1;
+h = (1+(A_disutil/(1-theta))*(1 - (beta*delta*theta)/(1-beta*(1-delta))))^(-1);
+k = h*(theta*a/(1/beta -(1-delta)))^(1/(1-theta));
+y = a*k^(theta)*h^(1-theta);
+c = y-delta*k;
+r =  1/beta - (1-delta);
+end;
+
+steady;
+
+shocks;
+var eps_a_surp; stderr 0;
+var eps_a_antic; stderr 0.01;
+var e_det;
+periods 8;
+values 0.01;
+end;
+
+stoch_simul(irf=40,nomoments, order=1);
+
+% make_ex_;
+
+forecast(periods=40);
+figure
+for ii=1:M_.orig_endo_nbr
+    subplot(3,3,ii)    
+    var_name=deblank(M_.endo_names(ii,:));
+    var_index=strmatch(var_name,deblank(M_.endo_names),'exact');
+    plot(1:40,oo_.dr.ys(var_index)+oo_.irfs.([var_name,'_eps_a_antic']),'b',1:40,... %
+            oo_.forecast.Mean.(var_name),'r--')
+    title(var_name)
+    difference(ii,:)=oo_.dr.ys(var_index)+oo_.irfs.([var_name,'_eps_a_antic'])-oo_.forecast.Mean.(var_name)';
+end
+
+if max(max(abs(difference)))>1e-10
+   error('Forecasts with exogenous deterministic variable is wrong') 
+end
\ No newline at end of file
diff --git a/tests/fs2000/fs2000_calib_dseries.mod b/tests/fs2000/fs2000_calib_dseries.mod
index 4354acf7ea96e428658f5e665ea33a0f6bab2b7b..18e41f33c3af9733f4242cedd6d3bed7d0d0374c 100644
--- a/tests/fs2000/fs2000_calib_dseries.mod
+++ b/tests/fs2000/fs2000_calib_dseries.mod
@@ -1,7 +1,5 @@
 // See fs2000.mod in the examples/ directory for details on the model
 
-set_time(1950Q1);
-
 var m P c e W R k d n l gy_obs gp_obs y dA;
 varexo e_a e_m;
 
diff --git a/tests/fs2000/fs2000_mode_compute_8.mod b/tests/fs2000/fs2000_mode_compute_8.mod
index 8ea1ec5786ea128e58e5da4ff1ef3b5ddb83a66d..4f39e10bfed58663ae0ec3e90966d4969f058ec7 100644
--- a/tests/fs2000/fs2000_mode_compute_8.mod
+++ b/tests/fs2000/fs2000_mode_compute_8.mod
@@ -72,4 +72,11 @@ varobs gp_obs gy_obs;
 
 options_.solve_tolf = 1e-12;
 
-estimation(order=1,datafile=fsdat_simul,nobs=192,mode_compute=8,loglinear,mh_replic=0);
+estimation(order=1,datafile=fsdat_simul,nobs=192,mode_compute=8,loglinear,mh_replic=0,optim=(
+'MaxIter',5000,
+'TolFun',1e-4,
+'TolX',1e-4,
+'MaxFunEvals',5000,
+'MaxFunEvalFactor',500,
+'InitialSimplexSize',0.05
+));
diff --git a/tests/gsa/ls2003a.mod b/tests/gsa/ls2003a.mod
new file mode 100644
index 0000000000000000000000000000000000000000..fcbd9b75cfb606ff7e5c4510b181ada0f7865400
--- /dev/null
+++ b/tests/gsa/ls2003a.mod
@@ -0,0 +1,97 @@
+var y y_s R pie dq pie_s de A y_obs pie_obs R_obs;
+varexo e_R e_q e_ys e_pies e_A;
+
+parameters psi1 psi2 psi3 rho_R tau alpha rr k rho_q rho_A rho_ys rho_pies;
+
+psi1 = 1.54;
+psi2 = 0.25;
+psi3 = 0.25;
+rho_R = 0.5;
+alpha = 0.3;
+rr = 2.51;
+k = 0.5;
+tau = 0.5;
+rho_q = 0.4;
+rho_A = 0.2;
+rho_ys = 0.9;
+rho_pies = 0.7;
+
+
+model(linear);
+y = y(+1) - (tau +alpha*(2-alpha)*(1-tau))*(R-pie(+1))-alpha*(tau +alpha*(2-alpha)*(1-tau))*dq(+1) + alpha*(2-alpha)*((1-tau)/tau)*(y_s-y_s(+1))-A(+1);
+pie = exp(-rr/400)*pie(+1)+alpha*exp(-rr/400)*dq(+1)-alpha*dq+(k/(tau+alpha*(2-alpha)*(1-tau)))*y+k*alpha*(2-alpha)*(1-tau)/(tau*(tau+alpha*(2-alpha)*(1-tau)))*y_s;
+pie = de+(1-alpha)*dq+pie_s;
+R = rho_R*R(-1)+(1-rho_R)*(psi1*pie+psi2*(y+alpha*(2-alpha)*((1-tau)/tau)*y_s)+psi3*de)+e_R;
+dq = rho_q*dq(-1)+e_q;
+y_s = rho_ys*y_s(-1)+e_ys;
+pie_s = rho_pies*pie_s(-1)+e_pies;
+A = rho_A*A(-1)+e_A;
+y_obs = y-y(-1)+A;
+pie_obs = 4*pie;
+R_obs = 4*R;
+end;
+
+shocks;
+	var e_R = 1.25^2;
+	var e_q = 2.5^2;
+	var e_A = 1.89;
+	var e_ys = 1.89;
+	var e_pies = 1.89;
+end;
+
+varobs y_obs R_obs pie_obs dq de;
+
+estimated_params;
+psi1 , gamma_pdf,1.5,0.5;
+psi2 , gamma_pdf,0.25,0.125;
+psi3 , gamma_pdf,0.25,0.125;
+rho_R ,beta_pdf,0.5,0.2;
+alpha ,beta_pdf,0.3,0.1;
+rr ,gamma_pdf,2.5,1;
+k , gamma_pdf,0.5,0.25;
+tau ,gamma_pdf,0.5,0.2;
+rho_q ,beta_pdf,0.4,0.2;
+rho_A ,beta_pdf,0.5,0.2;
+rho_ys ,beta_pdf,0.8,0.1;
+rho_pies,beta_pdf,0.7,0.15;
+stderr e_R,inv_gamma_pdf,1.2533,0.6551;
+stderr e_q,inv_gamma_pdf,2.5066,1.3103;
+stderr e_A,inv_gamma_pdf,1.2533,0.6551;
+stderr e_ys,inv_gamma_pdf,1.2533,0.6551;
+stderr e_pies,inv_gamma_pdf,1.88,0.9827;
+end;
+
+// endogenous prior restrictions
+options_.relative_irf=1;
+irf_calibration;
+y(1:4), e_ys, [ -50 50]; //[first year response]
+//y(1:4), e_ys, [-inf -50]; //[first year response]
+@#for ilag in 21:40
+R_obs(@{ilag}), e_ys, [0 6]; //[response after 4th year to 10th year]
+@#endfor
+end;
+
+/*
+irf_calibration;
+y(1:4), e_ys, [-inf -0.4]; //[first year response]
+@#for ilag in 21:40
+R_obs(@{ilag}), e_ys, [0 0.25]; //[response after 4th year to 10th year]
+@#endfor
+end;
+*/
+
+moment_calibration;
+//y_obs,y_obs, [0.8 1.1]; //[unconditional variance]
+y_obs,y_obs(-(1:4)), +; //[first year acf]
+@#for ilag in 0:1
+y_obs,R_obs(-@{ilag}), -; //[ccf]
+@#endfor
+end;
+
+dynare_sensitivity(prior_range=0);
+/*
+estimation(datafile='data_ca1.m',first_obs=8,nobs=79,mh_nblocks=2, mode_file = ls2003a_mode,
+  prefilter=1,mh_jscale=0.5,mh_replic=5000, mode_compute=0, mh_drop=0.6, bayesian_irf);
+//stoch_simul(irf=40, order=1, relative_irf) y_obs R_obs pie_obs dq de;
+stoch_simul(irf=40, order=1) y_obs R_obs pie_obs dq de;
+*/
diff --git a/tests/kalman/lyapunov/fs2000_lyap.mod b/tests/kalman/lyapunov/fs2000_lyap.mod
new file mode 100644
index 0000000000000000000000000000000000000000..10e1ed1f96abe0a9b7b02961157deed3eb240573
--- /dev/null
+++ b/tests/kalman/lyapunov/fs2000_lyap.mod
@@ -0,0 +1,136 @@
+/*
+ * This file replicates the estimation of the cash in advance model described
+ * Frank Schorfheide (2000): "Loss function-based evaluation of DSGE models",
+ * Journal of Applied Econometrics, 15(6), 645-670.
+ *
+ * The data are in file "fsdat_simul.m", and have been artificially generated.
+ * They are therefore different from the original dataset used by Schorfheide.
+ *
+ * The equations are taken from J. Nason and T. Cogley (1994): "Testing the
+ * implications of long-run neutrality for monetary business cycle models",
+ * Journal of Applied Econometrics, 9, S37-S70.
+ * Note that there is an initial minus sign missing in equation (A1), p. S63.
+ *
+ * This implementation was written by Michel Juillard. Please note that the
+ * following copyright notice only applies to this Dynare implementation of the
+ * model.
+ */
+
+/*
+ * Copyright (C) 2004-2010 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/>.
+ */
+
+var m P c e W R k d n l gy_obs gp_obs y dA;
+varexo e_a e_m;
+
+parameters alp bet gam mst rho psi del;
+
+alp = 0.33;
+bet = 0.99;
+gam = 0.003;
+mst = 1.011;
+rho = 0.7;
+psi = 0.787;
+del = 0.02;
+
+model;
+dA = exp(gam+e_a);
+log(m) = (1-rho)*log(mst) + rho*log(m(-1))+e_m;
+-P/(c(+1)*P(+1)*m)+bet*P(+1)*(alp*exp(-alp*(gam+log(e(+1))))*k^(alp-1)*n(+1)^(1-alp)+(1-del)*exp(-(gam+log(e(+1)))))/(c(+2)*P(+2)*m(+1))=0;
+W = l/n;
+-(psi/(1-psi))*(c*P/(1-n))+l/n = 0;
+R = P*(1-alp)*exp(-alp*(gam+e_a))*k(-1)^alp*n^(-alp)/W;
+1/(c*P)-bet*P*(1-alp)*exp(-alp*(gam+e_a))*k(-1)^alp*n^(1-alp)/(m*l*c(+1)*P(+1)) = 0;
+c+k = exp(-alp*(gam+e_a))*k(-1)^alp*n^(1-alp)+(1-del)*exp(-(gam+e_a))*k(-1);
+P*c = m;
+m-1+d = l;
+e = exp(e_a);
+y = k(-1)^alp*n^(1-alp)*exp(-alp*(gam+e_a));
+gy_obs = dA*y/y(-1);
+gp_obs = (P/P(-1))*m(-1)/dA;
+end;
+
+shocks;
+var e_a; stderr 0.014;
+var e_m; stderr 0.005;
+end;
+
+steady_state_model;
+  dA = exp(gam);
+  gst = 1/dA;
+  m = mst;
+  khst = ( (1-gst*bet*(1-del)) / (alp*gst^alp*bet) )^(1/(alp-1));
+  xist = ( ((khst*gst)^alp - (1-gst*(1-del))*khst)/mst )^(-1);
+  nust = psi*mst^2/( (1-alp)*(1-psi)*bet*gst^alp*khst^alp );
+  n  = xist/(nust+xist);
+  P  = xist + nust;
+  k  = khst*n;
+
+  l  = psi*mst*n/( (1-psi)*(1-n) );
+  c  = mst/P;
+  d  = l - mst + 1;
+  y  = k^alp*n^(1-alp)*gst^alp;
+  R  = mst/bet;
+  W  = l/n;
+  ist  = y-c;
+  q  = 1 - d;
+
+  e = 1;
+  
+  gp_obs = m/dA;
+  gy_obs = dA;
+end;
+
+steady;
+
+check;
+
+estimated_params;
+alp, beta_pdf, 0.356, 0.02;
+bet, beta_pdf, 0.993, 0.002;
+gam, normal_pdf, 0.0085, 0.003;
+mst, normal_pdf, 1.0002, 0.007;
+rho, beta_pdf, 0.129, 0.223;
+psi, beta_pdf, 0.65, 0.05;
+del, beta_pdf, 0.01, 0.005;
+stderr e_a, inv_gamma_pdf, 0.035449, inf;
+stderr e_m, inv_gamma_pdf, 0.008862, inf;
+end;
+
+varobs gp_obs gy_obs;
+
+options_.plot_priors=0;
+
+options_.lyapunov_fp = 0;
+options_.lyapunov_db = 0;
+options_.lyapunov_srs = 0;
+
+estimation(lyapunov=doubling,order=1,datafile='../../fs2000/fsdat_simul', nobs=192, loglinear, mh_replic=0, mh_nblocks=1, mh_jscale=0.8,nograph);
+
+
+if (isoctave && user_has_octave_forge_package('control')) || (~isoctave && user_has_matlab_license('control_toolbox'))
+    options_.lyapunov_fp = 0;
+    options_.lyapunov_db = 0;
+    options_.lyapunov_srs = 0;
+    estimation(lyapunov=square_root_solver,order=1,datafile='../../fs2000/fsdat_simul', nobs=192, loglinear, mh_replic=0, mh_nblocks=1, mh_jscale=0.8,nograph);
+end
+
+options_.lyapunov_fp = 0;
+options_.lyapunov_db = 0;
+options_.lyapunov_srs = 0;
+estimation(lyapunov=fixed_point,order=1,datafile='../../fs2000/fsdat_simul', nobs=192, loglinear, mh_replic=0, mh_nblocks=1, mh_jscale=0.8,nograph);
\ No newline at end of file
diff --git a/tests/kalman_filter_smoother/check_variable_dimensions/fs2000.mod b/tests/kalman_filter_smoother/check_variable_dimensions/fs2000.mod
new file mode 100644
index 0000000000000000000000000000000000000000..f13639d24fb268f7ed63e6e600afe7a1a5a2e3be
--- /dev/null
+++ b/tests/kalman_filter_smoother/check_variable_dimensions/fs2000.mod
@@ -0,0 +1,193 @@
+/*
+ * This file replicates the estimation of the cash in advance model described
+ * Frank Schorfheide (2000): "Loss function-based evaluation of DSGE models",
+ * Journal of Applied Econometrics, 15(6), 645-670.
+ *
+ * The data are in file "fsdat_simul.m", and have been artificially generated.
+ * They are therefore different from the original dataset used by Schorfheide.
+ *
+ * The equations are taken from J. Nason and T. Cogley (1994): "Testing the
+ * implications of long-run neutrality for monetary business cycle models",
+ * Journal of Applied Econometrics, 9, S37-S70.
+ * Note that there is an initial minus sign missing in equation (A1), p. S63.
+ *
+ * This implementation was written by Michel Juillard. Please note that the
+ * following copyright notice only applies to this Dynare implementation of the
+ * model.
+ */
+
+/*
+ * Copyright (C) 2004-2010 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/>.
+ */
+
+var m P c e W R k d n l gy_obs gp_obs y dA;
+varexo e_a e_m;
+
+parameters alp bet gam mst rho psi del;
+
+alp = 0.33;
+bet = 0.99;
+gam = 0.003;
+mst = 1.011;
+rho = 0.7;
+psi = 0.787;
+del = 0.02;
+
+model;
+dA = exp(gam+e_a);
+log(m) = (1-rho)*log(mst) + rho*log(m(-1))+e_m;
+-P/(c(+1)*P(+1)*m)+bet*P(+1)*(alp*exp(-alp*(gam+log(e(+1))))*k^(alp-1)*n(+1)^(1-alp)+(1-del)*exp(-(gam+log(e(+1)))))/(c(+2)*P(+2)*m(+1))=0;
+W = l/n;
+-(psi/(1-psi))*(c*P/(1-n))+l/n = 0;
+R = P*(1-alp)*exp(-alp*(gam+e_a))*k(-1)^alp*n^(-alp)/W;
+1/(c*P)-bet*P*(1-alp)*exp(-alp*(gam+e_a))*k(-1)^alp*n^(1-alp)/(m*l*c(+1)*P(+1)) = 0;
+c+k = exp(-alp*(gam+e_a))*k(-1)^alp*n^(1-alp)+(1-del)*exp(-(gam+e_a))*k(-1);
+P*c = m;
+m-1+d = l;
+e = exp(e_a);
+y = k(-1)^alp*n^(1-alp)*exp(-alp*(gam+e_a));
+gy_obs = dA*y/y(-1);
+gp_obs = (P/P(-1))*m(-1)/dA;
+end;
+
+shocks;
+var e_a; stderr 0.014;
+var e_m; stderr 0.005;
+end;
+
+steady_state_model;
+  dA = exp(gam);
+  gst = 1/dA;
+  m = mst;
+  khst = ( (1-gst*bet*(1-del)) / (alp*gst^alp*bet) )^(1/(alp-1));
+  xist = ( ((khst*gst)^alp - (1-gst*(1-del))*khst)/mst )^(-1);
+  nust = psi*mst^2/( (1-alp)*(1-psi)*bet*gst^alp*khst^alp );
+  n  = xist/(nust+xist);
+  P  = xist + nust;
+  k  = khst*n;
+
+  l  = psi*mst*n/( (1-psi)*(1-n) );
+  c  = mst/P;
+  d  = l - mst + 1;
+  y  = k^alp*n^(1-alp)*gst^alp;
+  R  = mst/bet;
+  W  = l/n;
+  ist  = y-c;
+  q  = 1 - d;
+
+  e = 1;
+  
+  gp_obs = m/dA;
+  gy_obs = dA;
+end;
+
+steady;
+
+check;
+
+estimated_params;
+alp, beta_pdf, 0.356, 0.02;
+bet, beta_pdf, 0.993, 0.002;
+gam, normal_pdf, 0.0085, 0.003;
+mst, normal_pdf, 1.0002, 0.007;
+rho, beta_pdf, 0.129, 0.223;
+psi, beta_pdf, 0.65, 0.05;
+del, beta_pdf, 0.01, 0.005;
+stderr e_a, inv_gamma_pdf, 0.035449, inf;
+stderr e_m, inv_gamma_pdf, 0.008862, inf;
+stderr gp_obs, inv_gamma_pdf, 0.001, inf;
+end;
+
+varobs gp_obs gy_obs;
+
+estimation(order=1,datafile='../fsdat_simul', nobs=192, loglinear, mh_replic=2000, mh_nblocks=1, mh_jscale=0.8,forecast=8,smoother,filtered_vars,filter_step_ahead=[1:2],filter_decomposition)  m P c e W R k d y gy_obs;
+
+if size(oo_.PointForecast.deciles.gy_obs,1)~=9
+    error('Number of deciles must be 9')
+end
+
+if size(oo_.PointForecast.deciles.gy_obs,2)~=options_.forecast || ...
+        size(oo_.PointForecast.Mean.gy_obs,1)~=options_.forecast || ...
+        size(oo_.PointForecast.Median.gy_obs,1)~=options_.forecast || ...
+        size(oo_.PointForecast.Var.gy_obs,1)~=options_.forecast || ...
+        size(oo_.PointForecast.HPDinf.gy_obs,1)~=options_.forecast || ...
+        size(oo_.PointForecast.HPDsup.gy_obs,1)~=options_.forecast || ...
+        size(oo_.MeanForecast.deciles.gy_obs,2)~=options_.forecast || ...
+        size(oo_.MeanForecast.Mean.gy_obs,1)~=options_.forecast || ...
+        size(oo_.MeanForecast.Median.gy_obs,1)~=options_.forecast || ...
+        size(oo_.MeanForecast.Var.gy_obs,1)~=options_.forecast || ...
+        size(oo_.MeanForecast.HPDinf.gy_obs,1)~=options_.forecast || ...
+        size(oo_.MeanForecast.HPDsup.gy_obs,1)~=options_.forecast 
+    error('Forecasts have the wrong length')
+end
+
+if size(oo_.UpdatedVariables.deciles.gy_obs,2)~=options_.nobs || ...
+        size(oo_.UpdatedVariables.Mean.gy_obs,1)~=options_.nobs || ...
+        size(oo_.UpdatedVariables.Median.gy_obs,1)~=options_.nobs || ...
+        size(oo_.UpdatedVariables.Var.gy_obs,1)~=options_.nobs || ...
+        size(oo_.UpdatedVariables.HPDinf.gy_obs,1)~=options_.nobs || ...
+        size(oo_.UpdatedVariables.HPDsup.gy_obs,1)~=options_.nobs
+    error('Updated Variables have the wrong length')
+end
+
+if size(oo_.Filtered_Variables_1_step_ahead.deciles.gy_obs,2)~=options_.nobs || ...
+        size(oo_.Filtered_Variables_1_step_ahead.Mean.gy_obs,1)~=options_.nobs || ...
+        size(oo_.Filtered_Variables_1_step_ahead.Median.gy_obs,1)~=options_.nobs || ...
+        size(oo_.Filtered_Variables_1_step_ahead.Var.gy_obs,1)~=options_.nobs || ...
+        size(oo_.Filtered_Variables_1_step_ahead.HPDinf.gy_obs,1)~=options_.nobs || ...
+        size(oo_.Filtered_Variables_1_step_ahead.HPDsup.gy_obs,1)~=options_.nobs
+    error('Filtered_Variables_1_step_ahead have the wrong length')
+end
+
+
+if size(oo_.SmoothedVariables.deciles.gy_obs,2)~=options_.nobs || ...
+        size(oo_.SmoothedVariables.Mean.gy_obs,1)~=options_.nobs || ...
+        size(oo_.SmoothedVariables.Median.gy_obs,1)~=options_.nobs || ...
+        size(oo_.SmoothedVariables.Var.gy_obs,1)~=options_.nobs || ...
+        size(oo_.SmoothedVariables.HPDinf.gy_obs,1)~=options_.nobs || ...
+        size(oo_.SmoothedVariables.HPDsup.gy_obs,1)~=options_.nobs
+    error('Smoothed Variables have the wrong length')
+end
+
+if size(oo_.SmoothedShocks.deciles.e_a,2)~=options_.nobs || ...
+        size(oo_.SmoothedShocks.Mean.e_a,1)~=options_.nobs || ...
+        size(oo_.SmoothedShocks.Median.e_a,1)~=options_.nobs || ...
+        size(oo_.SmoothedShocks.Var.e_a,1)~=options_.nobs || ...
+        size(oo_.SmoothedShocks.HPDinf.e_a,1)~=options_.nobs || ...
+        size(oo_.SmoothedShocks.HPDsup.e_a,1)~=options_.nobs
+    error('Smoothed Shocks have the wrong length')
+end
+
+if size(oo_.FilteredVariables.deciles.gy_obs,2)~=options_.nobs || ...
+        size(oo_.FilteredVariables.Mean.gy_obs,1)~=options_.nobs || ...
+        size(oo_.FilteredVariables.Median.gy_obs,1)~=options_.nobs || ...
+        size(oo_.FilteredVariables.Var.gy_obs,1)~=options_.nobs || ...
+        size(oo_.FilteredVariables.HPDinf.gy_obs,1)~=options_.nobs || ...
+        size(oo_.FilteredVariables.HPDsup.gy_obs,1)~=options_.nobs
+    error('Filtered Variables have the wrong length')
+end
+
+if size(oo_.SmoothedMeasurementErrors.deciles.SE_EOBS_gp_obs,2)~=options_.nobs || ...
+        size(oo_.SmoothedMeasurementErrors.Mean.SE_EOBS_gp_obs,1)~=options_.nobs || ...
+        size(oo_.SmoothedMeasurementErrors.Median.SE_EOBS_gp_obs,1)~=options_.nobs || ...
+        size(oo_.SmoothedMeasurementErrors.Var.SE_EOBS_gp_obs,1)~=options_.nobs || ...
+        size(oo_.SmoothedMeasurementErrors.HPDinf.SE_EOBS_gp_obs,1)~=options_.nobs || ...
+        size(oo_.SmoothedMeasurementErrors.HPDsup.SE_EOBS_gp_obs,1)~=options_.nobs
+    error('SmoothedMeasurementErrors have the wrong length')
+end
+
diff --git a/tests/kalman_filter_smoother/check_variable_dimensions/fs2000_ML.mod b/tests/kalman_filter_smoother/check_variable_dimensions/fs2000_ML.mod
new file mode 100644
index 0000000000000000000000000000000000000000..6b396682cbff9ebe9ecf695fa6b12d143494c478
--- /dev/null
+++ b/tests/kalman_filter_smoother/check_variable_dimensions/fs2000_ML.mod
@@ -0,0 +1,161 @@
+/*
+ * This file replicates the estimation of the cash in advance model described
+ * Frank Schorfheide (2000): "Loss function-based evaluation of DSGE models",
+ * Journal of Applied Econometrics, 15(6), 645-670.
+ *
+ * The data are in file "fsdat_simul.m", and have been artificially generated.
+ * They are therefore different from the original dataset used by Schorfheide.
+ *
+ * The equations are taken from J. Nason and T. Cogley (1994): "Testing the
+ * implications of long-run neutrality for monetary business cycle models",
+ * Journal of Applied Econometrics, 9, S37-S70.
+ * Note that there is an initial minus sign missing in equation (A1), p. S63.
+ *
+ * This implementation was written by Michel Juillard. Please note that the
+ * following copyright notice only applies to this Dynare implementation of the
+ * model.
+ */
+
+/*
+ * Copyright (C) 2004-2010 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/>.
+ */
+
+var m P c e W R k d n l gy_obs gp_obs y dA;
+varexo e_a e_m;
+
+parameters alp bet gam mst rho psi del theta;
+
+alp = 0.33;
+bet = 0.99;
+gam = 0.003;
+mst = 1.011;
+rho = 0.7;
+psi = 0.787;
+del = 0.02;
+theta=0;
+
+model;
+dA = exp(gam+e_a);
+log(m) = (1-rho)*log(mst) + rho*log(m(-1))+e_m;
+-P/(c(+1)*P(+1)*m)+bet*P(+1)*(alp*exp(-alp*(gam+log(e(+1))))*k^(alp-1)*n(+1)^(1-alp)+(1-del)*exp(-(gam+log(e(+1)))))/(c(+2)*P(+2)*m(+1))=0;
+W = l/n;
+-(psi/(1-psi))*(c*P/(1-n))+l/n = 0;
+R = P*(1-alp)*exp(-alp*(gam+e_a))*k(-1)^alp*n^(-alp)/W;
+1/(c*P)-bet*P*(1-alp)*exp(-alp*(gam+e_a))*k(-1)^alp*n^(1-alp)/(m*l*c(+1)*P(+1)) = 0;
+c+k = exp(-alp*(gam+e_a))*k(-1)^alp*n^(1-alp)+(1-del)*exp(-(gam+e_a))*k(-1);
+P*c = m;
+m-1+d = l;
+e = exp(e_a);
+y = k(-1)^alp*n^(1-alp)*exp(-alp*(gam+e_a));
+gy_obs = dA*y/y(-1);
+gp_obs = (P/P(-1))*m(-1)/dA;
+end;
+
+steady_state_model;
+  dA = exp(gam);
+  gst = 1/dA;
+  m = mst;
+  khst = ( (1-gst*bet*(1-del)) / (alp*gst^alp*bet) )^(1/(alp-1));
+  xist = ( ((khst*gst)^alp - (1-gst*(1-del))*khst)/mst )^(-1);
+  nust = psi*mst^2/( (1-alp)*(1-psi)*bet*gst^alp*khst^alp );
+  n  = xist/(nust+xist);
+  P  = xist + nust;
+  k  = khst*n;
+
+  l  = psi*mst*n/( (1-psi)*(1-n) );
+  c  = mst/P;
+  d  = l - mst + 1;
+  y  = k^alp*n^(1-alp)*gst^alp;
+  R  = mst/bet;
+  W  = l/n;
+  ist  = y-c;
+  q  = 1 - d;
+
+  e = 1;
+  
+  gp_obs = m/dA;
+  gy_obs = dA;
+end;
+
+
+shocks;
+var e_a; stderr 0.014;
+var e_m; stderr 0.005;
+end;
+
+varobs gp_obs gy_obs;
+
+steady;
+check;
+
+estimated_params;
+alp, 0.356;
+gam,  0.0085;
+mst, 1.0002;
+rho, 0.129;
+psi, 0.65;
+del,  0.02;
+stderr e_a, 0.035449;
+stderr e_m, 0.008862;
+corr e_m, e_a, 0;
+stderr gp_obs, 0.01;
+end;
+options_.prior_trunc=0;
+estimation(order=1,datafile='../fsdat_simul', nobs=192, loglinear, forecast=8,smoother,filtered_vars,filter_step_ahead=[1,2,4],filter_decomposition,selected_variables_only)  m P c e W R k d y gy_obs;
+
+
+if size(oo_.FilteredVariablesKStepAhead,3)~=(options_.nobs+max(options_.filter_step_ahead)) || ...
+        size(oo_.FilteredVariablesKStepAhead,1)~=(length(options_.filter_step_ahead))
+    error('FilteredVariablesKStepAhead has the wrong length')    
+end
+
+if size(oo_.FilteredVariablesKStepAheadVariances,4)~=(options_.nobs+max(options_.filter_step_ahead)) || ...
+        size(oo_.FilteredVariablesKStepAheadVariances,1)~=(length(options_.filter_step_ahead))
+    error('FilteredVariablesKStepAhead has the wrong length')    
+end
+
+if size(oo_.FilteredVariablesShockDecomposition,4)~=(options_.nobs+max(options_.filter_step_ahead)) || ...
+        size(oo_.FilteredVariablesShockDecomposition,1)~=(length(options_.filter_step_ahead))
+    error('FilteredVariablesShockDecomposition has the wrong length')    
+end
+
+if size(oo_.SmoothedVariables.gy_obs,1)~=options_.nobs
+    error('SmoothedVariables has the wrong length')    
+end
+
+if size(oo_.FilteredVariables.gy_obs,1)~=options_.nobs
+    error('FilteredVariables has the wrong length')    
+end
+
+if size(oo_.UpdatedVariables.gy_obs,1)~=options_.nobs
+    error('UpdatedVariables has the wrong length')    
+end
+
+if size(oo_.SmoothedShocks.e_a,1)~=options_.nobs
+    error('SmoothedShocks has the wrong length')    
+end
+
+if size(oo_.SmoothedMeasurementErrors.gy_obs,1)~=options_.nobs
+    error('SmoothedShocks has the wrong length')    
+end
+
+if size(oo_.forecast.Mean.gy_obs,1)~=options_.forecast || ...
+    size(oo_.forecast.HPDinf.gy_obs,1)~=options_.forecast || ...
+    size(oo_.forecast.HPDsup.gy_obs,1)~=options_.forecast
+    error('Forecasts have the wrong length')    
+end
diff --git a/tests/optimal_policy/Ramsey/find_c.m b/tests/optimal_policy/Ramsey/find_c.m
new file mode 100644
index 0000000000000000000000000000000000000000..badafbf989ce633e4f345f545cfe8b04e10957ad
--- /dev/null
+++ b/tests/optimal_policy/Ramsey/find_c.m
@@ -0,0 +1,8 @@
+function c = find_c(c0,pai,beta,epsilon,phi,gamma,omega)
+c = csolve(@nk_ss,c0,[],1e-8,100,pai,beta,epsilon,phi,gamma,omega);
+end
+
+function r = nk_ss(c,pai,beta,epsilon,phi,gamma,omega)
+r = pai*(pai-1)/c - beta*pai*(pai-1)/c-epsilon*phi*(c+(omega/2)*(pai-1)^2)^(gamma+1)/omega +(c+(omega/2)*(pai-1)^2)*(epsilon-1)/(omega*c);
+
+end
\ No newline at end of file
diff --git a/tests/optimal_policy/Ramsey/oo_ramsey_policy_initval.mat b/tests/optimal_policy/Ramsey/oo_ramsey_policy_initval.mat
new file mode 100644
index 0000000000000000000000000000000000000000..ff829dd9dc5fbf2a4d9b0d649c50e1537c7a672f
Binary files /dev/null and b/tests/optimal_policy/Ramsey/oo_ramsey_policy_initval.mat differ
diff --git a/tests/optimal_policy/Ramsey/ramsey_ex.mod b/tests/optimal_policy/Ramsey/ramsey_ex.mod
new file mode 100644
index 0000000000000000000000000000000000000000..d28882f970334f18e752b5c89b1110022200438d
--- /dev/null
+++ b/tests/optimal_policy/Ramsey/ramsey_ex.mod
@@ -0,0 +1,63 @@
+/* Mod file tests the correctness of the Ramsey command when used together with a steady state file by
+ * - checking whether the results coincide with the ones when used with an initval block
+ * - checking whether between stoch_simul and ramsey_planner are consistent
+ * The example is taken from Juillard, Michel (2011): User manual for optimal policy package, 
+ * MONFISPOL FP7 project SSH-225149, Deliverable 1.1.2
+*/
+
+var pai, c, n, r, a;
+varexo u;
+parameters beta, rho, epsilon, omega, phi, gamma;
+
+beta=0.99;
+gamma=3;
+omega=17;
+epsilon=8;
+phi=1;
+rho=0.95;
+
+model;
+a = rho*a(-1)+u;
+1/c = beta*r/(c(+1)*pai(+1));
+pai*(pai-1)/c = beta*pai(+1)*(pai(+1)-1)/c(+1)+epsilon*phi*n^(gamma+1)/omega -exp(a)*n*(epsilon-1)/(omega*c);
+exp(a)*n = c+(omega/2)*(pai-1)^2;
+end;
+
+initval;
+r=1;
+end;
+
+steady_state_model;
+a = 0;
+pai = beta*r;
+c = find_c(0.96,pai,beta,epsilon,phi,gamma,omega);
+n = c+(omega/2)*(pai-1)^2;
+end;
+
+shocks;
+var u; stderr 0.008;
+end;
+
+planner_objective(ln(c)-phi*((n^(1+gamma))/(1+gamma)));
+ramsey_policy(planner_discount=0.99,order=1,instruments=(r));
+oo_ramsey_policy_steady_state_file=oo_;
+stoch_simul(periods=0, order=1, irf=25, nograph);
+if max(abs((oo_ramsey_policy_steady_state_file.steady_state-oo_.steady_state)))>1e-5 ...
+    || max(abs(oo_ramsey_policy_steady_state_file.dr.ys-oo_.dr.ys))>1e-5 ...
+    || max(max(abs(oo_ramsey_policy_steady_state_file.dr.ghx-oo_.dr.ghx)))>1e-5 ...
+    || max(max(abs(oo_ramsey_policy_steady_state_file.dr.ghu-oo_.dr.ghu)))>1e-5 ...
+    || max(max(abs(oo_ramsey_policy_steady_state_file.dr.Gy-oo_.dr.Gy)))>1e-5 ...
+    || max(abs((oo_ramsey_policy_steady_state_file.planner_objective_value-oo_.planner_objective_value)))>1e-5
+    error('Running stoch_simul after ramsey_policy leads to inconsistent results')
+end
+
+load oo_ramsey_policy_initval;
+
+if max(abs((oo_ramsey_policy_initval.steady_state-oo_.steady_state)))>1e-5 ...
+    || max(abs(oo_ramsey_policy_initval.dr.ys-oo_.dr.ys))>1e-5 ...
+    || max(max(abs(oo_ramsey_policy_initval.dr.ghx-oo_.dr.ghx)))>1e-5 ...
+    || max(max(abs(oo_ramsey_policy_initval.dr.ghu-oo_.dr.ghu)))>1e-5 ...
+    || max(max(abs(oo_ramsey_policy_initval.dr.Gy-oo_.dr.Gy)))>1e-5 ...
+    || max(abs((oo_ramsey_policy_initval.planner_objective_value-oo_.planner_objective_value)))>1e-5
+    error('Initval and steady state file yield different results')
+end
diff --git a/tests/optimal_policy/Ramsey/ramsey_ex_aux.mod b/tests/optimal_policy/Ramsey/ramsey_ex_aux.mod
new file mode 100644
index 0000000000000000000000000000000000000000..bcf0669746306a7adac88af0564d87d1237993e4
--- /dev/null
+++ b/tests/optimal_policy/Ramsey/ramsey_ex_aux.mod
@@ -0,0 +1,52 @@
+/* Mod file tests the correctness of the Ramsey command when used together with a steady state file by
+ * - checking whether the results coincide with the ones when used with an initval block
+ * - checking whether between stoch_simul and ramsey_planner are consistent
+ * The example is taken from Juillard, Michel (2011): User manual for optimal policy package, 
+ * MONFISPOL FP7 project SSH-225149, Deliverable 1.1.2
+*/
+
+var pai, c, n, r, a, junk_endo_backward,junk_endo_forward,junk_expectation,junk_exo_backward,junk_exo_forward;
+varexo u;
+parameters beta, rho, epsilon, omega, phi, gamma;
+
+beta=0.99;
+gamma=3;
+omega=17;
+epsilon=8;
+phi=1;
+rho=0.95;
+
+model;
+a = rho*a(-1)+u;
+1/c = beta*r/(c(+1)*pai(+1));
+pai*(pai-1)/c = beta*pai(+1)*(pai(+1)-1)/c(+1)+epsilon*phi*n^(gamma+1)/omega -exp(a)*n*(epsilon-1)/(omega*c);
+junk_endo_backward=c(+2);
+junk_endo_forward=c(-2);
+junk_expectation=EXPECTATION(-1)(c(+1));
+junk_exo_backward=u(-2);
+junk_exo_forward=u(+2);
+exp(a)*n = c+(omega/2)*(pai-1)^2;
+end;
+
+initval;
+r=1;
+end;
+
+steady_state_model;
+a = 0;
+pai = beta*r;
+c = find_c(0.96,pai,beta,epsilon,phi,gamma,omega);
+n = c+(omega/2)*(pai-1)^2;
+junk_endo_backward=c;
+junk_endo_forward=c;
+junk_expectation=c;
+junk_exo_backward=0;
+junk_exo_forward=0;
+end;
+
+shocks;
+var u; stderr 0.008;
+end;
+
+planner_objective(ln(c)-phi*((n^(1+gamma))/(1+gamma)));
+ramsey_policy(planner_discount=0.99,order=1,instruments=(r));
diff --git a/tests/optimal_policy/Ramsey/ramsey_ex_initval.mod b/tests/optimal_policy/Ramsey/ramsey_ex_initval.mod
new file mode 100644
index 0000000000000000000000000000000000000000..170b956f99aca58e2d75bda91de8de2e973598ff
--- /dev/null
+++ b/tests/optimal_policy/Ramsey/ramsey_ex_initval.mod
@@ -0,0 +1,52 @@
+/* Mod file tests the functioning of the Ramsey command when used together with an initval-block
+ * - Tests whether subsequent calls to ramsey_policy and stoch_simul are possible
+ * The example is taken from Juillard, Michel (2011): User manual for optimal policy package, 
+ * MONFISPOL FP7 project SSH-225149, Deliverable 1.1.2
+*/
+
+var pai, c, n, r, a;
+varexo u;
+parameters beta, rho, epsilon, omega, phi, gamma;
+
+beta=0.99;
+gamma=3;
+omega=17;
+epsilon=8;
+phi=1;
+rho=0.95;
+
+model;
+a = rho*a(-1)+u;
+1/c = beta*r/(c(+1)*pai(+1));
+pai*(pai-1)/c = beta*pai(+1)*(pai(+1)-1)/c(+1)+epsilon*phi*n^(gamma+1)/omega -exp(a)*n*(epsilon-1)/(omega*c);
+exp(a)*n = c+(omega/2)*(pai-1)^2;
+end;
+
+initval;
+r=1;
+end;
+
+initval;
+a = 0;
+pai = beta;
+c = 0.9665;
+n = 0.9673;
+end;
+
+shocks;
+var u; stderr 0.008;
+end;
+
+planner_objective(ln(c)-phi*((n^(1+gamma))/(1+gamma)));
+ramsey_policy(planner_discount=0.99,order=1,instruments=(r));
+oo_ramsey_policy_initval=oo_;
+%save oo_ramsey_policy_initval oo_ramsey_policy_initval
+stoch_simul(periods=0, order=1, irf=25, nograph);
+if max(abs((oo_ramsey_policy_initval.steady_state-oo_.steady_state)))>1e-5 ...
+    || max(abs(oo_ramsey_policy_initval.dr.ys-oo_.dr.ys))>1e-5 ...
+    || max(max(abs(oo_ramsey_policy_initval.dr.ghx-oo_.dr.ghx)))>1e-5 ...
+    || max(max(abs(oo_ramsey_policy_initval.dr.ghu-oo_.dr.ghu)))>1e-5 ...
+    || max(max(abs(oo_ramsey_policy_initval.dr.Gy-oo_.dr.Gy)))>1e-5 ...
+    || max(abs((oo_ramsey_policy_initval.planner_objective_value-oo_.planner_objective_value)))>1e-5
+    error('Running stoch_simul after ramsey_policy leads to inconsistent results')
+end
diff --git a/tests/optimal_policy/Ramsey/ramsey_ex_initval_AR2.mod b/tests/optimal_policy/Ramsey/ramsey_ex_initval_AR2.mod
new file mode 100644
index 0000000000000000000000000000000000000000..c10204922724e360e6076f046a0195defdadcde1
--- /dev/null
+++ b/tests/optimal_policy/Ramsey/ramsey_ex_initval_AR2.mod
@@ -0,0 +1,50 @@
+/* Mod file tests the correctness of the Ramsey command when Auxiliary variables for AR2 are used
+ * The example is adapted from Juillard, Michel (2011): User manual for optimal policy package, 
+ * MONFISPOL FP7 project SSH-225149, Deliverable 1.1.2
+*/
+
+var pai, c, n, r, a;
+varexo u;
+parameters beta, rho, epsilon, omega, phi, gamma;
+
+beta=0.99;
+gamma=3;
+omega=17;
+epsilon=8;
+phi=1;
+rho=0.95;
+
+model;
+log(a) = rho*log(a(-2))+u;
+1/c = beta*r/(c(+1)*pai(+1));
+pai*(pai-1)/c = beta*pai(+1)*(pai(+1)-1)/c(+1)+epsilon*phi*n^(gamma+1)/omega -a*n*(epsilon-1)/(omega*c);
+a*n = c+(omega/2)*(pai-1)^2;
+end;
+
+initval;
+r=1;
+end;
+
+initval;
+a = 1;
+pai = beta;
+c = 0.9665;
+n = 0.9673;
+end;
+
+shocks;
+var u; stderr 0.008;
+end;
+
+planner_objective(ln(c)-phi*((n^(1+gamma))/(1+gamma)));
+ramsey_policy(planner_discount=0.99,order=1,instruments=(r));
+oo_ramsey_policy_initval_AR2=oo_;
+stoch_simul(periods=0, order=1, irf=25, nograph);
+if max(abs((oo_ramsey_policy_initval_AR2.steady_state-oo_.steady_state)))>1e-5 ...
+    || max(abs(oo_ramsey_policy_initval_AR2.dr.ys-oo_.dr.ys))>1e-5 ...
+    || max(max(abs(oo_ramsey_policy_initval_AR2.dr.ghx-oo_.dr.ghx)))>1e-5 ...
+    || max(max(abs(oo_ramsey_policy_initval_AR2.dr.ghu-oo_.dr.ghu)))>1e-5 ...
+    || max(max(abs(oo_ramsey_policy_initval_AR2.dr.Gy-oo_.dr.Gy)))>1e-5 ...
+    || max(abs((oo_ramsey_policy_initval_AR2.planner_objective_value-oo_.planner_objective_value)))>1e-5
+    error('Running stoch_simul after ramsey_policy leads to inconsistent results')
+end
\ No newline at end of file
diff --git a/tests/optimal_policy/Ramsey/ramsey_ex_wrong_ss_file.mod b/tests/optimal_policy/Ramsey/ramsey_ex_wrong_ss_file.mod
new file mode 100644
index 0000000000000000000000000000000000000000..3b44bad17b16465d7c398c498511b74928c7fb4c
--- /dev/null
+++ b/tests/optimal_policy/Ramsey/ramsey_ex_wrong_ss_file.mod
@@ -0,0 +1,41 @@
+/* Mod file tests whether the Ramsey command correctly filters out an incorrect steady state 
+ * The example is taken from Juillard, Michel (2011): User manual for optimal policy package, 
+ * MONFISPOL FP7 project SSH-225149, Deliverable 1.1.2
+*/
+
+
+var pai, c, n, r, a;
+varexo u;
+parameters beta, rho, epsilon, omega, phi, gamma;
+
+beta=0.99;
+gamma=3;
+omega=17;
+epsilon=8;
+phi=1;
+rho=0.95;
+
+model;
+a = rho*a(-1)+u;
+1/c = beta*r/(c(+1)*pai(+1));
+pai*(pai-1)/c = beta*pai(+1)*(pai(+1)-1)/c(+1)+epsilon*phi*n^(gamma+1)/omega -exp(a)*n*(epsilon-1)/(omega*c);
+exp(a)*n = c+(omega/2)*(pai-1)^2;
+end;
+
+initval;
+r=1;
+end;
+
+steady_state_model;
+a = 1;
+pai = beta*r;
+c = find_c(0.96,pai,beta,epsilon,phi,gamma,omega);
+n = c+(omega/2)*(pai-1)^2;
+end;
+
+shocks;
+var u; stderr 0.008;
+end;
+
+planner_objective(ln(c)-phi*((n^(1+gamma))/(1+gamma)));
+ramsey_policy(planner_discount=0.99,order=1,instruments=(r));
\ No newline at end of file
diff --git a/tests/optimal_policy/osr_example_obj_corr_non_stat_vars.mod b/tests/optimal_policy/osr_example_obj_corr_non_stat_vars.mod
new file mode 100644
index 0000000000000000000000000000000000000000..4720a2566f7c49c7418b379acb59cb6fb2db49f8
--- /dev/null
+++ b/tests/optimal_policy/osr_example_obj_corr_non_stat_vars.mod
@@ -0,0 +1,636 @@
+//This mod-file tests the value of the objective function in the presence of non-stationary variables
+
+Var
+
+
+p_U_Hat            
+
+pi_U_Hat               
+r_Hat              
+r_Gap
+r_Eff
+realrate_U_Hat
+realrate_U_Eff
+realrate_U_Gap     
+
+
+c_U_Gap            
+c_U_Eff
+c_U_Hat
+g_U_Gap            
+g_U_Eff
+g_U_Hat
+
+y_U_Gap            
+y_U_Eff
+y_U_Hat
+
+l_U_Gap             
+l_U_Eff
+l_U_Hat
+
+a_U_Hat            
+
+
+
+p_A_Hat             
+pc_A_Hat           
+
+tt_A_Hat           
+tt_A_Gap
+tt_A_Eff
+
+pi_A_Hat           
+pic_A_Hat         
+c_A_Gap             
+c_A_Eff
+c_A_Hat
+
+g_A_Gap             
+g_A_Eff
+g_A_Hat
+
+realrate_A_Hat      
+
+l_A_Gap             
+l_A_Eff
+l_A_Hat
+
+muW_A_Hat          
+y_A_Gap             
+y_A_Eff
+y_A_Hat
+
+a_A_Hat             
+mc_A_Hat           
+
+tau_A_Hat           
+tau_A_Gap
+tau_A_Eff
+
+Kdebt_A        
+                    
+
+
+
+
+
+p_B_Hat             
+pc_B_Hat            
+
+tt_B_Hat            
+tt_B_Gap
+tt_B_Eff
+
+pi_B_Hat           
+pic_B_Hat          
+c_B_Gap             
+c_B_Eff
+c_B_Hat
+
+g_B_Gap             
+g_B_Eff
+g_B_Hat
+
+realrate_B_Hat      
+
+l_B_Gap             
+l_B_Eff
+l_B_Hat
+
+muW_B_Hat          
+y_B_Gap             
+y_B_Eff
+y_B_Hat
+
+a_B_Hat             
+mc_B_Hat          
+
+tau_B_Hat          
+tau_B_Gap
+tau_B_Eff
+
+Kdebt_B        
+
+
+;
+
+
+%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+%%DECLARATION OF EXOGENOUS VARIABLES%%
+%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+
+Varexo
+
+eps_muW_A       
+eps_a_A         
+
+eps_muW_B       
+eps_a_B         
+
+; 
+
+%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+%%DECLARATION OF PARAMETERS%%
+%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+
+parameters
+n               
+alpha           
+beta            
+rho             
+lambdaA         
+lambdaB         
+sigma          
+chi             
+psi             
+
+epsilon         
+muP             
+gamma           
+ell             
+phi_GY          
+phi_caps       
+
+theta_A         
+               
+theta_B         
+                
+phi_A           
+phi_B          
+
+
+%%%%%%
+//Rule Parameters
+
+ruleR_U_y      
+ruleR_U_pi     
+ruleR_U_debt
+
+ruleG_A_y
+ruleG_A_tt
+ruleG_A_debt
+
+
+ruleG_B_y
+ruleG_B_tt
+ruleG_B_debt
+
+
+
+ruleT_A_y
+ruleT_A_tt
+ruleT_A_debt
+
+
+
+ruleT_B_y
+ruleT_B_tt
+ruleT_B_debt
+
+%%%%%%
+
+
+
+rho_a_A         
+rho_a_B	
+rho_muW_A      
+rho_muW_B
+rho_mp          
+
+
+
+r_SS
+
+muW_SS                  
+tau_A_SS                
+DebtOutput_A_SS         
+
+
+tau_B_SS
+DebtOutput_B_SS    
+
+
+;
+
+
+%%%%%%%%%%%%%%%%%%%%%%%%
+%%SET PARAMETER VALUES%%
+%%%%%%CALIBRATION%%%%%%%
+%%%%%%%%%%%%%%%%%%%%%%%%
+n = 0.5; 
+alpha = 0.4;    
+beta = 0.99 ;   
+rho = -log(beta);
+lambdaA = 1-(1-n)*alpha;
+lambdaB = 1-n*alpha;
+sigma = 0.4;   
+chi = 3;    
+psi = 0.4;    
+
+epsilon = 11;  
+muP = 1/(epsilon - 1);
+gamma	= 4.5;
+ell = 11;      
+
+phi_GY = 0.25; 
+phi_caps = alpha*(gamma-(1-alpha)*(-gamma+sigma));
+
+theta_A = 0.75;     
+theta_B = 0.75;     
+phi_A = (1 - theta_A*beta)*(1 - theta_A)/(theta_A*(1 + epsilon*chi)); 
+phi_B = (1 - theta_B*beta)*(1 - theta_B)/(theta_B*(1 + epsilon*chi));  
+
+
+
+
+//Rule Parameters
+
+ruleR_U_y = 0.5;     
+ruleR_U_pi = 1.5;     
+ruleR_U_debt = 0;
+
+
+ruleG_A_y = 0;
+ruleG_A_tt = 0;
+ruleG_A_debt = -0.05;
+
+
+ruleG_B_y = ruleG_A_y;
+ruleG_B_tt = 0;
+ruleG_B_debt = ruleG_A_debt;
+
+
+ruleT_A_y = 0;
+ruleT_A_tt = 0;
+ruleT_A_debt = 0.05;
+
+
+ruleT_B_y = ruleT_A_y;
+ruleT_B_tt = 0;
+ruleT_B_debt = ruleT_A_debt;
+
+
+
+%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+
+rho_a_A = 0.85;    
+rho_a_B = 0.85;
+rho_muW_A = 0;
+rho_muW_B = 0;
+rho_mp = 0;      
+
+
+
+%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+%%%%%%% STEADY STATE VALUES %%%%%%%
+%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 
+muW_SS = 1/(ell - 1);
+
+r_SS = log(1/beta);
+
+DebtOutput_A_SS = 4*0.6;
+                      
+DebtOutput_B_SS = 4*0.6; 
+
+
+tau_A_SS = phi_GY + r_SS*DebtOutput_A_SS; 
+tau_B_SS = phi_GY + r_SS*DebtOutput_B_SS; 
+
+
+
+
+
+
+
+model(linear);
+
+
+p_U_Hat = n*p_A_Hat + (1-n)*p_B_Hat; 
+pi_U_Hat = n*pi_A_Hat + (1-n)*pi_B_Hat; 
+
+
+c_U_Gap = c_U_Gap(+1)- sigma*(r_Gap - pi_U_Hat(+1));
+
+
+realrate_U_Gap = realrate_U_Hat - realrate_U_Eff; 
+realrate_U_Eff = ((1 + chi)/(1 + chi*(phi_GY*psi + (1 - phi_GY)*sigma)))*(a_U_Hat(+1) - a_U_Hat); 
+
+realrate_U_Hat = r_Hat - pi_U_Hat(+1);
+
+
+r_Eff = ((1 + chi)/(1 + chi*(phi_GY*psi + (1 - phi_GY)*sigma)))*(a_U_Hat(+1) - a_U_Hat);
+r_Hat = r_Gap + r_Eff;
+
+
+
+// Interest rate rule
+r_Gap = ruleR_U_y*y_U_Gap(-1) + ruleR_U_pi*pi_U_Hat(-1) + ruleR_U_debt*(n*Kdebt_A(-1) + (1-n)*Kdebt_B(-1));
+
+
+
+
+c_U_Gap = n*c_A_Gap + (1-n)*c_B_Gap; 
+c_U_Eff = n*c_A_Eff + (1-n)*c_B_Eff;
+c_U_Hat = n*c_A_Hat + (1-n)*c_B_Hat;
+
+g_U_Gap = n*g_A_Gap + (1-n)*g_B_Gap; 
+g_U_Eff = n*g_A_Eff + (1-n)*g_B_Eff;
+g_U_Hat = n*g_A_Hat + (1-n)*g_B_Hat;
+
+
+y_U_Gap = n*y_A_Gap + (1-n)*y_B_Gap; 
+y_U_Eff = n*y_A_Eff + (1-n)*y_B_Eff;
+y_U_Hat = n*y_A_Hat + (1-n)*y_B_Hat;
+
+l_U_Gap = n*l_A_Gap + (1-n)*l_B_Gap; 
+l_U_Eff = n*l_A_Eff + (1-n)*l_B_Eff;
+l_U_Hat = n*l_A_Hat + (1-n)*l_B_Hat;
+
+a_U_Hat = n*a_A_Hat + (1-n)*a_B_Hat; 
+
+
+tt_A_Hat = (p_U_Hat - p_A_Hat)/(1-n);                   
+
+pi_A_Hat = p_A_Hat - p_A_Hat(-1); 			
+pic_A_Hat = pc_A_Hat - pc_A_Hat(-1); 		
+
+
+pic_A_Hat = pi_A_Hat + (1-lambdaA)*(tt_A_Hat - tt_A_Hat(-1)); 
+			
+		
+
+c_A_Eff = (((1 + chi)*sigma)/(1 + chi*(phi_GY*psi + (1 - phi_GY)*sigma)))*a_U_Hat + (((1 - alpha)*(1 + chi)*sigma)/(1 + chi*(phi_GY*psi + (1 - phi_GY)*(gamma + (sigma - gamma)*(1 - 2*alpha + alpha*alpha)))))*(a_A_Hat - a_U_Hat);
+
+g_A_Eff = (((1 + chi)*psi)/(1 + chi*(phi_GY*psi + (1 - phi_GY)*sigma)))*a_U_Hat + (((1 + chi)*psi)/(1 + chi*(phi_GY*psi + (1 - phi_GY)*(gamma + (sigma - gamma)*(1 - 2*alpha + alpha*alpha)))))*(a_A_Hat - a_U_Hat);
+
+y_A_Eff = (((1 + chi)*(phi_GY*psi + (1 - phi_GY)*sigma))/(1 + chi*(phi_GY*psi + (1 - phi_GY)*sigma)))*a_U_Hat + (((1 + chi)*(phi_GY*psi + (1 - phi_GY)*(gamma + (sigma - gamma)*(1 - 2*alpha + alpha*alpha))))/(1 + chi*(phi_GY*psi + (1 - phi_GY)*(gamma + (sigma - gamma)*(1 - 2*alpha + alpha*alpha)))))*(a_A_Hat - a_U_Hat);
+
+l_A_Eff = y_A_Eff - a_A_Hat;
+
+
+realrate_A_Hat = r_Hat - pic_A_Hat(+1);
+
+
+tt_A_Gap = tt_A_Hat - tt_A_Eff;
+tt_A_Eff = ((1 + chi)/(1 + chi*(phi_GY*psi + (1 - phi_GY)*(gamma + (sigma - gamma)*(1 - 2*alpha + alpha*alpha)))))*((a_A_Hat - a_U_Hat)/(1-n)); 
+
+
+y_A_Gap = l_A_Gap; 
+
+
+pi_A_Hat = beta*pi_A_Hat(+1)+ phi_A*mc_A_Hat;
+
+mc_A_Hat = tau_A_Gap/(1 - tau_A_SS) +(chi + 1/((1- phi_GY)*(phi_caps+sigma*(1-alpha))))* y_A_Gap - (phi_GY /((1- phi_GY)*(phi_caps+sigma*(1-alpha))))*g_A_Gap + (1/(sigma*(1- phi_GY))- 1/((1- phi_GY)*(phi_caps+sigma*(1-alpha))))* y_U_Gap - phi_GY *(1/(sigma*(1 - phi_GY)) - 1/((1- phi_GY)*(phi_caps+sigma*(1-alpha))))*g_U_Gap;
+
+
+tau_A_Hat = tau_A_Gap + tau_A_Eff;
+tau_A_Eff = - (1 - tau_A_SS)*muW_A_Hat;
+
+
+y_A_Gap = (1- phi_GY)*c_U_Gap + (1 - phi_GY)*(sigma*(1 - alpha) + phi_caps)*(1-n)*tt_A_Gap + phi_GY*g_A_Gap;
+
+
+
+Kdebt_A - ((1 + r_SS)/r_SS)*(tau_A_SS - phi_GY)*r_Hat= (1/beta)*(Kdebt_A(-1) - ((1 + r_SS)/r_SS)*(tau_A_SS - phi_GY)*pi_A_Hat + (phi_GY*g_A_Gap - tau_A_SS*y_A_Gap - tau_A_Gap)) + (1/beta)*(phi_GY*g_A_Eff - tau_A_SS*y_A_Eff + (1 - tau_A_SS)*muW_A_Hat) + (1/beta)*((1 + r_SS)/r_SS)*(tau_A_SS - phi_GY)*alpha*(1-n)*(tt_A_Gap(-1) -(1/(1 + r_SS))*tt_A_Gap) + (1/beta)*((1 + r_SS)/r_SS)*(tau_A_SS - phi_GY)*alpha*(1-n)*(tt_A_Eff(-1) -(1/(1 + r_SS))*tt_A_Eff); 
+
+
+
+//FISCAL RULES
+
+g_A_Gap = ruleG_A_y*(y_A_Gap(-1) - y_U_Gap(-1)) + ruleG_A_tt*tt_A_Gap(-1) + ruleG_A_debt*Kdebt_A(-1); 
+
+tau_A_Gap = ruleT_A_y*(y_A_Gap(-1) - y_U_Gap(-1)) + ruleT_A_tt*tt_A_Gap(-1)+ ruleT_A_debt*Kdebt_A(-1); 
+
+
+c_A_Hat = c_A_Gap + c_A_Eff;
+g_A_Hat = g_A_Gap + g_A_Eff;
+y_A_Hat = y_A_Gap + y_A_Eff;
+l_A_Hat = l_A_Gap + l_A_Eff;
+
+
+
+
+
+
+
+tt_B_Hat = (p_U_Hat - p_B_Hat)/n;                  
+
+pi_B_Hat = p_B_Hat - p_B_Hat(-1); 			
+pic_B_Hat = pc_B_Hat - pc_B_Hat(-1); 		
+
+pic_B_Hat = pi_B_Hat + (1-lambdaB)*(tt_B_Hat - tt_B_Hat(-1)); 
+			
+
+c_B_Eff = (((1 + chi)*sigma)/(1 + chi*(phi_GY*psi + (1 - phi_GY)*sigma)))*a_U_Hat + (((1 - alpha)*(1 + chi)*sigma)/(1 + chi*(phi_GY*psi + (1 - phi_GY)*(gamma + (sigma - gamma)*(1 - 2*alpha + alpha*alpha)))))*(a_B_Hat - a_U_Hat);
+
+g_B_Eff = (((1 + chi)*psi)/(1 + chi*(phi_GY*psi + (1 - phi_GY)*sigma)))*a_U_Hat + (((1 + chi)*psi)/(1 + chi*(phi_GY*psi + (1 - phi_GY)*(gamma + (sigma - gamma)*(1 - 2*alpha + alpha*alpha)))))*(a_B_Hat - a_U_Hat);
+
+y_B_Eff = (((1 + chi)*(phi_GY*psi + (1 - phi_GY)*sigma))/(1 + chi*(phi_GY*psi + (1 - phi_GY)*sigma)))*a_U_Hat + (((1 + chi)*(phi_GY*psi + (1 - phi_GY)*(gamma + (sigma - gamma)*(1 - 2*alpha + alpha*alpha))))/(1 + chi*(phi_GY*psi + (1 - phi_GY)*(gamma + (sigma - gamma)*(1 - 2*alpha + alpha*alpha)))))*(a_B_Hat - a_U_Hat);
+
+l_B_Eff = y_B_Eff - a_B_Hat;
+
+
+realrate_B_Hat = r_Hat - pic_B_Hat(+1);
+
+
+c_A_Gap = c_B_Gap + sigma*(1 - alpha)*((1-n)*tt_A_Gap-n*(tt_B_Gap));
+
+
+tt_B_Gap = tt_B_Hat - tt_B_Eff;
+tt_B_Eff = ((1 + chi)/(1 + chi*(phi_GY*psi + (1 - phi_GY)*(gamma + (sigma - gamma)*(1 - 2*alpha + alpha*alpha)))))*((a_B_Hat - a_U_Hat)/n); 
+
+
+y_B_Gap = l_B_Gap; //l_B_Gap = y_B_Gap + z_B , up to a first order approximation z_B=0
+
+
+pi_B_Hat = beta*pi_B_Hat(+1)+ phi_B*mc_B_Hat;
+
+mc_B_Hat = tau_B_Gap/(1 - tau_B_SS) +(chi + 1/((1- phi_GY)*(phi_caps+sigma*(1-alpha))))* y_B_Gap - (phi_GY /((1- phi_GY)*(phi_caps+sigma*(1-alpha))))*g_B_Gap + (1/(sigma*(1- phi_GY))- 1/((1- phi_GY)*(phi_caps+sigma*(1-alpha))))* y_U_Gap - phi_GY *(1/(sigma*(1 - phi_GY)) - 1/((1- phi_GY)*(phi_caps+sigma*(1-alpha))))*g_U_Gap;
+
+
+tau_B_Hat = tau_B_Gap + tau_B_Eff;
+tau_B_Eff = - (1 - tau_B_SS)*muW_B_Hat;
+
+
+y_B_Gap = (1- phi_GY)*c_U_Gap + (1 - phi_GY)*(sigma*(1 - alpha) + phi_caps)*n*tt_B_Gap + phi_GY*g_B_Gap;
+
+
+Kdebt_B - ((1 + r_SS)/r_SS)*(tau_B_SS - phi_GY)*r_Hat= (1/beta)*(Kdebt_B(-1) - ((1 + r_SS)/r_SS)*(tau_B_SS - phi_GY)*pi_B_Hat + (phi_GY*g_B_Gap - tau_B_SS*y_B_Gap - tau_B_Gap)) + (1/beta)*(phi_GY*g_B_Eff - tau_B_SS*y_B_Eff + (1 - tau_B_SS)*muW_B_Hat) + (1/beta)*((1 + r_SS)/r_SS)*(tau_B_SS - phi_GY)*alpha*n*(tt_B_Gap(-1) -(1/(1 + r_SS))*tt_B_Gap) + (1/beta)*((1 + r_SS)/r_SS)*(tau_B_SS - phi_GY)*alpha*n*(tt_B_Eff(-1) -(1/(1 + r_SS))*tt_B_Eff); 
+
+
+
+
+//FISCAL RULES
+
+g_B_Gap = ruleG_B_y*(y_B_Gap(-1) - y_U_Gap(-1)) + ruleG_B_tt*tt_B_Gap(-1) + ruleG_B_debt*Kdebt_B(-1); // function of domestic inflation since government spending is oriented only to domestic production  
+
+tau_B_Gap = ruleT_B_y*(y_B_Gap(-1) - y_U_Gap(-1)) + ruleT_B_tt*tt_B_Gap(-1) + ruleT_B_debt*Kdebt_B(-1); // function of domenstic inflation(!?)
+
+
+
+c_B_Hat = c_B_Gap + c_B_Eff;
+g_B_Hat = g_B_Gap + g_B_Eff;
+y_B_Hat = y_B_Gap + y_B_Eff;
+l_B_Hat = l_B_Gap + l_B_Eff;
+
+
+%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+%%%%%% Exogenous processes %%%%%%%%
+%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 
+
+a_A_Hat 	= rho_a_A* a_A_Hat(-1) + eps_a_A;
+a_B_Hat 	= rho_a_B* a_B_Hat(-1) + eps_a_B;
+
+muW_A_Hat 	= rho_muW_A*muW_A_Hat(-1) + eps_muW_A;
+muW_B_Hat	= rho_muW_B*muW_B_Hat(-1) + eps_muW_B;
+
+
+end;
+
+
+
+shocks;
+
+var eps_a_B; stderr 1;
+var eps_a_A; stderr 1;
+
+var eps_muW_B;  stderr 1;
+var eps_muW_A;  stderr 1;
+
+end;
+
+
+steady; 
+//check; //do not use this command under optimal policy!!!
+
+//stoch_simul(order=1, irf=100);
+
+
+
+%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+%Optimized Simple Rule (osr)
+%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%   
+
+
+optim_weights;
+                                                    //for country A
+
+pi_A_Hat (1/2)*n*(epsilon/phi_A);
+c_A_Gap (1/2)*n*(1 - phi_GY)*(1/sigma + (1 - phi_GY)*chi);
+g_A_Gap (1/2)*n*phi_GY*(1/psi + phi_GY*chi);
+tt_A_Gap (1/2)*n*(1 - phi_GY)*(gamma*alpha*(alpha - 2) + 2*phi_caps + (1 - phi_GY)*(phi_caps^2)*chi)*((1-n)^2); 
+
+c_A_Gap, g_A_Gap (1/2)*(1/2)*n*2*phi_GY*(1 - phi_GY)*chi;
+c_A_Gap, tt_A_Gap (1/2)*(1/2)*n*(1 - phi_GY)*(2*alpha + 2*(1 - phi_GY)*phi_caps*chi)*(1-n);
+g_A_Gap, tt_A_Gap (1/2)*(1/2)*n*2*phi_GY*(1 - phi_GY)*phi_caps*chi*(1-n);
+
+g_A_Gap, c_A_Gap (1/2)*(1/2)*n*2*phi_GY*(1 - phi_GY)*chi;
+tt_A_Gap, c_A_Gap (1/2)*(1/2)*n*(1 - phi_GY)*(2*alpha + 2*(1 - phi_GY)*phi_caps*chi)*(1-n);
+tt_A_Gap, g_A_Gap (1/2)*(1/2)*n*2*phi_GY*(1 - phi_GY)*phi_caps*chi*(1-n);
+
+
+
+                                                    //now, the same for country B
+pi_B_Hat (1/2)*(1-n)*(epsilon/phi_B);
+c_B_Gap (1/2)*(1-n)*(1 - phi_GY)*(1/sigma + (1 - phi_GY)*chi);
+g_B_Gap (1/2)*(1-n)*phi_GY*(1/psi + phi_GY*chi);
+tt_B_Gap (1/2)*(1-n)*(1 - phi_GY)*(gamma*alpha*(alpha - 2) + 2*phi_caps + (1 - phi_GY)*(phi_caps^2)*chi)*(n^2); 
+
+c_B_Gap, g_B_Gap (1/2)*(1/2)*(1-n)*2*phi_GY*(1 - phi_GY)*chi;
+c_B_Gap, tt_B_Gap (1/2)*(1/2)*(1-n)*(1 - phi_GY)*(2*alpha + 2*(1 - phi_GY)*phi_caps*chi)*n;
+g_B_Gap, tt_B_Gap (1/2)*(1/2)*(1-n)*2*phi_GY*(1 - phi_GY)*phi_caps*chi*n;
+
+g_B_Gap, c_B_Gap (1/2)*(1/2)*(1-n)*2*phi_GY*(1 - phi_GY)*chi;
+tt_B_Gap, c_B_Gap (1/2)*(1/2)*(1-n)*(1 - phi_GY)*(2*alpha + 2*(1 - phi_GY)*phi_caps*chi)*n;
+tt_B_Gap, g_B_Gap (1/2)*(1/2)*(1-n)*2*phi_GY*(1 - phi_GY)*phi_caps*chi*n;
+
+end;
+
+
+
+osr_params 
+
+
+ruleR_U_y      
+ruleR_U_pi    
+ruleR_U_debt
+
+
+
+
+ruleG_A_y
+ruleG_A_tt
+ruleG_A_debt
+
+
+
+ruleG_B_y
+ruleG_B_tt
+ruleG_B_debt
+
+
+
+ruleT_A_y
+ruleT_A_tt
+ruleT_A_debt
+
+
+
+ruleT_B_y
+ruleT_B_tt
+ruleT_B_debt
+
+;
+
+osr(irf=5,maxit=10000, nograph);
+
+
+%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+
+asymptotic_loss=((1/2)*n*(epsilon/phi_A))...
+        *oo_.var(strmatch('pi_A_Hat',M_.endo_names,'exact'),strmatch('pi_A_Hat',M_.endo_names,'exact'))+...
+            ((1/2)*n*(1 - phi_GY)*(1/sigma + (1 - phi_GY)*chi))...
+        *oo_.var(strmatch('c_A_Gap',M_.endo_names,'exact'),strmatch('c_A_Gap',M_.endo_names,'exact'))+...
+            ((1/2)*n*phi_GY*(1/psi + phi_GY*chi))...
+        *oo_.var(strmatch('g_A_Gap',M_.endo_names,'exact'),strmatch('g_A_Gap',M_.endo_names,'exact'))+...
+            ((1/2)*n*(1 - phi_GY)*(gamma*alpha*(alpha - 2) + 2*phi_caps + (1 - phi_GY)*(phi_caps^2)*chi)*((1-n)^2))...
+        *oo_.var(strmatch('tt_A_Gap',M_.endo_names,'exact'),strmatch('tt_A_Gap',M_.endo_names,'exact'))+...
+            ((1/2)*(1/2)*n*2*phi_GY*(1 - phi_GY)*chi)...
+        *oo_.var(strmatch('c_A_Gap',M_.endo_names,'exact'),strmatch('g_A_Gap',M_.endo_names,'exact'))+...
+            ((1/2)*(1/2)*n*(1 - phi_GY)*(2*alpha + 2*(1 - phi_GY)*phi_caps*chi)*(1-n))...
+        *oo_.var(strmatch('c_A_Gap',M_.endo_names,'exact'),strmatch('tt_A_Gap',M_.endo_names,'exact'))+...
+            ((1/2)*(1/2)*n*2*phi_GY*(1 - phi_GY)*phi_caps*chi*(1-n))...
+        *oo_.var(strmatch('g_A_Gap',M_.endo_names,'exact'),strmatch('tt_A_Gap',M_.endo_names,'exact'))+...
+            ((1/2)*(1/2)*n*2*phi_GY*(1 - phi_GY)*chi)...
+        *oo_.var(strmatch('g_A_Gap',M_.endo_names,'exact'),strmatch('c_A_Gap',M_.endo_names,'exact'))+...
+            ((1/2)*(1/2)*n*(1 - phi_GY)*(2*alpha + 2*(1 - phi_GY)*phi_caps*chi)*(1-n))...
+        *oo_.var(strmatch('tt_A_Gap',M_.endo_names,'exact'),strmatch('c_A_Gap',M_.endo_names,'exact'))+...
+            ((1/2)*(1/2)*n*2*phi_GY*(1 - phi_GY)*phi_caps*chi*(1-n))...
+        *oo_.var(strmatch('tt_A_Gap',M_.endo_names,'exact'),strmatch('g_A_Gap',M_.endo_names,'exact'))+...
+            ((1/2)*(1-n)*(epsilon/phi_B))...
+        *oo_.var(strmatch('pi_B_Hat',M_.endo_names,'exact'),strmatch('pi_B_Hat',M_.endo_names,'exact'))+...
+            ((1/2)*(1-n)*(1 - phi_GY)*(1/sigma + (1 - phi_GY)*chi))...
+        *oo_.var(strmatch('c_B_Gap',M_.endo_names,'exact'),strmatch('c_B_Gap',M_.endo_names,'exact'))+...
+            ((1/2)*(1-n)*phi_GY*(1/psi + phi_GY*chi))...
+        *oo_.var(strmatch('g_B_Gap',M_.endo_names,'exact'),strmatch('g_B_Gap',M_.endo_names,'exact'))+...
+            ((1/2)*(1-n)*(1 - phi_GY)*(gamma*alpha*(alpha - 2) + 2*phi_caps + (1 - phi_GY)*(phi_caps^2)*chi)*(n^2))...
+        *oo_.var(strmatch('tt_B_Gap',M_.endo_names,'exact'),strmatch('tt_B_Gap',M_.endo_names,'exact'))+...
+            ((1/2)*(1/2)*(1-n)*2*phi_GY*(1 - phi_GY)*chi)...
+        *oo_.var(strmatch('c_B_Gap',M_.endo_names,'exact'),strmatch('g_B_Gap',M_.endo_names,'exact'))+...
+            ((1/2)*(1/2)*(1-n)*(1 - phi_GY)*(2*alpha + 2*(1 - phi_GY)*phi_caps*chi)*n)...
+        *oo_.var(strmatch('c_B_Gap',M_.endo_names,'exact'),strmatch('tt_B_Gap',M_.endo_names,'exact'))+...
+            ((1/2)*(1/2)*(1-n)*2*phi_GY*(1 - phi_GY)*phi_caps*chi*n)...
+        *oo_.var(strmatch('g_B_Gap',M_.endo_names,'exact'),strmatch('tt_B_Gap',M_.endo_names,'exact'))+...
+            ((1/2)*(1/2)*(1-n)*2*phi_GY*(1 - phi_GY)*chi)...
+        *oo_.var(strmatch('g_B_Gap',M_.endo_names,'exact'),strmatch('c_B_Gap',M_.endo_names,'exact'))+...
+            ((1/2)*(1/2)*(1-n)*(1 - phi_GY)*(2*alpha + 2*(1 - phi_GY)*phi_caps*chi)*n)...
+        *oo_.var(strmatch('tt_B_Gap',M_.endo_names,'exact'),strmatch('c_B_Gap',M_.endo_names,'exact'))+...
+            ((1/2)*(1/2)*(1-n)*2*phi_GY*(1 - phi_GY)*phi_caps*chi*n)...
+        *oo_.var(strmatch('tt_B_Gap',M_.endo_names,'exact'),strmatch('g_B_Gap',M_.endo_names,'exact'));
+
+if abs(asymptotic_loss-oo_.osr.objective_function)>1e-10
+    error('Objective Function with Non-stationary Variables is wrong')
+end
+        
+        
\ No newline at end of file
diff --git a/tests/optimal_policy/osr_example_objective_correctness.mod b/tests/optimal_policy/osr_example_objective_correctness.mod
new file mode 100644
index 0000000000000000000000000000000000000000..be67fa10a09f7a1e7c04aad721ac37ad5d6da684
--- /dev/null
+++ b/tests/optimal_policy/osr_example_objective_correctness.mod
@@ -0,0 +1,110 @@
+// Example of optimal simple rule
+var y inflation r dummy_var;
+varexo y_ inf_;
+
+parameters delta sigma alpha kappa gammax0 gammac0 gamma_y_ gamma_inf_;
+
+delta =  0.44;
+kappa =  0.18;
+alpha =  0.48;
+sigma = -0.06;
+
+
+model(linear);
+y  = delta * y(-1)  + (1-delta)*y(+1)+sigma *(r - inflation(+1)) + y_; 
+inflation  =   alpha * inflation(-1) + (1-alpha) * inflation(+1) + kappa*y + inf_;
+dummy_var=0.9*dummy_var(-1)+0.01*y;
+r = gammax0*y(-1)+gammac0*inflation(-1)+gamma_y_*y_+gamma_inf_*inf_;
+end;
+
+shocks;
+var y_;
+stderr 0.63;
+var inf_;
+stderr 0.4;
+end;
+
+options_.nograph=1;
+options_.nocorr=1;
+options_.osr.tolf=1e-20;
+osr_params gammax0 gammac0 gamma_y_ gamma_inf_;
+
+
+optim_weights;
+inflation 1;
+y 1;
+dummy_var 1;
+end;
+
+
+gammax0 = 0.2;
+gammac0 = 1.5;
+gamma_y_ = 8;
+gamma_inf_ = 3;
+
+osr;
+%compute objective function manually
+objective=oo_.var(strmatch('y',M_.endo_names,'exact'),strmatch('y',M_.endo_names,'exact'))+oo_.var(strmatch('inflation',M_.endo_names,'exact'),strmatch('inflation',M_.endo_names,'exact'))+oo_.var(strmatch('dummy_var',M_.endo_names,'exact'),strmatch('dummy_var',M_.endo_names,'exact'));
+        
+if abs(oo_.osr.objective_function-objective)>1e-8
+    error('Objective Function is wrong')
+end
+
+%redo computation with covariance specified
+optim_weights;
+inflation 1;
+y 1;
+dummy_var 1;
+y,inflation 0.5;
+end;
+
+osr;
+%compute objective function manually
+objective=oo_.var(strmatch('y',M_.endo_names,'exact'),strmatch('y',M_.endo_names,'exact'))+oo_.var(strmatch('inflation',M_.endo_names,'exact'),strmatch('inflation',M_.endo_names,'exact'))+oo_.var(strmatch('dummy_var',M_.endo_names,'exact'),strmatch('dummy_var',M_.endo_names,'exact'))+0.5*oo_.var(strmatch('y',M_.endo_names,'exact'),strmatch('inflation',M_.endo_names,'exact'));
+if abs(oo_.osr.objective_function-objective)>1e-8
+    error('Objective Function is wrong')
+end
+
+gammax0=1.35533;
+gammac0=1.39664;
+gamma_y_=16.6667;
+gamma_inf_=9.13199;
+        
+%redo computation with double weight on one covariance 
+optim_weights;
+inflation 1;
+y 1;
+dummy_var 1;
+y,inflation 1;
+end;
+
+osr;
+%compute objective function manually
+objective=oo_.var(strmatch('y',M_.endo_names,'exact'),strmatch('y',M_.endo_names,'exact'))+oo_.var(strmatch('inflation',M_.endo_names,'exact'),strmatch('inflation',M_.endo_names,'exact'))+oo_.var(strmatch('dummy_var',M_.endo_names,'exact'),strmatch('dummy_var',M_.endo_names,'exact'))+1*oo_.var(strmatch('y',M_.endo_names,'exact'),strmatch('inflation',M_.endo_names,'exact'));
+if abs(oo_.osr.objective_function-objective)>1e-8
+    error('Objective Function is wrong')
+end
+oo_covar_single=oo_;
+
+%redo computation with single weight on both covariances
+
+optim_weights;
+inflation 1;
+y 1;
+dummy_var 1;
+y,inflation 0.5;
+inflation,y 0.5;
+end;
+
+osr;
+%compute objective function manually
+objective=oo_.var(strmatch('y',M_.endo_names,'exact'),strmatch('y',M_.endo_names,'exact'))+oo_.var(strmatch('inflation',M_.endo_names,'exact'),strmatch('inflation',M_.endo_names,'exact'))+oo_.var(strmatch('dummy_var',M_.endo_names,'exact'),strmatch('dummy_var',M_.endo_names,'exact'))+0.5*oo_.var(strmatch('y',M_.endo_names,'exact'),strmatch('inflation',M_.endo_names,'exact'))+0.5*oo_.var(strmatch('inflation',M_.endo_names,'exact'),strmatch('y',M_.endo_names,'exact'));
+if abs(oo_.osr.objective_function-objective)>1e-8
+    error('Objective Function is wrong')
+end
+if abs(oo_.osr.objective_function-oo_covar_single.osr.objective_function)>1e-8
+    error('Objective Function is wrong')
+end
+if max(abs(cell2mat(struct2cell(oo_.osr.optim_params))-cell2mat(struct2cell(oo_covar_single.osr.optim_params))))>1e-5
+    error('Parameters should be identical')
+end
diff --git a/tests/particle/dsge_base2.mod b/tests/particle/dsge_base2.mod
index 9ebb71fef310c6edb064dd3c0463f34b46a451e2..448072aa385fc5016c0a90535a0fabf680df9744 100644
--- a/tests/particle/dsge_base2.mod
+++ b/tests/particle/dsge_base2.mod
@@ -35,26 +35,39 @@ steady;
 //disp(oo_.mean) ;
 
 estimated_params;
-alp, uniform_pdf,,, 0.0001, 0.5;
+alp, uniform_pdf,,, 0.0001, 0.99;
 bet, uniform_pdf,,, 0.0001, 0.99;
 tet, uniform_pdf,,, 0.0001, 1;
 tau, uniform_pdf,,, 0.0001, 100;
 delt, uniform_pdf,,, 0.0001, 0.05;
-rho, uniform_pdf,,, 0.8, 0.99;
+rho, uniform_pdf,,, 0.0001, 0.99;
 stderr e_a, uniform_pdf,,, 0.00001, 0.1;
 stderr y, uniform_pdf,,, 0.00001, 0.1;
 stderr l, uniform_pdf,,, 0.00001, 0.1;
 stderr i, uniform_pdf,,, 0.00001, 0.1;
 end;
 
+//estimated_params_init;
+//alp, 0.4;
+//bet, 0.99;
+//tet, 0.357 ;
+//tau, 50;
+//delt, 0.02;
+//rho, 0.95 ;
+//stderr e_a, .035;
+//stderr y, .0175;//.00158;
+//stderr l, .00312;//.0011;
+//stderr i, .00465;//.000866;
+//end;
+
 estimated_params_init;
 alp, 0.4;
-bet, 0.97;
-tet, 0.357 ;
-tau, 50;
-delt, 0.02;
-rho, 0.9 ;
-stderr e_a, .035;
+bet, 0.98;
+tet, 0.3;
+tau, 30;
+delt, 0.01;
+rho, 0.85;
+stderr e_a, .03;
 stderr y, .0175;//.00158;
 stderr l, .00312;//.0011;
 stderr i, .00465;//.000866;
@@ -68,20 +81,20 @@ varobs y l i ;
 options_.particle.status = 1;
 options_.particle.initialization = 1;
 options_.particle.pruning = 0;
-options_.particle.number_of_particles = 1000 ;
+options_.particle.number_of_particles = 5000 ;
 options_.particle.resampling.status = 'systematic';
 
-//options_.particle.resampling.method1 = 'traditional' ;
+options_.particle.resampling.method1 = 'traditional' ;
 //options_.particle.resampling.method1 = 'residual' ;
-options_.particle.resampling.method1 = 'smooth' ;
+//options_.particle.resampling.method1 = 'smooth' ;
 
-options_.particle.reampling.method2 = 'kitagawa' ;
-//options_.particle.resampling.method2 = 'stratified' ;
+options_.particle.reampling.method2 = 'kitagawa' ;//'stratified' ;
 
-options_.particle.resampling.number_of_partitions = 1;
 options_.particle.resampling.neff_threshold = .5;
+options_.mode_check.neighbourhood_size = .2 ;
+options_.mode_check.number_of_points = 250;
 
-set_dynare_threads('local_state_space_iteration_2',3);
+//set_dynare_threads('local_state_space_iteration_2',3);
 
 options_.particle.algorithm = 'sequential_importance_particle_filter';
 //options_.particle.algorithm = 'auxiliary_particle_filter';
@@ -94,14 +107,14 @@ options_.particle.IS_approximation_method = 'cubature' ;
 //options_.particle.IS_approximation_method = 'unscented' ;
 
 //options_.particle.approximation_method = 'quadrature' ;
-options_.particle.approximation_method = 'cubature' ;
+//options_.particle.approximation_method = 'cubature' ;
 //options_.particle.approximation_method = 'unscented' ;
 //options_.particle.approximation_method = 'MonteCarlo' ;
 
-//options_.mh_posterior_mode_estimation=1 ;
+options_.mh_posterior_mode_estimation=0 ;
 
 // online
-options_.particle.liu_west_delta = 0.9 ;
+options_.particle.liu_west_delta = 0.99 ;
 options_.mode_check_node_number = 250 ;
 
-estimation(datafile=data_risky_perturb2,nograph,order=2,nobs=100,mh_replic=0,mode_compute=7,mode_check);
+estimation(datafile=data_risky_perturb3,order=1,nograph,nobs=100,mh_replic=0,mode_compute=11);
diff --git a/tests/reporting/CountryGraphPage.m b/tests/reporting/CountryGraphPage.m
index 6323649b29d5dd62f7833bfa8f99cb9bbd51ed61..d67bb28a1817449028275d9e1fe1553f6abeacf5 100644
--- a/tests/reporting/CountryGraphPage.m
+++ b/tests/reporting/CountryGraphPage.m
@@ -25,7 +25,8 @@ rep = rep.addGraph('title', 'Interest Rate', ...
                    'showZeroline', true, ...
                    'xTicks', [1,5,10,15,find(srange(1)==prange),length(prange)], ...
                    'xTickLabels',{startpoint{:},'2008Q1','2009Q2','2010Q3',shaded{:}, endpoint{:}},...
-                   'xTickLabelRotation', 0);
+                   'xTickLabelRotation', 0, ...
+                   'writeCSV', true);
 rep = rep.addSeries('data', db_q{['RS_' countryAbbr]}, ...
                     'graphLineColor', 'blue', ...
                     'graphLineStyle', 'dashed', ...
diff --git a/tests/reporting/CountryTablePage.m b/tests/reporting/CountryTablePage.m
index 06ce66ea5d580ad57c366c61aabe53e39366da68..e73b865b28c379639841f6d8bbdf390109950c2e 100644
--- a/tests/reporting/CountryTablePage.m
+++ b/tests/reporting/CountryTablePage.m
@@ -43,7 +43,9 @@ notForOtherThree = {'BLT_', 'UNR_', 'UNR_BAR_', 'UNR_GAP_'};
 
 rep = rep.addTable('title', countryName, ...
                    'range', {trange, dates('2012a'):dates('2014a')}, ...
-                   'vlineAfter', {vline_after dates('2014q4')});
+                   'vlineAfter', {vline_after dates('2014q4')}, ...
+                   'writeCSV', true, ...
+                   'highlightRows', {'gray!22', 'cyan!33', 'blue!44', 'red!55'});
 
 
 
diff --git a/tests/reporting/runDynareReport.m b/tests/reporting/runDynareReport.m
index 305e2736d6bcae3c651e427bf62c2de31b53455d..4ce50f40835efc17a711a03eb2e0930403c75ff9 100644
--- a/tests/reporting/runDynareReport.m
+++ b/tests/reporting/runDynareReport.m
@@ -44,7 +44,8 @@ rep = rep.addVspace();
 % Table 1
 rep = rep.addTable('title', {'Real GDP Growth','subtitle 1', 'subtitle 2'}, ...
                    'range', larange, ...
-                   'vlineAfter', dates('2011y'));
+                   'vlineAfter', dates('2011y'), ...
+                   'highlightRows', {'gray!25','white','green!22'});
 rep = AnnualTable(rep, db_a, dc_a, 'PCH_GROWTH4_', larange);
 rep = rep.addVspace('number', 2);
 
diff --git a/tests/simul/Solow_no_varexo.mod b/tests/simul/Solow_no_varexo.mod
new file mode 100644
index 0000000000000000000000000000000000000000..542fd32584418e166e2abe9d8aacc3b988c3365d
--- /dev/null
+++ b/tests/simul/Solow_no_varexo.mod
@@ -0,0 +1,65 @@
+/*
+ * This file studies the transition to steady state in a simple Solow model with Cobb-Douglass production function
+ *
+ * This implementation was written by Johannes Pfeifer. 
+ * Please note that the following copyright notice only applies to this Dynare 
+ * implementation of the model.
+ */
+
+/*
+ * Copyright (C) 2014 Johannes Pfeifer
+ *
+ * This 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.
+ *
+ * It 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.
+ *
+ * For a copy of the GNU General Public License,
+ * see <http://www.gnu.org/licenses/>.
+ */
+
+
+
+var c k y invest;
+predetermined_variables k;
+parameters s alpha delta n g;
+
+s=0.2;
+alpha=0.3;
+delta=0.1;
+n=0.01;
+g=0.02;
+g_initial=0.02;
+
+model;
+(1+n+g+n*g)*k(+1)=(1-delta)*k+invest;
+invest+c=y;
+c=(1-s)*y;
+y=k^alpha;
+end;
+
+%set initial condition to 90% of steady state value
+initval;
+k=0.9*((delta+n+g+n*g)/s)^(1/(alpha-1));
+y=k^alpha;
+c=(1-s)*y;
+invest=y-c;
+end;
+
+%set terminal condition to steady state value
+endval;
+k=((delta+n+g+n*g)/s)^(1/(alpha-1));
+y=k^alpha;
+c=(1-s)*y;
+invest=y-c;
+end;
+resid(1);
+steady;
+
+simul(periods=200);
+rplot k;
diff --git a/tests/simul/simul_ZLB_purely_forward.mod b/tests/simul/simul_ZLB_purely_forward.mod
new file mode 100644
index 0000000000000000000000000000000000000000..4df56441dccec7eff067b10d239cf62e40f930f1
--- /dev/null
+++ b/tests/simul/simul_ZLB_purely_forward.mod
@@ -0,0 +1,96 @@
+var c, h, pi, w, R, r_e, y, gdp, gdp_hat, k, u, g, c_hat, w_hat, y_hat, h_hat;
+varexo d, z, eta; 
+
+parameters alpha, beta, sigma, gamma, theta, ni, tau_w, phi_p, phi_y;
+
+beta  = 0.997;
+sigma = 2;
+gamma = 25;
+theta = 7.67;
+tau_w = 0.2;
+ni    = 0.28;
+phi_p = 1.5;
+phi_y = 0.125;
+alpha = 0.064;
+
+model;
+
+// log-deviation of _ from its steady state value
+gdp_hat=log(gdp)-log(steady_state(gdp));
+c_hat=log(c)-log(steady_state(c));
+w_hat=log(w)-log(steady_state(w));
+y_hat=log(y)-log(steady_state(y));
+h_hat=log(h)-log(steady_state(h));
+
+// real interest rate
+r_e=1/(beta*d(+1))-1;
+
+//FOC labor
+c^sigma*h^ni=w*(1-tau_w);
+
+//Euler equation 1
+1=beta*d(+1)*(1+R)/(1+pi(+1))*(c/c(+1))^sigma;
+
+//Euler equation 2
+0=1/(1-alpha)*(steady_state(w)/z)*h^alpha-1-gamma/theta*pi*(1+pi)+beta*d(+1)*(c/c(+1))^sigma * y(+1)/y*gamma/theta*pi(+1)*(1+pi(+1));
+
+// Taylor rule with ZLB
+R=max(0,r_e+phi_p*pi+phi_y*gdp_hat);
+
+//output
+y=z*h^(1-alpha);
+
+//aggregate resource constraint
+c=(1-k-eta)*y;
+
+// resource cost of price adjustment
+k=(gamma/2)*(pi^2);
+
+//government purchases
+g=eta*y;
+
+// GDP
+gdp=(1-k)*y;
+
+//utility
+u=(c^(1-sigma))/(1-sigma)-(h^(1+ni))/(1+ni);
+end;
+
+initval;
+z=1;
+d=1;
+pi=0;
+k=(gamma/2)*(pi^2);
+r_e=1/(beta*d)-1;
+eta=0.2;
+h=1;
+y=z*h;
+g=eta*y;
+c=(1-k-eta)*y;
+w=z;
+gdp=(1-k)*y;
+R=r_e;
+end;
+
+steady;
+check;
+
+shocks;
+//5% preference shock
+var d;
+periods 1:10;
+values 1.05;
+
+//technology shock
+var z;
+periods 1:10;
+values 1.05;
+end;
+
+simul(periods=40,maxit=1000);
+
+rplot gdp_hat;
+rplot R;
+if oo_.deterministic_simulation.status~=1
+    error('This model has solution');
+end
\ No newline at end of file
diff --git a/tests/simul/simul_ZLB_purely_forward_no_solution.mod b/tests/simul/simul_ZLB_purely_forward_no_solution.mod
new file mode 100644
index 0000000000000000000000000000000000000000..73d96aa5c6be7848feac67bbb93f62a7a0546f5f
--- /dev/null
+++ b/tests/simul/simul_ZLB_purely_forward_no_solution.mod
@@ -0,0 +1,97 @@
+var c, h, pi, w, R, r_e, y, gdp, gdp_hat, k, u, g, c_hat, w_hat, y_hat, h_hat;
+varexo d, z, eta; 
+
+parameters alpha, beta, sigma, gamma, theta, ni, tau_w, phi_p, phi_y;
+
+beta  = 0.997;
+sigma = 2;
+gamma = 25;
+theta = 7.67;
+tau_w = 0.2;
+ni    = 0.28;
+phi_p = 1.5;
+phi_y = 0.125;
+alpha = 0.064;
+
+model;
+
+// log-deviation of _ from its steady state value
+gdp_hat=log(gdp)-log(steady_state(gdp));
+c_hat=log(c)-log(steady_state(c));
+w_hat=log(w)-log(steady_state(w));
+y_hat=log(y)-log(steady_state(y));
+h_hat=log(h)-log(steady_state(h));
+
+// real interest rate
+r_e=1/(beta*d(+1))-1;
+
+//FOC labor
+c^sigma*h^ni=steady_state(w)*(1-tau_w);
+
+//Euler equation 1
+1=beta*d(+1)*(1+R)/(1+pi(+1))*(c/c(+1))^sigma;
+
+//Euler equation 2
+0=1/(1-alpha)*(steady_state(w)/z)*h^alpha-1-gamma/theta*pi*(1+pi)+beta*d(+1)*(c/c(+1))^sigma * y(+1)/y*gamma/theta*pi(+1)*(1+pi(+1));
+
+// Taylor rule with ZLB
+R=max(0,r_e+phi_p*pi+phi_y*gdp_hat);
+
+//output
+y=z*h^(1-alpha);
+
+//aggregate resource constraint
+c=(1-k-eta)*y;
+
+// resource cost of price adjustment
+k=(gamma/2)*(pi^2);
+
+//government purchases
+g=eta*y;
+
+// GDP
+gdp=(1-k)*y;
+
+//utility
+u=(c^(1-sigma))/(1-sigma)-(h^(1+ni))/(1+ni);
+end;
+
+initval;
+z=1;
+d=1;
+pi=0;
+k=(gamma/2)*(pi^2);
+r_e=1/(beta*d)-1;
+eta=0.2;
+h=1;
+y=z*h;
+g=eta*y;
+c=(1-k-eta)*y;
+w=z;
+gdp=(1-k)*y;
+R=r_e;
+end;
+
+steady;
+check;
+
+shocks;
+//5% preference shock
+var d;
+periods 1:10;
+values 1.05;
+
+//technology shock
+var z;
+periods 1:10;
+values 1.05;
+end;
+
+simul(periods=40,maxit=1000);
+
+rplot gdp_hat;
+rplot R;
+
+if oo_.deterministic_simulation.status==1
+    error('This model has no solution');
+end
\ No newline at end of file
diff --git a/windows/dynare.nsi b/windows/dynare.nsi
index b88b4c067857b611d011c782473b854b3c302928..6f7a45b7a13490facb3c9d998fb07cdc11b068ac 100644
--- a/windows/dynare.nsi
+++ b/windows/dynare.nsi
@@ -83,9 +83,9 @@ SectionEnd
 
 SectionGroup "MEX files for MATLAB"
 
-Section "MEX files for MATLAB 32-bit, version 7.5 to 8.3 (R2007b to R2014a)"
- SetOutPath $INSTDIR\mex\matlab\win32-7.5-8.3
- File ..\mex\matlab\win32-7.5-8.3\*.mexw32
+Section "MEX files for MATLAB 32-bit, version 7.5 to 8.4 (R2007b to R2014b)"
+ SetOutPath $INSTDIR\mex\matlab\win32-7.5-8.4
+ File ..\mex\matlab\win32-7.5-8.4\*.mexw32
 SectionEnd
 
 Section "MEX files for MATLAB 64-bit, version 7.5 to 7.7 (R2007b to R2008b)"
@@ -93,9 +93,9 @@ Section "MEX files for MATLAB 64-bit, version 7.5 to 7.7 (R2007b to R2008b)"
  File ..\mex\matlab\win64-7.5-7.7\*.mexw64
 SectionEnd
 
-Section "MEX files for MATLAB 64-bit, version 7.8 to 8.3 (R2009a to R2014a)"
- SetOutPath $INSTDIR\mex\matlab\win64-7.8-8.3
- File ..\mex\matlab\win64-7.8-8.3\*.mexw64
+Section "MEX files for MATLAB 64-bit, version 7.8 to 8.4 (R2009a to R2014b)"
+ SetOutPath $INSTDIR\mex\matlab\win64-7.8-8.4
+ File ..\mex\matlab\win64-7.8-8.4\*.mexw64
 SectionEnd
 
 SectionGroupEnd