Merge branch 'remove-@dates'
commit
bc90d1d6da
|
@ -13,3 +13,7 @@
|
|||
[submodule "matlab/utilities/tests"]
|
||||
path = matlab/utilities/tests
|
||||
url = https://github.com/DynareTeam/m-unit-tests.git
|
||||
[submodule "matlab/modules/dates"]
|
||||
path = matlab/modules/dates
|
||||
url = git@github.com:DynareTeam/dates.git
|
||||
branch = old-oop-syntax
|
||||
|
|
|
@ -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
|
|
@ -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);
|
|
@ -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
|
|
@ -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
|
|
@ -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
|
|
@ -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
|
|
@ -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
|
|
@ -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;
|
|
@ -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
|
|
@ -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
|
|
@ -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
|
|
@ -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
|
|
@ -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
|
|
@ -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
|
|
@ -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);
|
|
@ -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
|
|
@ -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;
|
|
@ -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
|
|
@ -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
|
|
@ -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
|
|
@ -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
|
|
@ -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;
|
|
@ -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
|
|
@ -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
|
|
@ -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
|
|
@ -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
|
|
@ -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
|
|
@ -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
|
|
@ -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
|
|
@ -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')
|
|
@ -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
|
||||
|
|
@ -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
|
|
@ -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
|
|
@ -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
|
|
@ -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
|
|
@ -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{:});
|
|
@ -58,9 +58,9 @@ addpath([dynareroot '/particle/'])
|
|||
addpath([dynareroot '/gsa/'])
|
||||
addpath([dynareroot '/ep/'])
|
||||
addpath([dynareroot '/lmmcp/'])
|
||||
addpath([dynareroot '/modules/dates/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/'])
|
||||
|
|
|
@ -0,0 +1 @@
|
|||
Subproject commit 6374a597d9cb4e24f2083229d58ba4e15642779d
|
|
@ -1,83 +0,0 @@
|
|||
function time = add_periods_to_array_of_dates(time, freq, p) % --*-- Unitary tests --*--
|
||||
|
||||
% Adds a p periods (p can be negative) to a date (or a set of dates) characterized by array time and frequency freq.
|
||||
|
||||
% Copyright (C) 2013 Dynare Team
|
||||
%
|
||||
% This file is part of Dynare.
|
||||
%
|
||||
% Dynare is free software: you can redistribute it and/or modify
|
||||
% it under the terms of the GNU General Public License as published by
|
||||
% the Free Software Foundation, either version 3 of the License, or
|
||||
% (at your option) any later version.
|
||||
%
|
||||
% Dynare is distributed in the hope that it will be useful,
|
||||
% but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
% MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
% GNU General Public License for more details.
|
||||
%
|
||||
% You should have received a copy of the GNU General Public License
|
||||
% along with Dynare. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
if isequal(rows(time),1) && length(p)>1
|
||||
time = repmat(time,length(p),1);
|
||||
end
|
||||
|
||||
time(:,1) = time(:,1) + fix(p/freq);
|
||||
time(:,2) = time(:,2) + rem(p,freq);
|
||||
|
||||
id1 = find(time(:,2)>freq);
|
||||
if ~isempty(id1)
|
||||
time(id1,1) = time(id1,1) + 1;
|
||||
time(id1,2) = time(id1,2) - freq;
|
||||
end
|
||||
|
||||
id2 = find(time(:,2)<1);
|
||||
if ~isempty(id2)
|
||||
time(id2,1) = time(id2,1) - 1;
|
||||
time(id2,2) = time(id2,2) + freq;
|
||||
end
|
||||
|
||||
%@test:1
|
||||
%$ t(1) = dassert(add_periods_to_array_of_dates([1950 1], 4, 1),[1950 2]);
|
||||
%$ t(2) = dassert(add_periods_to_array_of_dates([1950 1], 4, 2),[1950 3]);
|
||||
%$ t(3) = dassert(add_periods_to_array_of_dates([1950 1], 4, 3),[1950 4]);
|
||||
%$ t(4) = dassert(add_periods_to_array_of_dates([1950 1], 4, 4),[1951 1]);
|
||||
%$ t(5) = dassert(add_periods_to_array_of_dates([1950 1], 4, 5),[1951 2]);
|
||||
%$ t(6) = dassert(add_periods_to_array_of_dates([1950 1], 4, 6),[1951 3]);
|
||||
%$ t(7) = dassert(add_periods_to_array_of_dates([1950 1], 4, 7),[1951 4]);
|
||||
%$ t(8) = dassert(add_periods_to_array_of_dates([1950 1], 4, 8),[1952 1]);
|
||||
%$ T = all(t);
|
||||
%@eof:1
|
||||
|
||||
%@test:2
|
||||
%$ t(1) = dassert(add_periods_to_array_of_dates(repmat([1950 1],8,1), 4, transpose(1:8)),[1950 2; 1950 3; 1950 4; 1951 1; 1951 2; 1951 3; 1951 4; 1952 1]);
|
||||
%$ T = all(t);
|
||||
%@eof:2
|
||||
|
||||
%@test:3
|
||||
%$ t(1) = dassert(add_periods_to_array_of_dates([1950 1], 1, 1),[1951 1]);
|
||||
%$ T = all(t);
|
||||
%@eof:3
|
||||
|
||||
%@test:4
|
||||
%$ t(1) = dassert(add_periods_to_array_of_dates([1950 1; 1950 2; 1950 3; 1950 4], 4, 1),[1950 2; 1950 3; 1950 4; 1951 1]);
|
||||
%$ T = all(t);
|
||||
%@eof:4
|
||||
|
||||
%@test:5
|
||||
%$ t(1) = dassert(add_periods_to_array_of_dates([1950 1], 4, transpose(1:8)),[1950 2; 1950 3; 1950 4; 1951 1; 1951 2; 1951 3; 1951 4; 1952 1]);
|
||||
%$ T = all(t);
|
||||
%@eof:5
|
||||
|
||||
%@test:6
|
||||
%$ t(1) = dassert(add_periods_to_array_of_dates([1950 1], 4, -1),[1949 4]);
|
||||
%$ t(2) = dassert(add_periods_to_array_of_dates([1950 1], 4, -2),[1949 3]);
|
||||
%$ t(3) = dassert(add_periods_to_array_of_dates([1950 1], 4, -3),[1949 2]);
|
||||
%$ t(4) = dassert(add_periods_to_array_of_dates([1950 1], 4, -4),[1949 1]);
|
||||
%$ t(5) = dassert(add_periods_to_array_of_dates([1950 1], 4, -5),[1948 4]);
|
||||
%$ t(6) = dassert(add_periods_to_array_of_dates([1950 1], 4, -6),[1948 3]);
|
||||
%$ t(7) = dassert(add_periods_to_array_of_dates([1950 1], 4, -7),[1948 2]);
|
||||
%$ t(8) = dassert(add_periods_to_array_of_dates([1950 1], 4, -8),[1948 1]);
|
||||
%$ T = all(t);
|
||||
%@eof:6
|
|
@ -1,57 +0,0 @@
|
|||
function time = add_periods_to_date(time, freq, p) % --*-- Unitary tests --*--
|
||||
|
||||
% Adds a p periods (p can be negative) to a date (or a set of dates) characterized by array time and frequency freq.
|
||||
|
||||
% Copyright (C) 2013 Dynare Team
|
||||
%
|
||||
% This file is part of Dynare.
|
||||
%
|
||||
% Dynare is free software: you can redistribute it and/or modify
|
||||
% it under the terms of the GNU General Public License as published by
|
||||
% the Free Software Foundation, either version 3 of the License, or
|
||||
% (at your option) any later version.
|
||||
%
|
||||
% Dynare is distributed in the hope that it will be useful,
|
||||
% but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
% MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
% GNU General Public License for more details.
|
||||
%
|
||||
% You should have received a copy of the GNU General Public License
|
||||
% along with Dynare. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
time(1) = time(1) + fix(p/freq);
|
||||
time(2) = time(2) + rem(p,freq);
|
||||
|
||||
if time(2)>freq
|
||||
time(1) = time(1) + 1;
|
||||
time(2) = time(2) - freq;
|
||||
end
|
||||
|
||||
if time(2)<1
|
||||
time(1) = time(1) - 1;
|
||||
time(2) = time(2) + freq;
|
||||
end
|
||||
|
||||
%@test:1
|
||||
%$ t(1) = dassert(add_periods_to_date([1950 1], 4, 1),[1950 2]);
|
||||
%$ t(2) = dassert(add_periods_to_date([1950 1], 4, 2),[1950 3]);
|
||||
%$ t(3) = dassert(add_periods_to_date([1950 1], 4, 3),[1950 4]);
|
||||
%$ t(4) = dassert(add_periods_to_date([1950 1], 4, 4),[1951 1]);
|
||||
%$ t(5) = dassert(add_periods_to_date([1950 1], 4, 5),[1951 2]);
|
||||
%$ t(6) = dassert(add_periods_to_date([1950 1], 4, 6),[1951 3]);
|
||||
%$ t(7) = dassert(add_periods_to_date([1950 1], 4, 7),[1951 4]);
|
||||
%$ t(8) = dassert(add_periods_to_date([1950 1], 4, 8),[1952 1]);
|
||||
%$ T = all(t);
|
||||
%@eof:1
|
||||
|
||||
%@test:2
|
||||
%$ t(1) = dassert(add_periods_to_date([1950 1], 4, -1),[1949 4]);
|
||||
%$ t(2) = dassert(add_periods_to_date([1950 1], 4, -2),[1949 3]);
|
||||
%$ t(3) = dassert(add_periods_to_date([1950 1], 4, -3),[1949 2]);
|
||||
%$ t(4) = dassert(add_periods_to_date([1950 1], 4, -4),[1949 1]);
|
||||
%$ t(5) = dassert(add_periods_to_date([1950 1], 4, -5),[1948 4]);
|
||||
%$ t(6) = dassert(add_periods_to_date([1950 1], 4, -6),[1948 3]);
|
||||
%$ t(7) = dassert(add_periods_to_date([1950 1], 4, -7),[1948 2]);
|
||||
%$ t(8) = dassert(add_periods_to_date([1950 1], 4, -8),[1948 1]);
|
||||
%$ T = all(t);
|
||||
%@eof:2
|
|
@ -1,51 +0,0 @@
|
|||
function s = date2string(varargin)
|
||||
|
||||
% Returns date as a string.
|
||||
%
|
||||
% INPUTS
|
||||
% o varargin{1} + dates object with one element, if nargin==1.
|
||||
% + 1*2 vector of integers (first element is the year, second element is the subperiod), if nargin==2.
|
||||
% o varargin{2} integer scalar equal to 1, 4, 12 or 52 (frequency).
|
||||
%
|
||||
% OUTPUTS
|
||||
% o s string.
|
||||
|
||||
% Copyright (C) 2013 Dynare Team
|
||||
%
|
||||
% This file is part of Dynare.
|
||||
%
|
||||
% Dynare is free software: you can redistribute it and/or modify
|
||||
% it under the terms of the GNU General Public License as published by
|
||||
% the Free Software Foundation, either version 3 of the License, or
|
||||
% (at your option) any later version.
|
||||
%
|
||||
% Dynare is distributed in the hope that it will be useful,
|
||||
% but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
% MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
% GNU General Public License for more details.
|
||||
%
|
||||
% You should have received a copy of the GNU General Public License
|
||||
% along with Dynare. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
if isequal(nargin,1)
|
||||
if ~(isa(varargin{1},'dates') && isequal(length(varargin{1}),1))
|
||||
error(['dates::format: Input argument ' inputname(1) ' has to be a dates object with one element!'])
|
||||
else
|
||||
time = varargin{1}.time;
|
||||
freq = varargin{1}.freq;
|
||||
end
|
||||
end
|
||||
|
||||
if isequal(nargin,2)
|
||||
if ~(isvector(varargin{1}) && isequal(length(varargin{1}),2) && all(isint(varargin{1})) && isscalar(varargin{2} && ismember(varargin{2},[1 4 12 52])))
|
||||
error(['dates::format: First input must be a 1*2 vector of integers and second input must be a scalar integer (1, 4, 12 or 52)!'])
|
||||
else
|
||||
time = varargin{1};
|
||||
freq = varargin{2};
|
||||
end
|
||||
end
|
||||
|
||||
s = [num2str(time(1)) freq2string(freq)];
|
||||
if freq>1
|
||||
s = strcat(s, num2str(time(2)));
|
||||
end
|
|
@ -1,37 +0,0 @@
|
|||
function s = freq2string(freq)
|
||||
|
||||
% INPUTS
|
||||
% o freq scalar integer, equal to 1, 4, 12 or 52 (resp. annual, quaterly, monthly or weekly)
|
||||
%
|
||||
% OUTPUTS
|
||||
% o s character, equal to Y, Q, M or W (resp. annual, quaterly, monthly or weekly)
|
||||
|
||||
% Copyright (C) 2013 Dynare Team
|
||||
%
|
||||
% This file is part of Dynare.
|
||||
%
|
||||
% Dynare is free software: you can redistribute it and/or modify
|
||||
% it under the terms of the GNU General Public License as published by
|
||||
% the Free Software Foundation, either version 3 of the License, or
|
||||
% (at your option) any later version.
|
||||
%
|
||||
% Dynare is distributed in the hope that it will be useful,
|
||||
% but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
% MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
% GNU General Public License for more details.
|
||||
%
|
||||
% You should have received a copy of the GNU General Public License
|
||||
% along with Dynare. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
switch freq
|
||||
case 1
|
||||
s = 'Y';
|
||||
case 4
|
||||
s = 'Q';
|
||||
case 12
|
||||
s = 'M';
|
||||
case 52
|
||||
s = 'W';
|
||||
otherwise
|
||||
error('dates::freq2string: Unknown frequency!')
|
||||
end
|
|
@ -1,55 +0,0 @@
|
|||
function b = isdate(str) % --*-- Unitary tests --*--
|
||||
|
||||
% Tests if the input string can be interpreted as a date.
|
||||
%
|
||||
% INPUTS
|
||||
% o str string.
|
||||
%
|
||||
% OUTPUTS
|
||||
% o b integer scalar, equal to 1 if str can be interpreted as a date or 0 otherwise.
|
||||
|
||||
% Copyright (C) 2013 Dynare Team
|
||||
%
|
||||
% This file is part of Dynare.
|
||||
%
|
||||
% Dynare is free software: you can redistribute it and/or modify
|
||||
% it under the terms of the GNU General Public License as published by
|
||||
% the Free Software Foundation, either version 3 of the License, or
|
||||
% (at your option) any later version.
|
||||
%
|
||||
% Dynare is distributed in the hope that it will be useful,
|
||||
% but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
% MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
% GNU General Public License for more details.
|
||||
%
|
||||
% You should have received a copy of the GNU General Public License
|
||||
% along with Dynare. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
if isnumeric(str) && isscalar(str)
|
||||
b = true;
|
||||
return
|
||||
end
|
||||
|
||||
b = isstringdate(str);
|
||||
|
||||
%@test:1
|
||||
%$
|
||||
%$ date_1 = 1950;
|
||||
%$ date_2 = '1950m2';
|
||||
%$ date_3 = '-1950m2';
|
||||
%$ date_4 = '1950m52';
|
||||
%$ date_5 = ' 1950';
|
||||
%$ date_6 = '1950Y';
|
||||
%$ date_7 = '-1950a';
|
||||
%$ date_8 = '1950m ';
|
||||
%$
|
||||
%$ t(1) = dassert(isdate(date_1),true);
|
||||
%$ t(2) = dassert(isdate(date_2),true);
|
||||
%$ t(3) = dassert(isdate(date_3),true);
|
||||
%$ t(4) = dassert(isdate(date_4),false);
|
||||
%$ t(5) = dassert(isdate(date_5),false);
|
||||
%$ t(6) = dassert(isdate(date_6),true);
|
||||
%$ t(7) = dassert(isdate(date_7),true);
|
||||
%$ t(8) = dassert(isdate(date_8),false);
|
||||
%$ T = all(t);
|
||||
%@eof:1
|
|
@ -1,22 +0,0 @@
|
|||
function B = isdates(A)
|
||||
|
||||
% Tests if the input A is a dates object.
|
||||
|
||||
% Copyright (C) 2013 Dynare Team
|
||||
%
|
||||
% This file is part of Dynare.
|
||||
%
|
||||
% Dynare is free software: you can redistribute it and/or modify
|
||||
% it under the terms of the GNU General Public License as published by
|
||||
% the Free Software Foundation, either version 3 of the License, or
|
||||
% (at your option) any later version.
|
||||
%
|
||||
% Dynare is distributed in the hope that it will be useful,
|
||||
% but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
% MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
% GNU General Public License for more details.
|
||||
%
|
||||
% You should have received a copy of the GNU General Public License
|
||||
% along with Dynare. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
B = isa(A,'dates');
|
|
@ -1,39 +0,0 @@
|
|||
function B = isfreq(A)
|
||||
|
||||
% Tests if A can be interpreted as a frequency.
|
||||
%
|
||||
% INPUTS
|
||||
% o A scalar integer or character.
|
||||
%
|
||||
% OUTPUTS
|
||||
% o B scalar integer equal to one if A can be interpreted as a frequency, zero otherwise.
|
||||
|
||||
% Copyright (C) 2013 Dynare Team
|
||||
%
|
||||
% This file is part of Dynare.
|
||||
%
|
||||
% Dynare is free software: you can redistribute it and/or modify
|
||||
% it under the terms of the GNU General Public License as published by
|
||||
% the Free Software Foundation, either version 3 of the License, or
|
||||
% (at your option) any later version.
|
||||
%
|
||||
% Dynare is distributed in the hope that it will be useful,
|
||||
% but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
% MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
% GNU General Public License for more details.
|
||||
%
|
||||
% You should have received a copy of the GNU General Public License
|
||||
% along with Dynare. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
B = 0;
|
||||
|
||||
if ischar(A)
|
||||
if isequal(length(A),1) && ismember(upper(A),{'Y','A','Q','M','W'})
|
||||
B = 1;
|
||||
return
|
||||
end
|
||||
end
|
||||
|
||||
if isnumeric(A) && isequal(length(A),1) && ismember(A,[1 4 12 52])
|
||||
B = 1;
|
||||
end
|
|
@ -1,58 +0,0 @@
|
|||
function b = ismonthly(str) % --*-- Unitary tests --*--
|
||||
|
||||
% Tests if the input can be interpreted as a monthly date.
|
||||
%
|
||||
% INPUTS
|
||||
% o str string.
|
||||
%
|
||||
% OUTPUTS
|
||||
% o b integer scalar, equal to 1 if str can be interpreted as a monthly date or 0 otherwise.
|
||||
|
||||
% Copyright (C) 2012-2013 Dynare Team
|
||||
%
|
||||
% This file is part of Dynare.
|
||||
%
|
||||
% Dynare is free software: you can redistribute it and/or modify
|
||||
% it under the terms of the GNU General Public License as published by
|
||||
% the Free Software Foundation, either version 3 of the License, or
|
||||
% (at your option) any later version.
|
||||
%
|
||||
% Dynare is distributed in the hope that it will be useful,
|
||||
% but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
% MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
% GNU General Public License for more details.
|
||||
%
|
||||
% You should have received a copy of the GNU General Public License
|
||||
% along with Dynare. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
if ischar(str)
|
||||
if isempty(regexp(str,'^-?[0-9]*[Mm]([1-9]|1[0-2])$','once'))
|
||||
b = 0;
|
||||
else
|
||||
b = 1;
|
||||
end
|
||||
else
|
||||
b = 0;
|
||||
end
|
||||
|
||||
%@test:1
|
||||
%$
|
||||
%$ date_1 = '1950M2';
|
||||
%$ date_2 = '1950m2';
|
||||
%$ date_3 = '-1950m2';
|
||||
%$ date_4 = '1950m12';
|
||||
%$ date_5 = '1950 azd ';
|
||||
%$ date_6 = '1950Y';
|
||||
%$ date_7 = '1950Q3';
|
||||
%$ date_8 = '1950m24';
|
||||
%$
|
||||
%$ t(1) = dassert(ismonthly(date_1),1);
|
||||
%$ t(2) = dassert(ismonthly(date_2),1);
|
||||
%$ t(3) = dassert(ismonthly(date_3),1);
|
||||
%$ t(4) = dassert(ismonthly(date_4),1);
|
||||
%$ t(5) = dassert(ismonthly(date_5),0);
|
||||
%$ t(6) = dassert(ismonthly(date_6),0);
|
||||
%$ t(7) = dassert(ismonthly(date_7),0);
|
||||
%$ t(8) = dassert(ismonthly(date_8),0);
|
||||
%$ T = all(t);
|
||||
%@eof:1
|
|
@ -1,56 +0,0 @@
|
|||
function b = isquaterly(str) % --*-- Unitary tests --*--
|
||||
|
||||
% Tests if the input can be interpreted as a quaterly date.
|
||||
%
|
||||
% INPUTS
|
||||
% o str string.
|
||||
%
|
||||
% OUTPUTS
|
||||
% o b integer scalar, equal to 1 if str can be interpreted as a quaterly date or 0 otherwise.
|
||||
|
||||
% Copyright (C) 2012-2013 Dynare Team
|
||||
%
|
||||
% This file is part of Dynare.
|
||||
%
|
||||
% Dynare is free software: you can redistribute it and/or modify
|
||||
% it under the terms of the GNU General Public License as published by
|
||||
% the Free Software Foundation, either version 3 of the License, or
|
||||
% (at your option) any later version.
|
||||
%
|
||||
% Dynare is distributed in the hope that it will be useful,
|
||||
% but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
% MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
% GNU General Public License for more details.
|
||||
%
|
||||
% You should have received a copy of the GNU General Public License
|
||||
% along with Dynare. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
if ischar(str)
|
||||
if isempty(regexp(str,'^-?[0-9]*[Qq][1-4]$','once'))
|
||||
b = 0;
|
||||
else
|
||||
b = 1;
|
||||
end
|
||||
else
|
||||
b = 0;
|
||||
end
|
||||
|
||||
%@test:1
|
||||
%$
|
||||
%$ date_1 = '1950Q2';
|
||||
%$ date_2 = '1950q2';
|
||||
%$ date_3 = '-1950q2';
|
||||
%$ date_4 = '1950q12';
|
||||
%$ date_5 = '1950 azd ';
|
||||
%$ date_6 = '1950Y';
|
||||
%$ date_7 = '1950m24';
|
||||
%$
|
||||
%$ t(1) = dassert(isquaterly(date_1),1);
|
||||
%$ t(2) = dassert(isquaterly(date_2),1);
|
||||
%$ t(3) = dassert(isquaterly(date_3),1);
|
||||
%$ t(4) = dassert(isquaterly(date_4),0);
|
||||
%$ t(5) = dassert(isquaterly(date_5),0);
|
||||
%$ t(6) = dassert(isquaterly(date_6),0);
|
||||
%$ t(7) = dassert(isquaterly(date_7),0);
|
||||
%$ T = all(t);
|
||||
%@eof:1
|
|
@ -1,54 +0,0 @@
|
|||
function b = isstringdate(str) % --*-- Unitary tests --*--
|
||||
|
||||
% Tests if the input string can be interpreted as a date.
|
||||
%
|
||||
% INPUTS
|
||||
% o str string.
|
||||
%
|
||||
% OUTPUTS
|
||||
% o b integer scalar, equal to 1 if str can be interpreted as a date or 0 otherwise.
|
||||
|
||||
% Copyright (C) 2013 Dynare Team
|
||||
%
|
||||
% This file is part of Dynare.
|
||||
%
|
||||
% Dynare is free software: you can redistribute it and/or modify
|
||||
% it under the terms of the GNU General Public License as published by
|
||||
% the Free Software Foundation, either version 3 of the License, or
|
||||
% (at your option) any later version.
|
||||
%
|
||||
% Dynare is distributed in the hope that it will be useful,
|
||||
% but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
% MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
% GNU General Public License for more details.
|
||||
%
|
||||
% You should have received a copy of the GNU General Public License
|
||||
% along with Dynare. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
if ischar(str)
|
||||
b = isquaterly(str) || isyearly(str) || ismonthly(str) || isweekly(str);
|
||||
else
|
||||
b = 0;
|
||||
end
|
||||
|
||||
%@test:1
|
||||
%$
|
||||
%$ date_1 = '1950M2';
|
||||
%$ date_2 = '1950m2';
|
||||
%$ date_3 = '-1950m2';
|
||||
%$ date_4 = '1950m52';
|
||||
%$ date_5 = ' 1950';
|
||||
%$ date_6 = '1950Y';
|
||||
%$ date_7 = '-1950a';
|
||||
%$ date_8 = '1950m ';
|
||||
%$
|
||||
%$ t(1) = dassert(isstringdate(date_1),true);
|
||||
%$ t(2) = dassert(isstringdate(date_2),true);
|
||||
%$ t(3) = dassert(isstringdate(date_3),true);
|
||||
%$ t(4) = dassert(isstringdate(date_4),false);
|
||||
%$ t(5) = dassert(isstringdate(date_5),false);
|
||||
%$ t(6) = dassert(isstringdate(date_6),true);
|
||||
%$ t(7) = dassert(isstringdate(date_7),true);
|
||||
%$ t(8) = dassert(isstringdate(date_8),false);
|
||||
%$ T = all(t);
|
||||
%@eof:1
|
|
@ -1,24 +0,0 @@
|
|||
function C = issubperiod(A,B)
|
||||
|
||||
% Copyright (C) 2013 Dynare Team
|
||||
%
|
||||
% This file is part of Dynare.
|
||||
%
|
||||
% Dynare is free software: you can redistribute it and/or modify
|
||||
% it under the terms of the GNU General Public License as published by
|
||||
% the Free Software Foundation, either version 3 of the License, or
|
||||
% (at your option) any later version.
|
||||
%
|
||||
% Dynare is distributed in the hope that it will be useful,
|
||||
% but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
% MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
% GNU General Public License for more details.
|
||||
%
|
||||
% You should have received a copy of the GNU General Public License
|
||||
% along with Dynare. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
if isfreq(B)
|
||||
C = all(isint(A)) && all(A>=1) && all(A<=B);
|
||||
else
|
||||
error('issubperiod:: Second input argument must be equal to 1, 4, 12 or 52 (frequency)!')
|
||||
end
|
|
@ -1,58 +0,0 @@
|
|||
function b = isweekly(str) % --*-- Unitary tests --*--
|
||||
|
||||
% Tests if the input can be interpreted as a weekly date.
|
||||
%
|
||||
% INPUTS
|
||||
% o str string.
|
||||
%
|
||||
% OUTPUTS
|
||||
% o b integer scalar, equal to 1 if str can be interpreted as a weekly date or 0 otherwise.
|
||||
|
||||
% Copyright (C) 2012-2013 Dynare Team
|
||||
%
|
||||
% This file is part of Dynare.
|
||||
%
|
||||
% Dynare is free software: you can redistribute it and/or modify
|
||||
% it under the terms of the GNU General Public License as published by
|
||||
% the Free Software Foundation, either version 3 of the License, or
|
||||
% (at your option) any later version.
|
||||
%
|
||||
% Dynare is distributed in the hope that it will be useful,
|
||||
% but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
% MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
% GNU General Public License for more details.
|
||||
%
|
||||
% You should have received a copy of the GNU General Public License
|
||||
% along with Dynare. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
if ischar(str)
|
||||
if isempty(regexp(str,'^-?[0-9]*[Ww]([1-9]|[1-4][0-9]|5[0-2])$','once'))
|
||||
b = 0;
|
||||
else
|
||||
b = 1;
|
||||
end
|
||||
else
|
||||
b = 0;
|
||||
end
|
||||
|
||||
%@test:1
|
||||
%$
|
||||
%$ date_1 = '1950W2';
|
||||
%$ date_2 = '1950w2';
|
||||
%$ date_3 = '-1950w2';
|
||||
%$ date_4 = '1950w22';
|
||||
%$ date_5 = '1950 azd ';
|
||||
%$ date_6 = '1950Y';
|
||||
%$ date_7 = '1950Q3';
|
||||
%$ date_8 = '1950m54';
|
||||
%$
|
||||
%$ t(1) = dassert(isweekly(date_1),1);
|
||||
%$ t(2) = dassert(isweekly(date_2),1);
|
||||
%$ t(3) = dassert(isweekly(date_3),1);
|
||||
%$ t(4) = dassert(isweekly(date_4),1);
|
||||
%$ t(5) = dassert(isweekly(date_5),0);
|
||||
%$ t(6) = dassert(isweekly(date_6),0);
|
||||
%$ t(7) = dassert(isweekly(date_7),0);
|
||||
%$ t(8) = dassert(isweekly(date_8),0);
|
||||
%$ T = all(t);
|
||||
%@eof:1
|
|
@ -1,58 +0,0 @@
|
|||
function b = isyearly(str) % --*-- Unitary tests --*--
|
||||
|
||||
% Tests if the input can be interpreted as a yearly date.
|
||||
%
|
||||
% INPUTS
|
||||
% o str string.
|
||||
%
|
||||
% OUTPUTS
|
||||
% o b integer scalar, equal to 1 if str can be interpreted as a yearly date or 0 otherwise.
|
||||
|
||||
% Copyright (C) 2012-2013 Dynare Team
|
||||
%
|
||||
% This file is part of Dynare.
|
||||
%
|
||||
% Dynare is free software: you can redistribute it and/or modify
|
||||
% it under the terms of the GNU General Public License as published by
|
||||
% the Free Software Foundation, either version 3 of the License, or
|
||||
% (at your option) any later version.
|
||||
%
|
||||
% Dynare is distributed in the hope that it will be useful,
|
||||
% but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
% MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
% GNU General Public License for more details.
|
||||
%
|
||||
% You should have received a copy of the GNU General Public License
|
||||
% along with Dynare. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
if ischar(str)
|
||||
if isempty(regexp(str,'^-?[0-9]*[YyAa]$','once'))
|
||||
b = 0;
|
||||
else
|
||||
b = 1;
|
||||
end
|
||||
else
|
||||
b = 0;
|
||||
end
|
||||
|
||||
%@test:1
|
||||
%$
|
||||
%$ date_1 = '1950M2';
|
||||
%$ date_2 = '1950m2';
|
||||
%$ date_3 = '-1950m2';
|
||||
%$ date_4 = '1950m12';
|
||||
%$ date_5 = '1950 azd ';
|
||||
%$ date_6 = '1950Y';
|
||||
%$ date_7 = '-1950a';
|
||||
%$ date_8 = '1950m24';
|
||||
%$
|
||||
%$ t(1) = dassert(isyearly(date_1),0);
|
||||
%$ t(2) = dassert(isyearly(date_2),0);
|
||||
%$ t(3) = dassert(isyearly(date_3),0);
|
||||
%$ t(4) = dassert(isyearly(date_4),0);
|
||||
%$ t(5) = dassert(isyearly(date_5),0);
|
||||
%$ t(6) = dassert(isyearly(date_6),1);
|
||||
%$ t(7) = dassert(isyearly(date_7),1);
|
||||
%$ t(8) = dassert(isyearly(date_8),0);
|
||||
%$ T = all(t);
|
||||
%@eof:1
|
|
@ -1,109 +0,0 @@
|
|||
function date = string2date(a) % --*-- Unitary tests --*--
|
||||
|
||||
% Copyright (C) 2013 Dynare Team
|
||||
%
|
||||
% This file is part of Dynare.
|
||||
%
|
||||
% Dynare is free software: you can redistribute it and/or modify
|
||||
% it under the terms of the GNU General Public License as published by
|
||||
% the Free Software Foundation, either version 3 of the License, or
|
||||
% (at your option) any later version.
|
||||
%
|
||||
% Dynare is distributed in the hope that it will be useful,
|
||||
% but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
% MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
% GNU General Public License for more details.
|
||||
%
|
||||
% You should have received a copy of the GNU General Public License
|
||||
% along with Dynare. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
date = struct('freq', NaN, 'time', NaN(1,2));
|
||||
|
||||
if ~ischar(a) || ~isdate(a)
|
||||
error('dates::string2date: Input must be a string that can be interpreted as a date!');
|
||||
end
|
||||
|
||||
if isyearly(a)
|
||||
year = 1:(regexp(a,'[AaYy]')-1);
|
||||
date.freq = 1;
|
||||
date.time = write_time_field_y(a, year);
|
||||
return
|
||||
end
|
||||
|
||||
if isquaterly(a)
|
||||
year = 1:(regexp(a,'[Qq]')-1);
|
||||
date.freq = 4;
|
||||
date.time = write_time_field(a, year);
|
||||
return
|
||||
end
|
||||
|
||||
if ismonthly(a)
|
||||
year = 1:(regexp(a,'[Mm]')-1);
|
||||
date.freq = 12;
|
||||
date.time = write_time_field(a, year);
|
||||
return
|
||||
end
|
||||
|
||||
if isweekly(a)
|
||||
year = 1:(regexp(a,'[Ww]')-1);
|
||||
date.freq = 52;
|
||||
date.time = write_time_field(a, year);
|
||||
return
|
||||
end
|
||||
|
||||
|
||||
function b = write_time_field(c, d)
|
||||
b(1) = str2double(c(d));
|
||||
b(2) = str2double(c(d(end)+2:end));
|
||||
|
||||
function b = write_time_field_y(c, d)
|
||||
b(1) = str2double(c(d));
|
||||
b(2) = 1;
|
||||
|
||||
%@test:1
|
||||
%$
|
||||
%$ % Define some dates
|
||||
%$ date_1 = '1950Q2';
|
||||
%$ date_2 = '1950m10';
|
||||
%$ date_3 = '1950w50';
|
||||
%$ date_4 = '1950a';
|
||||
%$ date_5 = '1967y';
|
||||
%$ date_6 = '2009A';
|
||||
%$
|
||||
%$ % Define expected results.
|
||||
%$ e_date_1 = [1950 2];
|
||||
%$ e_freq_1 = 4;
|
||||
%$ e_date_2 = [1950 10];
|
||||
%$ e_freq_2 = 12;
|
||||
%$ e_date_3 = [1950 50];
|
||||
%$ e_freq_3 = 52;
|
||||
%$ e_date_4 = [1950 1];
|
||||
%$ e_freq_4 = 1;
|
||||
%$ e_date_5 = [1967 1];
|
||||
%$ e_freq_5 = 1;
|
||||
%$ e_date_6 = [2009 1];
|
||||
%$ e_freq_6 = 1;
|
||||
%$
|
||||
%$ % Call the tested routine.
|
||||
%$ d1 = string2date(date_1);
|
||||
%$ d2 = string2date(date_2);
|
||||
%$ d3 = string2date(date_3);
|
||||
%$ d4 = string2date(date_4);
|
||||
%$ d5 = string2date(date_5);
|
||||
%$ d6 = string2date(date_6);
|
||||
%$
|
||||
%$ % Check the results.
|
||||
%$ t(1) = dassert(d1.time,e_date_1);
|
||||
%$ t(2) = dassert(d2.time,e_date_2);
|
||||
%$ t(3) = dassert(d3.time,e_date_3);
|
||||
%$ t(4) = dassert(d4.time,e_date_4);
|
||||
%$ t(5) = dassert(d5.time,e_date_5);
|
||||
%$ t(6) = dassert(d6.time,e_date_6);
|
||||
%$ t(7) = dassert(d1.freq,e_freq_1);
|
||||
%$ t(8) = dassert(d2.freq,e_freq_2);
|
||||
%$ t(9) = dassert(d3.freq,e_freq_3);
|
||||
%$ t(10) = dassert(d4.freq,e_freq_4);
|
||||
%$ t(11)= dassert(d5.freq,e_freq_5);
|
||||
%$ t(12)= dassert(d6.freq,e_freq_6);
|
||||
%$ T = all(t);
|
||||
%@eof:1
|
|
@ -1,37 +0,0 @@
|
|||
function freq = string2freq(s)
|
||||
|
||||
% INPUTS
|
||||
% o s character, equal to Y, Q, M or W (resp. annual, quaterly, monthly or weekly)
|
||||
%
|
||||
% OUTPUTS
|
||||
% o freq scalar integer, equal to 1, 4, 12 or 52 (resp. annual, quaterly, monthly or weekly)
|
||||
|
||||
% Copyright (C) 2013 Dynare Team
|
||||
%
|
||||
% This file is part of Dynare.
|
||||
%
|
||||
% Dynare is free software: you can redistribute it and/or modify
|
||||
% it under the terms of the GNU General Public License as published by
|
||||
% the Free Software Foundation, either version 3 of the License, or
|
||||
% (at your option) any later version.
|
||||
%
|
||||
% Dynare is distributed in the hope that it will be useful,
|
||||
% but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
% MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
% GNU General Public License for more details.
|
||||
%
|
||||
% You should have received a copy of the GNU General Public License
|
||||
% along with Dynare. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
switch upper(s)
|
||||
case {'Y','A'}
|
||||
freq = 1;
|
||||
case 'Q'
|
||||
freq = 4;
|
||||
case 'M'
|
||||
freq = 12;
|
||||
case 'W'
|
||||
freq = 52;
|
||||
otherwise
|
||||
error('dates::freq2string: Unknown frequency!')
|
||||
end
|
Loading…
Reference in New Issue