Renamed dynDates class as dates.

time-shift
Stéphane Adjemian (Charybdis) 2013-10-15 15:36:21 +02:00
parent aec191c825
commit 868c3c6a5e
45 changed files with 429 additions and 429 deletions

View File

@ -1,16 +1,16 @@
function B = append(A,a) % --*-- Unitary tests --*--
% append method for dynDates class.
% append method for dates class.
%
% INPUTS
% o A dynDates object.
% o a dynDates object with one element or string that can be interpreted as a date.
% o A dates object.
% o a dates object with one element or string that can be interpreted as a date.
%
% OUTPUTS
% o B dynDates object containing dates defined in A and a.
% o B dates object containing dates defined in A and a.
%
% EXAMPLE 1
% If A is a dynDates object with quarterly frequency, then B = A.append(dynDates('1950Q2')) and
% 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
@ -30,23 +30,23 @@ function B = append(A,a) % --*-- Unitary tests --*--
% 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,'dynDates')
if isa(a,'dates')
if ~isequal(length(a),1)
error(['dynDates::append: Input argument ' inputname(a) ' has to be a dynDates object with one element.'])
error(['dates::append: Input argument ' inputname(a) ' has to be a dates object with one element.'])
end
if isempty(a)
B = A;
return
end
elseif isdate(a)
a = dynDates(a);
a = dates(a);
end
if ~isequal(A.freq, a.freq)
error(['dynDates::append: A and a must have common frequency!'])
error(['dates::append: A and a must have common frequency!'])
end
B = dynDates();
B = dates();
B.ndat = A.ndat+1;
B.freq = A.freq;
B.time = NaN(B.ndat,2);
@ -67,8 +67,8 @@ B.time(A.ndat+1,:) = a.time;
%$ e.ndat = 5;
%$
%$ % Call the tested routine.
%$ d = dynDates(B4,B3,B2,B1);
%$ d = d.append(dynDates(B5));
%$ d = dates(B4,B3,B2,B1);
%$ d = d.append(dates(B5));
%$
%$ % Check the results.
%$ t(1) = dyn_assert(d.time,e.time);
@ -91,7 +91,7 @@ B.time(A.ndat+1,:) = a.time;
%$ e.ndat = 5;
%$
%$ % Call the tested routine.
%$ d = dynDates(B4,B3,B2,B1);
%$ d = dates(B4,B3,B2,B1);
%$ d = d.append(B5);
%$
%$ % Check the results.

View File

@ -3,12 +3,12 @@ function C = colon(varargin) % --*-- Unitary tests --*--
% Overloads the colon operator (:). This method can be used to create ranges of dates.
%
% INPUTS
% o A dynDates object with one element.
% 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 dynDates object with one element.
% o B dates object with one element.
%
% OUTPUTS
% o C dynDates object with length(B-A) elements (if d==1).
% o C dates object with length(B-A) elements (if d==1).
%
% REMARKS
% B must be greater than A if d>0.
@ -34,39 +34,39 @@ if isequal(nargin,2)
A = varargin{1};
B = varargin{2};
d = 1;
if ~(isa(A,'dynDates') && isa(B,'dynDates') && isequal(length(A),1) && isequal(length(B),1))
error('dynDates::colon: In an expression like A:B, A and B must be dynDates objects!')
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,'dynDates') && isa(B,'dynDates') && isequal(length(A),1) && isequal(length(B),1))
error('dynDates::colon: In an expression like A:d:B, A and B must be dynDates objects and d a scalar integer (number of periods)!')
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('dynDates::colon: In an expression like A:d:B, A and B must be dynDates objects and d a scalar integer (number of periods)!')
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('dynDates::colon: In an expression like A:d:B, d (the incremental number of periods) must nonzero!')
error('dates::colon: In an expression like A:d:B, d (the incremental number of periods) must nonzero!')
end
else
error('dynDates::colon: Wrong calling sequence! See the manual for the colon (:) operator and dynDates objects.')
error('dates::colon: Wrong calling sequence! See the manual for the colon (:) operator and dates objects.')
end
if ~isequal(A.freq,B.freq)
error(['dynDates::colon: Input arguments ' inputname(1) 'and ' inputname(2) ' must have common frequency!'])
error(['dates::colon: Input arguments ' inputname(1) 'and ' inputname(2) ' must have common frequency!'])
end
if A>B && d>0
error(['dynDates::colon: ' inputname(1) ' must precede ' inputname(2) '!' ])
error(['dates::colon: ' inputname(1) ' must precede ' inputname(2) '!' ])
end
if B>A && d<0
error(['dynDates::colon: ' inputname(2) ' must precede ' inputname(1) '!' ])
error(['dates::colon: ' inputname(2) ' must precede ' inputname(1) '!' ])
end
C = dynDates();
C = dates();
n = (B-A)+1;
C.freq = A.freq;
C.ndat = n;
@ -95,8 +95,8 @@ C.ndat = rows(C.time);
%$ e.time = [1950 2; 1950 3; 1950 4; 1951 1; 1951 2; 1951 3; 1951 4];
%$
%$ % Call the tested routine.
%$ d1 = dynDates(date_1);
%$ d2 = dynDates(date_2);
%$ d1 = dates(date_1);
%$ d2 = dates(date_2);
%$ d3 = d1:d2;
%$
%$ % Check the results.
@ -111,7 +111,7 @@ C.ndat = rows(C.time);
%$ e.time = [1950 2; 1950 3; 1950 4; 1951 1; 1951 2; 1951 3; 1951 4];
%$
%$ % Call the tested routine.
%$ d = dynDates('1950Q2'):dynDates('1951Q4');
%$ d = dates('1950Q2'):dates('1951Q4');
%$
%$ % Check the results.
%$ t(1) = dyn_assert(d.time,e.time);
@ -125,7 +125,7 @@ C.ndat = rows(C.time);
%$ e.time = [1950 2; 1950 4; 1951 2; 1951 4];
%$
%$ % Call the tested routine.
%$ d = dynDates('1950Q2'):2:dynDates('1951Q4');
%$ d = dates('1950Q2'):2:dates('1951Q4');
%$
%$ % Check the results.
%$ t(1) = dyn_assert(d.time,e.time);

View File

@ -18,14 +18,14 @@ function disp(dd)
% along with Dynare. If not, see <http://www.gnu.org/licenses/>.
if isempty(dd)
fprintf('Empty dynDates object.\n');
fprintf('Empty dates object.\n');
return
end
max_displayed = 5;
first_displayed = 2;
fprintf('<dynDates: ');
fprintf('<dates: ');
if dd.ndat<=max_displayed
for i=1:dd.ndat

View File

@ -18,14 +18,14 @@ function display(dd)
% along with Dynare. If not, see <http://www.gnu.org/licenses/>.
if isempty(dd)
fprintf('%s is an empty dynDates object.\n', inputname(1));
fprintf('%s is an empty dates object.\n', inputname(1));
return
end
max_displayed = 5;
first_displayed = 2;
fprintf('%s = <dynDates: ', inputname(1));
fprintf('%s = <dates: ', inputname(1));
if dd.ndat<=max_displayed
for i=1:dd.ndat

View File

@ -1,8 +1,8 @@
function dd = dynDates(varargin) % --*-- Unitary tests --*--
function dd = dates(varargin) % --*-- Unitary tests --*--
%@info:
%! @deftypefn {Function File} {@var{dd} =} dynDates (@var{a},@var{b},...)
%! @anchor{dynDates}
%! @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
@ -63,14 +63,14 @@ function dd = dynDates(varargin) % --*-- Unitary tests --*--
% along with Dynare. If not, see <http://www.gnu.org/licenses/>.
dd = struct('ndat', 0, 'freq', NaN(0), 'time', NaN(0,2));
dd = class(dd,'dynDates');
dd = class(dd,'dates');
switch nargin
case 0
% Returns an empty object
return
case 1
if isa(varargin{1},'dynDates')
if isa(varargin{1},'dates')
% Returns a copy of the input argument
dd = varargin{1};
elseif isdate(varargin{1})
@ -79,14 +79,14 @@ switch nargin
dd.freq = date.freq;
dd.time = date.time;
elseif isfreq(varargin{1})
% Instantiate an empty dynDates object (only set frequency)
% Instantiate an empty dates object (only set frequency)
if ischar(varargin{1})
dd.freq = string2freq(varargin{1});
else
dd.freq = varargin{1};
end
else
error('dynDates:: Wrong calling sequence of the constructor!')
error('dates:: Wrong calling sequence of the constructor!')
end
otherwise
dd.ndat = nargin;
@ -96,7 +96,7 @@ switch nargin
dd.freq = date.freq;
dd.time(1,:) = date.time;
else
error(['dynDates::dynDates: Input 1 has to be a string date!'])
error(['dates::dates: Input 1 has to be a string date!'])
end
for i=2:dd.ndat
if isdate(varargin{i})
@ -104,10 +104,10 @@ switch nargin
if isequal(date.freq,dd.freq)
dd.time(i,:) = date.time;
else
error(['dynDates::dynDates: Check that all the inputs have the same frequency (see input number ' str2num(i) ')!'])
error(['dates::dates: Check that all the inputs have the same frequency (see input number ' str2num(i) ')!'])
end
else
error(['dynDates::dynDates: Input ' str2num(i) ' has to be a string date!'])
error(['dates::dates: Input ' str2num(i) ' has to be a string date!'])
end
end
end
@ -125,7 +125,7 @@ end
%$ e.ndat = 4;
%$
%$ % Call the tested routine.
%$ d = dynDates(B1,B2,B3,B4);
%$ d = dates(B1,B2,B3,B4);
%$
%$ % Check the results.
%$ t(1) = dyn_assert(d.time,e.time);
@ -147,7 +147,7 @@ end
%$ e.ndat = 4;
%$
%$ % Call the tested routine.
%$ d = dynDates(B1,B2,B3,B4);
%$ d = dates(B1,B2,B3,B4);
%$
%$ % Check the results.
%$ t(1) = dyn_assert(d.time,e.time);
@ -169,7 +169,7 @@ end
%$ e.ndat = 4;
%$
%$ % Call the tested routine.
%$ d = dynDates(B1,B2,B3,B4);
%$ d = dates(B1,B2,B3,B4);
%$
%$ % Check the results.
%$ t(1) = dyn_assert(d.time,e.time);
@ -179,7 +179,7 @@ end
%@eof:3
%% @test:4
%$ % Define a dynDates object
%$ % Define a dates object
%$ B = dynDate('1950Q1'):dynDate('1960Q3');
%$
%$

View File

@ -1,5 +1,5 @@
function y = dynDates2decimal(dd)
% function y = dynDates2decimal(dd)
function y = dates2decimal(dd)
% function y = dates2decimal(dd)
% returns a vector of doubles with the fractional part corresponding
% to the subperiod. Mostly used for plots.

View File

@ -3,12 +3,12 @@ function lastIndex = end(o, k, n)
% End keyword
%
% INPUTS
% o [dynDates] dynDates object
% o [dates] dates object
% k [integer] index where end appears
% n [integer] number of indices
%
% OUTPUTS
% lastIndex [integer] last dynDates index
% lastIndex [integer] last dates index
%
% SPECIAL REQUIREMENTS
% none
@ -30,6 +30,6 @@ function lastIndex = end(o, k, n)
% 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, '@dynDates/end: dynDates only has one dimension');
assert(k==1 && n==1, '@dates/end: dates only has one dimension');
lastIndex = o.ndat;
end

View File

@ -1,10 +1,10 @@
function C = eq(A,B) % --*-- Unitary tests --*--
% Overloads == operator for dynDates objects.
% Overloads == operator for dates objects.
%
% INPUTS
% o A dynDates object with n or 1 elements.
% o B dynDates object with n or 1 elements.
% 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).
@ -27,11 +27,11 @@ function C = eq(A,B) % --*-- Unitary tests --*--
% along with Dynare. If not, see <http://www.gnu.org/licenses/>.
if ~isequal(nargin,2)
error('dynDates::eq: I need exactly two input arguments!')
error('dates::eq: I need exactly two input arguments!')
end
if ~isa(A,'dynDates') || ~isa(B,'dynDates')
error(['dynDates::eq: Input arguments ''' inputname(1) ''' and ''' inputname(2) ''' have to be a dynDates objects!'])
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)
@ -50,10 +50,10 @@ else
end
%@test:1
%$ % Define some dynDates objects
%$ d1 = dynDates('1950Q1','1950Q2','1950Q3','1950Q4') ;
%$ d2 = dynDates('1960Q1','1960Q2','1960Q3','1960Q4') ;
%$ d3 = dynDates('1950Q1','1960Q2','1950Q3','1960Q4') ;
%$ % 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;
@ -68,10 +68,10 @@ end
%@eof:1
%@test:2
%$ % Define some dynDates objects
%$ d1 = dynDates('1950Q1') ;
%$ d2 = dynDates('1960Q1') ;
%$ d3 = dynDates('1960Q1') ;
%$ % Define some dates objects
%$ d1 = dates('1950Q1') ;
%$ d2 = dates('1960Q1') ;
%$ d3 = dates('1960Q1') ;
%$
%$ % Call the tested routine.
%$ t1 = d1==d1;
@ -86,10 +86,10 @@ end
%@eof:2
%@test:3
%$ % Define some dynDates objects
%$ d1 = dynDates('1950Q1','1950Q2','1950Q3','1950Q4') ;
%$ d2 = dynDates('1950Q2') ;
%$ d3 = dynDates('1970Q1') ;
%$ % Define some dates objects
%$ d1 = dates('1950Q1','1950Q2','1950Q3','1950Q4') ;
%$ d2 = dates('1950Q2') ;
%$ d3 = dates('1970Q1') ;
%$
%$ % Call the tested routine.
%$ t1 = d1==d2;

View File

@ -1,10 +1,10 @@
function C = ge(A,B) % --*-- Unitary tests --*--
% Overloads the >= operator for dynDates objects.
% Overloads the >= operator for dates objects.
%
% INPUTS
% o A dynDates object with n or 1 elements.
% o B dynDates object with n or 1 elements.
% 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).
@ -27,11 +27,11 @@ function C = ge(A,B) % --*-- Unitary tests --*--
% along with Dynare. If not, see <http://www.gnu.org/licenses/>.
if ~isequal(nargin,2)
error('dynDates::ge: I need exactly two input arguments!')
error('dates::ge: I need exactly two input arguments!')
end
if ~isa(A,'dynDates') || ~isa(B,'dynDates')
error(['dynDates::ge: Input arguments ''' inputname(1) ''' and ''' inputname(2) ''' have to be a dynDates objects!'])
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)
@ -71,10 +71,10 @@ end
%$ date_5 = '1949Q2';
%$
%$ % Call the tested routine.
%$ d2 = dynDates(date_2);
%$ d3 = dynDates(date_3);
%$ d4 = dynDates(date_4);
%$ d5 = dynDates(date_5);
%$ 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);
@ -98,15 +98,15 @@ end
%$ B4 = '1945Q4';
%$ B5 = '1950Q1';
%$
%$ % Create dynDates objects.
%$ dd = dynDates(B1,B2,B3,B4);
%$ % Create dates objects.
%$ dd = dates(B1,B2,B3,B4);
%$
%$ % Check the results.
%$ t(1) = dyn_assert(dynDates(B1)>=dynDates(B2),0);
%$ t(2) = dyn_assert(dynDates(B2)>=dynDates(B1),1);
%$ t(3) = dyn_assert(dynDates(B2)>=dynDates(B2),1);
%$ t(4) = dyn_assert(dd>=dynDates(B5),zeros(4,1));
%$ t(5) = dyn_assert(dynDates(B5)>=dd,ones(4,1));
%$ t(6) = dyn_assert(dynDates(B1)>=dd,[1; zeros(3,1)]);
%$ t(1) = dyn_assert(dates(B1)>=dates(B2),0);
%$ t(2) = dyn_assert(dates(B2)>=dates(B1),1);
%$ t(3) = dyn_assert(dates(B2)>=dates(B2),1);
%$ t(4) = dyn_assert(dd>=dates(B5),zeros(4,1));
%$ t(5) = dyn_assert(dates(B5)>=dd,ones(4,1));
%$ t(6) = dyn_assert(dates(B1)>=dd,[1; zeros(3,1)]);
%$ T = all(t);
%@eof:2

View File

@ -3,7 +3,7 @@ function m = getDatesCellStringArray(dd)
% Returns a cell array of strings containing the dates
%
% INPUTS
% dd - dynDates object
% dd - dates object
%
% OUTPUTS
% m - cell array of strings

View File

@ -1,10 +1,10 @@
function C = gt(A,B) % --*-- Unitary tests --*--
% Overloads the > operator for dynDates objects.
% Overloads the > operator for dates objects.
%
% INPUTS
% o A dynDates object with n or 1 elements.
% o B dynDates object with n or 1 elements.
% 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).
@ -27,11 +27,11 @@ function C = gt(A,B) % --*-- Unitary tests --*--
% along with Dynare. If not, see <http://www.gnu.org/licenses/>.
if ~isequal(nargin,2)
error('dynDates::gt: I need exactly two input arguments!')
error('dates::gt: I need exactly two input arguments!')
end
if ~isa(A,'dynDates') || ~isa(B,'dynDates')
error(['dynDates::gt: Input arguments ''' inputname(1) ''' and ''' inputname(2) ''' have to be a dynDates objects!'])
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)
@ -70,10 +70,10 @@ end
%$ date_5 = '1949Q2';
%$
%$ % Call the tested routine.
%$ d2 = dynDates(date_2);
%$ d3 = dynDates(date_3);
%$ d4 = dynDates(date_4);
%$ d5 = dynDates(date_5);
%$ 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);
@ -95,15 +95,15 @@ end
%$ B4 = '1945Q4';
%$ B5 = '1950Q1';
%$
%$ % Create dynDates objects.
%$ dd = dynDates(B1,B2,B3,B4);
%$ % Create dates objects.
%$ dd = dates(B1,B2,B3,B4);
%$
%$ % Check the results.
%$ t(1) = dyn_assert(dynDates(B1)>dynDates(B2),0);
%$ t(2) = dyn_assert(dynDates(B2)>dynDates(B1),1);
%$ t(3) = dyn_assert(dynDates(B5)>dynDates(B1),1);
%$ t(4) = dyn_assert(dd>dynDates(B5),zeros(4,1));
%$ t(5) = dyn_assert(dynDates(B5)>dd,ones(4,1));
%$ t(6) = dyn_assert(dynDates(B1)>dd,[0; zeros(3,1)]);
%$ t(1) = dyn_assert(dates(B1)>dates(B2),0);
%$ t(2) = dyn_assert(dates(B2)>dates(B1),1);
%$ t(3) = dyn_assert(dates(B5)>dates(B1),1);
%$ t(4) = dyn_assert(dd>dates(B5),zeros(4,1));
%$ t(5) = dyn_assert(dates(B5)>dd,ones(4,1));
%$ t(6) = dyn_assert(dates(B1)>dd,[0; zeros(3,1)]);
%$ T = all(t);
%@eof:2

View File

@ -2,7 +2,7 @@ function C = intersect(A,B) % --*-- Unitary tests --*--
%@info:
%! @deftypefn {Function File} {@var{C} =} intersect (@var{A},@var{B})
%! @anchor{@dynDates/intersect}
%! @anchor{@dates/intersect}
%! @sp 1
%! C of B and A.
%! if A and B are not disjoints.
@ -11,16 +11,16 @@ function C = intersect(A,B) % --*-- Unitary tests --*--
%! @sp 1
%! @table @ @var
%! @item A
%! @ref{dynDates} object.
%! @ref{dates} object.
%! @item B
%! @ref{dynDates} object.
%! @ref{dates} object.
%! @end table
%! @sp 2
%! @strong{Outputs}
%! @sp 1
%! @table @ @var
%! @item C
%! @ref{dynDates} object.
%! @ref{dates} object.
%! @end table
%! @end deftypefn
%@eod:
@ -42,8 +42,8 @@ function C = intersect(A,B) % --*-- Unitary tests --*--
% 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,'dynDates') || ~isa(B,'dynDates')
error(['dynDates::plus: Input arguments ''' inputname(1) ''' and ''' inputname(2) ''' must be dynDates objects!'])
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)
@ -52,13 +52,13 @@ if eq(A,B)
end
if ~isequal(A.freq,B.freq)
C = dynDates();
C = dates();
return
end
time = intersect(A.time,B.time,'rows');
C = dynDates();
C = dates();
if isempty(time)
return
end
@ -68,7 +68,7 @@ C.time = time;
C.ndat = rows(time);
%@test:1
%$ % Define some dynDates objects
%$ % Define some dates objects
%$ d1 = dynDate('1950Q1'):dynDate('1969Q4') ;
%$ d2 = dynDate('1960Q1'):dynDate('1969Q4') ;
%$ d3 = dynDate('1970Q1'):dynDate('1979Q4') ;

View File

@ -2,15 +2,15 @@ function B = isempty(A) % --*-- Unitary tests --*--
%@info:
%! @deftypefn {Function File} {@var{B} =} isempty (@var{A})
%! @anchor{@dynDates/isempty}
%! @anchor{@dates/isempty}
%! @sp 1
%! Overloads the isempty function for the @ref{dynDates} class.
%! Overloads the isempty function for the @ref{dates} class.
%! @sp 2
%! @strong{Inputs}
%! @sp 1
%! @table @ @var
%! @item A
%! @ref{dynDates} object.
%! @ref{dates} object.
%! @end table
%! @sp 1
%! @strong{Outputs}
@ -43,7 +43,7 @@ B = isequal(A.ndat,0);
%@test:1
%$ % Instantiate an empty dynDate object
%$ d = dynDates();
%$ d = dates();
%$ % Test if this object is empty
%$ t(1) = isempty(d);
%$ T = all(t);

View File

@ -1,6 +1,6 @@
function C = isequal(A,B)
% Overloads isequal function for dynDates objects.
% Overloads isequal function for dates objects.
% Copyright (C) 2013 Dynare Team
%
@ -19,8 +19,8 @@ function C = isequal(A,B)
% 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,'dynDates') || ~isa(B,'dynDates')
error('dynDates::isequal: Both inputs must be dynDates objects!')
if ~isa(A,'dates') || ~isa(B,'dates')
error('dates::isequal: Both inputs must be dates objects!')
end
if ~isequal(A.freq, B.freq)

View File

@ -1,10 +1,10 @@
function C = le(A,B) % --*-- Unitary tests --*--
% Overloads the <= operator for dynDates objects.
% Overloads the <= operator for dates objects.
%
% INPUTS
% o A dynDates object with n or 1 elements.
% o B dynDates object with n or 1 elements.
% 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).
@ -27,11 +27,11 @@ function C = le(A,B) % --*-- Unitary tests --*--
% along with Dynare. If not, see <http://www.gnu.org/licenses/>.
if ~isequal(nargin,2)
error('dynDates::le: I need exactly two input arguments!')
error('dates::le: I need exactly two input arguments!')
end
if ~isa(A,'dynDates') || ~isa(B,'dynDates')
error(['dynDates::le: Input arguments ''' inputname(1) ''' and ''' inputname(2) ''' have to be a dynDates objects!'])
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)
@ -71,10 +71,10 @@ end
%$ date_5 = '1949Q2';
%$
%$ % Call the tested routine.
%$ d2 = dynDates(date_2);
%$ d3 = dynDates(date_3);
%$ d4 = dynDates(date_4);
%$ d5 = dynDates(date_5);
%$ 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);
@ -98,15 +98,15 @@ end
%$ B4 = '1945Q4';
%$ B5 = '1950Q1';
%$
%$ % Create dynDates objects.
%$ dd = dynDates(B1,B2,B3,B4);
%$ % Create dates objects.
%$ dd = dates(B1,B2,B3,B4);
%$
%$ % Check the results.
%$ t(1) = dyn_assert(dynDates(B1)<=dynDates(B2),1);
%$ t(2) = dyn_assert(dynDates(B2)<=dynDates(B1),0);
%$ t(3) = dyn_assert(dynDates(B2)<=dynDates(B2),1);
%$ t(4) = dyn_assert(dd<=dynDates(B5),ones(4,1));
%$ t(5) = dyn_assert(dynDates(B5)<=dd,zeros(4,1));
%$ t(6) = dyn_assert(dynDates(B1)<=dd,ones(4,1));
%$ t(1) = dyn_assert(dates(B1)<=dates(B2),1);
%$ t(2) = dyn_assert(dates(B2)<=dates(B1),0);
%$ t(3) = dyn_assert(dates(B2)<=dates(B2),1);
%$ t(4) = dyn_assert(dd<=dates(B5),ones(4,1));
%$ t(5) = dyn_assert(dates(B5)<=dd,zeros(4,1));
%$ t(6) = dyn_assert(dates(B1)<=dd,ones(4,1));
%$ T = all(t);
%@eof:2

View File

@ -1,6 +1,6 @@
function n = length(A)
% Returns the number of elements in a dynDates object.
% Returns the number of elements in a dates object.
% Copyright (C) 2013 Dynare Team
%

View File

@ -1,10 +1,10 @@
function C = lt(A,B) % --*-- Unitary tests --*--
% Overloads the < operator for dynDates objects.
% Overloads the < operator for dates objects.
%
% INPUTS
% o A dynDates object with n or 1 elements.
% o B dynDates object with n or 1 elements.
% 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).
@ -27,11 +27,11 @@ function C = lt(A,B) % --*-- Unitary tests --*--
% along with Dynare. If not, see <http://www.gnu.org/licenses/>.
if ~isequal(nargin,2)
error('dynDates::lt: I need exactly two input arguments!')
error('dates::lt: I need exactly two input arguments!')
end
if ~isa(A,'dynDates') || ~isa(B,'dynDates')
error(['dynDates::lt: Input arguments ''' inputname(1) ''' and ''' inputname(2) ''' have to be a dynDates objects!'])
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)
@ -70,10 +70,10 @@ end
%$ date_5 = '1949Q2';
%$
%$ % Call the tested routine.
%$ d2 = dynDates(date_2);
%$ d3 = dynDates(date_3);
%$ d4 = dynDates(date_4);
%$ d5 = dynDates(date_5);
%$ 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);
@ -95,15 +95,15 @@ end
%$ B4 = '1945Q4';
%$ B5 = '1950Q1';
%$
%$ % Create dynDates objects.
%$ dd = dynDates(B1,B2,B3,B4);
%$ % Create dates objects.
%$ dd = dates(B1,B2,B3,B4);
%$
%$ % Check the results.
%$ t(1) = dyn_assert(dynDates(B1)<dynDates(B2),1);
%$ t(2) = dyn_assert(dynDates(B2)<dynDates(B1),0);
%$ t(3) = dyn_assert(dynDates(B2)<dynDates(B1),0);
%$ t(4) = dyn_assert(dd<dynDates(B5),ones(4,1));
%$ t(5) = dyn_assert(dynDates(B5)<dd,zeros(4,1));
%$ t(6) = dyn_assert(dynDates(B1)<dd,[0; ones(3,1)]);
%$ t(1) = dyn_assert(dates(B1)<dates(B2),1);
%$ t(2) = dyn_assert(dates(B2)<dates(B1),0);
%$ t(3) = dyn_assert(dates(B2)<dates(B1),0);
%$ t(4) = dyn_assert(dd<dates(B5),ones(4,1));
%$ t(5) = dyn_assert(dates(B5)<dd,zeros(4,1));
%$ t(6) = dyn_assert(dates(B1)<dd,[0; ones(3,1)]);
%$ T = all(t);
%@eof:2

View File

@ -1,6 +1,6 @@
function C = max(varargin)
% Overloads the max function for dynDates objects.
% Overloads the max function for dates objects.
% Copyright (C) 2013 Dynare Team
%
@ -24,34 +24,34 @@ switch nargin
A = varargin{1};
switch length(A)
case 0
C= dynDates();
C= dates();
case 1
C = A;
otherwise
tmp = sortrows(A.time);
C = dynDates();
C = dates();
C.freq = A.freq;
C.ndat = 1;
C.time = tmp(A.ndat,:);
end
case 2
A = varargin{1};
if ~isa(A,'dynDates')
error('dynDates::max: All inputs must be dynDates objects!')
if ~isa(A,'dates')
error('dates::max: All inputs must be dates objects!')
end
B = varargin{2};
if ~isa(B,'dynDates')
error('dynDates::max: All inputs must be dynDates objects!')
if ~isa(B,'dates')
error('dates::max: All inputs must be dates objects!')
end
C = max(A+B);
otherwise
if ~isa(varargin{1},'dynDates')
error('dynDates::max: All inputs must be dynDates objects!')
if ~isa(varargin{1},'dates')
error('dates::max: All inputs must be dates objects!')
end
A = varargin{1};
for i=2:nargin
if ~isa(varargin{i},'dynDates')
error('dynDates::max: All inputs must be dynDates objects!')
if ~isa(varargin{i},'dates')
error('dates::max: All inputs must be dates objects!')
end
A = A + varargin{i};
end
@ -60,10 +60,10 @@ end
%@test:1
%$ % Define some dates
%$ d3 = dynDates('1950q2');
%$ d4 = dynDates('1950Q3');
%$ d5 = dynDates('1950m1');
%$ d6 = dynDates('1948M6');
%$ d3 = dates('1950q2');
%$ d4 = dates('1950Q3');
%$ d5 = dates('1950m1');
%$ d6 = dates('1948M6');
%$ m2 = max(d3,d4);
%$ i2 = (m2==d4);
%$ m3 = max(d5,d6);
@ -77,9 +77,9 @@ end
%@test:2
%$ % Define some dates
%$ d = dynDates('1950Q2','1951Q3','1949Q1','1950Q4');
%$ d = dates('1950Q2','1951Q3','1949Q1','1950Q4');
%$ m = max(d);
%$ i = (m==dynDates('1951Q3'));
%$ i = (m==dates('1951Q3'));
%$
%$ % Check the results.
%$ t(1) = dyn_assert(i,1);
@ -88,8 +88,8 @@ end
%@test:3
%$ % Define some dates
%$ m = max(dynDates('1950Q2','1951Q3'),dynDates('1949Q1'),dynDates('1950Q4'));
%$ i = (m==dynDates('1951Q3'));
%$ m = max(dates('1950Q2','1951Q3'),dates('1949Q1'),dates('1950Q4'));
%$ i = (m==dates('1951Q3'));
%$
%$ % Check the results.
%$ t(1) = dyn_assert(i,1);
@ -98,8 +98,8 @@ end
%@test:4
%$ % Define some dates
%$ m = max(dynDates('1950Q2'),dynDates('1951Q3'),dynDates('1949Q1'),dynDates('1950Q4'));
%$ i = (m==dynDates('1951Q3'));
%$ m = max(dates('1950Q2'),dates('1951Q3'),dates('1949Q1'),dates('1950Q4'));
%$ i = (m==dates('1951Q3'));
%$
%$ % Check the results.
%$ t(1) = dyn_assert(i,1);

View File

@ -1,6 +1,6 @@
function C = min(varargin)
% Overloads the min function for dynDates objects.
% Overloads the min function for dates objects.
% Copyright (C) 2013 Dynare Team
%
@ -24,34 +24,34 @@ switch nargin
A = varargin{1};
switch length(A)
case 0
C= dynDates();
C= dates();
case 1
C = A;
otherwise
tmp = sortrows(A.time);
C = dynDates();
C = dates();
C.freq = A.freq;
C.ndat = 1;
C.time = tmp(1,:);
end
case 2
A = varargin{1};
if ~isa(A,'dynDates')
error('dynDates::min: All inputs must be dynDates objects!')
if ~isa(A,'dates')
error('dates::min: All inputs must be dates objects!')
end
B = varargin{2};
if ~isa(B,'dynDates')
error('dynDates::min: All inputs must be dynDates objects!')
if ~isa(B,'dates')
error('dates::min: All inputs must be dates objects!')
end
C = min(A+B);
otherwise
if ~isa(varargin{1},'dynDates')
error('dynDates::min: All inputs must be dynDates objects!')
if ~isa(varargin{1},'dates')
error('dates::min: All inputs must be dates objects!')
end
A = varargin{1};
for i=2:nargin
if ~isa(varargin{i},'dynDates')
error('dynDates::min: All inputs must be dynDates objects!')
if ~isa(varargin{i},'dates')
error('dates::min: All inputs must be dates objects!')
end
A = A + varargin{i};
end
@ -60,10 +60,10 @@ end
%@test:1
%$ % Define some dates
%$ d3 = dynDates('1950q2');
%$ d4 = dynDates('1950Q3');
%$ d5 = dynDates('1950m1');
%$ d6 = dynDates('1948M6');
%$ d3 = dates('1950q2');
%$ d4 = dates('1950Q3');
%$ d5 = dates('1950m1');
%$ d6 = dates('1948M6');
%$ m2 = min(d3,d4);
%$ i2 = (m2==d3);
%$ m3 = min(d5,d6);
@ -77,9 +77,9 @@ end
%@test:2
%$ % Define some dates
%$ d = dynDates('1950Q2','1951Q3','1949Q1','1950Q4');
%$ d = dates('1950Q2','1951Q3','1949Q1','1950Q4');
%$ m = min(d);
%$ i = (m==dynDates('1949Q1'));
%$ i = (m==dates('1949Q1'));
%$
%$ % Check the results.
%$ t(1) = dyn_assert(i,1);
@ -88,8 +88,8 @@ end
%@test:3
%$ % Define some dates
%$ m = min(dynDates('1950Q2','1951Q3'),dynDates('1949Q1'),dynDates('1950Q4'));
%$ i = (m==dynDates('1949Q1'));
%$ m = min(dates('1950Q2','1951Q3'),dates('1949Q1'),dates('1950Q4'));
%$ i = (m==dates('1949Q1'));
%$
%$ % Check the results.
%$ t(1) = dyn_assert(i,1);
@ -98,8 +98,8 @@ end
%@test:4
%$ % Define some dates
%$ m = min(dynDates('1950Q2'),dynDates('1951Q3'),dynDates('1949Q1'),dynDates('1950Q4'));
%$ i = (m==dynDates('1949Q1'));
%$ m = min(dates('1950Q2'),dates('1951Q3'),dates('1949Q1'),dates('1950Q4'));
%$ i = (m==dates('1949Q1'));
%$
%$ % Check the results.
%$ t(1) = dyn_assert(i,1);

View File

@ -1,7 +1,7 @@
function C = minus(A,B) % --*-- Unitary tests --*--
% Overloads the minus operator (-). If A and B are dynDates 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 dynDates object by X (the interger input) periods backward.
% 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
%
@ -20,13 +20,13 @@ function C = minus(A,B) % --*-- Unitary tests --*--
% 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,'dynDates') && isa(B,'dynDates')
% Concatenate dynDates objects without removing repetitions if A and B are not disjoint sets of dates.
if isa(A,'dates') && 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)
error(['dynDates::minus: Input arguments ''' inputname(1) ''' and ''' inputname(2) ''' must have common frequencies!'])
error(['dates::minus: Input arguments ''' inputname(1) ''' and ''' inputname(2) ''' must have common frequencies!'])
end
if isempty(A) || isempty(B)
error(['dynDates::minus: Input arguments ''' inputname(1) ''' and ''' inputname(2) ''' must not be empty!'])
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
@ -36,7 +36,7 @@ if isa(A,'dynDates') && isa(B,'dynDates')
B.time = repmat(B.time,A.ndat,1);
B.ndat = A.ndat;
else
error(['dynDates::minus: Input arguments ''' inputname(1) ''' and ''' inputname(2) ''' lengths are not consistent!'])
error(['dates::minus: Input arguments ''' inputname(1) ''' and ''' inputname(2) ''' lengths are not consistent!'])
end
end
C = zeros(length(A),1);
@ -45,26 +45,26 @@ if isa(A,'dynDates') && isa(B,'dynDates')
return
end
C(id) = A.time(id,2)-B.time(id,2) + (A.time(id,1)-B.time(id,1))*A.freq;
elseif isa(A,'dynDates') && ( (isvector(B) && isequal(length(B),A.ndat) && all(isint(B))) || isscalar(B) && isint(B) || isequal(length(A),1) && isvector(B) && all(isint(B)))
C = dynDates();
elseif isa(A,'dates') && ( (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);
elseif isa(B,'dynDates') && ( (isvector(A) && isequal(length(A),B.ndat) && all(isint(A))) || isscalar(A) && isint(A) )
C = dynDates();
elseif isa(B,'dates') && ( (isvector(A) && isequal(length(A),B.ndat) && all(isint(A))) || isscalar(A) && isint(A) )
C = dates();
C.freq = A.freq;
C.time = add_periods_to_array_of_dates(B.time, B.freq, -A);
C.ndat = rows(C.time);
else
error('dynDates::plus: I don''t understand what you want to do! Check the manual.')
error('dates::plus: I don''t understand what you want to do! Check the manual.')
end
%@test:1
%$ % Define some dynDates objects
%$ d1 = dynDates('1950Q1','1950Q2','1960Q1');
%$ d2 = dynDates('1950Q3','1950Q4','1960Q1');
%$ d3 = dynDates('2000Q1');
%$ d4 = dynDates('2002Q2');
%$ % 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;
@ -82,11 +82,11 @@ end
%@eof:1
%@test:2
%$ % Define some dynDates objects
%$ d1 = dynDates('1950Y','1951Y','1953Y');
%$ d2 = dynDates('1951Y','1952Y','1953Y');
%$ d3 = dynDates('2000Y');
%$ d4 = dynDates('1999Y');
%$ % 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;
@ -104,9 +104,9 @@ end
%@eof:2
%@test:3
%$ % Define some dynDates objects
%$ d1 = dynDates('2000Y');
%$ d2 = dynDates('1999Y');
%$ % Define some dates objects
%$ d1 = dates('2000Y');
%$ d2 = dates('1999Y');
%$ % Call the tested routine.
%$ try
%$ e1 = d1-1;
@ -124,9 +124,9 @@ end
%@eof:3
%@test:4
%$ % Define some dynDates objects
%$ d1 = dynDates('2000Q1');
%$ e1 = dynDates('1999Q4','1999Q3','1999Q2','1999Q1','1998Q4');
%$ % Define some dates objects
%$ d1 = dates('2000Q1');
%$ e1 = dates('1999Q4','1999Q3','1999Q2','1999Q1','1998Q4');
%$ % Call the tested routine.
%$ try
%$ f1 = d1-transpose(1:5);
@ -142,9 +142,9 @@ end
%@eof:4
%@test:5
%$ % Define some dynDates objects
%$ d1 = dynDates('1999Q4','1999Q3','1999Q2','1999Q1','1998Q4');
%$ e1 = dynDates('2000Q1')*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));

View File

@ -1,18 +1,18 @@
function B = mtimes(A,n)
% Overloads the times operator (*). Returns dynDates object A replicated n times.
% Overloads the times operator (*). Returns dates object A replicated n times.
%
% INPUTS
% o A dynDates object with m elements.
% o A dates object with m elements.
%
% OUTPUTS
% o B dynDates object with m*n elements.
% o B dates object with m*n elements.
%
% EXAMPLE 1
% If A = dynDates('2000Q1'), then B=A*3 is a dynDates object equal to dynDates('2000Q1','2000Q1','2000Q1')
% If A = dates('2000Q1'), then B=A*3 is a dates object equal to dates('2000Q1','2000Q1','2000Q1')
%
% EXAMPLE 2
% If A = dynDates('2003Q1','2009Q2'), then B=A*2 is a dynDates object equal to dynDates('2003Q1','2009Q2','2003Q1','2009Q2')
% 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
%
@ -32,7 +32,7 @@ function B = mtimes(A,n)
% along with Dynare. If not, see <http://www.gnu.org/licenses/>.
if ~(isscalar(n) && isint(n))
error('dynDates::m: First and second input arguments have to be a dynDates object and a scalar integer!')
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);

View File

@ -1,7 +1,7 @@
function C = plus(A,B) % --*-- Unitary tests --*--
% Overloads the plus operator. If A and B are dynDates 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 dynDates object by X (the interger input)
% 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
@ -21,10 +21,10 @@ function C = plus(A,B) % --*-- Unitary tests --*--
% 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,'dynDates') && isa(B,'dynDates')
% Concatenate dynDates objects without removing repetitions if A and B are not disjoint sets of dates.
if isa(A,'dates') && 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)
error(['dynDates::plus: Input arguments ''' inputname(1) ''' and ''' inputname(2) ''' must have common frequencies!'])
error(['dates::plus: Input arguments ''' inputname(1) ''' and ''' inputname(2) ''' must have common frequencies!'])
end
if isempty(B)
C = A;
@ -34,29 +34,29 @@ if isa(A,'dynDates') && isa(B,'dynDates')
C = B;
return
end
C = dynDates();
C = dates();
C.freq = A.freq;
C.time = [A.time; B.time];
C.ndat = A.ndat+B.ndat;
elseif isa(A,'dynDates') && ( (isvector(B) && isequal(length(B),A.ndat) && all(isint(B))) || isscalar(B) && isint(B) || isequal(length(A),1) && isvector(B) && all(isint(B)))
C = dynDates();
elseif isa(A,'dates') && ( (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);
elseif isa(B,'dynDates') && ( (isvector(A) && isequal(length(A),B.ndat) && all(isint(A))) || isscalar(A) && isint(A) )
C = dynDates();
elseif isa(B,'dates') && ( (isvector(A) && isequal(length(A),B.ndat) && all(isint(A))) || isscalar(A) && isint(A) )
C = dates();
C.freq = B.freq;
C.time = add_periods_to_array_of_dates(B.time, B.freq, A);
C.ndat = rows(C.time);
else
error('dynDates::plus: I don''t understand what you want to do! Check the manual.')
error('dates::plus: I don''t understand what you want to do! Check the manual.')
end
%@test:1
%$ % Define some dynDates objects
%$ d1 = dynDates('1950Q1','1950Q2') ;
%$ d2 = dynDates('1950Q3','1950Q4') ;
%$ d3 = dynDates('1950Q1','1950Q2','1950Q3','1950Q4') ;
%$ % Define some dates objects
%$ d1 = dates('1950Q1','1950Q2') ;
%$ d2 = dates('1950Q3','1950Q4') ;
%$ d3 = dates('1950Q1','1950Q2','1950Q3','1950Q4') ;
%$
%$ % Call the tested routine.
%$ try
@ -69,19 +69,19 @@ end
%$
%$ if t(1)
%$ t(2) = dyn_assert(e1==d3,1);
%$ t(3) = dyn_assert(e2==dynDates('1950Q1','1950Q2','1950Q3','1950Q4','1950Q1','1950Q2','1950Q3','1950Q4'),1);
%$ t(3) = dyn_assert(e2==dates('1950Q1','1950Q2','1950Q3','1950Q4','1950Q1','1950Q2','1950Q3','1950Q4'),1);
%$ end
%$ T = all(t);
%@eof:1
%@test:2
%$ % Define some dynDates objects
%$ d1 = dynDates('1950Q1');
%$ e1 = dynDates('1950Q2');
%$ e2 = dynDates('1950Q3');
%$ e3 = dynDates('1950Q4');
%$ e4 = dynDates('1951Q1');
%$ e5 = dynDates('1950Q2','1950Q3','1950Q4','1951Q1');
%$ % 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
@ -106,13 +106,13 @@ end
%@eof:2
%@test:3
%$ % Define some dynDates objects
%$ d1 = dynDates('1950Q1');
%$ e1 = dynDates('1949Q4');
%$ e2 = dynDates('1949Q3');
%$ e3 = dynDates('1949Q2');
%$ e4 = dynDates('1949Q1');
%$ e5 = dynDates('1948Q4');
%$ % 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

View File

@ -1,13 +1,13 @@
function B = pop(A,a) % --*-- Unitary tests --*--
% pop method for dynDates class (removes a date).
% pop method for dates class (removes a date).
%
% INPUTS
% o A dynDates object.
% o a dynDates object with one element, string which can be interpreted as a date or integer scalar.
% 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 dynDates object (with B.ndat==A.ndat-1).
% 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
@ -32,7 +32,7 @@ function B = pop(A,a) % --*-- Unitary tests --*--
if nargin<2
% Remove last date
B = dynDates();
B = dates();
B.ndat = A.ndat-1;
B.freq = A.freq;
B.time = NaN(B.ndat,2);
@ -40,15 +40,15 @@ if nargin<2
return
end
if ~(isa(a,'dynDates') || isdate(a) || (isscalar(a) && isint(a)))
error(['dynDates::pop: Input argument ' inputname(2) ' has to be a dynDates object with a single element, a string (which can be interpreted as a date) or an integer.'])
if ~(isa(a,'dates') || 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 = dynDates(a);
a = dates(a);
end
B = dynDates();
B = dates();
B.ndat = A.ndat-1;
B.freq = A.freq;
B.time = NaN(B.ndat,2);
@ -58,7 +58,7 @@ if isscalar(a) && isint(a)
B.time = A.time(idx,:);
else
if ~isequal(A.freq,a.freq)
error('dynDates::pop: Inputs must have common frequency!')
error('dates::pop: Inputs must have common frequency!')
end
idx = find(A==a);
jdx = find(transpose(1:A.ndat)~=idx(end));
@ -79,8 +79,8 @@ end
%$ e.ndat = 5;
%$
%$ % Call the tested routine
%$ d = dynDates(B4,B3,B2,B1);
%$ d = d.append(dynDates(B5));
%$ d = dates(B4,B3,B2,B1);
%$ d = d.append(dates(B5));
%$ f = d.pop();
%$ t(1) = dyn_assert(f.time,e.time(1:end-1,:));
%$ t(2) = dyn_assert(f.freq,e.freq);
@ -89,7 +89,7 @@ end
%$ t(4) = dyn_assert(f.time,[1945 3; 1950 1; 1950 2; 2009 2]);
%$ t(5) = dyn_assert(f.freq,e.freq);
%$ t(6) = dyn_assert(f.ndat,e.ndat-1);
%$ f = d.pop(dynDates(B1));
%$ f = d.pop(dates(B1));
%$ t(7) = dyn_assert(f.time,[1945 3; 1950 1; 1950 2; 2009 2]);
%$ t(8) = dyn_assert(f.freq,e.freq);
%$ t(9) = dyn_assert(f.ndat,e.ndat-1);
@ -107,13 +107,13 @@ end
%$ B5 = '2009Q2';
%$
%$ % Call the tested routine
%$ d = dynDates(B1,B2,B3,B4);
%$ d = d.append(dynDates(B5));
%$ d = dates(B1,B2,B3,B4);
%$ d = d.append(dates(B5));
%$ f = d.pop();
%$ t(1) = dyn_assert(isequal(f,dynDates(B1,B2,B3,B4)),1);
%$ t(1) = dyn_assert(isequal(f,dates(B1,B2,B3,B4)),1);
%$ f = d.pop(B1);
%$ t(2) = dyn_assert(isequal(f,dynDates(B1,B2,B4,B5)),1);
%$ t(2) = dyn_assert(isequal(f,dates(B1,B2,B4,B5)),1);
%$ g = f.pop(1);
%$ t(3) = dyn_assert(isequal(g,dynDates(B2,B4,B5)),1);
%$ t(3) = dyn_assert(isequal(g,dates(B2,B4,B5)),1);
%$ T = all(t);
%@eof:2

View File

@ -1,10 +1,10 @@
function dd = sort(dd) % --*-- Unitary tests --*--
% sort method for dynDates class.
% sort method for dates class.
%@info:
%! @deftypefn {Function File} {@var{a} =} sort (@var{a})
%! @anchor{dynDates/sort}
%! @anchor{dates/sort}
%! @sp 1
%! Sort method for the Dynare dates class.
%! @sp 2
@ -12,14 +12,14 @@ function dd = sort(dd) % --*-- Unitary tests --*--
%! @sp 1
%! @table @ @var
%! @item a
%! Object instantiated by @ref{dynDates}.
%! Object instantiated by @ref{dates}.
%! @end table
%! @sp 2
%! @strong{Outputs}
%! @sp 1
%! @table @ @var
%! @item a
%! Object instantiated by @ref{dynDates}, with dates sorted by increasing order.
%! Object instantiated by @ref{dates}, with dates sorted by increasing order.
%! @end table
%! @sp 2
%! @strong{This function is called by:}
@ -46,8 +46,8 @@ function dd = sort(dd) % --*-- Unitary tests --*--
% 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(dd,'dynDates')
error(['dynDates::sort: Input argument ' inputname(1) ' has to be a dynDates object.'])
if ~isa(dd,'dates')
error(['dates::sort: Input argument ' inputname(1) ' has to be a dates object.'])
end
if dd.ndat==1
@ -69,7 +69,7 @@ dd.time = sortrows(dd.time,[1,2]);
%$ e.ndat = 4;
%$
%$ % Call the tested routine.
%$ d = dynDates(B1,B2,B3,B4);
%$ d = dates(B1,B2,B3,B4);
%$ d = d.sort;
%$
%$ % Check the results.
@ -92,7 +92,7 @@ dd.time = sortrows(dd.time,[1,2]);
%$ e.ndat = 4;
%$
%$ % Call the tested routine.
%$ d = dynDates(B1,B2,B3,B4);
%$ d = dates(B1,B2,B3,B4);
%$ d = d.sort();
%$
%$ % Check the results.

View File

@ -17,4 +17,4 @@ function val = subsasgn(val, idx, rhs)
% You should have received a copy of the GNU General Public License
% along with Dynare. If not, see <http://www.gnu.org/licenses/>.
error('dynDates::subsasgn: Members of dynDates class are private')
error('dates::subsasgn: Members of dates class are private')

View File

@ -1,13 +1,13 @@
function B = subsref(A,S) % --*-- Unitary tests --*--
% Overload the subsref method for dynDates objects.
% Overload the subsref method for dates objects.
%
% INPUTS
% o A dynDates object.
% o A dates object.
% o S matlab's structure.
%
% OUTPUTS
% o B dynDates object.
% o B dates object.
%
% REMARKS
% See the matlab's documentation about the subsref method.
@ -34,7 +34,7 @@ switch S(1).type
switch S(1).subs
case {'time','freq','ndat'}% Access public members.
if length(S)>1 && isequal(S(2).type,'()') && isempty(S(2).subs)
error(['dynDates::subsref: ' S(1).subs ' is not a method but a member!'])
error(['dates::subsref: ' S(1).subs ' is not a method but a member!'])
end
B = builtin('subsref', A, S(1));
case {'sort','unique'}% Public methods (without arguments)
@ -47,19 +47,19 @@ switch S(1).type
B = feval(S(1).subs,A,S(2).subs{:});
S = shiftS(S);
else
error('dynDates::subsref: Something is wrong in your syntax!')
error('dates::subsref: Something is wrong in your syntax!')
end
otherwise
error('dynDates::subsref: Unknown public member or method!')
error('dates::subsref: Unknown public member or method!')
end
case '()'
if isempty(A)
if isempty(A.freq)
% Populate an empty dynDates object with time member (freq is not specified). Needs two or three inputs. First input is an integer
% 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 = dynDates();
B = dates();
% First input is the frequency.
if isfreq(S(1).subs{1})
if ischar(S(1).subs{1})
@ -68,103 +68,103 @@ switch S(1).type
B.freq = S(1).subs{1};
end
else
error('dynDates::subsref: First input must be a frequency!')
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('dynDates::subsref: Second input argument array cannot have more than two columns!')
error('dates::subsref: Second input argument array cannot have more than two columns!')
end
if ~isequal(m,2) && ~isequal(B.freq,1)
error('dynDates::subsref: Second argument has to be a n*2 array for non annual frequency!')
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('dynDates::subsref: Second argument has be an array of intergers!')
error('dates::subsref: Second argument has be an array of intergers!')
end
if m>1 && ~issubperiod(S(1).subs{2}(:,2),B.freq)
error(['dynDates::subsref: Elements in the second column of the first input argument are not legal subperiods (should be integers betwwen 1 and ' num2str(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(['dynDates::subsref: This is a bug!'])
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('dynDates::subsref: Second input argument must be a column vector of integers!')
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(['dynDates::subsref: Third input argument must be a column vector of subperiods (integers between 1 and ' num2str(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('dynDates::subsref: Second and third input arguments must have the same number of elements!')
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('dynDates::subsref: Wrong calling sequence!')
error('dates::subsref: Wrong calling sequence!')
end
else
% Populate an empty dynDates object with time member (freq is already specified).
% 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('dynDates::subsref: First argument has to be a column vector of integers!')
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(['dynDates::subsref: Second argument has to be a column vector of subperiods (integers between 1 and ' num2str(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('dynDates::subsref: First and second argument must have the same number of rows!')
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('dynDates::subsref: First argument has to be a n*2 array!')
error('dates::subsref: First argument has to be a n*2 array!')
end
if ~all(isint(S(1).subs{1}(:,1)))
error('dynDates::subsref: First column of the first argument has to be a column vector of integers!')
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(['dynDates::subsref: The second column of the first input argument has to be a column vector of subperiods (integers between 1 and ' num2str(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(['dynDates::subsref: This is a bug!'])
error(['dates::subsref: This is a bug!'])
end
B.ndat = rows(B.time);
else
error('dynDates::subsref: Wrong number of inputs!')
error('dates::subsref: Wrong number of inputs!')
end
end
else
% dynDates object A is not empty. We extract some dates
% 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 = dynDates();
B = dates();
B.freq = A.freq;
B.time = A.time(S(1).subs{1},:);
B.ndat = rows(B.time);
else
error(['dynDates::subsref: indices has to be a vector of positive integers less than or equal to ' int2str(A.ndat) '!'])
error(['dates::subsref: indices has to be a vector of positive integers less than or equal to ' int2str(A.ndat) '!'])
end
end
otherwise
error('dynDates::subsref: Something is wrong in your syntax!')
error('dates::subsref: Something is wrong in your syntax!')
end
S = shiftS(S);
@ -173,13 +173,13 @@ if ~isempty(S)
end
%@test:1
%$ % Define a dynDates object
%$ B = dynDates('1950Q1','1950Q2','1950Q3','1950Q4','1951Q1');
%$ % Define a dates object
%$ B = dates('1950Q1','1950Q2','1950Q3','1950Q4','1951Q1');
%$
%$ % Try to extract a sub-dynDates object.
%$ % Try to extract a sub-dates object.
%$ d = B(2:3);
%$
%$ if isa(d,'dynDates')
%$ if isa(d,'dates')
%$ t(1) = 1;
%$ else
%$ t(1) = 0;
@ -194,14 +194,14 @@ end
%@eof:1
%@test:2
%$ % Define a dynDates object
%$ B = dynDates('1950Q1'):dynDates('1960Q3');
%$ % Define a dates object
%$ B = dates('1950Q1'):dates('1960Q3');
%$
%$ % Try to extract a sub-dynDates object and apply a method
%$ % Try to extract a sub-dates object and apply a method
%$
%$ d = B(2:3).sort ;
%$
%$ if isa(d,'dynDates')
%$ if isa(d,'dates')
%$ t(1) = 1;
%$ else
%$ t(1) = 0;
@ -216,14 +216,14 @@ end
%@eof:2
%@test:3
%$ % Define a dynDates object
%$ B = dynDates('1950Q1'):dynDates('1960Q3');
%$ % Define a dates object
%$ B = dates('1950Q1'):dates('1960Q3');
%$
%$ % Try to extract a sub-dynDates object and apply a method
%$ % Try to extract a sub-dates object and apply a method
%$
%$ d = B(2:3).sort() ;
%$
%$ if isa(d,'dynDates')
%$ if isa(d,'dates')
%$ t(1) = 1;
%$ else
%$ t(1) = 0;
@ -238,13 +238,13 @@ end
%@eof:3
%@test:4
%$ % Define a dynDates object
%$ B = dynDates('1950Q1','1950Q2','1950Q3','1950Q4','1951Q1');
%$ % Define a dates object
%$ B = dates('1950Q1','1950Q2','1950Q3','1950Q4','1951Q1');
%$
%$ % Try to extract a sub-dynDates object.
%$ % Try to extract a sub-dates object.
%$ d = B(2);
%$
%$ if isa(d,'dynDates')
%$ if isa(d,'dates')
%$ t(1) = 1;
%$ else
%$ t(1) = 0;
@ -259,8 +259,8 @@ end
%@eof:4
%@test:5
%$ % Define an empty dynDates object with quaterly frequency.
%$ qq = dynDates('Q');
%$ % Define an empty dates object with quaterly frequency.
%$ qq = dates('Q');
%$
%$ % Define a ranges of dates using qq.
%$ try
@ -294,8 +294,8 @@ end
%@eof:5
%@test:6
%$ % Define an empty dynDates object with quaterly frequency.
%$ date = dynDates();
%$ % Define an empty dates object with quaterly frequency.
%$ date = dates();
%$
%$ % Define a ranges of dates using qq.
%$ try

View File

@ -1,12 +1,12 @@
function B = uminus(A) % --*-- Unitary tests --*--
% Overloads the unary plus operator for dynDates objects. Shifts all the elements by one period.
% Overloads the unary plus operator for dates objects. Shifts all the elements by one period.
%
% INPUTS
% o A dynDates object with n elements.
% o A dates object with n elements.
%
% OUTPUTS
% o B dynDates object with n elements.
% o B dates object with n elements.
% Copyright (C) 2013 Dynare Team
%
@ -25,7 +25,7 @@ function B = uminus(A) % --*-- Unitary tests --*--
% You should have received a copy of the GNU General Public License
% along with Dynare. If not, see <http://www.gnu.org/licenses/>.
B = dynDates(A);
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;
@ -40,16 +40,16 @@ B.time(idx,2) = B.freq;
%$ date_5 = '1950M1';
%$
%$ % Call the tested routine.
%$ d1 = dynDates(date_1); d1 = -d1;
%$ d2 = dynDates(date_2); d2 = -d2;
%$ d3 = dynDates(date_3); d3 = -d3;
%$ d4 = dynDates(date_4); d4 = -d4;
%$ d5 = dynDates(date_5); d5 = -d5;
%$ i1 = (d1==dynDates('1949Y'));
%$ i2 = (d2==dynDates('1950Q1'));
%$ i3 = (d3==dynDates('1949Q4'));
%$ i4 = (d4==dynDates('1950M1'));
%$ i5 = (d5==dynDates('1949M12'));
%$ d1 = dates(date_1); d1 = -d1;
%$ d2 = dates(date_2); d2 = -d2;
%$ d3 = dates(date_3); d3 = -d3;
%$ d4 = dates(date_4); d4 = -d4;
%$ d5 = dates(date_5); d5 = -d5;
%$ i1 = (d1==dates('1949Y'));
%$ i2 = (d2==dates('1950Q1'));
%$ i3 = (d3==dates('1949Q4'));
%$ i4 = (d4==dates('1950M1'));
%$ i5 = (d5==dates('1949M12'));
%$
%$ % Check the results.
%$ t(1) = dyn_assert(i1,1);
@ -61,8 +61,8 @@ B.time(idx,2) = B.freq;
%@eof:1
%@test:2
%$ d1 = dynDates('1950Q1','1950Q2','1950Q3','1950Q4','1951Q1');
%$ d2 = dynDates('1949Q4','1950Q1','1950Q2','1950Q3','1950Q4');
%$ d1 = dates('1950Q1','1950Q2','1950Q3','1950Q4','1951Q1');
%$ d2 = dates('1949Q4','1950Q1','1950Q2','1950Q3','1950Q4');
%$ try
%$ d3 = -d1;
%$ t(1) = 1;

View File

@ -2,7 +2,7 @@ function C = union(A,varargin) % --*-- Unitary tests --*--
%@info:
%! @deftypefn {Function File} {@var{C} =} union (@var{A},@var{B})
%! @anchor{dynDates/union}
%! @anchor{dates/union}
%! @sp 1
%! Union method for the Dynare dates class (removes repetitions if any). Dates in C are sorted in increasing order.
%! @sp 2
@ -10,16 +10,16 @@ function C = union(A,varargin) % --*-- Unitary tests --*--
%! @sp 1
%! @table @ @var
%! @item A
%! Object instantiated by @ref{dynDates}.
%! Object instantiated by @ref{dates}.
%! @item B
%! Object instantiated by @ref{dynDates}.
%! Object instantiated by @ref{dates}.
%! @end table
%! @sp 2
%! @strong{Outputs}
%! @sp 1
%! @table @ @var
%! @item C
%! Object instantiated by @ref{dynDates}.
%! Object instantiated by @ref{dates}.
%! @end table
%! @end deftypefn
%@eod:
@ -41,8 +41,8 @@ function C = union(A,varargin) % --*-- Unitary tests --*--
% 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,'dynDates')
error(['dynDates::union: Input argument ''' inputname(1) ''' has to be a dynDates object!'])
if ~isa(A,'dates')
error(['dates::union: Input argument ''' inputname(1) ''' has to be a dates object!'])
end
C = A;
@ -52,17 +52,17 @@ if ~length(varargin)
end
for i=1:length(varargin)
if isa(varargin{i},'dynDates')
if isa(varargin{i},'dates')
C = C + varargin{i};
else
error(['dynDates::union: Input argument ''' inputname(i) ''' has to be a dynDates object!'])
error(['dates::union: Input argument ''' inputname(i) ''' has to be a dates object!'])
end
end
C = sort(unique(C));
%@test:1
%$ % Define some dynDates objects
%$ % Define some dates objects
%$ d1 = dynDate('1950Q1'):dynDate('1959Q4') ;
%$ d2 = dynDate('1960Q1'):dynDate('1969Q4') ;
%$ d3 = dynDate('1970Q1'):dynDate('1979Q4') ;

View File

@ -1,10 +1,10 @@
function dd = unique(dd) % --*-- Unitary tests --*--
% unique method for dynDates class.
% unique method for dates class.
%@info:
%! @deftypefn {Function File} {@var{a} =} unique (@var{a})
%! @anchor{dynDates/unique}
%! @anchor{dates/unique}
%! @sp 1
%! Unique method for the Dynare dates class (removes repetitions).
%! @sp 2
@ -12,14 +12,14 @@ function dd = unique(dd) % --*-- Unitary tests --*--
%! @sp 1
%! @table @ @var
%! @item a
%! Object instantiated by @ref{dynDates}.
%! Object instantiated by @ref{dates}.
%! @end table
%! @sp 2
%! @strong{Outputs}
%! @sp 1
%! @table @ @var
%! @item a
%! Object instantiated by @ref{dynDates}.
%! Object instantiated by @ref{dates}.
%! @end table
%! @sp 2
%! @strong{This function is called by:}
@ -46,8 +46,8 @@ function dd = unique(dd) % --*-- Unitary tests --*--
% 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(dd,'dynDates')
error(['dynDates::unique: Input argument ' inputname(1) ' has to be a dynDates object.'])
if ~isa(dd,'dates')
error(['dates::unique: Input argument ' inputname(1) ' has to be a dates object.'])
end
if dd.ndat==1
@ -72,7 +72,7 @@ dd.ndat = size(dd.time,1);
%$ e.ndat = 4;
%$
%$ % Call the tested routine.
%$ d = dynDates(B1,B2,B3,B4,B5);
%$ d = dates(B1,B2,B3,B4,B5);
%$ d = d.unique;
%$
%$ % Check the results.

View File

@ -1,12 +1,12 @@
function B = uplus(A) % --*-- Unitary tests --*--
% Overloads the unary plus operator for dynDates objects. Shifts all the elements by one period.
% Overloads the unary plus operator for dates objects. Shifts all the elements by one period.
%
% INPUTS
% o A dynDates object with n elements.
% o A dates object with n elements.
%
% OUTPUTS
% o B dynDates object with n elements.
% o B dates object with n elements.
% Copyright (C) 2013 Dynare Team
%
@ -25,7 +25,7 @@ function B = uplus(A) % --*-- Unitary tests --*--
% You should have received a copy of the GNU General Public License
% along with Dynare. If not, see <http://www.gnu.org/licenses/>.
B = dynDates(A);
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;
@ -40,16 +40,16 @@ B.time(idx,2) = 1;
%$ date_5 = '1950M12';
%$
%$ % Call the tested routine.
%$ d1 = dynDates(date_1); d1 = +d1;
%$ d2 = dynDates(date_2); d2 = +d2;
%$ d3 = dynDates(date_3); d3 = +d3;
%$ d4 = dynDates(date_4); d4 = +d4;
%$ d5 = dynDates(date_5); d5 = +d5;
%$ i1 = (d1==dynDates('1951Y'));
%$ i2 = (d2==dynDates('1950Q3'));
%$ i3 = (d3==dynDates('1951Q1'));
%$ i4 = (d4==dynDates('1950M3'));
%$ i5 = (d5==dynDates('1951M1'));
%$ d1 = dates(date_1); d1 = +d1;
%$ d2 = dates(date_2); d2 = +d2;
%$ d3 = dates(date_3); d3 = +d3;
%$ d4 = dates(date_4); d4 = +d4;
%$ d5 = dates(date_5); d5 = +d5;
%$ i1 = (d1==dates('1951Y'));
%$ i2 = (d2==dates('1950Q3'));
%$ i3 = (d3==dates('1951Q1'));
%$ i4 = (d4==dates('1950M3'));
%$ i5 = (d5==dates('1951M1'));
%$
%$ % Check the results.
%$ t(1) = dyn_assert(i1,1);
@ -61,8 +61,8 @@ B.time(idx,2) = 1;
%@eof:1
%@test:2
%$ d1 = dynDates('1950Q1','1950Q2','1950Q3','1950Q4','1951Q1');
%$ d2 = dynDates('1950Q2','1950Q3','1950Q4','1951Q1','1951Q2');
%$ d1 = dates('1950Q1','1950Q2','1950Q3','1950Q4','1951Q1');
%$ d2 = dates('1950Q2','1950Q3','1950Q4','1951Q1','1951Q2');
%$ try
%$ d3 = +d1;
%$ t(1) = 1;

View File

@ -85,7 +85,7 @@ ts.name = {};
ts.tex = {};
ts.freq = [];
ts.init = dynDate();
ts.time = dynDates();
ts.time = dates();
ts = class(ts,'dynSeries');

View File

@ -42,7 +42,7 @@ function C = eq(A,B) % --*-- Unitary tests --*--
% along with Dynare. If not, see <http://www.gnu.org/licenses/>.
if nargin~=2
error('dynDates::eq: I need exactly two input arguments!')
error('dates::eq: I need exactly two input arguments!')
end
C = isequal(A,B);

View File

@ -105,7 +105,7 @@ switch length(S)
A.freq = A.init.freq;
A.time = A.init:A.init+(A.nobs-1);
return
elseif isequal(S(1).subs,'time') && isa(B,'dynDates')
elseif isequal(S(1).subs,'time') && isa(B,'dates')
% Overwrite the time member...
A.time = B;
% ... and update the freq and init members.
@ -131,7 +131,7 @@ switch length(S)
end
end
case '()' % Date(s) selection
if isa(S(1).subs{1},'dynDates') || isa(S(1).subs{1},'dynDate')
if isa(S(1).subs{1},'dates') || isa(S(1).subs{1},'dynDate')
[junk, tdx] = intersect(A.time.time,S(1).subs{1}.time,'rows');
if isa(B,'dynSeries')
[junk, tdy] = intersect(B.time.time,S(1).subs{1}.time,'rows');
@ -172,7 +172,7 @@ switch length(S)
sA = extract(A,S(1).subs);
end
if (isa(B,'dynSeries') && isequal(sA.vobs,B.vobs)) || (isnumeric(B) && isequal(sA.vobs,columns(B))) || (isnumeric(B) && isequal(columns(B),1))
if isa(S(2).subs{1},'dynDates') || isa(S(2).subs{1},'dynDate')
if isa(S(2).subs{1},'dates') || isa(S(2).subs{1},'dynDate')
[junk, tdx] = intersect(sA.time.time,S(2).subs{1}.time,'rows');
if isa(B,'dynSeries')
[junk, tdy] = intersect(B.time.time,S(2).subs{1}.time,'rows');

View File

@ -184,8 +184,8 @@ switch S(1).type
% Do nothing.
B = A;
end
elseif isa(S(1).subs{1},'dynDates')
% Extract a subsample using a dynDates object
elseif isa(S(1).subs{1},'dates')
% Extract a subsample using a dates object
[junk,tdx] = intersect(A.time.time,S(1).subs{1}.time,'rows');
B = dynSeries();
B.data = A.data(tdx,:);
@ -199,7 +199,7 @@ switch S(1).type
elseif isvector(S(1).subs{1}) && all(isint(S(1).subs{1}))
% Extract a subsample using a vector of integers (observation index).
% Note that this does not work if S(1).subs is an integer scalar... In which case S(1).subs is interpreted as a lead/lag operator (as in the Dynare syntax).
% To extract one observation, a dynDates with one element or a dynDate input must be used.
% To extract one observation, a dates with one element or a dynDate input must be used.
if all(S(1).subs{1}>0) && all(S(1).subs{1}<=A.nobs)
if size(A.data,2)>1
S(1).subs = [S(1).subs, ':'];
@ -216,7 +216,7 @@ switch S(1).type
error('dynSeries::subsref: Indices are out of bounds!')
end
elseif isa(S(1).subs{1},'dynDate')
% Extract a subsample using a dynDates object
% Extract a subsample using a dates object
[junk,tdx] = intersect(A.time.time,S(1).subs{1}.time,'rows');
B = dynSeries();
B.data = A.data(tdx,:);

View File

@ -115,12 +115,12 @@ valid_legend_orientations = {'vertical', 'horizontal'};
assert(any(strcmp(o.legendOrientation, valid_legend_orientations)), ...
['@graph.graph: legendOrientation must be one of ' strjoin(valid_legend_orientations, ' ')]);
assert(isempty(o.shade) || (isa(o.shade, 'dynDates') && o.shade.ndat >= 2), ...
['@graph.graph: shade is specified as a dynDates range, e.g. ' ...
'''dynDates(''1999q1''):dynDates(''1999q3'')''.']);
assert(isempty(o.xrange) || (isa(o.xrange, 'dynDates') && o.xrange.ndat >= 2), ...
['@graph.graph: xrange is specified as a dynDates range, e.g. ' ...
'''dynDates(''1999q1''):dynDates(''1999q3'')''.']);
assert(isempty(o.shade) || (isa(o.shade, 'dates') && o.shade.ndat >= 2), ...
['@graph.graph: shade is specified as a dates range, e.g. ' ...
'''dates(''1999q1''):dates(''1999q3'')''.']);
assert(isempty(o.xrange) || (isa(o.xrange, 'dates') && o.xrange.ndat >= 2), ...
['@graph.graph: xrange is specified as a dates range, e.g. ' ...
'''dates(''1999q1''):dates(''1999q3'')''.']);
assert(isempty(o.yrange) || (isfloat(o.yrange) && length(o.yrange) == 2 && ...
o.yrange(1) < o.yrange(2)), ...
['@graph.graph: yrange is specified an array with two float entries, ' ...

View File

@ -18,6 +18,6 @@ function ds = getData(o, dates)
% You should have received a copy of the GNU General Public License
% along with Dynare. If not, see <http://www.gnu.org/licenses/>.
assert(~isempty(o.data) && size(o.data, 2) == 1 && isa(dates, 'dynDates'));
assert(~isempty(o.data) && size(o.data, 2) == 1 && isa(dates, 'dates'));
ds = o.data(dates);
end

View File

@ -4,7 +4,7 @@ function h = getLine(o, xrange)
%
% INPUTS
% o [series] series object
% xrange [dynDates] range of x values for line
% xrange [dates] range of x values for line
%
% OUTPUTS
% h [handle] handle to line
@ -58,7 +58,7 @@ assert(~(strcmp(o.graphLineStyle, 'none') && isempty(o.graphMarker)), ['@series.
'you must provide at least one of graphLineStyle and graphMarker']);
% Validate xrange
assert(isempty(xrange) || isa(xrange, 'dynDates'));
assert(isempty(xrange) || isa(xrange, 'dates'));
% Zero tolerance
assert(isfloat(o.zerotol), '@series.write: zerotol must be a float');

View File

@ -5,7 +5,7 @@ function o = write(o, fid, dates, precision, yrsForAvgs)
% INPUTS
% o [series] series object
% fid [int] file id
% dates [dynDates] dates for series slice
% dates [dates] dates for series slice
% precision [float] precision with which to print the data
% yrsForAvgs [bool] the years for which to compute averages
%
@ -35,7 +35,7 @@ function o = write(o, fid, dates, precision, yrsForAvgs)
%% Validate options passed to function
assert(fid ~= -1);
assert(isa(dates, 'dynDates'));
assert(isa(dates, 'dates'));
assert(isint(precision));
%% Validate options provided by user

View File

@ -79,9 +79,9 @@ assert(islogical(o.annualAverages), '@table.table: annualAverages must be true o
assert(islogical(o.showHlines), '@table.table: showHlines must be true or false');
assert(islogical(o.showVlines), '@table.table: showVlines must be true or false');
assert(isint(o.precision), '@table.table: precision must be an int');
assert(isempty(o.range) || (isa(o.range, 'dynDates') && o.range.ndat >= 2), ...
['@table.table: range is specified as a dynDates range, e.g. ' ...
'''dynDates(''1999q1''):dynDates(''1999q3'')''.']);
assert(isempty(o.range) || (isa(o.range, 'dates') && o.range.ndat >= 2), ...
['@table.table: range is specified as a dates range, e.g. ' ...
'''dates(''1999q1''):dates(''1999q3'')''.']);
assert(isempty(o.data) || isa(o.data, 'dynSeries'), ...
'@table.table: data must be a dynSeries');
assert(isempty(o.seriesToUse) || iscellstr(o.seriesToUse), ...

View File

@ -66,8 +66,8 @@ for i=1:length(fields)
fprintf('false');
end
elseif isobject(val)
if isa(val, 'dynDates')
fprintf('<dynDates: %s, ..., %s>', ...
if isa(val, 'dates')
fprintf('<dates: %s, ..., %s>', ...
val(1).format, val(end).format);
elseif isa(val, 'dynSeries')
if numel(val) == 1

View File

@ -3,7 +3,7 @@ function s = date2string(varargin)
% Returns date as a string.
%
% INPUTS
% o varargin{1} + dynDates object with one element, if nargin==1.
% 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).
%
@ -28,8 +28,8 @@ function s = date2string(varargin)
% along with Dynare. If not, see <http://www.gnu.org/licenses/>.
if isequal(nargin,1)
if ~(isa(varargin{1},'dynDates') && isequal(length(varargin{1}),1))
error(['dynDates::format: Input argument ' inputname(1) ' has to be a dynDates object with one element!'])
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;
@ -38,7 +38,7 @@ 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(['dynDates::format: First input must be a 1*2 vector of integers and second input must be a scalar integer (1, 4, 12 or 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};

View File

@ -33,5 +33,5 @@ switch freq
case 52
s = 'W';
otherwise
error('dynDates::freq2string: Unknown frequency!')
error('dates::freq2string: Unknown frequency!')
end

View File

@ -20,7 +20,7 @@ function date = string2date(a) % --*-- Unitary tests --*--
date = struct('freq', NaN, 'time', NaN(1,2));
if ~ischar(a) || ~isdate(a)
error('dynDates::string2date: Input must be a string that can be interpreted as a date!');
error('dates::string2date: Input must be a string that can be interpreted as a date!');
end
if isyearly(a)

View File

@ -33,5 +33,5 @@ switch upper(s)
case 'W'
freq = 52;
otherwise
error('dynDates::freq2string: Unknown frequency!')
error('dates::freq2string: Unknown frequency!')
end