Merge branch 'master' into rewrite-nonlinear-filters

Conflicts:
	.gitmodules
	matlab/particle/online_auxiliary_filter.m
	matlab/particle/solve_model_for_online_filter.m
time-shift
Stéphane Adjemian (Charybdis) 2014-12-12 16:22:06 +01:00
commit 092455419b
168 changed files with 3202 additions and 12871 deletions

8
.gitmodules vendored
View File

@ -16,3 +16,11 @@
[submodule "matlab/particles"]
path = matlab/particles
url = https://github.com/DynareTeam/particles.git
[submodule "matlab/modules/dates"]
path = matlab/modules/dates
url = https://github.com/DynareTeam/dates.git
branch = old-oop-style
[submodule "matlab/modules/dseries"]
path = matlab/modules/dseries
url = https://github.com/DynareTeam/dseries.git
branch = old-oop-style

@ -1 +1 @@
Subproject commit b642763676536c148ad827a0286862be87c5ae8e
Subproject commit 4be470341a73bb22d58bb0d930ff624a5bf1a7f6

View File

@ -356,8 +356,8 @@ 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)
and Sébastien Villemot (Cepremap).
Perendia, Johannes Pfeifer (University of Mannheim), Marco Ratto (European Commission, Joint Research Centre - JRC)
and Sébastien Villemot (OFCE Sciences Po).
Increasingly, the developer base is expanding, as tools developed by
researchers outside of Cepremap are integrated into Dynare. Financial
support is provided by Cepremap, Banque de France and DSGE-net (an
@ -3599,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).
@ -3707,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
@ -5158,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
@ -5183,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}
@ -5483,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}}
@ -5491,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
@ -6402,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;
@ -7137,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}
@ -7166,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.
@ -7213,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}.
@ -10236,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).

View File

@ -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

View File

@ -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) = dassert(d.time,e.time);
%$ t(2) = dassert(d.freq,e.freq);
%$ t(3) = dassert(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) = dassert(d.time,e.time);
%$ t(2) = dassert(d.freq,e.freq);
%$ t(3) = dassert(d.ndat,e.ndat);
%$ T = all(t);
%@eof:2

View File

@ -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);

View File

@ -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) = dassert(d3.time,e.time);
%$ t(2) = dassert(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) = dassert(d.time,e.time);
%$ t(2) = dassert(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) = dassert(d.time,e.time);
%$ t(2) = dassert(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) = dassert(d.time,e.time);
%$ t(2) = dassert(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) = dassert(d.time,e.time);
%$ t(2) = dassert(d.freq,e.freq);
%$ T = all(t);
%$ @eof:4

View File

@ -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) = dassert(d.time,e.time);
%$ t(2) = dassert(d.freq,e.freq);
%$ t(3) = dassert(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) = dassert(d.time,e.time);
%$ t(2) = dassert(d.freq,e.freq);
%$ t(3) = dassert(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) = dassert(d.time,e.time);
%$ t(2) = dassert(d.freq,e.freq);
%$ t(3) = dassert(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) = dassert(d.freq,B.freq);
%$ t(3) = dassert(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) = dassert(d.freq,B.freq);
%$ t(3) = dassert(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) = dassert(d.freq,B.freq);
%$ t(3) = dassert(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

View File

@ -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

View File

@ -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

View File

@ -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) = dassert(C,E);
%$ 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) = dassert(C,E);
%$ end
%$ T = all(t);
%@eof:2

View File

@ -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;

View File

@ -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 = false;
return
end
if isequal(A.ndat, B.ndat)
C = logical(transpose(all(transpose(eq(A.time,B.time)))));
else
if isequal(A.ndat,1) || isequal(B.ndat,1)
C = logical(transpose(all(transpose(bsxfun(@eq,A.time,B.time)))));
else
C = false;
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) = dassert(t1,true(4,1));
%$ t(2) = dassert(t2,false(4,1));
%$ t(2) = dassert(t3,[true; false; true; false]);
%$ 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) = dassert(t1,true);
%$ t(2) = dassert(t2,false);
%$ t(2) = dassert(t3,false);
%$ 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) = dassert(t1,[false; true; false; false]);
%$ t(2) = dassert(t2,false(4,1));
%$ T = all(t);
%@eof:3

View File

@ -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 = false;
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 = false(B.ndat,1);
for i=1:B.ndat
C(i) = greaterorequal(A.time, B.time(i,:));
end
elseif isequal(B.ndat,1)
C = false(A.ndat,1);
for i=1:A.ndat
C(i) = greaterorequal(A.time(i,:), B.time);
end
else
C = false;
end
end
function c = greaterorequal(a,b)
if a(1)>b(1)
c = true;
else
if a(1)<b(1)
c = false;
else
if a(2)>=b(2)
c = true;
else
c = false;
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) = dassert(i1,false);
%$ t(2) = dassert(i2,true);
%$ t(3) = dassert(i3,false);
%$ t(4) = dassert(i4,false);
%$ t(5) = dassert(i5,true);
%$ 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) = dassert(dates(B1)>=dates(B2),false);
%$ t(2) = dassert(dates(B2)>=dates(B1),true);
%$ t(3) = dassert(dates(B2)>=dates(B2),true);
%$ t(4) = dassert(dd>=dates(B5),false(4,1));
%$ t(5) = dassert(dates(B5)>=dd,true(4,1));
%$ t(6) = dassert(dates(B1)>=dd,[true; false(3,1)]);
%$ T = all(t);
%@eof:2

View File

@ -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 = false;
return
end
if isequal(A.ndat, B.ndat)
C = false(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 = false(B.ndat,1);
for i=1:B.ndat
C(i) = greaterthan(A.time, B.time(i,:));
end
elseif isequal(B.ndat,1)
C = false(A.ndat,1);
for i=1:A.ndat
C(i) = greaterthan(A.time(i,:), B.time);
end
else
C = false;
end
end
function c = greaterthan(a,b)
if a(1)>b(1)
c = true;
else
if a(1)<b(1)
c = false;
else
if a(2)>b(2)
c = true;
else
c = false;
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) = dassert(i1,false);
%$ t(2) = dassert(i2,true);
%$ t(3) = dassert(i3,false);
%$ t(4) = dassert(i4,false);
%$ 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) = dassert(dates(B1)>dates(B2),false);
%$ t(2) = dassert(dates(B2)>dates(B1),true);
%$ t(3) = dassert(dates(B5)>dates(B1),true);
%$ t(4) = dassert(dd>dates(B5),false(4,1));
%$ t(5) = dassert(dates(B5)>dd,true(4,1));
%$ t(6) = dassert(dates(B1)>dd,false(4,1));
%$ T = all(t);
%@eof:2

View File

@ -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) = dassert(d.time,e.time);
%$ t(2) = dassert(d.freq,e.freq);
%$ t(3) = dassert(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) = dassert(d.time,e.time);
%$ t(2) = dassert(d.freq,e.freq);
%$ t(3) = dassert(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) = dassert(d.time,e.time);
%$ t(2) = dassert(d.freq,e.freq);
%$ t(3) = dassert(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) = dassert(d.time,e.time);
%$ t(2) = dassert(d.freq,e.freq);
%$ t(3) = dassert(d.ndat,e.ndat);
%$ T = all(t);
%@eof:4

View File

@ -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) = dassert(c1,d2);
%$ t(2) = dassert(isempty(c2),true);
%$ T = all(t);
%@eof:1

View File

@ -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

View File

@ -1,36 +0,0 @@
function C = isequal(A, B, fake)
% 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);

View File

@ -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 = false;
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 = false(B.ndat,1);
for i=1:B.ndat
C(i) = lessorequal(A.time, B.time(i,:));
end
elseif isequal(B.ndat,1)
C = false(A.ndat,1);
for i=1:A.ndat
C(i) = lessorequal(A.time(i,:), B.time);
end
else
C = false;
end
end
function c = lessorequal(a, b)
if a(1)<b(1)
c = true;
else
if a(1)>b(1)
c = false;
else
if a(2)<=b(2)
c = true;
else
c = false;
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) = dassert(i1,true);
%$ t(2) = dassert(i2,false);
%$ t(3) = dassert(i3,true);
%$ t(4) = dassert(i4,true);
%$ t(5) = dassert(i5,true);
%$ 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) = dassert(dates(B1)<=dates(B2),true);
%$ t(2) = dassert(dates(B2)<=dates(B1),false);
%$ t(3) = dassert(dates(B2)<=dates(B2),true);
%$ t(4) = dassert(dd<=dates(B5),true(4,1));
%$ t(5) = dassert(dates(B5)<=dd,false(4,1));
%$ t(6) = dassert(dates(B1)<=dd,true(4,1));
%$ T = all(t);
%@eof:2

View File

@ -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;

View File

@ -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 = false;
return
end
if isequal(A.ndat, B.ndat)
C = false(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 = false(B.ndat,1);
for i=1:B.ndat
C(i) = lessthan(A.time,B.time(i,:));
end
elseif isequal(B.ndat,1)
C = false(A.ndat,1);
for i=1:A.ndat
C(i) = lessthan(A.time(i,:),B.time);
end
else
C = false;
end
end
function c = lessthan(a,b)
if a(1)<b(1)
c = true;
else
if a(1)>b(1)
c = false;
else
if a(2)<b(2)
c = true;
else
c = false;
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) = dassert(i1,true);
%$ t(2) = dassert(i2,false);
%$ t(3) = dassert(i3,true);
%$ t(4) = dassert(i4,true);
%$ 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) = dassert(dates(B1)<dates(B2),true);
%$ t(2) = dassert(dates(B2)<dates(B1),false);
%$ t(3) = dassert(dates(B2)<dates(B1),false);
%$ t(4) = dassert(dd<dates(B5),true(4,1));
%$ t(5) = dassert(dates(B5)<dd,false(4,1));
%$ t(6) = dassert(dates(B1)<dd,[false; true(3,1)]);
%$ T = all(t);
%@eof:2

View File

@ -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) = dassert(i2,1);
%$ t(2) = dassert(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) = dassert(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) = dassert(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) = dassert(i,1);
%$ T = all(t);
%@eof:4

View File

@ -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) = dassert(i2,1);
%$ t(2) = dassert(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) = dassert(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) = dassert(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) = dassert(i,1);
%$ T = all(t);
%@eof:4

View File

@ -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) = dassert(e1,[2; 2; 0]);
%$ t(3) = dassert(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) = dassert(e1,[1; 1; 0]);
%$ t(3) = dassert(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) = dassert(e1,d2);
%$ t(3) = dassert(e2,d1);
%$ 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) = dassert(e1,f1);
%$ 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) = dassert(e1,f1);
%$ end
%$ T = all(t);
%@eof:5

View File

@ -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;

View File

@ -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 = false;
return
end
if isequal(A.ndat, B.ndat)
C = logical(transpose(any(transpose(ne(A.time,B.time)))));
else
if isequal(A.ndat,1) || isequal(B.ndat,1)
C = logical(transpose(any(transpose(bsxfun(@ne,A.time,B.time)))));
else
C = false;
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) = dassert(t1,false(4,1));
%$ t(2) = dassert(t2,true(4,1));
%$ t(3) = dassert(t3,[false; true; false; true]);
%$ 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) = dassert(t1,false);
%$ t(2) = dassert(t2,true);
%$ t(3) = dassert(t3,true);
%$ 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) = dassert(t1,[true; false; true; true]);
%$ t(2) = dassert(t2,true(4,1));
%$ T = all(t);
%@eof:3

View File

@ -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) = dassert(e1,d3);
%$ t(3) = dassert(e2,dates('1950Q1','1950Q2','1950Q3','1950Q4','1950Q1','1950Q2','1950Q3','1950Q4'));
%$ 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) = dassert(e1,f1);
%$ t(3) = dassert(e2,f2);
%$ t(4) = dassert(e3,f3);
%$ t(5) = dassert(e4,f4);
%$ t(6) = dassert(e5,f5);
%$ 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) = dassert(e1,f1);
%$ t(3) = dassert(e2,f2);
%$ t(4) = dassert(e3,f3);
%$ t(5) = dassert(e4,f4);
%$ t(6) = dassert(e5,f5);
%$ end
%$ T = all(t);
%@eof:3

View File

@ -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) = dassert(f.time,e.time(1:end-1,:));
%$ t(2) = dassert(f.freq,e.freq);
%$ t(3) = dassert(f.ndat,e.ndat-1);
%$ f = d.pop(B1);
%$ t(4) = dassert(f.time,[1945 3; 1950 1; 1950 2; 2009 2]);
%$ t(5) = dassert(f.freq,e.freq);
%$ t(6) = dassert(f.ndat,e.ndat-1);
%$ f = d.pop(dates(B1));
%$ t(7) = dassert(f.time,[1945 3; 1950 1; 1950 2; 2009 2]);
%$ t(8) = dassert(f.freq,e.freq);
%$ t(9) = dassert(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) = dassert(f,dates(B1,B2,B3,B4));
%$ f = d.pop(B1);
%$ t(2) = dassert(f,dates(B1,B2,B4,B5));
%$ g = f.pop(1);
%$ t(3) = dassert(g,dates(B2,B4,B5));
%$ T = all(t);
%@eof:2

View File

@ -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) = dassert(c1,d2);
%$ t(2) = dassert(isempty(c2),logical(1));
%$ T = all(t);
%@eof:1

View File

@ -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

View File

@ -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) = dassert(d.time,e.time);
%$ t(2) = dassert(d.freq,e.freq);
%$ t(3) = dassert(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) = dassert(d.time,e.time);
%$ t(2) = dassert(d.freq,e.freq);
%$ t(3) = dassert(d.ndat,e.ndat);
%$ T = all(t);
%@eof:1

View File

@ -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

View File

@ -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')

View File

@ -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) = dassert(d.freq,B.freq);
%$ t(3) = dassert(d.time,[1950 2; 1950 3]);
%$ t(4) = dassert(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) = dassert(d.freq,B.freq);
%$ t(3) = dassert(d.time,[1950 2; 1950 3]);
%$ t(4) = dassert(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) = dassert(d.freq,B.freq);
%$ t(3) = dassert(d.time,[1950 2; 1950 3]);
%$ t(4) = dassert(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) = dassert(d.freq,B.freq);
%$ t(3) = dassert(d.time,[1950 2]);
%$ t(4) = dassert(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) = dassert(r1,r2);
%$ t(5) = dassert(r1,r3);
%$ 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) = dassert(r1,r2);
%$ t(5) = dassert(r1,r3);
%$ end
%$ T = all(t);
%@eof:6

View File

@ -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) = dassert(i1,true);
%$ t(2) = dassert(i2,true);
%$ t(3) = dassert(i3,true);
%$ t(4) = dassert(i4,true);
%$ t(5) = dassert(i5,true);
%$ 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) = dassert(all(d2==d3),true);
%$ end
%$
%$ T = all(t);
%@eof:2

View File

@ -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) = dassert(e1,d1);
%$ t(2) = dassert(e2,d1+d2);
%$ t(3) = dassert(e3,d1+d2+d3);
%$ t(4) = dassert(e4,d1+d2+d3);
%$ t(5) = dassert(e5,d1+d2+d3);
%$ T = all(t);
%@eof:1

View File

@ -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) = dassert(d.time,e.time);
%$ t(2) = dassert(d.freq,e.freq);
%$ t(3) = dassert(d.ndat,e.ndat);
%$ T = all(t);
%@eof:1

View File

@ -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) = dassert(i1,true);
%$ t(2) = dassert(i2,true);
%$ t(3) = dassert(i3,true);
%$ t(4) = dassert(i4,true);
%$ t(5) = dassert(i5,true);
%$ 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) = dassert(all(d2==d3),true);
%$ end
%$
%$ T = all(t);
%@eof:2

View File

@ -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{:});

View File

@ -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) = dassert(ts2.vobs,2);
%$ t(3) = dassert(ts2.nobs,10);
%$ t(4) = dassert(ts2.data,abs(A),1e-15);
%$ t(5) = dassert(ts2.name,{'abs(A1)';'abs(A2)'});
%$ t(6) = dassert(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) = dassert(ts2.vobs,2);
%$ t(3) = dassert(ts2.nobs,10);
%$ t(4) = dassert(ts2.data,abs(A),1e-15);
%$ t(5) = dassert(ts2.name,{'abs(A1)';'abs(A2)'});
%$ t(6) = dassert(ts2.tex,{'|A_1|';'|A_2|'});
%$ end
%$ T = all(t);
%@eof:2

View File

@ -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) = dassert(ts1.nobs,ts2.nobs);
%$ t(3) = dassert(ts1.init,ts2.init);
%$ t(4) = dassert(ts1.data,[NaN(3,3); A], 1e-15);
%$ t(5) = dassert(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) = dassert(ts1.nobs,ts2.nobs);
%$ t(3) = dassert(ts1.init,ts2.init);
%$ t(4) = dassert(ts1.data,A, 1e-15);
%$ t(5) = dassert(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) = dassert(ts1.nobs,ts2.nobs);
%$ t(3) = dassert(ts1.init,ts2.init);
%$ t(4) = dassert(ts1.data,A, 1e-15);
%$ t(5) = dassert(ts2.data,[B; NaN(1,2)], 1e-15);
%$ end
%$ T = all(t);
%@eof:3

View File

@ -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) = dassert(ts.freq,4);
%$ t(3) = dassert(ts.init.freq,4);
%$ t(4) = dassert(ts.init.time,[1953, 1]);
%$ t(5) = dassert(ts.vobs,1);
%$ t(6) = dassert(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

View File

@ -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) = dassert(vs.freq,4);
%$ t(3) = dassert(vs.init.freq,4);
%$ t(4) = dassert(vs.init.time,[1950, 1]);
%$ t(5) = dassert(ts.vobs,1);
%$ t(6) = dassert(vs.nobs,6);
%$ t(7) = isequal(vs.data,transpose(1:6));
%$ end
%$
%$ T = all(t);
%@eof:1

View File

@ -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

View File

@ -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) = dassert(ts,ts);
%$ 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) = dassert(ts3,ts4);
%$ 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) = dassert(ts3,ts4);
%$ warning_config
%$ T = all(t);
%@eof:5

View File

@ -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) = dassert(ts1,ts2);
%$ 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) = dassert(ts1,ts2);
%$ 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) = dassert(ts1,ts2);
%$ 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) = dassert(ts3,ts4);
%$ 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) = dassert(ts3,ts4);
%$ warning_config
%$ T = all(t);
%@eof:5

View File

@ -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) = dassert(max(mean(b1.data)),0,1e-12);
%$ t(7) = dassert(max(mean(b2.data)),0,1e-12);
%$ t(8) = dassert(max(mean(b3.data)),0,1e-12);
%$ t(9) = dassert(max(mean(b4.data)),0,1e-12);
%$ t(10) = dassert(max(mean(b5.data)),0,1e-12);
%$ end
%$ T = all(t);
%@eof:1

View File

@ -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);

View File

@ -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

View File

@ -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 (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 ' varargin{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) = dassert(ts.freq,12);
%$ t(3) = dassert(ts.init.freq,12);
%$ t(4) = dassert(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) = dassert(ts.freq,4);
%$ t(3) = dassert(ts.init.freq,4);
%$ t(4) = dassert(ts.init.time,[1994, 3]);
%$ t(5) = dassert(ts.vobs,2);
%$ t(6) = dassert(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) = dassert(ts.freq,4);
%$ t(3) = dassert(ts.init.freq,4);
%$ t(4) = dassert(ts.init.time,[1994, 3]);
%$ t(5) = dassert(ts.vobs,2);
%$ t(6) = dassert(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) = dassert(ts.freq,4);
%$ t(3) = dassert(ts.init.freq,4);
%$ t(4) = dassert(ts.init.time,[1990, 1]);
%$ t(5) = dassert(ts.vobs,4);
%$ t(6) = dassert(ts.nobs,4);
%$ t(7) = dassert(ts.name,{'azert';'yuiop';'qsdfg';'jklm'});
%$ t(8) = dassert(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) = dassert(ts.freq,1);
%$ t(3) = dassert(ts.init.freq,1);
%$ t(4) = dassert(ts.init.time,[1, 1]);
%$ t(5) = dassert(ts.vobs,1);
%$ t(6) = dassert(ts.nobs,5);
%$ t(7) = dassert(ts.name,{'Variable_1'});
%$ t(8) = dassert(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) = dassert(ts.freq,4);
%$ t(3) = dassert(ts.init.freq,4);
%$ t(4) = dassert(ts.init.time,[1950, 1]);
%$ t(5) = dassert(ts.vobs,1);
%$ t(6) = dassert(ts.nobs,5);
%$ t(7) = dassert(ts.name,{'Variable_1'});
%$ t(8) = dassert(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) = dassert(ts.freq,4);
%$ t(3) = dassert(ts.init.freq,4);
%$ t(4) = dassert(ts.init.time,[1950, 1]);
%$ t(5) = dassert(ts.vobs,2);
%$ t(6) = dassert(ts.nobs,5);
%$ t(7) = dassert(ts.name,{'Output'; 'Consumption'});
%$ t(8) = dassert(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) = dassert(ts.freq,4);
%$ t(3) = dassert(ts.init.freq,4);
%$ t(4) = dassert(ts.init.time,[1990, 1]);
%$ t(5) = dassert(ts.vobs,3);
%$ t(6) = dassert(ts.nobs,5);
%$ t(7) = dassert(ts.name,{'GDP';'Consumption';'CPI'});
%$ t(8) = dassert(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) = dassert(ts.freq,4);
%$ t(3) = dassert(ts.init.freq,4);
%$ t(4) = dassert(ts.init.time,[1990, 1]);
%$ t(5) = dassert(ts.vobs,3);
%$ t(6) = dassert(ts.nobs,5);
%$ t(7) = dassert(ts.name,{'Variable_1';'Variable_2';'Variable_3'});
%$ t(8) = dassert(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) = dassert(ts.freq,1);
%$ t(3) = dassert(ts.init.freq,1);
%$ t(4) = dassert(ts.init.time,[1, 1]);
%$ t(5) = dassert(ts.vobs,3);
%$ t(6) = dassert(ts.nobs,5);
%$ t(7) = dassert(ts.name,{'Variable_1';'Variable_2';'Variable_3'});
%$ t(8) = dassert(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) = dassert(ts.freq,1);
%$ t(3) = dassert(ts.init.freq,1);
%$ t(4) = dassert(ts.init.time,[1, 1]);
%$ t(5) = dassert(ts.vobs,3);
%$ t(6) = dassert(ts.nobs,5);
%$ t(7) = dassert(ts.name,{'GDP';'Consumption';'CPI'});
%$ t(8) = dassert(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) = dassert(ts.freq,4);
%$ t(3) = dassert(ts.init.freq,4);
%$ t(4) = dassert(ts.init.time,[1990, 1]);
%$ t(5) = dassert(ts.vobs,1);
%$ t(6) = dassert(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) = dassert(ts.freq,4);
%$ t(3) = dassert(ts.init.freq,4);
%$ t(4) = dassert(ts.init.time,[1990, 1]);
%$ t(5) = dassert(ts.vobs,2);
%$ t(6) = dassert(ts.nobs,4);
%$ t(7) = dassert(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

View File

@ -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);

View File

@ -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) = dassert(a,logical(ones(10,3)));
%$ end
%$ T = all(t);
%@eof:1

View File

@ -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

View File

@ -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) = dassert(e1.data,a.data);
%$ t(2) = dassert(e1.nobs,a.nobs);
%$ t(3) = dassert(e1.vobs,a.vobs);
%$ t(4) = dassert(e1.name,a.name);
%$ t(5) = dassert(e1.init,a.init);
%$ t(6) = dassert(e2.data,b.data);
%$ t(7) = dassert(e2.nobs,b.nobs);
%$ t(8) = dassert(e2.vobs,b.vobs);
%$ t(9) = dassert(e2.name,b.name);
%$ t(10) = dassert(e2.init,b.init);
%$ 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) = dassert(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

View File

@ -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);

View File

@ -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;

View File

@ -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) = dassert(ts3.init,e.init);
%$ t(2) = dassert(ts3.freq,e.freq);
%$ t(3) = dassert(ts3.data,e.data);
%$ t(4) = dassert(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) = dassert(ts3.init,e.init);
%$ t(2) = dassert(ts3.freq,e.freq);
%$ t(3) = dassert(ts3.data,e.data);
%$ t(4) = dassert(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) = dassert(ts3.init,e.init);
%$ t(2) = dassert(ts3.freq,e.freq);
%$ t(3) = dassert(ts3.data,e.data);
%$ t(4) = dassert(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) = dassert(ts3.init,e.init);
%$ t(2) = dassert(ts3.freq,e.freq);
%$ t(3) = dassert(ts3.data,e.data);
%$ t(4) = dassert(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) = dassert(ts4.init,e.init);
%$ t(2) = dassert(ts4.freq,e.freq);
%$ t(3) = dassert(ts4.data,e.data);
%$ t(4) = dassert(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) = dassert(ts3.freq,4);
%$ t(3) = dassert(ts3.data,X);
%$ t(4) = dassert(ts3.dates(1),dates('1950Q2'));
%$ end
%$
%$ T = t;
%@eof:7

View File

@ -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) = dassert(ts2.freq,4);
%$ t(3) = dassert(ts2.init.freq,4);
%$ t(4) = dassert(ts2.init.time,[1950, 1]);
%$ t(5) = dassert(ts2.vobs,1);
%$ t(6) = dassert(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

View File

@ -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) = dassert(ts2.freq,4);
%$ t(3) = dassert(ts2.init.freq,4);
%$ t(4) = dassert(ts2.init.time,[1950, 1]);
%$ t(5) = dassert(ts2.vobs,1);
%$ t(6) = dassert(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

View File

@ -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) = dassert(ts1.vobs,{'B1';'A1';'B2';'A3'});
%$ t(3) = dassert(ts1.nobs,10);
%$ eB = [NaN(2,2); B; NaN(3,2)];
%$ t(4) = dassert(ts1.data,[eB(:,1), A(:,1), eB(:,2), A(:,2:3)], 1e-15);
%$ end
%$ T = all(t);
%@eof:1

View File

@ -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);

View File

@ -1,70 +0,0 @@
function C = isequal(A, B, tol)
% Overloads the isequal Matlab/Octave's function.
%
% INPUTS
% o A dseries object (T periods, N variables).
% o B dseries object (T periods, N variables).
% o tol tolerance parameter.
%
% 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
if nargin<3
C = isequal(A.data, B.data);
else
C = ~(max(abs(A.data(:)-B.data(:)))>tol);
end

View File

@ -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) = dassert(a.data,DATA,1e-15);
%$ DATA = [NaN(2,ts.vobs); transpose(0:1:48)];
%$ t(3) = dassert(b.data,DATA,1e-15);
%$ t(4) = dassert(b.data,c.data,1e-15);
%$ end
%$
%$ T = all(t);
%@eof:1

View File

@ -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);

View File

@ -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) = dassert(a.data,DATA,1e-15);
%$ DATA = [transpose(2:50); NaN(2,ts.vobs)];
%$ t(3) = dassert(b.data,DATA,1e-15);
%$ t(4) = dassert(b.data,c.data,1e-15);
%$ end
%$
%$ T = all(t);
%@eof:1

View File

@ -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);

View File

@ -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) = dassert(ts3.vobs,2);
%$ t(3) = dassert(ts3.nobs,10);
%$ t(4) = dassert(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) = dassert(ts3.vobs,3);
%$ t(3) = dassert(ts3.nobs,10);
%$ t(4) = dassert(ts3.data,[A, B],1e-15);
%$ end
%$ T = all(t);
%@eof:2

View File

@ -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) = dassert(ts3.vobs,2);
%$ t(3) = dassert(ts3.nobs,10);
%$ t(4) = dassert(ts3.data,[A(:,1)-B, A(:,2)-B],1e-15);
%$ t(5) = dassert(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) = dassert(ts3.vobs,2);
%$ t(3) = dassert(ts3.nobs,10);
%$ t(4) = dassert(ts3.data,[A(1:5,1)-B(1:5), A(1:5,2)-B(1:5) ; NaN(5,2)],1e-15);
%$ t(5) = dassert(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

View File

@ -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) = dassert(ts3.vobs,2);
%$ t(3) = dassert(ts3.nobs,10);
%$ t(4) = dassert(ts3.data,A.^B,1e-15);
%$ t(5) = dassert(ts3.name,{'power(A1;B1)';'power(A2;B2)'});
%$ t(6) = dassert(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) = dassert(ts3.vobs,2);
%$ t(3) = dassert(ts3.nobs,10);
%$ t(4) = dassert(ts3.data,A.^2,1e-15);
%$ t(5) = dassert(ts3.name,{'power(A1;2)';'power(A2;2)'});
%$ t(6) = dassert(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) = dassert(ts2.vobs,2);
%$ t(3) = dassert(ts2.nobs,3);
%$ t(4) = dassert(ts2.data,bsxfun(@power,ts1.data,transpose(1:3)),1e-15);
%$ t(5) = dassert(ts2.name,{'MyVar1';'MyVar2'});
%$ t(6) = dassert(ts2.tex,{'MyVar1';'MyVar2'});
%$ end
%$ T = all(t);
%@eof:3

View File

@ -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) = dassert(ts3.vobs,2);
%$ t(3) = dassert(ts3.nobs,10);
%$ t(4) = dassert(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) = dassert(ts2.vobs,2);
%$ t(3) = dassert(ts2.nobs,10);
%$ t(4) = dassert(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) = dassert(ts2.vobs,2);
%$ t(3) = dassert(ts2.nobs,10);
%$ t(4) = dassert(ts2.data,B./A,1e-15);
%$ end
%$ T = all(t);
%@eof:3

View File

@ -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) = dassert(ts3.vobs,2);
%$ t(3) = dassert(ts3.nobs,10);
%$ t(4) = dassert(ts3.data,[A(:,1).*B, A(:,2).*B],1e-15);
%$ t(5) = dassert(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) = dassert(ts2.vobs,2);
%$ t(3) = dassert(ts2.nobs,10);
%$ t(4) = dassert(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) = dassert(ts2.vobs,2);
%$ t(3) = dassert(ts2.nobs,10);
%$ t(4) = dassert(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) = dassert(ts2.vobs,2);
%$ t(3) = dassert(ts2.nobs,10);
%$ t(4) = dassert(ts2.data,bsxfun(@times,A,B),1e-15);
%$ end
%$ T = all(t);
%@eof:4

View File

@ -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 t(1)
%$ t(2) = dassert(a,logical([ones(10,2), ones(10,1)]));
%$ end
%$ T = all(t);
%@eof:1

View File

@ -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);

View File

@ -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;

View File

@ -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

View File

@ -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) = dassert(ts3.vobs,2);
%$ t(3) = dassert(ts3.nobs,10);
%$ t(4) = dassert(ts3.data,[A(:,1)+B, A(:,2)+B],1e-15);
%$ t(5) = dassert(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) = dassert(ts4.vobs,2);
%$ t(3) = dassert(ts4.nobs,10);
%$ t(4) = dassert(ts4.data,[A(:,1)+B, A(:,2)+B]+A,1e-15);
%$ t(5) = dassert(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) = dassert(ts3.vobs,2);
%$ t(3) = dassert(ts3.nobs,10);
%$ t(4) = dassert(ts3.data,[A(1:5,1)+B(1:5), A(1:5,2)+B(1:5) ; NaN(5,2)],1e-15);
%$ t(5) = dassert(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) = dassert(ts.freq,4);
%$ t(3) = dassert(us.freq,4);
%$ t(4) = dassert(ts.init.time,[1950, 1]);
%$ t(5) = dassert(us.init.time,[1949, 4]);
%$ t(6) = dassert(vs.init.time,[1949, 4]);
%$ t(7) = dassert(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) = dassert(ts.freq,4);
%$ t(3) = dassert(us.freq,4);
%$ t(4) = dassert(ts.init.time,[1950, 1]);
%$ t(5) = dassert(us.init.time,[1950, 1]);
%$ t(6) = dassert(vs.init.time,[1950, 1]);
%$ t(7) = dassert(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) = dassert(ts.freq,4);
%$ t(3) = dassert(us.freq,4);
%$ t(4) = dassert(ts.init.time,[1950, 1]);
%$ t(5) = dassert(us.init.time,[1950, 1]);
%$ t(6) = dassert(vs.init.time,[1950, 1]);
%$ t(7) = dassert(vs.nobs,5);
%$ t(8) = dassert(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) = dassert(ts.freq,4);
%$ t(3) = dassert(us.freq,4);
%$ t(4) = dassert(ts.init.time,[1950, 1]);
%$ t(5) = dassert(us.init.time,[1950, 1]);
%$ t(6) = dassert(vs.init.time,[1950, 1]);
%$ t(7) = dassert(vs.nobs,5);
%$ t(8) = dassert(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

View File

@ -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) = dassert(ts2.vobs,2);
%$ t(3) = dassert(ts2.nobs,10);
%$ t(4) = dassert(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) = dassert(id,0);
%$ t(2) = dassert(ts1,ts2);
%$ end
%$ T = all(t);
%@eof:2

View File

@ -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

View File

@ -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) = dassert(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) = dassert(ts.data,DATA,1e-15);
%$ end
%$
%$ T = all(t);
%@eof:2

View File

@ -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) = dassert(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) = dassert(ts.data,DATA,1e-15);
%$ end
%$
%$ T = all(t);
%@eof:2

View File

@ -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) = dassert(ts2.vobs,2);
%$ t(3) = dassert(ts2.nobs,10);
%$ t(4) = dassert(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) = dassert(ts2.vobs,2);
%$ t(3) = dassert(ts2.nobs,10);
%$ t(4) = dassert(ts2.data,[A(:,1), A(:,3)],1e-15);
%$ end
%$ T = all(t);
%@eof:2

View File

@ -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) = dassert(ts.freq,4);
%$ t(3) = dassert(ts.init.freq,4);
%$ t(4) = dassert(ts.init.time,[1950, 1]);
%$ t(5) = dassert(ts.vobs,2);
%$ t(6) = dassert(ts.nobs,5);
%$ t(7) = dassert(ts.name,{'Production'; 'Consumption'});
%$ t(8) = dassert(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) = dassert(ts.freq,4);
%$ t(3) = dassert(ts.init.freq,4);
%$ t(4) = dassert(ts.init.time,[1950, 1]);
%$ t(5) = dassert(ts.vobs,2);
%$ t(6) = dassert(ts.nobs,5);
%$ t(7) = dassert(ts.name,{'Production'; 'Consumption'});
%$ t(8) = dassert(ts.tex,{'Y_t'; 'C_t'});
%$ end
%$
%$ T = all(t);
%@eof:2

View File

@ -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

View File

@ -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) = dassert(ts2.vobs,3);
%$ t(3) = dassert(ts2.nobs,10);
%$ t(4) = dassert(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) = dassert(ts1.vobs,3);
%$ t(3) = dassert(ts1.nobs,10);
%$ t(4) = dassert(ts1.name,A_name);
%$ end
%$ T = all(t);
%@eof:2

View File

@ -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

View File

@ -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) = dassert(ts1.vobs,3);
%$ t(3) = dassert(ts1.nobs,10);
%$ t(4) = dassert(ts1.name{2},'A2');
%$ t(5) = dassert(ts1.name{1},'A1');
%$ t(6) = dassert(ts1.name{3},'A3');
%$ t(7) = dassert(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) = dassert(ts1.vobs,3);
%$ t(2) = dassert(ts1.nobs,10);
%$ t(3) = dassert(ts1.name{2},'A2');
%$ t(4) = dassert(ts1.name{1},'A1');
%$ t(5) = dassert(ts1.name{3},'A3');
%$ t(6) = dassert(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) = dassert(ts1.vobs,3);
%$ t(2) = dassert(ts1.nobs,10);
%$ t(3) = dassert(ts1.name{2},'A2');
%$ t(4) = dassert(ts1.name{1},'A1');
%$ t(5) = dassert(ts1.name{3},'A3');
%$ t(6) = dassert(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) = dassert(ts1.vobs,3);
%$ t(2) = dassert(ts1.nobs,10);
%$ t(3) = dassert(ts1.name{1},'A1') && dassert(ts1.name{2},'A2') && dassert(ts1.name{3},'A3');
%$ t(4) = dassert(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) = dassert(ts1.vobs,3);
%$ t(2) = dassert(ts1.nobs,10);
%$ t(3) = dassert(ts1.name{1},'A1');
%$ t(4) = dassert(ts1.data(:,1),B(:,1), 1e-15);
%$ t(5) = dassert(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) = dassert(ts1.vobs,4);
%$ t(3) = dassert(ts1.nobs,10);
%$ t(4) = dassert(ts1.name{1},'A1');
%$ t(5) = dassert(ts1.name{2},'A2');
%$ t(6) = dassert(ts1.name{3},'A3');
%$ t(7) = dassert(ts1.name{4},'B2');
%$ t(8) = dassert(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) = dassert(ts1.vobs,4);
%$ t(3) = dassert(ts1.nobs,10);
%$ t(4) = dassert(ts1.name{1},'A1');
%$ t(5) = dassert(ts1.name{2},'A2');
%$ t(6) = dassert(ts1.name{3},'A3');
%$ t(6) = dassert(ts1.name{4},'B2');
%$ t(7) = dassert(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) = dassert(ts1.vobs,4);
%$ t(3) = dassert(ts1.nobs,10);
%$ t(4) = dassert(ts1.name{2},'A2');
%$ t(5) = dassert(ts1.name{1},'A1');
%$ t(6) = dassert(ts1.name{3},'A3');
%$ t(7) = dassert(ts1.name{4},'A4');
%$ t(8) = dassert(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) = dassert(ts1.vobs,4);
%$ t(3) = dassert(ts1.nobs,10);
%$ t(4) = dassert(ts1.name{2},'A2');
%$ t(5) = dassert(ts1.name{1},'A1');
%$ t(6) = dassert(ts1.name{3},'A3');
%$ t(7) = dassert(ts1.name{4},'A4');
%$ t(8) = dassert(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) = dassert(ts1.vobs,4);
%$ t(3) = dassert(ts1.nobs,10);
%$ t(4) = dassert(ts1.name{1},'A1');
%$ t(5) = dassert(ts1.name{2},'A2');
%$ t(6) = dassert(ts1.name{3},'A3');
%$ t(7) = dassert(ts1.name{4},'A4');
%$ t(8) = dassert(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) = dassert(ts1.vobs,4);
%$ %t(3) = dassert(ts1.nobs,10);
%$ %t(4) = dassert(ts1.name,{'A1','A2';'A3';'B1';'B2'});
%$ %t(5) = dassert(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) = dassert(ts1.vobs,3);
%$ t(3) = dassert(ts1.nobs,40);
%$ t(4) = dassert(ts1.name{2},'A2');
%$ t(5) = dassert(ts1.name{1},'A1');
%$ t(6) = dassert(ts1.name{3},'A3');
%$ t(7) = dassert(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) = dassert(ts1.vobs,3);
%$ t(3) = dassert(ts1.nobs,40);
%$ t(4) = dassert(ts1.name{2},'A2');
%$ t(5) = dassert(ts1.name{1},'A1');
%$ t(6) = dassert(ts1.name{3},'A3');
%$ t(7) = dassert(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) = dassert(ts1.vobs,3);
%$ t(3) = dassert(ts1.nobs,40);
%$ t(4) = dassert(ts1.name{2},'A2');
%$ t(5) = dassert(ts1.name{1},'A1');
%$ t(6) = dassert(ts1.name{3},'A3');
%$ t(7) = dassert(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) = dassert(ts1.vobs,3);
%$ t(3) = dassert(ts1.nobs,40);
%$ t(4) = dassert(ts1.name{2},'A2');
%$ t(5) = dassert(ts1.name{1},'A1');
%$ t(6) = dassert(ts1.name{3},'A3');
%$ t(7) = dassert(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) = dassert(ts1.vobs,3);
%$ t(3) = dassert(ts1.nobs,40);
%$ t(4) = dassert(ts1.name{2},'A2');
%$ t(5) = dassert(ts1.name{1},'A1');
%$ t(6) = dassert(ts1.name{3},'A3');
%$ t(7) = dassert(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) = dassert(ts1.vobs,3);
%$ t(3) = dassert(ts1.nobs,40);
%$ t(4) = dassert(ts1.name{2},'A2');
%$ t(5) = dassert(ts1.name{1},'A1');
%$ t(6) = dassert(ts1.name{3},'A3');
%$ t(7) = dassert(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) = dassert(ts1.vobs,3);
%$ t(3) = dassert(ts1.nobs,40);
%$ t(4) = dassert(ts1.name{2},'A2');
%$ t(5) = dassert(ts1.name{1},'A1');
%$ t(6) = dassert(ts1.name{3},'A3');
%$ t(7) = dassert(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) = dassert(ts1.vobs,3);
%$ t(3) = dassert(ts1.nobs,40);
%$ t(4) = dassert(ts1.name{2},'A2');
%$ t(5) = dassert(ts1.name{1},'A1');
%$ t(6) = dassert(ts1.name{3},'A3');
%$ t(7) = dassert(ts1.data,A,1e-15);
%$ t(8) = dassert(ts1.init,dd);
%$ t(9) = dassert(ts1.dates(1),dd);
%$ 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) = dassert(ts1.vobs,3);
%$ t(3) = dassert(ts1.nobs,40);
%$ t(4) = dassert(ts1.name{2},'A2');
%$ t(5) = dassert(ts1.name{1},'A1');
%$ t(6) = dassert(ts1.name{3},'A3');
%$ t(7) = dassert(ts1.data,A,1e-15);
%$ t(8) = dassert(ts1.init,dd);
%$ t(9) = dassert(ts1.dates(1),dd);
%$ 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) = dassert(ts.vobs,3);
%$ t(3) = dassert(ts.nobs,4);
%$ t(4) = dassert(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) = dassert(ts.vobs,3);
%$ t(3) = dassert(ts.nobs,4);
%$ t(4) = dassert(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

View File

@ -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) = dassert(a.data,e.data);
%$ t(2) = dassert(a.nobs,e.nobs);
%$ t(3) = dassert(a.vobs,e.vobs);
%$ t(4) = dassert(a.freq,e.freq);
%$ t(5) = dassert(a.init,e.init);
%$ 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) = dassert(a.data,e.data);
%$ t(2) = dassert(a.init,e.init);
%$ t(3) = dassert(a.nobs,e.nobs);
%$ t(4) = dassert(a.vobs,e.vobs);
%$ t(5) = dassert(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) = dassert(a.data,e.data);
%$ t(2) = dassert(a.nobs,e.nobs);
%$ t(3) = dassert(a.vobs,e.vobs);
%$ t(4) = dassert(a.freq,e.freq);
%$ t(5) = dassert(a.init,e.init);
%$ 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) = dassert(A.nobs,4);
%$ t(3) = dassert(A.vobs,4);
%$ t(4) = dassert(A.freq,4);
%$ t(5) = dassert(A.init,dates('1990Q1'));
%$ 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) = dassert(e.data,a.data);
%$ t(2) = dassert(e.nobs,a.nobs);
%$ t(3) = dassert(e.vobs,a.vobs);
%$ t(4) = dassert(e.name,a.name);
%$ t(5) = dassert(e.init,a.init);
%$ 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) = dassert(e1.data,a.data);
%$ t(2) = dassert(e1.nobs,a.nobs);
%$ t(3) = dassert(e1.vobs,a.vobs);
%$ t(4) = dassert(e1.name,a.name);
%$ t(5) = dassert(e1.init,a.init);
%$ t(6) = dassert(e2.data,b.data);
%$ t(7) = dassert(e2.nobs,b.nobs);
%$ t(8) = dassert(e2.vobs,b.vobs);
%$ t(9) = dassert(e2.name,b.name);
%$ t(10) = dassert(e2.init,b.init);
%$ 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) = dassert(e.data,a.data);
%$ t(2) = dassert(e.nobs,a.nobs);
%$ t(3) = dassert(e.vobs,a.vobs);
%$ t(4) = dassert(e.name,a.name);
%$ t(5) = dassert(e.init,a.init);
%$ 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) = dassert(B,[60, 3]);
%$ t(2) = dassert(E,[60, 3]);
%$ t(3) = dassert(C,60);
%$ t(4) = dassert(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) = dassert(B.name{1},'A1');
%$ t(2) = dassert(B.data,A(:,1));
%$ t(3) = dassert(C.name{1},'A1');
%$ t(4) = dassert(C.data(:,1),A(:,1));
%$ t(5) = dassert(C.name{2},'B1');
%$ t(6) = dassert(C.data(:,2),A(:,3));
%$ t(7) = dassert(D.name{1},'A1');
%$ t(8) = dassert(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

View File

@ -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) = dassert(ts.freq,4);
%$ t(3) = dassert(ts.init.freq,4);
%$ t(4) = dassert(ts.init.time,[1950, 1]);
%$ t(5) = dassert(ts.vobs,2);
%$ t(6) = dassert(ts.nobs,5);
%$ t(7) = dassert(ts.name,{'Output'; 'Consumption'});
%$ t(8) = dassert(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) = dassert(ts.freq,4);
%$ t(3) = dassert(ts.init.freq,4);
%$ t(4) = dassert(ts.init.time,[1950, 1]);
%$ t(5) = dassert(ts.vobs,2);
%$ t(6) = dassert(ts.nobs,5);
%$ t(7) = dassert(ts.name,{'Output'; 'Consumption'});
%$ t(8) = dassert(ts.tex,{'\\Delta Y_t'; 'C_t'});
%$ end
%$
%$ T = all(t);
%@eof:2

View File

@ -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) = dassert(ts2.vobs,2);
%$ t(3) = dassert(ts2.nobs,10);
%$ t(4) = dassert(ts2.data,-A,1e-15);
%$ t(5) = dassert(ts2.name,{'-A1';'-A2'});
%$ t(6) = dassert(ts2.tex,{'-A_1';'-A_2'});
%$ end
%$ T = all(t);
%@eof:1

View File

@ -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) = dassert(ts3.init,e.init);
%$ t(2) = dassert(ts3.freq,e.freq);
%$ t(3) = dassert(ts3.data,e.data);
%$ t(4) = dassert(ts3.name,e.name);
%$ t(5) = dassert(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) = dassert(ts4.init,e.init);
%$ t(2) = dassert(ts4.freq,e.freq);
%$ t(3) = dassert(ts4.data,e.data);
%$ t(4) = dassert(ts4.name,e.name);
%$ t(5) = dassert(ts4.nobs,30);
%$ T = all(t);
%@eof:2

View File

@ -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);

View File

@ -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) = dassert(ts.data,DATA);
%$ t(3) = dassert(ts.name{1},['ydiff(A1)']);
%$ t(4) = dassert(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) = dassert(ts.data,DATA);
%$ t(3) = dassert(ts.name{1},['ydiff(A1)']);
%$ t(4) = dassert(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) = dassert(ts.data,DATA);
%$ t(3) = dassert(ts.name{1},['ydiff(A1)']);
%$ t(4) = dassert(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) = dassert(ts.data,DATA);
%$ t(3) = dassert(ts.name{1},['ydiff(A1)']);
%$ t(4) = dassert(ts.tex{1},['\\Delta A_1']);
%$ end
%$
%$ T = all(t);
%@eof:4

View File

@ -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) = dassert(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) = dassert(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) = dassert(ts.data,DATA);
%$ end
%$
%$ T = all(t);
%@eof:3

View File

@ -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);

View File

@ -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
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
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
% CONDITIONAL VARIANCE DECOMPOSITION.
if Steps

View File

@ -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

View File

@ -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;
@ -51,7 +53,9 @@ oo_.mean = m;
oo_.var = oo_.gamma_y{1};
if size(stationary_vars, 1) > 0
oo_.variance_decomposition=100*oo_.gamma_y{options_.ar+2};
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,7 @@ if size(stationary_vars, 1) > 0
lh = size(labels,2)+2;
dyntable(title,headers,labels,z,lh,11,4);
if M_.exo_nbr > 1
if M_.exo_nbr > 1 && ~nodecomposition
skipline()
if options_.order == 2
title='APPROXIMATED VARIANCE DECOMPOSITION (in percent)';

View File

@ -94,7 +94,7 @@ if options_.steadystate_flag
end
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
[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_);

View File

@ -57,12 +57,12 @@ addpath([dynareroot '/particles/src'])
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/src/'])
addpath([dynareroot '/utilities/dates/'])
addpath([dynareroot '/utilities/dataset/'])
addpath([dynareroot '/utilities/general/'])
addpath([dynareroot '/utilities/dseries/'])
addpath([dynareroot '/reports/'])
% For functions that exist only under some Octave versions
@ -90,6 +90,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'))
@ -250,7 +255,7 @@ if verbose
end
% Save empty dates and dseries objects (necessary if a mod file is not preprocessed).
dates('initialize');
initialize_dates_toolbox;
dseries('initialize');
cd(origin);

Some files were not shown because too many files have changed in this diff Show More