diff --git a/matlab/@dseries/abs.m b/matlab/@dseries/abs.m index b8d49bce7fce513167b7a89ebf0f8341d8ae290a..72a9520ce73bbe21ed373cc716d9fc842ec836da 100644 --- a/matlab/@dseries/abs.m +++ b/matlab/@dseries/abs.m @@ -40,10 +40,8 @@ function A = abs(B) % --*-- Unitary tests --*-- A = dseries(); -A.freq = B.freq; A.nobs = B.nobs; A.vobs = B.vobs; -A.init = B.init; A.dates = B.dates; A.name = cell(A.vobs,1); A.tex = cell(A.vobs,1); diff --git a/matlab/@dseries/align.m b/matlab/@dseries/align.m index 60c65a9472d2e0dd1000a7754007dbe3ab775bcb..e785e081d0cb16d91caa45d7e1a916a98d41cf60 100644 --- a/matlab/@dseries/align.m +++ b/matlab/@dseries/align.m @@ -44,50 +44,50 @@ function [a,b] = align(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 ~isequal(a.freq,b.freq) +if ~isequal(frequency(a),frequency(b)) error(['dseries::align: ''' inputname(1) ''' and ''' inputname(2) ''' dseries objects must have common frequencies!']) end -init = min(a.init,b.init); +init = min(firstdate(a),firstdate(b)); +last = max(lastdate(a),lastdate(b)); -time_range_of_a = a.init:a.init+a.nobs; -time_range_of_b = b.init:b.init+b.nobs; - -last_a = time_range_of_a(a.nobs); -last_b = time_range_of_b(b.nobs); - -common_time_range = intersect(time_range_of_a,time_range_of_b); - -if isempty(common_time_range) +if isempty(intersect(a.dates,b.dates)) error(['dseries::align: ''' inputname(1) ''' and ''' inputname(2) ''' dseries object must have at least one common date!']) end -if a.init<b.init - n = b.init-a.init; +a_init = init; +b_init = init; +a_last = last; +b_last = last; + +if firstdate(b)>init + n = firstdate(b)-init; b.data = [NaN(n,b.vobs); b.data]; b.nobs = b.nobs+n; - b.init = init; + b_init = init; end -if a.init>b.init - n = a.init-b.init; +if firstdate(a)>init + n = firstdate(a)-init; a.data = [NaN(n,a.vobs); a.data]; a.nobs = a.nobs+n; - a.init = init; + a_init = init; end -if last_a>last_b - n = last_a-last_b; +if lastdate(b)<last + n = last-lastdate(b); b.data = [b.data; NaN(n,b.vobs)]; b.nobs = b.nobs+n; -elseif last_a<last_b - n = last_b-last_a; +end + +if lastdate(a)<last + n = last-lastdate(a); a.data = [a.data; NaN(n,a.vobs)]; a.nobs = a.nobs+n; end -a.dates = a.init:a.init+(a.nobs-1); -b.dates = b.init:b.init+(b.nobs-1); +a.dates = a_init:a_init+(a.nobs-1); +b.dates = b_init:b_init+(b.nobs-1); %@test:1 %$ % Define a datasets. @@ -111,7 +111,7 @@ b.dates = b.init:b.init+(b.nobs-1); %$ catch %$ t(1) = 0; %$ end -%$ +%$ %$ if t(1) %$ t(2) = dyn_assert(ts1.nobs,ts2.nobs); %$ t(3) = dyn_assert(isequal(ts1.init,ts2.init),1); diff --git a/matlab/@dseries/baxter_king_filter.m b/matlab/@dseries/baxter_king_filter.m index 8dce6288a69df337800b20d34bb353e82d00ddb9..d019e38c72b4f286d453c74ae494725ce918477f 100644 --- a/matlab/@dseries/baxter_king_filter.m +++ b/matlab/@dseries/baxter_king_filter.m @@ -94,8 +94,8 @@ end % Update dseries object. ts.data = tmp(K+1:end-K,:); ts.nobs = ts.nobs-2*K; -ts.init = ts.init+K; -ts.dates = ts.init:ts.init+(ts.nobs-1); +init = firstdate(ts)+K; +ts.dates = init:init+(ts.nobs-1); %@test:1 %$ plot_flag = 0; diff --git a/matlab/@dseries/chain.m b/matlab/@dseries/chain.m index dccf3bb525f854ce5d51d1b00375b5fc58f6bcb0..2c261758edb72ce3ecf9701cac0b488db5164f42 100644 --- a/matlab/@dseries/chain.m +++ b/matlab/@dseries/chain.m @@ -1,4 +1,4 @@ -function vs = chain(ts,us) +function vs = chain(ts,us) % --*-- Unitary tests --*-- % Copyright (C) 2014 Dynare Team % @@ -21,11 +21,11 @@ if ts.vobs-us.vobs error(['dseries::chain: dseries objects ' inputname(1) ' and ' inputname(2) ' must have the same number of variables!']) end -if ts.freq-us.freq +if frequency(ts)-frequency(us) error(['dseries::chain: dseries objects ' inputname(1) ' and ' inputname(2) ' must have common frequencies!']) end -if ts.dates(end)<us.dates(1) +if lastdate(ts)<firstdate(us) error(['dseries::chain: The last date in ' inputname(1) ' (' date2string(ts.dates(end)) ') must not preceed the first date in ' inputname(2) ' (' date2string(us.dates(1)) ')!']) end @@ -37,7 +37,7 @@ vs = ts; vs.data = [vs.data; bsxfun(@times,CumulatedGrowthFactors,vs.data(end,:))]; vs.nobs = rows(vs.data); -vs.dates = vs.init:(vs.init+vs.nobs); +vs.dates = firstdate(vs):firstdate(vs)+vs.nobs; %@test:1 %$ try diff --git a/matlab/@dseries/check.m b/matlab/@dseries/check.m index 9f07b011948bb5ab3a725b79da6ece3fc409ba63..a190b0dccd6ec8a1ccd392ebd92157764b672ad0 100644 --- a/matlab/@dseries/check.m +++ b/matlab/@dseries/check.m @@ -69,7 +69,7 @@ if ~isequal(numel(unique(A.name)),numel(A.name)); return end -if ~isequa(numel(unique(A.tex)),numel(A.tex)); +if ~isequal(numel(unique(A.tex)),numel(A.tex)); error_flag = 1; if nargout>1 message = ['dseries: The variable tex names in dseries object ''' inputname(1) ''' are not unique!']; @@ -77,7 +77,7 @@ if ~isequa(numel(unique(A.tex)),numel(A.tex)); return end -if ~isequal(A.dates,A.init:A.init+A.nobs) +if ~isequal(A.dates,firstdate(A):firstdate(A)+A.nobs) error_flag = 1; if nargout>1 message = ['dseries: Wrong definition of the dates member in dseries object ''' inputname(1) '''!']; diff --git a/matlab/@dseries/cumprod.m b/matlab/@dseries/cumprod.m index 54a4e33add9f29a2563565eb6ab5e97e38ec5aeb..35ed8275edb94848b9d02933c7f395fc2b61eba3 100644 --- a/matlab/@dseries/cumprod.m +++ b/matlab/@dseries/cumprod.m @@ -67,7 +67,7 @@ switch nargin B = cumprod(varargin{1}); t = find(B.dates==varargin{2}); if isempty(t) - if varargin{2}==(B.init-1) + if varargin{2}==(firstdate(B)-1) return else error(['dseries::cumprod: date ' date2string(varargin{2}) ' is not in the sample!']) @@ -96,7 +96,7 @@ switch nargin B = cumprod(varargin{1}); t = find(B.dates==varargin{2}); if isempty(t) - if varargin{2}==(B.init-1) + if varargin{2}==(firstdate(B)-1) B.data = bsxfun(@times,B.data,varargin{3}.data); return else diff --git a/matlab/@dseries/cumsum.m b/matlab/@dseries/cumsum.m index 8dc442041c409b50d7967def70179745f70c302d..4c082c4ba9c8ef5354993ed06c73820788a357ba 100644 --- a/matlab/@dseries/cumsum.m +++ b/matlab/@dseries/cumsum.m @@ -66,7 +66,7 @@ switch nargin B = cumsum(varargin{1}); t = find(B.dates==varargin{2}); if isempty(t) - if varargin{2}==(B.init-1) + if varargin{2}==(firstdate(B)-1) return else error(['dseries::cumsum: date ' date2string(varargin{2}) ' is not in the sample!']) @@ -95,7 +95,7 @@ switch nargin B = cumsum(varargin{1}); t = find(B.dates==varargin{2}); if isempty(t) - if varargin{2}==(B.init-1) + if varargin{2}==(firstdate(B)-1) B.data = bsxfun(@plus,B.data,varargin{3}.data); return else diff --git a/matlab/@dseries/dseries.m b/matlab/@dseries/dseries.m index b905ef31a7454ce740fecc7550f69133ead21579..6bcfd2820ad0fbd2e73b4c962965bea049d47223 100644 --- a/matlab/@dseries/dseries.m +++ b/matlab/@dseries/dseries.m @@ -83,8 +83,6 @@ if nargin>0 && ischar(varargin{1}) && isequal(varargin{1},'initialize') ts.vobs = 0; ts.name = {}; ts.tex = {}; - ts.freq = []; - ts.init = dates(); ts.dates = dates(); ts = class(ts,'dseries'); assignin('base','emptydseriesobject',ts); @@ -104,13 +102,10 @@ switch nargin error(['dseries::dseries: Input ' inputname(1) ' (identified as a dates object) must be non empty!']) case 1 % Create an empty dseries object with an initial date. - ts.init = varargin{1}; - ts.freq = varargin{1}.freq; + ts.dates = varargin{1}; otherwise % A range of dates is passed to the constructor ts.dates = varargin{1}; - ts.init = varargin{1}(1); - ts.freq = varargin{1}.freq; end return elseif ischar(varargin{1}) @@ -140,12 +135,11 @@ switch nargin else error(['dseries:: I''m not able to load data from ' inputname(1) '!']) end - ts.init = init; - ts.freq = freq; ts.data = data; ts.name = varlist; ts.vobs = length(varlist); ts.nobs = size(data,1); + ts.dates = init:init+(ts.nobs-1); if isempty(tex) ts.tex = name2tex(varlist); else @@ -154,10 +148,9 @@ switch nargin elseif isnumeric(varargin{1}) && isequal(ndims(varargin{1}),2) ts.data = varargin{1}; [ts.nobs, ts.vobs] = size(ts.data); - ts.freq = 1; - ts.init = dates(1,1); ts.name = default_name(ts.vobs); ts.tex = name2tex(ts.name); + ts.dates = dates(1,1):dates(1,1)+(ts.nobs-1); end case {2,3,4} a = varargin{1}; @@ -184,20 +177,15 @@ switch nargin ts.vobs = size(a,2); % Get the first date and set the frequency. if isempty(b) - ts.freq = 1; - ts.init = dates(1,1); + init = dates(1,1); elseif (isdates(b) && isequal(length(b),1)) - ts.freq = b.freq; - ts.init = b; + init = b; elseif isdate(b)% Weekly, Monthly, Quaterly or Annual data (string). - ts.init = dates(b); - ts.freq = ts.init.freq; + init = dates(b); elseif (isnumeric(b) && isscalar(b) && isint(b)) % Yearly data. - ts.freq = 1; - ts.init = dates([num2str(b) 'Y']); + init = dates([num2str(b) 'Y']); elseif isdates(b) % Range of dates - ts.freq = b.freq; - ts.init = b(1); + init = b(1); if ts.nobs>1 && ~isequal(b.ndat,ts.nobs) message = 'dseries::dseries: If second input is a range, its number of elements must match '; message = char(message, ' the number of rows in the first input, unless the first input'); @@ -222,7 +210,7 @@ switch nargin if ~isempty(c) if ts.vobs==length(c) for i=1:ts.vobs - ts.name = vertcat(ts.name, c(i) ); + ts.name = vertcat(ts.name, c(i)); end else error('dseries::dseries: The number of declared names does not match the number of variables!') @@ -246,7 +234,7 @@ switch nargin end if isempty(ts.dates) - ts.dates = ts.init:ts.init+(ts.nobs-1); + ts.dates = init:init+(ts.nobs-1); end %@test:1 diff --git a/matlab/@dseries/eq.m b/matlab/@dseries/eq.m index 0f961fb551fad9a7e85f723d8e4dd2fab6f778c5..7dcd86b2a4ba0e8af774474cef52235478ed8d60 100644 --- a/matlab/@dseries/eq.m +++ b/matlab/@dseries/eq.m @@ -49,13 +49,13 @@ if ~isequal(A.vobs,B.vobs) return end -if ~isequal(A.freq,B.freq) +if ~isequal(frequency(A),frequency(B)) warning('dseries::eq: Both input arguments should have the same frequencies!') C = 0; return end -if ~isequal(A.init,B.init) +if ~isequal(firstdate(A),firstdate(B)) warning('dseries::eq: Both input arguments should have the same initial period!') C = 0; return diff --git a/matlab/@dseries/extract.m b/matlab/@dseries/extract.m index 2c0e0be7999014bea818dd55d9b51d67b65f7c9b..2d61a0b95767f20337a7e91350e851d5322e09d0 100644 --- a/matlab/@dseries/extract.m +++ b/matlab/@dseries/extract.m @@ -126,8 +126,6 @@ end A.data = B.data(:,idVariableName); A.dates = B.dates; -A.init = B.init; -A.freq = B.freq; A.nobs = B.nobs; A.vobs = length(idVariableName); A.name = B.name(idVariableName); diff --git a/matlab/@dseries/firstdate.m b/matlab/@dseries/firstdate.m new file mode 100644 index 0000000000000000000000000000000000000000..9a7db50ea427161d35e0a58e8a83900a07d14349 --- /dev/null +++ b/matlab/@dseries/firstdate.m @@ -0,0 +1,20 @@ +function f = firstdate(o) + +% Copyright (C) 2014 Dynare Team +% +% This file is part of Dynare. +% +% Dynare is free software: you can redistribute it and/or modify +% it under the terms of the GNU General Public License as published by +% the Free Software Foundation, either version 3 of the License, or +% (at your option) any later version. +% +% Dynare is distributed in the hope that it will be useful, +% but WITHOUT ANY WARRANTY; without even the implied warranty of +% MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +% GNU General Public License for more details. +% +% You should have received a copy of the GNU General Public License +% along with Dynare. If not, see <http://www.gnu.org/licenses/>. + +f = o.dates(1); \ No newline at end of file diff --git a/matlab/@dseries/frequency.m b/matlab/@dseries/frequency.m new file mode 100644 index 0000000000000000000000000000000000000000..c2befb5477059cc992cc9f2fb4d0efd95f9fb892 --- /dev/null +++ b/matlab/@dseries/frequency.m @@ -0,0 +1,20 @@ +function f = frequency(o) + +% Copyright (C) 2014 Dynare Team +% +% This file is part of Dynare. +% +% Dynare is free software: you can redistribute it and/or modify +% it under the terms of the GNU General Public License as published by +% the Free Software Foundation, either version 3 of the License, or +% (at your option) any later version. +% +% Dynare is distributed in the hope that it will be useful, +% but WITHOUT ANY WARRANTY; without even the implied warranty of +% MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +% GNU General Public License for more details. +% +% You should have received a copy of the GNU General Public License +% along with Dynare. If not, see <http://www.gnu.org/licenses/>. + +f = o.dates.freq; \ No newline at end of file diff --git a/matlab/@dseries/horzcat.m b/matlab/@dseries/horzcat.m index 2ddf2ca756f83c9cfd692a90452144e775ac6616..5f05af87fb08f44aa013aeb11fd4806a9b700dcc 100644 --- a/matlab/@dseries/horzcat.m +++ b/matlab/@dseries/horzcat.m @@ -62,11 +62,10 @@ function a = concatenate(b,c) if n error(['dseries::horzcat: I cannot concatenate dseries objects with common variable names (' message ')!']) end - if ~isequal(b.freq,c.freq) + if ~isequal(frequency(b),frequency(c)) error('dseries::horzcat: All time series objects must have common frequency!') else a = dseries(); - a.freq = b.freq; end d_nobs_flag = 0; if ~isequal(b.nobs,c.nobs) @@ -75,29 +74,26 @@ function a = concatenate(b,c) a.nobs = b.nobs; end d_init_flag = 0; - if ~isequal(b.init,c.init) + if ~isequal(firstdate(b),firstdate(c)) d_init_flag = 1; end a.vobs = b.vobs+c.vobs; a.name = vertcat(b.name,c.name); a.tex = vertcat(b.tex,c.tex); if ~( d_nobs_flag(1) || d_init_flag(1) ) - a.init = b.init; a.data = [b.data,c.data]; a.dates = b.dates; else - if b.init<=c.init - a.init = b.init; - if b.init<c.init - c.data = [NaN(c.init-b.init,c.vobs); c.data]; + if firstdate(b)<=firstdate(c) + if firstdate(b)<firstdate(c) + c.data = [NaN(firstdate(c)-firstdate(b),c.vobs); c.data]; end else - a.init = c.init; - b_first_lines = b.init-c.init; - b.data = [NaN(b.init-c.init,b.vobs); b.data]; + b_first_lines = firstdate(b)-firstdate(c); + b.data = [NaN(firstdate(b)-firstdate(c),b.vobs); b.data]; end - b_last_date = b.init+b.nobs; - c_last_date = c.init+c.nobs; + b_last_date = firstdate(b)+b.nobs; + c_last_date = firstdate(c)+c.nobs; if b_last_date<c_last_date b.data = [b.data; NaN(c_last_date-b_last_date,b.vobs)]; elseif b_last_date>c_last_date diff --git a/matlab/@dseries/insert.m b/matlab/@dseries/insert.m index 4b8aa06b9ca0e8cbac21a6b41e96843a1ffdff25..128c72dff5a32be4aabe6cde6234e9c9e3a24f8e 100644 --- a/matlab/@dseries/insert.m +++ b/matlab/@dseries/insert.m @@ -52,7 +52,7 @@ if n error(['dseries::insert: Variable(s) ' message ' already exist in ''' inputname(1) '''!']) end -if ~isequal(ts.freq,us.freq) +if ~isequal(frequency(ts),frequency(us)) error(['dseries::insert: ''' inputname(1) ''' and ''' inputname(2) ''' dseries objects must have common frequencies!']) end diff --git a/matlab/@dseries/isequal.m b/matlab/@dseries/isequal.m index 50b93b097ebde6020b6a207d4f9826a48c1cae06..003f6903cb32d181383304adfd70765150f056b7 100644 --- a/matlab/@dseries/isequal.m +++ b/matlab/@dseries/isequal.m @@ -44,12 +44,12 @@ if ~isequal(A.vobs,B.vobs) return end -if ~isequal(A.freq,B.freq) +if ~isequal(frequency(A),frequency(B)) C = 0; return end -if ~isequal(A.init,B.init) +if ~isequal(A.dates,B.dates) C = 0; return end diff --git a/matlab/@dseries/lastdate.m b/matlab/@dseries/lastdate.m new file mode 100644 index 0000000000000000000000000000000000000000..972a70e1899f3ea255d10db1522466c0da7e21d3 --- /dev/null +++ b/matlab/@dseries/lastdate.m @@ -0,0 +1,20 @@ +function l = lastdate(o) + +% Copyright (C) 2014 Dynare Team +% +% This file is part of Dynare. +% +% Dynare is free software: you can redistribute it and/or modify +% it under the terms of the GNU General Public License as published by +% the Free Software Foundation, either version 3 of the License, or +% (at your option) any later version. +% +% Dynare is distributed in the hope that it will be useful, +% but WITHOUT ANY WARRANTY; without even the implied warranty of +% MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +% GNU General Public License for more details. +% +% You should have received a copy of the GNU General Public License +% along with Dynare. If not, see <http://www.gnu.org/licenses/>. + +l = o.dates(end); \ No newline at end of file diff --git a/matlab/@dseries/merge.m b/matlab/@dseries/merge.m index 52fe8ac48ec551adfbbfdb982a910748fd2ec5f2..0f02ceea8b9aeada18fa26d803815047e5555132 100644 --- a/matlab/@dseries/merge.m +++ b/matlab/@dseries/merge.m @@ -44,12 +44,11 @@ if ~isdseries(C) error('dseries::merge: Both inputs must be dseries objects!') end -if ~isequal(B.freq,C.freq) +if ~isequal(frequency(B),frequency(C)) error(['dseries::merge: Cannot merge ' inputname(1) ' and ' inputname(2) ' (frequencies are different)!']) end A = dseries(); -A.freq = B.freq; [A.name, IBC, junk] = unique([B.name; C.name], 'last'); tex = [B.tex; C.tex]; A.tex = tex(IBC); @@ -59,8 +58,8 @@ if B.nobs == 0 A = C; elseif C.nobs == 0 A = B; -elseif B.init >= C.init - diff = B.init - C.init; +elseif firstdate(B) >= firstdate(C) + diff = firstdate(B) - firstdate(C); A.nobs = max(B.nobs + diff, C.nobs); A.data = NaN(A.nobs, A.vobs); Z1 = [NaN(diff,B.vobs);B.data]; @@ -68,14 +67,14 @@ elseif B.init >= C.init Z1 = [Z1; NaN(A.nobs-(B.nobs + diff),B.vobs)]; end; Z2 = C.data; - if A.nobs > C.nobs + if A.nobs > C.nobs Z2 = [Z2; NaN(A.nobs - C.nobs,C.vobs)]; end; Z = [Z1 Z2]; A.data = Z(:,IBC); - A.init = C.init; + A_init = firstdate(C); else - diff = C.init - B.init; + diff = firstdate(C) - firstdate(B); A.nobs = max(C.nobs + diff, B.nobs); A.data = NaN(A.nobs, A.vobs); Z1 = [NaN(diff,C.vobs);C.data]; @@ -88,10 +87,10 @@ else end; Z = [Z2 Z1]; A.data = Z(:,IBC); - A.init = B.init; + A_init = B.init; end -A.dates = A.init:A.init+(A.nobs-1); +A.dates = A_init:A_init+(A.nobs-1); %@test:1 %$ % Define a datasets. diff --git a/matlab/@dseries/minus.m b/matlab/@dseries/minus.m index 6f7c47dbcb88211a3fbeadebc66c342a9dc7e006..f563485bcb334a5b8aa7cad49613e1faf1e3bff3 100644 --- a/matlab/@dseries/minus.m +++ b/matlab/@dseries/minus.m @@ -73,11 +73,11 @@ else end end -if ~isequal(B.freq,C.freq) +if ~isequal(frequency(B),frequency(C)) error(['dseries::plus: Cannot substract ' inputname(1) ' and ' inputname(2) ' (frequencies are different)!']) end -if ~isequal(B.nobs,C.nobs) || ~isequal(B.init,C.init) +if ~isequal(B.nobs,C.nobs) || ~isequal(firstdate(B),firstdate(C)) [B, C] = align(B, C); end @@ -93,8 +93,6 @@ end A = dseries(); -A.freq = B.freq; -A.init = B.init; A.dates = B.dates; A.nobs = max(B.nobs,C.nobs); A.vobs = max(B.vobs,C.vobs); diff --git a/matlab/@dseries/mpower.m b/matlab/@dseries/mpower.m index 6ba3ed95828743e9fae5a5c82f24c1c9e5e3811a..06cc5af737f357086ba6635e1d80b1fde654bb5b 100644 --- a/matlab/@dseries/mpower.m +++ b/matlab/@dseries/mpower.m @@ -60,8 +60,6 @@ end if isdseries(B) && isnumeric(C) && isreal(C) && isscalar(C) A = dseries(); - A.freq = B.freq; - A.init = B.init; A.dates = B.dates; A.nobs = B.nobs; A.vobs = B.vobs; @@ -76,10 +74,8 @@ if isdseries(B) && isnumeric(C) && isreal(C) && isscalar(C) end if isdseries(B) && isdseries(C) - if isequal(B.nobs,C.nobs) && isequal(B.vobs,C.vobs) && isequal(B.freq,C.freq) + if isequal(B.nobs,C.nobs) && isequal(B.vobs,C.vobs) && isequal(frequency(B),frequency(C)) A = dseries(); - A.freq = B.freq; - A.init = B.init; A.dates = B.dates; A.nobs = B.nobs; A.vobs = B.vobs; diff --git a/matlab/@dseries/mrdivide.m b/matlab/@dseries/mrdivide.m index e42b47aa99c2702956d03bfe878fea5032251b50..47d4c2127f2d0d983a1ef7ac858f6646266761df 100644 --- a/matlab/@dseries/mrdivide.m +++ b/matlab/@dseries/mrdivide.m @@ -74,15 +74,13 @@ if isdseries(B) && isdseries(C) idC = 1:C.vobs; end end - if ~isequal(B.freq,C.freq) + if ~isequal(frequency(B),frequency(C)) error(['dseries::times: Cannot divide ' inputname(1) ' and ' inputname(2) ' (frequencies are different)!']) end - if ~isequal(B.nobs,C.nobs) || ~isequal(B.init,C.init) + if ~isequal(B.nobs,C.nobs) || ~isequal(firstdate(B),firstdate(C)) [B, C] = align(B, C); end A = dseries(); - A.freq = B.freq; - A.init = B.init; A.dates = B.dates; A.nobs = max(B.nobs,C.nobs); A.vobs = max(B.vobs,C.vobs); diff --git a/matlab/@dseries/mtimes.m b/matlab/@dseries/mtimes.m index 79f2019c2c423744e018c910fc664c48515ba437..719687efd151b4a0cb8d089bfa9c6fe24ad34e22 100644 --- a/matlab/@dseries/mtimes.m +++ b/matlab/@dseries/mtimes.m @@ -74,15 +74,13 @@ if isdseries(B) && isdseries(C) idC = 1:C.vobs; end end - if ~isequal(B.freq,C.freq) + if ~isequal(frequency(B),frequency(C)) error(['dseries::times: Cannot multiply ' inputname(1) ' and ' inputname(2) ' (frequencies are different)!']) end - if ~isequal(B.nobs,C.nobs) || ~isequal(B.init,C.init) + if ~isequal(B.nobs,C.nobs) || ~isequal(firstdate(B),firstdate(C)) [B, C] = align(B, C); end A = dseries(); - A.freq = B.freq; - A.init = B.init; A.dates = B.dates; A.nobs = max(B.nobs,C.nobs); A.vobs = max(B.vobs,C.vobs); diff --git a/matlab/@dseries/ne.m b/matlab/@dseries/ne.m index 53c98867cfe1b0c18e0475ccf71b42e28f410e7c..b8056d82f07d28ec1480b7f8d47953c9a640f851 100644 --- a/matlab/@dseries/ne.m +++ b/matlab/@dseries/ne.m @@ -38,35 +38,35 @@ if ~(isdseries(A) && isdseries(B)) end if ~isequal(A.nobs,B.nobs) - warning('dseries::eq: Both input arguments should have the same number of observations!') + warning('dseries::ne: Both input arguments should have the same number of observations!') C = 1; return end if ~isequal(A.vobs,B.vobs) - warning('dseries::eq: Both input arguments should have the same number of observations!') + warning('dseries::ne: Both input arguments should have the same number of observations!') C = 1; return end -if ~isequal(A.freq,B.freq) - warning('dseries::eq: Both input arguments should have the same frequencies!') +if ~isequal(frequency(A),frequency(B)) + warning('dseries::ne: Both input arguments should have the same frequencies!') C = 1; return end -if ~isequal(A.init,B.init) - warning('dseries::eq: Both input arguments should have the same initial period!') +if ~isequal(firstdate(A),firstdate(B)) + warning('dseries::ne: Both input arguments should have the same initial period!') C = 1; return end if ~isequal(A.name,B.name) - warning('dseries::eq: Both input arguments do not have the same variables!') + warning('dseries::ne: Both input arguments do not have the same variables!') end if ~isequal(A.tex,B.tex) - warning('dseries::eq: Both input arguments do not have the same tex names!') + warning('dseries::ne: Both input arguments do not have the same tex names!') end C = ne(A.data, B.data); diff --git a/matlab/@dseries/plus.m b/matlab/@dseries/plus.m index b9d20a798be05b117f67c00c325947a72a6db1cb..be116601ccbb6685bd50902b8bc0416dfa120472 100644 --- a/matlab/@dseries/plus.m +++ b/matlab/@dseries/plus.m @@ -73,11 +73,11 @@ else end end -if ~isequal(B.freq,C.freq) +if ~isequal(frequency(B),frequency(C)) error(['dseries::plus: Cannot add ' inputname(1) ' and ' inputname(2) ' (frequencies are different)!']) end -if ~isequal(B.nobs,C.nobs) || ~isequal(B.init,C.init) +if ~isequal(B.nobs,C.nobs) || ~isequal(firstdate(B),firstdate(C)) [B, C] = align(B, C); end @@ -93,8 +93,9 @@ end A = dseries(); -A.freq = B.freq; -A.init = B.init; +A.dates = B.dates; +%A.freq = B.freq; +%A.init = B.init; A.nobs = max(B.nobs,C.nobs); A.vobs = max(B.vobs,C.vobs); A.name = cell(A.vobs,1); @@ -104,7 +105,7 @@ for i=1:A.vobs A.tex(i) = {['(' B.tex{idB(i)} '+' C.tex{idC(i)} ')']}; end A.data = bsxfun(@plus,B.data,C.data); -A.dates = A.init:A.init+(A.nobs-1); +%A.dates = A.init:A.init+(A.nobs-1); %@test:1 %$ % Define a datasets. diff --git a/matlab/@dseries/qdiff.m b/matlab/@dseries/qdiff.m index b1683f1d6b60a9308f7dcbc3866de77b71bf9685..f57410e31fe389ed3a5d288b962dc7676ed49443 100644 --- a/matlab/@dseries/qdiff.m +++ b/matlab/@dseries/qdiff.m @@ -41,7 +41,7 @@ function us = qdiff(ts) % --*-- Unitary tests --*-- us = ts; -switch ts.freq +switch frequency(ts) case 1 error('dseries::qgrowth: I cannot compute quaterly differences from yearly data!') case 4 diff --git a/matlab/@dseries/qgrowth.m b/matlab/@dseries/qgrowth.m index f86233abeea21c65c0b1bee58f335db676182e69..796a889bfba2222d494f3abcf0e91c3246d61ad8 100644 --- a/matlab/@dseries/qgrowth.m +++ b/matlab/@dseries/qgrowth.m @@ -41,7 +41,7 @@ function us = qgrowth(ts) % --*-- Unitary tests --*-- us = ts; -switch ts.freq +switch frequency(ts) case 1 error('dseries::qgrowth: I cannot compute quaterly growth rates from yearly data!') case 4 diff --git a/matlab/@dseries/save.m b/matlab/@dseries/save.m index cad2b2e8aeb4d83f371690453a987253f80051d6..2f3ff7c49ecffe72faa20691f518754cef889103 100644 --- a/matlab/@dseries/save.m +++ b/matlab/@dseries/save.m @@ -35,8 +35,8 @@ switch format fid = fopen([basename, '.m'],'w'); fprintf(fid,'%% File created on %s.\n',datestr(now)); fprintf(fid,'\n'); - fprintf(fid,'FREQ__ = %s;\n',num2str(A.freq)); - fprintf(fid,'INIT__ = '' %s'';\n',date2string(A.init)); + fprintf(fid,'FREQ__ = %s;\n',num2str(frequency(A))); + fprintf(fid,'INIT__ = '' %s'';\n',date2string(firstdate(A))); fprintf(fid,'\n'); fprintf(fid,'NAMES__ = {'); for i=1:A.vobs @@ -61,8 +61,8 @@ switch format end fclose(fid); case 'mat' - FREQ__ = A.freq; - INIT__ = date2string(A.init); + FREQ__ = frequency(A); + INIT__ = date2string(firstdate(A)); NAMES__ = A.name; TEX__ = A.tex; str = []; diff --git a/matlab/@dseries/subsasgn.m b/matlab/@dseries/subsasgn.m index b74937812a63af64c633c292f3c70e445d235dba..3937fd09291a65a5b3f14fd1c4bfc45fc1e292b4 100644 --- a/matlab/@dseries/subsasgn.m +++ b/matlab/@dseries/subsasgn.m @@ -25,7 +25,7 @@ function A = subsasgn(A,S,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/>. -merge_dseries_objects = 1; +merge_dseries_objects = 1; switch length(S) case 1 @@ -105,20 +105,14 @@ switch length(S) end case '.' if isequal(S(1).subs,'init') && isdates(B) && isequal(length(B),1) - % Overwrite the init member... - A.init = B; - % ... and update freq and time members. - A.freq = A.init.freq; - A.dates = A.init:A.init+(A.nobs-1); + % Change the initial date (update dates member) + A.dates = B:B+(A.nobs-1); return elseif isequal(S(1).subs,'dates') && isdates(B) - % Overwrite the time member... + % Overwrite the dates member A.dates = B; - % ... and update the freq and init members. - A.init = B(1); - A.freq = A.init.freq; return - elseif ismember(S(1).subs,{'freq','nobs','vobs','data','name','tex'}) + elseif ismember(S(1).subs,{'nobs','vobs','data','name','tex'}) error(['dseries::subsasgn: You cannot overwrite ' S(1).subs ' member!']) elseif ~isequal(S(1).subs,B.name) % Single variable selection. @@ -217,7 +211,7 @@ switch length(S) else sA = extract(A,S(1).subs); end - if (isdseries(B) && isequal(sA.vobs,B.vobs)) || (isnumeric(B) && isequal(sA.vobs,columns(B))) || (isnumeric(B) && isequal(columns(B),1)) + if (isdseries(B) && isequal(sA.vobs,B.vobs)) || (isnumeric(B) && isequal(sA.vobs,columns(B))) || (isnumeric(B) && isequal(columns(B),1)) if isdates(S(2).subs{1}) [junk, tdx] = intersect(sA.dates.time,S(2).subs{1}.time,'rows'); if isdseries(B) @@ -284,8 +278,8 @@ end %$ t(1) = 1; %$ catch %$ t(1) = 0; -%$ end -%$ +%$ end +%$ %$ % Instantiate a time series object. %$ if t(1) %$ t(2) = dyn_assert(ts1.vobs,3); @@ -446,8 +440,8 @@ end %$ t(1) = 1; %$ catch %$ t(1) = 0; -%$ end -%$ +%$ end +%$ %$ % Instantiate a time series object. %$ if t(1) %$ t(2) = dyn_assert(ts1.vobs,4); @@ -475,8 +469,8 @@ end %$ t(1) = 1; %$ catch %$ t(1) = 0; -%$ end -%$ +%$ end +%$ %$ % Instantiate a time series object. %$ if t(1) %$ t(2) = dyn_assert(ts1.vobs,4); @@ -505,8 +499,8 @@ end %$ t(1) = 1; %$ catch %$ t(1) = 0; -%$ end -%$ +%$ end +%$ %$ % Instantiate a time series object. %$ if t(1) %$ t(2) = dyn_assert(ts1.vobs,4); diff --git a/matlab/@dseries/subsref.m b/matlab/@dseries/subsref.m index f3713016ee87c02e289382f0f1db1d63e29eecf1..d2ecdaa90df3d3850c27e99f0aae9d2fec1b654a 100644 --- a/matlab/@dseries/subsref.m +++ b/matlab/@dseries/subsref.m @@ -65,7 +65,7 @@ function B = subsref(A, S) % --*-- Unitary tests --*-- switch S(1).type case '.' switch S(1).subs - case {'data','nobs','vobs','name','tex','freq','dates','init'} % Public members. + case {'data','nobs','vobs','name','tex','dates'} % Public members. if length(S)>1 && isequal(S(2).type,'()') && isempty(S(2).subs) error(['dseries::subsref: ' S(1).subs ' is not a method but a member!']) end @@ -75,6 +75,15 @@ switch S(1).type if length(S)>1 && isequal(S(2).type,'()') && isempty(S(2).subs) S = shiftS(S,1); end + case 'init' + % Returns a dates object (first date). + B = A.dates(1); + case 'last' + % Returns a dates object (last date). + B = A.dates(end); + case 'freq' + % Returns an integer characterizing the data frequency (1, 4, 12 or 52) + B = A.dates.freq; case {'lag','lead','hptrend','hpcycle','chain'} % Methods with less than two arguments. if length(S)>1 && isequal(S(2).type,'()') if isempty(S(2).subs) @@ -170,8 +179,6 @@ switch S(1).type B.tex = deblank(A.tex(ndx,:)); B.nobs = A.nobs; B.vobs = 1; - B.freq = A.freq; - B.init = A.init; B.dates = A.dates; else error('dseries::subsref: Unknown public method, public member or variable!') @@ -227,8 +234,6 @@ switch S(1).type B.tex = A.tex; B.nobs = length(tdx); B.vobs = A.vobs; - B.freq = A.freq; - B.init = A.init+(tdx(1)-1); B.dates = A.dates(tdx); elseif isvector(S(1).subs{1}) && all(isint(S(1).subs{1})) error('dseries::subsref: It is not possible to select observations with a vector of integers. You have to index with a dates object instead!'); @@ -249,8 +254,6 @@ switch S(1).type B.tex = A.tex(idx); B.nobs = A.nobs; B.vobs = length(idx); - B.freq = A.freq; - B.init = A.init; B.dates = A.dates; else error('dseries::subsref: What the Hell are you tryin'' to do?!') @@ -275,7 +278,7 @@ end %$ ts1 = dseries(A,[],A_name,[]); %$ %$ % Call the tested method. -%$ a = ts1(2:9); +%$ a = ts1(ts1.dates(2:9)); %$ %$ % Expected results. %$ e.data = [transpose(2:9),2*transpose(2:9)]; @@ -635,7 +638,7 @@ end %@test:15 %$ try %$ ds = dseries(transpose(1:5)); -%$ ts = ds(2:3); +%$ ts = ds(ds.dates(2:3)); %$ t(1) = 1; %$ catch %$ t(1) = 0; @@ -652,7 +655,7 @@ end %@test:16 %$ try %$ ds = dseries(transpose(1:5)); -%$ ts = ds(2:6); +%$ ts = ds(ds.dates(2:6)); %$ t(1) = 0; %$ catch %$ t(1) = 1; diff --git a/matlab/@dseries/uminus.m b/matlab/@dseries/uminus.m index bcccca70ae88d09abb1160a71c25639a7fe319e1..e8214cd59449d1a38091971a7bd827def4f34a4c 100644 --- a/matlab/@dseries/uminus.m +++ b/matlab/@dseries/uminus.m @@ -42,10 +42,8 @@ function A = uminus(B) % --*-- Unitary tests --*-- A = dseries(); -A.freq = B.freq; A.nobs = B.nobs; A.vobs = B.vobs; -A.init = B.init; A.dates = B.dates; A.name = cell(A.vobs,1); A.tex = cell(A.vobs,1); diff --git a/matlab/@dseries/vertcat.m b/matlab/@dseries/vertcat.m index 9b286945dc70a480041ddde295d4527581429c30..4b4a680fe6005578a7d67adaff7b073846078d8f 100644 --- a/matlab/@dseries/vertcat.m +++ b/matlab/@dseries/vertcat.m @@ -60,7 +60,7 @@ end function d = vertcat_(b, c) d = NaN; - if ~isequal(b.freq, c.freq) + if ~isequal(frequency(b), frequency(c)) error('dseries::vertcat: Frequencies must be common!') end if ~isequal(b.vobs, c.vobs) diff --git a/matlab/@dseries/ydiff.m b/matlab/@dseries/ydiff.m index 4e20608e66004db0e8c674e6d9b9f23920cfd570..49b94dc6f61aedbb2a2e8be4d1695cfccd5d2e4c 100644 --- a/matlab/@dseries/ydiff.m +++ b/matlab/@dseries/ydiff.m @@ -41,7 +41,7 @@ function us = ydiff(ts) % --*-- Unitary tests --*-- us = ts; -switch ts.freq +switch frequency(ts) case 1 us.data(2:end,:) = ts.data(2:end,:)-ts.data(1:end-1,:); us.data(1,:) = NaN; @@ -55,21 +55,21 @@ switch ts.freq for i = 1:ts.vobs us.name(i) = {['ydiff(' us.name{i} ')']}; us.tex(i) = {['\Delta_4 ' us.tex{i}]}; - end + end case 12 us.data(13:end,:) = ts.data(13:end,:)-ts.data(1:end-12,:); us.data(1:12,:) = NaN; for i = 1:ts.vobs us.name(i) = {['ydiff(' us.name{i} ')']}; us.tex(i) = {['\Delta_{12} ' us.tex{i}]}; - end + end case 52 us.data(53:end,:) = ts.data(53:end,:)-ts.data(1:end-52,:); us.data(1:52,:) = NaN; for i = 1:ts.vobs us.name(i) = {['ydiff(' us.name{i} ')']}; us.tex(i) = {['\Delta_{52} ' us.tex{i}]}; - end + end otherwise error(['dseries::ygrowth: object ' inputname(1) ' has unknown frequency']); end diff --git a/matlab/@dseries/ygrowth.m b/matlab/@dseries/ygrowth.m index 8b26d52521eb0fc5e5347cd3938b4271fa60ee14..ba988ec2e13b5f0ac47b6a9840804de18795c816 100644 --- a/matlab/@dseries/ygrowth.m +++ b/matlab/@dseries/ygrowth.m @@ -41,7 +41,7 @@ function us = ygrowth(ts) % --*-- Unitary tests --*-- us = ts; -switch ts.freq +switch frequency(ts) case 1 us.data(2:end,:) = ts.data(2:end,:)./ts.data(1:end-1,:) - 1; us.data(1,:) = NaN; @@ -55,7 +55,7 @@ switch ts.freq for i = 1:ts.vobs us.name(i) = {['ygrowth(' us.name{i} ')']}; us.tex(i) = {['\delta_4 ' us.tex{i}]}; - end + end case 12 us.data(13:end,:) = ts.data(13:end,:)./ts.data(1:end-12,:) - 1; us.data(1:12,:) = NaN;