Commit 8997ae8a authored by Stéphane Adjemian's avatar Stéphane Adjemian
Browse files

Merge branch 'master' into maxit

parents d369b8ad 40a4678a
......@@ -3735,7 +3735,7 @@ declaration order. Conversely, k-th declared variable is numbered
@vindex M_.nsfwrd
@vindex M_.ndynamic
Finally, the state variables of the model are the purely backward variables
and the mixed variables. They are orderer in DR-order when they appear in
and the mixed variables. They are ordered in DR-order when they appear in
decision rules elements. There are @code{M_.nspred = M_.npred + M_.nboth} such
variables. Similarly, one has @code{M_.nsfwrd = M_.nfwrd + M_.nboth},
and @code{M_.ndynamic = M_.nfwrd+M_.nboth+M_.npred}.
......@@ -3743,7 +3743,7 @@ and @code{M_.ndynamic = M_.nfwrd+M_.nboth+M_.npred}.
@node First order approximation
@subsection First order approximation
The approximation has the form:
The approximation has the stylized form:
@math{y_t = y^s + A y^h_{t-1} + B u_t}
......@@ -3772,6 +3772,12 @@ endogenous in DR-order. The matrix columns correspond to exogenous
variables in declaration order.
@end itemize
Of course, the shown form of the approximation is only stylized, because it neglects the required different ordering in @math{y^s} and @math{y^h_t}. The precise form of the approximation that shows the way Dynare deals with differences between declaration and DR-order, is
@math{y_t(oo_.dr.order_var) = y^s(oo_.dr.order_var) + A (y_{t-1}(oo_.dr.order_var(k2))-y^s(oo_.dr.order_var(k2))) + B u_t}
where @math{k2} selects the state variables, @math{y_t} and @math{y^s} are in declaration order and the coefficient matrices are in DR-order. Effectively, all variables on the right hand side are brought into DR order for computations and then assigned to @math{y_t} in declaration order.
@node Second order approximation
@subsection Second order approximation
......@@ -3785,7 +3791,7 @@ A y^h_{t-1} + B u_t + 0.5 C
where @math{y^s} is the steady state value of @math{y},
@math{y^h_t=y_t-y^s}, and @math{\Delta^2} is the shift effect of the
variance of future shocks.
variance of future shocks. For the reordering required due to differences in declaration and DR order, see the first order approximation.
The coefficients of the decision rules are stored in the variables
described for first order approximation, plus the following variables:
......@@ -4212,12 +4218,19 @@ graphs of smoothed shocks, smoothed observation errors, smoothed and historical
@algorithmshead
The Monte Carlo Markov Chain (MCMC) univariate diagnostics are generated
by the estimation command if @ref{mh_nblocks} is larger than 1, if
@ref{mh_replic} is larger than 2000, and if option @ref{nodiagnostic} is
not used. As described in section 3 of @cite{Brooks and Gelman (1998)}
the convergence diagnostics are based on comparing pooled and within
MCMC moments (Dynare displays the second and third order moments, and
The Monte Carlo Markov Chain (MCMC) diagnostics are generated
by the estimation command if @ref{mh_replic} is larger than 2000 and if
option @ref{nodiagnostic} is not used. If @ref{mh_nblocks} is equal to one,
the convergence diagnostics of @cite{Geweke (1992,1999)} is computed. It uses a
chi square test to compare the means of the first and last draws specified by
@ref{geweke_interval} after discarding the burnin of @ref{mh_drop}. The test is
computed using variance estimates under the assumption of no serial correlation
as well as using tapering windows specified in @ref{taper_steps}.
If @ref{mh_nblocks} is larger than 1, the convergence diagnostics of
@cite{Brooks and Gelman (1998)} are used instead.
As described in section 3 of @cite{Brooks and Gelman (1998)} the univariate
convergence diagnostics are based on comparing pooled and within MCMC moments
(Dynare displays the second and third order moments, and
the length of the Highest Probability Density interval covering 80% of
the posterior distribution). Due to computational reasons, the
multivariate convergence diagnostic does not follow @cite{Brooks and
......@@ -4358,8 +4371,8 @@ the total number of Metropolis draws available. Default:
@code{2}
@item mh_drop = @var{DOUBLE}
The fraction of initially generated parameter vectors to be dropped
before using posterior simulations. Default: @code{0.5}
@anchor{mh_drop}
The fraction of initially generated parameter vectors to be dropped as a burnin before using posterior simulations. Default: @code{0.5}
@item mh_jscale = @var{DOUBLE}
The scale to be used for the jumping distribution in
......@@ -4388,13 +4401,14 @@ hessian (@code{hh}, only if @code{cova_compute=1}) in a file called
@file{@var{MODEL_FILENAME}_mode.mat}
@item mode_compute = @var{INTEGER} | @var{FUNCTION_NAME}
@anchor{mode_compute}
Specifies the optimizer for the mode computation:
@table @code
@item 0
The mode isn't computed. When @code{mode_file} option is specified, the
mode is simply read from that file.
mode is simply read from that file.
When @code{mode_file} option is not
specified, Dynare reports the value of the log posterior (log likelihood)
......@@ -4444,6 +4458,10 @@ available with @code{mode_compute=7})
@item 9
Uses the CMA-ES (Covariance Matrix Adaptation Evolution Strategy) algorithm, an evolutionary algorithm for difficult non-linear non-convex optimization
@item 10
Uses the simpsa algorithm, based on the combination of the non-linear simplex and simulated annealing algorithms and proposed by
@cite{Cardoso, Salcedo and Feyo de Azevedo (1996)}.
@item @var{FUNCTION_NAME}
It is also possible to give a @var{FUNCTION_NAME} to this option,
instead of an @var{INTEGER}. In that case, Dynare takes the return
......@@ -4487,11 +4505,135 @@ parameters. Default: @code{1e-32}
Metropolis-Hastings simulations instead of starting from
scratch. Shouldn't be used together with @code{mh_recover}
@item optim = (@var{fmincon options})
Can be used to set options for @code{fmincon}, the optimizing function
of MATLAB Optimization toolbox. Use MATLAB's syntax for these
options. Default:
@code{('display','iter','LargeScale','off','MaxFunEvals',100000,'TolFun',1e-8,'TolX',1e-6)}
@item optim = (@var{NAME}, @var{VALUE}, ...)
A list of @var{NAME} and @var{VALUE} pairs. Can be used to set options for the optimization routines. The set of available options depends on the selected optimization routine (ie on the value of option @ref{mode_compute}):
@table @code
@item 1, 3, 7
Available options are given in the documentation of the MATLAB optimization toolbox or in Octave's documentation.
@item 4
Available options are:
@table @code
@item 'MaxIter'
Maximum number of iterations. Default: @code{1000}
@item 'NumgradAlgorithm'
Possible values are @code{2}, @code{3} and @code{5} respectively corresponding to the two, three and five points formula used to compute the gradient of the objective function (see @cite{Abramowitz and Stegun (1964)}). Values @code{13} and @code{15} are more experimental. If perturbations on the right and the left increase the value of the objective function (we minimize this function) then we force the corresponding element of the gradient to be zero. The idea is to temporarly reduce the size of the optimization problem. Default: @code{2}.
@item 'NumgradEpsilon'
Size of the perturbation used to compute numerically the gradient of the objective function. Default: @code{1e-6}
@item 'TolFun'
Stopping criteria. Default: @code{1e-7}
@item 'InitialInverseHessian'
Initial approximation for the inverse of the Hessian matrix of the posterior kernel (or likelihood). Obviously this approximation has to be a square, positive definite and symmetric matrix. Default: @code{'1e-4*eye(nx)'}, where @code{nx} is the number of parameters to be estimated.
@end table
@item 6
Available options are:
@table @code
@item 'NumberOfMh'
Number of MCMC run sequentially. Default: @code{3}
@item 'ncov-mh'
Number of iterations used for updating the covariance matrix of the jumping distribution. Default: @code{20000}
@item 'nscale-mh'
Maximum number of iterations used for adjusting the scale parameter of the jumping distribution. @code{200000}
@item 'nclimb'
Number of iterations in the last MCMC (climbing mode).
@item 'InitialCovarianceMatrix'
Initial covariance matrix of the jumping distribution. Default is @code{'previous'} if option @code{mode_file} is used, @code{'prior'} otherwise.
@item 'AcceptanceRateTarget'
A real number between zero and one. The scale parameter of the jumping distribution is adjusted so that the effective acceptance rate matches the value of option @code{'AcceptanceRateTarget'}. Default: @code{1.0/3.0}
@end table
@item 8
Available options are:
@table @code
@item 'MaxIter'
Maximum number of iterations. Default: @code{5000}
@item 'MaxFunEvals'
Maximum number of objective function evaluations. No default.
@item 'MaxFunvEvalFactor'
Set @code{MaxFunvEvals} equal to @code{MaxFunvEvalFactor} times the number of estimated parameters. Default: @code{500}.
@item 'TolFun'
Tolerance parameter (w.r.t the objective function). Default: @code{1e-4}
@item 'TolX'
Tolerance parameter (w.r.t the instruments). Default: @code{1e-4}
@item 'InitialSimplexSize'
Initial size of the simplex, expressed as percentage deviation from the provided initial guess in each direction. Default: @code{.05}
@end table
@item 9
Available options are:
@table @code
@item 'MaxIter'
Maximum number of iterations.
@item 'MaxFunEvals'
Maximum number of objective function evaluations. Default: @code{Inf}.
@item 'TolFun'
Tolerance parameter (w.r.t the objective function). Default: @code{1e-7}
@item 'TolX'
Tolerance parameter (w.r.t the instruments). Default: @code{1e-7}
@end table
@item 10
Available options are:
@table @code
@item 'MaxIter'
Maximum number of iterations. Default: @code{5000}
@item 'MaxFunvEvals'
Maximum number of objective function evaluations. No default.
@item 'TolFun'
Tolerance parameter (w.r.t the objective function). Default: @code{1e-4}
@item 'TolX'
Tolerance parameter (w.r.t the instruments). Default: @code{1e-4}
@item 'EndTemperature'
Terminal condition w.r.t the temperature. When the temperature reaches @code{EndTemperature}, the temperature is set to zero and the algorithm falls back into a standard simplex algorithm. Default: @code{.1}
@end table
@end table
@customhead{Example 1}
To change the defaults of csminwel (@code{mode_compute=4}):
@code{estimation(..., mode_compute=4, optim=('NumgradAlgorithm',3,'TolFun',1e-5), ...);}
@item nodiagnostic
@anchor{nodiagnostic} Does not compute the convergence diagnostics for
......@@ -4758,6 +4900,18 @@ Value used to test if a generalized eigenvalue is 0/0 in the generalized
Schur decomposition (in which case the model does not admit a unique
solution). Default: @code{1e-6}.
@item taper_steps = [@var{INTEGER1} @var{INTEGER2} @dots{}]
@anchor{taper_steps}
Percent tapering used for the spectral window in the @cite{Geweke (1992,1999)}
convergence diagnostics (requires @ref{mh_nblocks}=1). The tapering is used to
take the serial correlation of the posterior draws into account. Default: @code{[4 8 15]}.
@item geweke_interval = [@var{DOUBLE} @var{DOUBLE}]
@anchor{geweke_interval}
Percentage of MCMC draws at the beginning and end of the MCMC chain taken
to compute the @cite{Geweke (1992,1999)} convergence diagnostics (requires @ref{mh_nblocks}=1)
after discarding the first @ref{mh_drop} percent of draws as a burnin. Default: @code{[0.2 0.5]}.
@end table
@customhead{Note}
......@@ -5048,6 +5202,56 @@ Upper/lower bound of the 90\% HPD interval taking into account both parameter an
@end defvr
@defvr {MATLAB/Octave variable} oo_.convergence.geweke
@anchor{convergence.geweke}
Variable set by the convergence diagnostics of the @code{estimation} command when used with @ref{mh_nblocks}=1 option (@pxref{mh_nblocks}).
Fields are of the form:
@example
@code{oo_.convergence.geweke.@var{VARIABLE_NAME}.@var{DIAGNOSTIC_OBJECT}}
@end example
where @var{DIAGNOSTIC_OBJECT} is one of the following:
@table @code
@item posteriormean
Mean of the posterior parameter distribution
@item posteriorstd
Standard deviation of the posterior parameter distribution
@item nse_iid
Numerical standard error (NSE) under the assumption of iid draws
@item rne_iid
Relative numerical efficiency (RNE) under the assumption of iid draws
@item nse_x
Numerical standard error (NSE) when using an x% taper
@item rne_x
Relative numerical efficiency (RNE) when using an x% taper
@item pooled_mean
Mean of the parameter when pooling the beginning and end parts of the chain
specified in @ref{geweke_interval} and weighting them with their relative precision.
It is a vector containing the results under the iid assumption followed by the ones
using the @ref{taper_steps} (@pxref{taper_steps}).
@item pooled_nse
NSE of the parameter when pooling the beginning and end parts of the chain and weighting them with their relative precision. See @code{pooled_mean}
@item prob_chi2_test
p-value of a chi squared test for equality of means in the beginning and the end
of the MCMC chain. See @code{pooled_mean}. A value above 0.05 indicates that
the null hypothesis of equal means and thus convergence cannot be rejected
at the 5 percent level. Differing values along the @ref{taper_steps} signal
the presence of significant autocorrelation in draws. In this case, the
estimates using a higher tapering are usually more reliable.
@end table
@end defvr
@deffn Command model_comparison @var{FILENAME}[(@var{DOUBLE})]@dots{};
@deffnx Command model_comparison (marginal_density = laplace | modifiedharmonicmean) @var{FILENAME}[(@var{DOUBLE})]@dots{};
......@@ -8352,11 +8556,16 @@ Display a solid black line at @math{y = 0}. Default: @code{false}
@end table
@end defmethod
@defmethod Report addTable data, showHlines, precision, range, seriesToUse, title, titleSize, vlineAfter, showVlines
@defmethod Report addTable annualAverages, data, showHlines, precision, range, seriesToUse, title, titleSize, vlineAfter, vlineAfterEndOfPeriod, showVlines
Adds a @code{Table} to a @code{Section}.
@optionshead
@table @code
@item annualAverages, @code{bool}
Compute the average over every year in the table and display it in a
column to the right of the data (one column for every year). Only
works for quarterly data. Default: @code{false}
@item data, @code{dynSeries}
@xref{data}.
......@@ -8381,13 +8590,17 @@ Title for the table. Default: @code{none}
@item vlineAfter, @code{dynDate}
Show a vertical line after the specified date. Default: @code{empty}
@item vlineAfterEndOfPeriod, @code{BOOLEAN}
Show a vertical line after the end of every period (@i{i.e.} after
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}
@end table
@end defmethod
@anchor{addSeries}
@defmethod Report addSeries data, graphLineColor, graphLineStyle, graphLineWidth, graphMarker, graphMarkerEdgeColor, graphMarkerFaceColor, graphMarkerSize, tableShowMarkers, tableAlignRight, tableNegColor, tablePosColor, zerotol
@defmethod Report addSeries data, graphLineColor, graphLineStyle, graphLineWidth, graphMarker, graphMarkerEdgeColor, graphMarkerFaceColor, graphMarkerSize, tableRowColor, tableShowMarkers, tableAlignRight, tableNegColor, tablePosColor, tableSubSectionHeader, zerotol
Adds a @code{Series} to a @code{Graph} or a @code{Table}.
@optionshead
@table @code
......@@ -8416,6 +8629,10 @@ The face color of the graph marker. Default: @code{`auto'}
@item graphMarkerSize, @code{DOUBLE}
The size of the graph marker. Default: @code{6}
@item tableRowColor, @code{STRING}
The color that you want the row to be. Predefined values include
@code{LightCyan} and @code{Gray}. Default: @code{white}.
@item tableShowMarkers, @code{BOOLEAN}
In a Table, if @code{true}, surround each cell with brackets and color
it according to @ref{tableNegColor} and @ref{tablePosColor}. No effect
......@@ -8441,6 +8658,11 @@ zero. Default: @code{`red'}
The color to use when marking Table data that is greater than
zero. Default: @code{`blue'}
@item tableSubSectionHeader, @code{STRING}
A header for a subsection of the table. No data will be associated
with it. It is equivalent to adding an empty series with a
name. Default: @code{''}
@item zerotol, @code{DOUBLE}
The zero tolerance. Anything smaller than @code{zerotol} and larger
than @code{-zerotol} will be set to zero before being
......@@ -8622,6 +8844,9 @@ internals --test particle/local_state_iteration
@itemize
@item
Milton Abramowitz, Irene A. Stegun (1964): ``Handbook of Mathematical Functions'', Courier Dover Publications
@item
Aguiar, Mark and Gopinath, Gita (2004): ``Emerging Market Business
Cycles: The Cycle is the Trend,'' @i{NBER Working Paper}, 10734
......@@ -8644,6 +8869,10 @@ Brooks, Stephen P., and Andrew Gelman (1998): ``General methods for
monitoring convergence of iterative simulations,'' @i{Journal of
computational and graphical statistics}, 7, pp. 434--455
@item
Cardoso, Margarida F., R. L. Salcedo and S. Feyo de Azevedo (1996): ``The simplex simulated annealing approach to continuous non-linear optimization'', @i{Computers chem. Engng}, 20(9), 1065-1080
@item
Collard, Fabrice (2001): ``Stochastic simulations with Dynare: A practical guide''
......@@ -8688,6 +8917,16 @@ Fernández-Villaverde, Jesús and Juan Rubio-Ramírez (2005): ``Estimating
Dynamic Equilibrium Economies: Linear versus Nonlinear Likelihood,''
@i{Journal of Applied Econometrics}, 20, 891--910
@item
Geweke, John (1992): ``Evaluating the accuracy of sampling-based approaches
to the calculation of posterior moments'', in J.O. Berger, J.M. Bernardo,
A.P. Dawid, and A.F.M. Smith (eds.) Proceedings of the Fourth Valencia
International Meeting on Bayesian Statistics, pp. 169--194, Oxford University Press
@item
Geweke, John (1999): ``Using simulation methods for Bayesian econometric models:
Inference, development and communication,'' @i{Econometric Reviews}, 18(1), 1--73
@item
Ireland, Peter (2004): ``A Method for Taking Models to the Data,''
@i{Journal of Economic Dynamics and Control}, 28, 1205--26
......
......@@ -40,12 +40,12 @@ License: public-domain
pages 472-489
Files: matlab/bfgsi1.m matlab/csolve.m matlab/csminit1.m matlab/numgrad2.m
matlab/numgrad2_.m matlab/numgrad3.m matlab/numgrad3_.m matlab/numgrad5.m
matlab/numgrad3.m matlab/numgrad3_.m matlab/numgrad5.m
matlab/numgrad5_.m matlab/csminwel1.m matlab/bvar_density.m
matlab/bvar_toolbox.m matlab/partial_information/PI_gensys.m matlab/qzswitch.m
matlab/qzdiv.m
Copyright: 1993-2009 Christopher Sims
2006-2012 Dynare Team
2006-2013 Dynare Team
License: GPL-3+
Files: matlab/cmaes.m
......@@ -58,6 +58,12 @@ Copyright: 2011 Lawrence J. Christiano, Mathias Trabandt and Karl Walentin
2013 Dynare Team
License: GPL-3+
Files: matlab/simpsa.m matlab/simpsaget.m matlab/simpsaset.m
Copyright: 2005 Henning Schmidt, FCC, henning@fcc.chalmers.se
2006 Brecht Donckels, BIOMATH, brecht.donckels@ugent.be
2013 Dynare Team
License: GPL-3+
Files: matlab/missing/stats/normpdf.m matlab/missing/stats/gamcdf.m
matlab/missing/stats/common_size.m matlab/missing/stats/chi2inv.m
matlab/missing/stats/gaminv.m matlab/missing/stats/gampdf.m
......
......@@ -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
*2013b | *2013B)
MATLAB_VERSION="8.2"
;;
*2013a | *2013A)
MATLAB_VERSION="8.1"
;;
......
......@@ -75,7 +75,7 @@ if ~isequal(B.vobs,C.vobs) && ~(isequal(B.vobs,1) || isequal(C.vobs,1))
else
if B.vobs>C.vobs
idB = 1:B.vobs;
idC = ones(1:B.vobs);
idC = ones(1,B.vobs);
elseif B.vobs<C.vobs
idB = ones(1,C.vobs);
idC = 1:C.vobs;
......@@ -116,6 +116,7 @@ for i=1:A.vobs
A.tex(i) = {['(' B.tex{idB(i)} '+' C.tex{idC(i)} ')']};
end
A.data = bsxfun(@plus,B.data,C.data);
A.time = A.init:A.init+A.nobs;
%@test:1
%$ % Define a datasets.
......
......@@ -97,8 +97,25 @@ switch length(S)
end
end
end
case '.' % Single variable selection.
if ~isequal(S(1).subs,B.name)
case '.'
if isequal(S(1).subs,'init') && isa(B,'dynDate')
% Overwrite the init member...
A.init = B;
% ... and update freq and time members.
A.freq = A.init.freq;
A.time = A.init:(A.init+(A.nobs-1));
return
elseif isequal(S(1).subs,'time') && isa(B,'dynDates')
% Overwrite the time member...
A.time = B;
% ... and update the freq and init members.
A.init = B(1);
A.freq = A.init.freq;
return
elseif ismember(S(1).subs,{'freq','nobs','vobs','data','name','tex'})
error(['dynSeries::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 = strmatch(S(1).subs,A.name);
......@@ -125,6 +142,7 @@ switch length(S)
error('dynSeries::subsasgn: Dimension error! The number of variables on the left and right hand side must match.')
end
A.data(tdx,:) = B.data(tdy,:);
merge_dynSeries_objects = 0;
elseif isnumeric(B)
merge_dynSeries_objects = 0;
if isequal(length(tdx),rows(B))
......@@ -691,4 +709,68 @@ end
%$ 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
\ No newline at end of file
%@eof:18
%@test:19
%$ % Define a datasets.
%$ A = rand(40,3);
%$
%$ % Instantiate two dynSeries object.
%$ ts1 = dynSeries(A,'1950Q1',{'A1';'A2';'A3'},[]);
%$
%$ % Instantiate a dynDate object.
%$ dd = dynDate('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.time(1),dd),1);
%$ end
%$ T = all(t);
%@eof:19
%@test:20
%$ % Define a datasets.
%$ A = rand(40,3);
%$
%$ % Instantiate two dynSeries object.
%$ ts1 = dynSeries(A,'1950Q1',{'A1';'A2';'A3'},[]);
%$
%$ % Instantiate a dynDate object.
%$ dd = dynDate('1952Q1');
%$
%$ % modify first object.
%$ try
%$ ts1.time = 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.time(1),dd),1);
%$ end
%$ T = all(t);
%@eof:20
\ No newline at end of file
......@@ -174,6 +174,16 @@ switch S(1).type
% 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 isa(S(1).subs{1},'dynDates')
% Extract a subsample using a dynDates object
[junk,tdx] = intersect(A.time.time,S(1).subs{1}.time,'rows');
......@@ -188,6 +198,8 @@ switch S(1).type
B.time = A.time(tdx,:);
elseif isvector(S(1).subs{1}) && all(isint(S(1).subs{1}))
% Extract a subsample using a vector of integers (observation index).
% Note that this does not work if S(1).subs is an integer scalar... In which case S(1).subs is interpreted as a lead/lag operator (as in the Dynare syntax).
% To extract one observation, a dynDates with one element or a dynDate input must be used.
if all(S(1).subs{1}>0) && all(S(1).subs{1}<=A.nobs)
if size(A.data,2)>1
S(1).subs = [S(1).subs, ':'];
......@@ -203,6 +215,18 @@ switch S(1).type
else
error('dynSeries::subsref: Indices are out of bounds!')
end
elseif isa(S(1).subs{1},'dynDate')
% Extract a subsample using a dynDates object
[junk,tdx] = intersect(A.time.time,S(1).subs{1}.time,'rows');
B = dynSeries();
B.data = A.data(tdx,:);