Removed @dynDate class.
parent
f836e485f9
commit
aec191c825
|
@ -1,24 +0,0 @@
|
|||
function disp(d)
|
||||
|
||||
% 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(d)
|
||||
fprintf('Empty dynDate object.\n');
|
||||
else
|
||||
fprintf('<dynDate: %s>\n', format(d));
|
||||
end
|
|
@ -1,24 +0,0 @@
|
|||
function display(d)
|
||||
|
||||
% 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(d)
|
||||
fprintf('%s is an empty dynDate object.\n', inputname(1));
|
||||
else
|
||||
fprintf('%s = <dynDate: %s>\n', inputname(1), format(d));
|
||||
end
|
|
@ -1,310 +0,0 @@
|
|||
function date = dynDate(a,b) % --*-- Unitary tests --*--
|
||||
|
||||
%@info:
|
||||
%! @deftypefn {Function File} {@var{date} =} dynDate (@var{a})
|
||||
%! @anchor{dynDate}
|
||||
%! @sp 1
|
||||
%! Constructor for the Dynare dates class.
|
||||
%! @sp 2
|
||||
%! @strong{Inputs}
|
||||
%! @sp 1
|
||||
%! @table @ @var
|
||||
%! @item a
|
||||
%! Date. For Quaterly, Monthly or Weekly data, a must be a string. For yearly data or if the frequence is not
|
||||
%! defined must be an integer. If @var{a} is a dynDate object, then date will be a copy of this object. If
|
||||
%! the constructor is called without input argument, it will return an empty dynDate object.
|
||||
%! @end table
|
||||
%! @sp 1
|
||||
%! @strong{Outputs}
|
||||
%! @sp 1
|
||||
%! @table @ @var
|
||||
%! @item date
|
||||
%! Dynare date object.
|
||||
%! @end table
|
||||
%! @sp 1
|
||||
%! @strong{Properties}
|
||||
%! @sp 1
|
||||
%! The constructor defines the following properties:
|
||||
%! @sp 1
|
||||
%! @table @ @var
|
||||
%! @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
|
||||
%! Row vector of integers (1*2) indicating the year and the week, month or quarter of the first observation.
|
||||
%! @end table
|
||||
%! @sp 1
|
||||
%! @strong{This function is called by:}
|
||||
%! @sp 2
|
||||
%! @strong{This function calls:}
|
||||
%! @ref{set_time}
|
||||
%!
|
||||
%! @end deftypefn
|
||||
%@eod:
|
||||
|
||||
% Copyright (C) 2011-2013 Dynare Team
|
||||
%
|
||||
% This file is part of Dynare.
|
||||
%
|
||||
% Dynare is free software: you can redistribute it and/or modify
|
||||
% it under the terms of the GNU General Public License as published by
|
||||
% the Free Software Foundation, either version 3 of the License, or
|
||||
% (at your option) any later version.
|
||||
%
|
||||
% Dynare is distributed in the hope that it will be useful,
|
||||
% but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
% MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
% GNU General Public License for more details.
|
||||
%
|
||||
% You should have received a copy of the GNU General Public License
|
||||
% along with Dynare. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
date = struct;
|
||||
|
||||
date.freq = NaN;
|
||||
date.time = NaN(1,2);
|
||||
|
||||
date = class(date,'dynDate');
|
||||
|
||||
switch nargin
|
||||
case 0
|
||||
% Return an empty dynDate object (without specified frequency).
|
||||
return
|
||||
case 1
|
||||
if ischar(a)% Weekly, Monthly or Quaterly data.
|
||||
a = upper(a);
|
||||
if length(a)>1
|
||||
yearly = findstr('Y',a);
|
||||
if isempty(yearly)
|
||||
yearly = findstr('A',a);
|
||||
end
|
||||
quaterly = findstr('Q',a);
|
||||
monthly = findstr('M',a);
|
||||
weekly = findstr('W',a);
|
||||
if ~isempty(yearly)
|
||||
date.freq = 1;
|
||||
date.time(1) = str2num(a(1:yearly-1));
|
||||
date.time(2) = 1;
|
||||
end
|
||||
if ~isempty(quaterly)
|
||||
date.freq = 4;
|
||||
date.time(1) = str2num(a(1:quaterly-1));
|
||||
date.time(2) = str2num(a(quaterly+1:end));
|
||||
end
|
||||
if ~isempty(monthly)
|
||||
date.freq = 12;
|
||||
date.time(1) = str2num(a(1:monthly-1));
|
||||
date.time(2) = str2num(a(monthly+1:end));
|
||||
end
|
||||
if ~isempty(weekly)
|
||||
date.freq = 52;
|
||||
date.time(1) = str2num(a(1:weekly-1));
|
||||
date.time(2) = str2num(a(weekly+1:end));
|
||||
end
|
||||
if isempty(yearly) && isempty(quaterly) && isempty(monthly) && isempty(weekly)
|
||||
if isaletter(a)
|
||||
error('dynDate:: Using a string as an input argument, I can only handle weekly (W), monthly (M), quaterly (Q) or yearly (Y, A), data!');
|
||||
else
|
||||
% Yearly data declared with a string
|
||||
date.freq = 1;
|
||||
date.time(1) = str2num(a);
|
||||
date.time(2) = 1;
|
||||
end
|
||||
end
|
||||
else
|
||||
% Return an empty dynDate object (with a specified frequency).
|
||||
switch a
|
||||
case {'Y','A'}
|
||||
date.freq = 1;
|
||||
case 'Q'
|
||||
date.freq = 4;
|
||||
case 'M'
|
||||
date.freq = 12;
|
||||
case 'W'
|
||||
date.freq = 52;
|
||||
otherwise
|
||||
error(['dynDate:: With one string argument of length one, you must provide one of weekly (''W''), monthly (''M''), quaterly (''Q'') or yearly (''Y'').']);
|
||||
end
|
||||
end
|
||||
elseif isa(a,'dynDate') % If input argument is a dynDate object then do a copy.
|
||||
date = a;
|
||||
else
|
||||
if isequal(length(a),1) && isnumeric(a) && isint(a)
|
||||
% If b is not a string then yearly data are assumed.
|
||||
date.freq = 1;
|
||||
date.time(1) = a;
|
||||
date.time(2) = 1;
|
||||
else
|
||||
error('dynDate:: Can''t instantiate the class, wrong calling sequence!')
|
||||
end
|
||||
end
|
||||
case 2 % provide time and freq to instantiate a dynDate object
|
||||
date = dynDate();
|
||||
if isnumeric(b) && isscalar(b) && ismember(b,[1,4,12,52])
|
||||
date.freq = b;
|
||||
elseif ischar(b) && isequal(length(b),1) && ismember(upper(b),{'Y','A','W','M','Q'})
|
||||
b = upper(b);
|
||||
switch b
|
||||
case {'Y','A'}
|
||||
date.freq = 1;
|
||||
case 'W'
|
||||
date.freq = 52;
|
||||
case 'M'
|
||||
date.freq = 12;
|
||||
case 'Q'
|
||||
date.freq = 4;
|
||||
otherwise
|
||||
error(['dynDate:: Can''t instantiate the class! The second argument ' inputname(2) ' must be an integer equal to 1, 4, 12 or 52, or a character equal to ''Y'', ''A'', ''W'', ''M'' or ''Q''!'])
|
||||
end
|
||||
else
|
||||
error(['dynDate:: Can''t instantiate the class! The second argument ' inputname(2) ' must be an integer equal to 1, 4, 12 or 52, or a character equal to ''Y'', ''A'', ''W'', ''M'' or ''Q''!'])
|
||||
end
|
||||
if ~isnumeric(a)
|
||||
error(['dynDate:: Can''t instantiate the class! The first argument ' inputname(1) ' must be numeric!'])
|
||||
end
|
||||
if ~all(isint(a))
|
||||
error(['dynDate:: Can''t instantiate the class! The first argument ' inputname(1) ' must be a scalar or a 1*2 vector of integers!'])
|
||||
end
|
||||
if ~isequal(size(a),[1,2])
|
||||
if date.freq>1
|
||||
error(['dynDate:: Can''t instantiate the class! The first argument ' inputname(1) ' must be a 1*2 vector of integers.'])
|
||||
end
|
||||
else
|
||||
if isequal(date.freq,1) && ~isequal(a(2),1)
|
||||
error(['dynDate:: Can''t instantiate the class! The second element of the first input argument ' inputname(1) ' must be equal to one (because freq==1)!'])
|
||||
end
|
||||
end
|
||||
if a(2)<=0 || a(2)>date.freq
|
||||
error(['dynDate:: Can''t instantiate the class! The second element of the first argument ' inputname(1) ' must be a positive integer be <=' int2str(2) '!' ])
|
||||
end
|
||||
if length(a)==1
|
||||
date.time = [a, 1];
|
||||
else
|
||||
date.time = a;
|
||||
end
|
||||
otherwise
|
||||
error('dynDate:: Can''t instantiate the class, wrong calling sequence!')
|
||||
end
|
||||
|
||||
%@test:1
|
||||
%$ % Define some dates
|
||||
%$ date_1 = 1950;
|
||||
%$ date_2 = '1950Q2';
|
||||
%$ date_3 = '1950m10';
|
||||
%$ date_4 = '1950w50';
|
||||
%$ date_5 = '1950';
|
||||
%$ date_6 = '1967y';
|
||||
%$ date_7 = '2009A';
|
||||
%$
|
||||
%$ % Define expected results.
|
||||
%$ e_date_1 = [1950 1];
|
||||
%$ e_freq_1 = 1;
|
||||
%$ e_date_2 = [1950 2];
|
||||
%$ e_freq_2 = 4;
|
||||
%$ e_date_3 = [1950 10];
|
||||
%$ e_freq_3 = 12;
|
||||
%$ e_date_4 = [1950 50];
|
||||
%$ e_freq_4 = 52;
|
||||
%$ e_date_5 = [1950 1];
|
||||
%$ e_freq_5 = 1;
|
||||
%$ e_date_6 = [1967 1];
|
||||
%$ e_freq_6 = 1;
|
||||
%$ e_date_7 = [2009 1];
|
||||
%$ e_freq_7 = 1;
|
||||
%$
|
||||
%$ % Call the tested routine.
|
||||
%$ d1 = dynDate(date_1);
|
||||
%$ d2 = dynDate(date_2);
|
||||
%$ d3 = dynDate(date_3);
|
||||
%$ d4 = dynDate(date_4);
|
||||
%$ d5 = dynDate(date_5);
|
||||
%$ d6 = dynDate(date_6);
|
||||
%$ d7 = dynDate(date_7);
|
||||
%$
|
||||
%$ % Check the results.
|
||||
%$ t(1) = dyn_assert(d1.time,e_date_1);
|
||||
%$ t(2) = dyn_assert(d2.time,e_date_2);
|
||||
%$ t(3) = dyn_assert(d3.time,e_date_3);
|
||||
%$ t(4) = dyn_assert(d4.time,e_date_4);
|
||||
%$ t(5) = dyn_assert(d5.time,e_date_5);
|
||||
%$ t(6) = dyn_assert(d1.freq,e_freq_1);
|
||||
%$ t(7) = dyn_assert(d2.freq,e_freq_2);
|
||||
%$ t(8) = dyn_assert(d3.freq,e_freq_3);
|
||||
%$ t(9) = dyn_assert(d4.freq,e_freq_4);
|
||||
%$ t(10)= dyn_assert(d5.freq,e_freq_5);
|
||||
%$ t(11)= dyn_assert(d6.freq,e_freq_6);
|
||||
%$ t(12)= dyn_assert(d7.freq,e_freq_7);
|
||||
%$ t(13)= dyn_assert(d6.time,e_date_6);
|
||||
%$ t(14)= dyn_assert(d7.time,e_date_7);
|
||||
%$ T = all(t);
|
||||
%@eof:1
|
||||
|
||||
%@test:2
|
||||
%$ % Instatiate an empty objects for quaterly, monthly and weekly dates.
|
||||
%$ qq = dynDate('Q');
|
||||
%$ mm = dynDate('M');
|
||||
%$ ww = dynDate('W');
|
||||
%$ yy = dynDate('Y');
|
||||
%$
|
||||
%$ % Check the results.
|
||||
%$ t(1) = dyn_assert(qq.freq,4);
|
||||
%$ t(2) = dyn_assert(mm.freq,12);
|
||||
%$ t(3) = dyn_assert(ww.freq,52);
|
||||
%$ t(4) = dyn_assert(yy.freq,1);
|
||||
%$ t(5) = dyn_assert(all(isnan(qq.time)),1);
|
||||
%$ t(6) = dyn_assert(all(isnan(mm.time)),1);
|
||||
%$ t(7) = dyn_assert(all(isnan(ww.time)),1);
|
||||
%$ t(8) = dyn_assert(all(isnan(yy.time)),1);
|
||||
%$ T = all(t);
|
||||
%@eof:2
|
||||
|
||||
%@test:3
|
||||
%$ % Try to instatiate dynDate objects.
|
||||
%$ try
|
||||
%$ a = dynDate([1950 1],4);
|
||||
%$ t(1) = 1;
|
||||
%$ catch
|
||||
%$ t(1) = 0;
|
||||
%$ end
|
||||
%$ try
|
||||
%$ a = dynDate([1950 5],4);
|
||||
%$ t(2) = 0;
|
||||
%$ catch
|
||||
%$ t(2) = 1;
|
||||
%$ end
|
||||
%$ T = all(t);
|
||||
%@eof:3
|
||||
|
||||
%@test:4
|
||||
%$ % Instatiate an empty objects for quaterly, monthly and weekly dates.
|
||||
%$ qq = dynDate('q');
|
||||
%$ mm = dynDate('m');
|
||||
%$ ww = dynDate('w');
|
||||
%$
|
||||
%$ % Check the results.
|
||||
%$ t(1) = dyn_assert(qq.freq,4);
|
||||
%$ t(2) = dyn_assert(mm.freq,12);
|
||||
%$ t(3) = dyn_assert(ww.freq,52);
|
||||
%$ t(4) = dyn_assert(all(isnan(qq.time)),1);
|
||||
%$ t(5) = dyn_assert(all(isnan(mm.time)),1);
|
||||
%$ t(6) = dyn_assert(all(isnan(ww.time)),1);
|
||||
%$ T = all(t);
|
||||
%@eof:4
|
||||
|
||||
%@test:5
|
||||
%$ % Try to instatiate dynDate objects.
|
||||
%$ try
|
||||
%$ a = dynDate([1950 1],'Q');
|
||||
%$ t(1) = 1;
|
||||
%$ catch
|
||||
%$ t(1) = 0;
|
||||
%$ end
|
||||
%$ try
|
||||
%$ a = dynDate([1950 5],'Q');
|
||||
%$ t(2) = 0;
|
||||
%$ catch
|
||||
%$ t(2) = 1;
|
||||
%$ end
|
||||
%$ T = all(t);
|
||||
%@eof:5
|
|
@ -1,124 +0,0 @@
|
|||
function c = eq(a,b) % --*-- Unitary tests --*--
|
||||
|
||||
%@info:
|
||||
%! @deftypefn {Function File} {@var{c} =} eq (@var{a},@var{b})
|
||||
%! @anchor{@dynDate/eq}
|
||||
%! @sp 1
|
||||
%! Overloads the eq (equal) operator for the Dynare dates class (@ref{dynDate}).
|
||||
%! @sp 2
|
||||
%! @strong{Inputs}
|
||||
%! @sp 1
|
||||
%! @table @ @var
|
||||
%! @item a
|
||||
%! Dynare date object instantiated by @ref{dynDate}.
|
||||
%! @item b
|
||||
%! Dynare date object instantiated by @ref{dynDate}.
|
||||
%! @end table
|
||||
%! @sp 1
|
||||
%! @strong{Outputs}
|
||||
%! @sp 1
|
||||
%! @table @ @var
|
||||
%! @item c
|
||||
%! scalar integer equal to one if a==b, 0 otherwise.
|
||||
%! @end table
|
||||
%! @sp 2
|
||||
%! @strong{This function is called by:}
|
||||
%! @sp 2
|
||||
%! @strong{This function calls:}
|
||||
%!
|
||||
%! @end deftypefn
|
||||
%@eod:
|
||||
|
||||
% Copyright (C) 2011-2013 Dynare Team
|
||||
%
|
||||
% This file is part of Dynare.
|
||||
%
|
||||
% Dynare is free software: you can redistribute it and/or modify
|
||||
% it under the terms of the GNU General Public License as published by
|
||||
% the Free Software Foundation, either version 3 of the License, or
|
||||
% (at your option) any later version.
|
||||
%
|
||||
% Dynare is distributed in the hope that it will be useful,
|
||||
% but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
% MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
% GNU General Public License for more details.
|
||||
%
|
||||
% You should have received a copy of the GNU General Public License
|
||||
% along with Dynare. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
if nargin~=2
|
||||
error('dynDate::eq: I need exactly two input arguments!')
|
||||
end
|
||||
|
||||
if ~( isa(a,'dynDate') && isa(b,'dynDate'))
|
||||
error(['dynDate::eq: Input arguments ' inputname(1) ' and ' inputname(2) ' have to be a dynDate objects!'])
|
||||
end
|
||||
|
||||
if ~isequal(a.freq,b.freq)
|
||||
c = 0;
|
||||
return
|
||||
end
|
||||
|
||||
c = isequal(a.time,b.time);
|
||||
|
||||
%@test:1
|
||||
%$ % Define some dates
|
||||
%$ date_1 = 1950;
|
||||
%$ date_2 = '1950Q2';
|
||||
%$ date_3 = '1950M10';
|
||||
%$ date_4 = '1950W50';
|
||||
%$ date_5 = '1950W32';
|
||||
%$
|
||||
%$ % Call the tested routine.
|
||||
%$ d1 = dynDate(date_1);
|
||||
%$ d2 = dynDate(date_2);
|
||||
%$ d3 = dynDate(date_3);
|
||||
%$ d4 = dynDate(date_4);
|
||||
%$ d5 = dynDate(date_5);
|
||||
%$ try
|
||||
%$ i1 = (d1==d2);
|
||||
%$ t1 = 1;
|
||||
%$ catch
|
||||
%$ t1 = 0;
|
||||
%$ end
|
||||
%$ t1 = t1 & ~i1;
|
||||
%$ i2 = (d2==d2);
|
||||
%$ i3 = (d4==d5);
|
||||
%$
|
||||
%$ % Check the results.
|
||||
%$ t(1) = t1;
|
||||
%$ t(2) = dyn_assert(i2,1);
|
||||
%$ t(3) = dyn_assert(i3,0);
|
||||
%$ T = all(t);
|
||||
%@eof:1
|
||||
|
||||
%@test:2
|
||||
%$ % Define some dates
|
||||
%$ date_1 = 1950;
|
||||
%$ date_2 = '1950q2';
|
||||
%$ date_3 = '1950m10';
|
||||
%$ date_4 = '1950w50';
|
||||
%$ date_5 = '1950w32';
|
||||
%$
|
||||
%$ % Call the tested routine.
|
||||
%$ d1 = dynDate(date_1);
|
||||
%$ d2 = dynDate(date_2);
|
||||
%$ d3 = dynDate(date_3);
|
||||
%$ d4 = dynDate(date_4);
|
||||
%$ d5 = dynDate(date_5);
|
||||
%$ try
|
||||
%$ i1 = (d1==d2);
|
||||
%$ t1 = 1;
|
||||
%$ catch
|
||||
%$ t1 = 0;
|
||||
%$ end
|
||||
%$ t1 = t1 & ~i1;
|
||||
%$ i2 = (d2==d2);
|
||||
%$ i3 = (d4==d5);
|
||||
%$
|
||||
%$ % Check the results.
|
||||
%$ t(1) = t1;
|
||||
%$ t(2) = dyn_assert(i2,1);
|
||||
%$ t(3) = dyn_assert(i3,0);
|
||||
%$ T = all(t);
|
||||
%@eof:2
|
|
@ -1,49 +0,0 @@
|
|||
function a = horzcat(varargin)
|
||||
|
||||
%@info:
|
||||
%! @deftypefn {Function file} {@var{a} =} horzcat (@var{b},@var{c}, ...)
|
||||
%! @anchor{horzcat}
|
||||
%! @sp 1
|
||||
%! Method of the dynDate class.
|
||||
%! @sp 1
|
||||
%! Concatenate dynDate objects to form a dynDates object. This method overloads the horizontal concatenation operator, so that
|
||||
%! two (or more) dynDate objects an be concatenated :
|
||||
%!
|
||||
%! a = [b, c, d];
|
||||
%! @sp 2
|
||||
%! @strong{Inputs}
|
||||
%! @sp 1
|
||||
%! @table @ @var
|
||||
%! @item b
|
||||
%! dynDate object, instantiated by @ref{dynDate}.
|
||||
%! @item c
|
||||
%! dynDate object, instantiated by @ref{dynDate}.
|
||||
%! @end table
|
||||
%! @sp 2
|
||||
%! @strong{Outputs}
|
||||
%! @sp 1
|
||||
%! @table @var
|
||||
%! @item a
|
||||
%! dynDates 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/>.
|
||||
|
||||
a = dynDates(varargin{:});
|
|
@ -1,92 +0,0 @@
|
|||
function c = ne(a,b) % --*-- Unitary tests --*--
|
||||
|
||||
%@info:
|
||||
%! @deftypefn {Function File} {@var{c} =} ne (@var{a},@var{b})
|
||||
%! @anchor{@dynDate/ne}
|
||||
%! @sp 1
|
||||
%! Overloads the ne (not equal) operator for the Dynare dates class (@ref{dynDate}).
|
||||
%! @sp 2
|
||||
%! @strong{Inputs}
|
||||
%! @sp 1
|
||||
%! @table @ @var
|
||||
%! @item a
|
||||
%! Dynare date object instantiated by @ref{dynDate}.
|
||||
%! @item b
|
||||
%! Dynare date object instantiated by @ref{dynDate}.
|
||||
%! @end table
|
||||
%! @sp 1
|
||||
%! @strong{Outputs}
|
||||
%! @sp 1
|
||||
%! @table @ @var
|
||||
%! @item c
|
||||
%! scalar integer equal to one if a~=b, 0 otherwise.
|
||||
%! @end table
|
||||
%! @sp 2
|
||||
%! @strong{This function is called by:}
|
||||
%! @sp 2
|
||||
%! @strong{This function calls:}
|
||||
%!
|
||||
%! @end deftypefn
|
||||
%@eod:
|
||||
|
||||
% Copyright (C) 2011-2013 Dynare Team
|
||||
%
|
||||
% This file is part of Dynare.
|
||||
%
|
||||
% Dynare is free software: you can redistribute it and/or modify
|
||||
% it under the terms of the GNU General Public License as published by
|
||||
% the Free Software Foundation, either version 3 of the License, or
|
||||
% (at your option) any later version.
|
||||
%
|
||||
% Dynare is distributed in the hope that it will be useful,
|
||||
% but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
% MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
% GNU General Public License for more details.
|
||||
%
|
||||
% You should have received a copy of the GNU General Public License
|
||||
% along with Dynare. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
if nargin~=2
|
||||
error('dynDate::ne: I need exactly two input arguments!')
|
||||
end
|
||||
|
||||
if ~( isa(a,'dynDate') && isa(b,'dynDate'))
|
||||
error(['dynDate::ne: Input arguments ' inputname(1) 'and ' inputname(2) ' have to be a dynDate objects!'])
|
||||
end
|
||||
|
||||
if ~isequal(a.freq,b.freq)
|
||||
error(['dynDate::ne: Input arguments ' inputname(1) 'and ' inputname(2) ' have no common frequencies!'])
|
||||
end
|
||||
|
||||
c = ~isequal(a.time,b.time);
|
||||
|
||||
%@test:1
|
||||
%$ % Define some dates
|
||||
%$ date_1 = 1950;
|
||||
%$ date_2 = '1950q2';
|
||||
%$ date_3 = '1950M10';
|
||||
%$ date_4 = '1950W50';
|
||||
%$ date_5 = '1950W32';
|
||||
%$
|
||||
%$ % Call the tested routine.
|
||||
%$ d1 = dynDate(date_1);
|
||||
%$ d2 = dynDate(date_2);
|
||||
%$ d3 = dynDate(date_3);
|
||||
%$ d4 = dynDate(date_4);
|
||||
%$ d5 = dynDate(date_5);
|
||||
%$ try
|
||||
%$ What follows should fail because d1 and d2 do not have common frequency
|
||||
%$ d1~=d2;
|
||||
%$ t1 = 0;
|
||||
%$ catch
|
||||
%$ t1 = 1;
|
||||
%$ end
|
||||
%$ i2 = (d2~=d2);
|
||||
%$ i3 = (d4~=d5);
|
||||
%$
|
||||
%$ % Check the results.
|
||||
%$ t(1) = t1;
|
||||
%$ t(2) = dyn_assert(i2,0);
|
||||
%$ t(3) = dyn_assert(i3,1);
|
||||
%$ T = all(t);
|
||||
%@eof:1
|
|
@ -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('dynDate::subsasgn: Members of dynDate class are private')
|
|
@ -1,241 +0,0 @@
|
|||
function B = subsref(A,S) % --*-- Unitary tests --*--
|
||||
|
||||
%@info:
|
||||
%! @deftypefn {Function File} {@var{us} =} subsref (@var{ts},S)
|
||||
%! @anchor{@dynDate/subsref}
|
||||
%! @sp 1
|
||||
%! Overloads the subsref method for the Dynare dates class (@ref{dynDate}).
|
||||
%! @sp 2
|
||||
%! @strong{Inputs}
|
||||
%! @sp 1
|
||||
%! @table @ @var
|
||||
%! @item A
|
||||
%! Dynare date object instantiated by @ref{dynDate}.
|
||||
%! @item S
|
||||
%! Matlab's structure array S with two fields, type and subs. The type field is string containing '()', '@{@}', or '.', where '()' specifies
|
||||
%! integer subscripts, '@{@}' specifies cell array subscripts, and '.' specifies subscripted structure fields. The subs field is a cell array
|
||||
%! or a string containing the actual subscripts (see matlab's documentation).
|
||||
%! @end table
|
||||
%! @sp 1
|
||||
%! @strong{Outputs}
|
||||
%! @sp 1
|
||||
%! @table @ @var
|
||||
%! @item B
|
||||
%! A matlab object (public member of the @ref{dynDate} object).
|
||||
%! @end table
|
||||
%! @sp 2
|
||||
%! @strong{This function is called by:}
|
||||
%! @sp 2
|
||||
%! @strong{This function calls:}
|
||||
%! @sp2
|
||||
%!
|
||||
%! @end deftypefn
|
||||
%@eod:
|
||||
|
||||
% Copyright (C) 2011-2013 Dynare Team
|
||||
%
|
||||
% This file is part of Dynare.
|
||||
%
|
||||
% Dynare is free software: you can redistribute it and/or modify
|
||||
% it under the terms of the GNU General Public License as published by
|
||||
% the Free Software Foundation, either version 3 of the License, or
|
||||
% (at your option) any later version.
|
||||
%
|
||||
% Dynare is distributed in the hope that it will be useful,
|
||||
% but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
% MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
% GNU General Public License for more details.
|
||||
%
|
||||
% You should have received a copy of the GNU General Public License
|
||||
% along with Dynare. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
switch S(1).type
|
||||
case '.'
|
||||
switch S(1).subs
|
||||
case 'format'
|
||||
B = format(A);
|
||||
case {'time', 'freq'}
|
||||
if length(S)>1 && isequal(S(2).type,'()') && isempty(S(2).subs)
|
||||
error(['dynDate::subsref: ' S(1).subs ' is not a method but a member!'])
|
||||
end
|
||||
B = builtin('subsref', A, S(1));
|
||||
otherwise
|
||||
error('dynDate::subsref: Unknown public member of method!')
|
||||
end
|
||||
case '()'
|
||||
switch length(S(1).subs)
|
||||
case 1
|
||||
if ischar(S(1).subs{1})
|
||||
if numel(S(1).subs{1})==1 && isempty(strmatch(S(1).subs{1},{'W','M','Q','Y'},'exact'))
|
||||
error(['dynDate::subsref: To set the frequency, the input argument of dynDate object ''' inputname(1) ''' should be ''W'', ''M'', ''Q'' or ''Y''.'])
|
||||
end
|
||||
% Set the frequency (if numel==1) of an empty dynDate object or set the date (if numel>1).
|
||||
B = dynDate(S(1).subs{1});
|
||||
elseif isnumeric(S(1).subs{1}) && isscalar(S(1).subs{1}) && isint(S(1).subs{1})
|
||||
if (~isnan(A.freq) && A.freq==1) || isnan(A.freq)
|
||||
B = dynDate(S(1).subs{1});
|
||||
else
|
||||
error(['dynDate::subsref: dynDate object ''' inputname(1) ''' was not instantiated for years.'])
|
||||
end
|
||||
else
|
||||
error('dynDate::subsref: Something is wrong in your syntax!')
|
||||
end
|
||||
case 2% Populate an empty dynDate object
|
||||
if isnan(A.freq)
|
||||
error(['dynDate::subsref: I cannot interpret the two inputs of dynDate object ''' inputname(1) ''' because frequency is not set.'])
|
||||
else
|
||||
tmp = [];
|
||||
switch A.freq
|
||||
case 4
|
||||
% Quaterly data
|
||||
if isint(S(1).subs{2}) && isint(S(1).subs{1}) && S(1).subs{2}<5 && S(1).subs{2}>0
|
||||
tmp = [int2str(S(1).subs{1}), 'Q' int2str(S(1).subs{2})];
|
||||
else
|
||||
if ~isint(S(1).subs{2}) || ~(S(1).subs{2}<5 && S(1).subs{2}>0)
|
||||
error(['dynDate::subsref: The second input argument of dynDate object ''' inputname(1) ''' (' num2str(S(1).subs{2}) ') should be a positive integer less than or equal to 4.'])
|
||||
end
|
||||
if ~isint(S(1).subs{2})
|
||||
error(['dynDate::subsref: The first input argument of dynDate object ''' inputname(1) ''' (' num2str(S(1).subs{1}) ') should be an integer.'])
|
||||
end
|
||||
end
|
||||
case 12
|
||||
% Monthly data
|
||||
if isint(S(1).subs{2}) && isint(S(1).subs{1}) && S(1).subs{2}<13 && S(1).subs{2}>0
|
||||
tmp = [num2str(S(1).subs{1}), 'M' num2str(S(1).subs{2})];
|
||||
else
|
||||
if ~isint(S(1).subs{2}) || ~(S(1).subs{2}<13 && S(1).subs{2}>0)
|
||||
error(['dynDate::subsref: The second input argument of dynDate object ''' inputname(1) ''' (' num2str(S(1).subs{2}) ') should be a positive integer less than or equal to 12.'])
|
||||
end
|
||||
if ~isint(S(1).subs{2})
|
||||
error(['dynDate::subsref: The first input argument of dynDate object ''' inputname(1) ''' (' num2str(S(1).subs{1}) ') should be an integer.'])
|
||||
end
|
||||
end
|
||||
case 52
|
||||
% Weekly data
|
||||
if isint(S(1).subs{2}) && isint(S(1).subs{1}) && S(1).subs{2}<53 && S(1).subs{2}>0
|
||||
tmp = [num2str(S(1).subs{1}), 'W' num2str(S(1).subs{2})];
|
||||
else
|
||||
if ~isint(S(1).subs{2}) || ~(S(1).subs{2}<53 && S(1).subs{2}>0)
|
||||
error(['dynDate::subsref: The second input argument of dynDate object ''' inputname(1) ''' (' num2str(S(1).subs{2}) ') should be a positive integer less than or equal to 52.'])
|
||||
end
|
||||
if ~isint(S(1).subs{2})
|
||||
error(['dynDate::subsref: The first input argument of dynDate object ''' inputname(1) ''' (' num2str(S(1).subs{1}) ') should be an integer.'])
|
||||
end
|
||||
end
|
||||
case 1
|
||||
% Yearly data
|
||||
error('dynDate::subsref: Frequency is set for years. You should not provide more than one integer input argument (to set the year)!')
|
||||
otherwise
|
||||
error('dynDate::subsref: Unknown frequency!')
|
||||
end
|
||||
if ~isempty(tmp)
|
||||
B = dynDate(tmp);
|
||||
end
|
||||
end
|
||||
otherwise
|
||||
error(['dynDate::subsref: dynDate object ''' inputname(1) ''' cannot have more than two inputs.'])
|
||||
end
|
||||
otherwise
|
||||
error('dynDate::subsref: Something is wrong in your syntax!')
|
||||
end
|
||||
|
||||
S = shiftS(S);
|
||||
if ~isempty(S)
|
||||
B = subsref(B, S);
|
||||
end
|
||||
|
||||
%@test:1
|
||||
%$ t = zeros(3,1);
|
||||
%$
|
||||
%$ % Instantiate an empty dynDate object
|
||||
%$ a = dynDate();
|
||||
%$ if all(isnan(a.time)) && isnan(a.freq)
|
||||
%$ t(1) = 1;
|
||||
%$ end
|
||||
%$
|
||||
%$ % Populate the empty dynDate object
|
||||
%$ try
|
||||
%$ a = a('1950Q1');
|
||||
%$ if isequal(a.time,[1950 1]) && isequal(a.freq,4)
|
||||
%$ t(2) = 1;
|
||||
%$ end
|
||||
%$ catch
|
||||
%$ % Nothing to do here...
|
||||
%$ end
|
||||
%$
|
||||
%$ % "Overwrite" a dynDate object
|
||||
%$ try
|
||||
%$ a = a('1945Q3');
|
||||
%$ if isequal(a.time,[1945 3]) && isequal(a.freq,4)
|
||||
%$ t(3) = 1;
|
||||
%$ end
|
||||
%$ catch
|
||||
%$ % Nothing to do here...
|
||||
%$ end
|
||||
%$
|
||||
%$ % Check the results.
|
||||
%$ T = all(t);
|
||||
%@eof:1
|
||||
|
||||
%@test:2
|
||||
%$ % Instantiate a dynDate object
|
||||
%$ a = dynDate('1938Q4');
|
||||
%$
|
||||
%$ % Try to access a non existent (or forbidden) property
|
||||
%$ try
|
||||
%$ a.Time;
|
||||
%$ t = 0;
|
||||
%$ catch
|
||||
%$ t = 1;
|
||||
%$ end
|
||||
%$
|
||||
%$ T = all(t);
|
||||
%@eof:2
|
||||
|
||||
%@test:3
|
||||
%$ % Try more complex call to overloaded subsref
|
||||
%$ t = zeros(3,1);
|
||||
%$ try
|
||||
%$ a = dynDate('M');
|
||||
%$ time = a('1973M1').time;
|
||||
%$ t(1) = 1;
|
||||
%$ t(2) = dyn_assert(time,[1973,1]);
|
||||
%$ t(3) = dyn_assert(a.freq,12);
|
||||
%$ catch
|
||||
%$ % Nothing to do here.
|
||||
%$ end
|
||||
%$
|
||||
%$ T = all(t);
|
||||
%@eof:3
|
||||
|
||||
%@test:4
|
||||
%$ t = NaN(3,1);
|
||||
%$ % Instantiate an empty object for quaterly date
|
||||
%$ qq = dynDate('Q');
|
||||
%$ % Populate this object
|
||||
%$ a = qq(1938,4);
|
||||
%$ try
|
||||
%$ a = dynDate(1938,11);
|
||||
%$ t(3) = 0;
|
||||
%$ catch
|
||||
%$ t(3) = 1;
|
||||
%$ end
|
||||
%$
|
||||
%$ % Check the results
|
||||
%$ t(1) = dyn_assert(a.freq,4);
|
||||
%$ t(2) = dyn_assert(a.time,[1938,4]);
|
||||
%$ T = all(t);
|
||||
%@eof:4
|
||||
|
||||
%@test:5
|
||||
%$ t = NaN(2,1);
|
||||
%$ % Instantiate an empty object for quaterly date
|
||||
%$ qq = dynDate('Q');
|
||||
%$ % Populate this object and get the time member
|
||||
%$ time = qq(1938,4).time;
|
||||
%$
|
||||
%$ % Check the results
|
||||
%$ t(1) = dyn_assert(qq.freq,4);
|
||||
%$ t(2) = dyn_assert(time,[1938,4]);
|
||||
%$ T = all(t);
|
||||
%@eof:5
|
Loading…
Reference in New Issue