Removed init and freq members from dseries class (redundant informations).
The frequency and initial date can still be accessed with the usual syntax: ts.freq ts.init It is also possible to get the last date: ts.last Added new methods frequency, firstdate and lastdate as alias for ts.dates.freq, ts.dates(1) and ts.dates(end)time-shift
parent
8507c27fab
commit
955dcab449
|
@ -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);
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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) '''!'];
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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);
|
|
@ -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;
|
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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);
|
|
@ -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.
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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.
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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 = [];
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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;
|
||||
|
|
Loading…
Reference in New Issue