Removed nobs and vobs members in @dseries class.
The syntax to get the number of observations and the number of variables remains unaffected by this commit. If ts a @dseries object, ts.nobs and ts.vobs are respectively the number of observations and the number of variables.time-shift
parent
555e2cf73b
commit
c5af1d43ed
|
@ -40,16 +40,15 @@ function A = abs(B) % --*-- Unitary tests --*--
|
|||
|
||||
A = dseries();
|
||||
|
||||
A.nobs = B.nobs;
|
||||
A.vobs = B.vobs;
|
||||
A.data = abs(B.data);
|
||||
A.dates = B.dates;
|
||||
A.name = cell(A.vobs,1);
|
||||
A.tex = cell(A.vobs,1);
|
||||
for i = 1:A.vobs
|
||||
|
||||
A.name = cell(vobs(A), 1);
|
||||
A.tex = cell(vobs(A), 1);
|
||||
for i = 1:vobs(A)
|
||||
A.name(i) = {[ 'abs(' B.name{i} ')']};
|
||||
A.tex(i) = {[ '|' B.tex{i} '|']};
|
||||
end
|
||||
A.data = abs(B.data);
|
||||
|
||||
%@test:1
|
||||
%$ % Define a datasets.
|
||||
|
|
|
@ -62,32 +62,28 @@ 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.data = [NaN(n, vobs(b)); b.data];
|
||||
b_init = init;
|
||||
end
|
||||
|
||||
if firstdate(a)>init
|
||||
n = firstdate(a)-init;
|
||||
a.data = [NaN(n,a.vobs); a.data];
|
||||
a.nobs = a.nobs+n;
|
||||
a.data = [NaN(n, vobs(a)); a.data];
|
||||
a_init = init;
|
||||
end
|
||||
|
||||
if lastdate(b)<last
|
||||
n = last-lastdate(b);
|
||||
b.data = [b.data; NaN(n,b.vobs)];
|
||||
b.nobs = b.nobs+n;
|
||||
b.data = [b.data; NaN(n, vobs(b))];
|
||||
end
|
||||
|
||||
if lastdate(a)<last
|
||||
n = last-lastdate(a);
|
||||
a.data = [a.data; NaN(n,a.vobs)];
|
||||
a.nobs = a.nobs+n;
|
||||
a.data = [a.data; NaN(n, vobs(a))];
|
||||
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+(nobs(a)-1);
|
||||
b.dates = b_init:b_init+(nobs(b)-1);
|
||||
|
||||
%@test:1
|
||||
%$ % Define a datasets.
|
||||
|
|
|
@ -87,15 +87,14 @@ weights = [flipud(weights(2:K+1)); weights];
|
|||
tmp = zeros(size(ts.data));
|
||||
|
||||
% Filtering step.
|
||||
for t = K+1:ts.nobs-K
|
||||
for t = K+1:nobs(ts)-K
|
||||
tmp(t,:) = weights'*ts.data(t-K:t+K,:);
|
||||
end
|
||||
|
||||
% Update dseries object.
|
||||
ts.data = tmp(K+1:end-K,:);
|
||||
ts.nobs = ts.nobs-2*K;
|
||||
init = firstdate(ts)+K;
|
||||
ts.dates = init:init+(ts.nobs-1);
|
||||
ts.dates = init:init+(nobs(ts)-1);
|
||||
|
||||
%@test:1
|
||||
%$ plot_flag = 0;
|
||||
|
|
|
@ -17,7 +17,7 @@ function vs = chain(ts,us) % --*-- 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 ts.vobs-us.vobs
|
||||
if vobs(ts)-vobs(us)
|
||||
error(['dseries::chain: dseries objects ' inputname(1) ' and ' inputname(2) ' must have the same number of variables!'])
|
||||
end
|
||||
|
||||
|
@ -35,9 +35,8 @@ CumulatedGrowthFactors = cumprod(GrowthFactor);
|
|||
|
||||
vs = ts;
|
||||
vs.data = [vs.data; bsxfun(@times,CumulatedGrowthFactors,vs.data(end,:))];
|
||||
vs.nobs = rows(vs.data);
|
||||
|
||||
vs.dates = firstdate(vs):firstdate(vs)+vs.nobs;
|
||||
vs.dates = firstdate(vs):firstdate(vs)+nobs(vs);
|
||||
|
||||
%@test:1
|
||||
%$ try
|
||||
|
|
|
@ -21,7 +21,7 @@ error_flag = 0;
|
|||
|
||||
[n,m] = size(A.data);
|
||||
|
||||
if ~isequal(m,A.vobs);
|
||||
if ~isequal(m, vobs(A));
|
||||
error_flag = 1;
|
||||
if nargout>1
|
||||
message = ['dseries: Wrong number of variables in dseries object ''' inputname(1) '''!'];
|
||||
|
@ -29,7 +29,7 @@ if ~isequal(m,A.vobs);
|
|||
return
|
||||
end
|
||||
|
||||
if ~isequal(n,A.nobs);
|
||||
if ~isequal(n,nobs(A));
|
||||
error_flag = 1;
|
||||
if nargout>1
|
||||
message = ['dseries: Wrong number of observations in dseries object ''' inputname(1) '''!'];
|
||||
|
@ -77,7 +77,7 @@ if ~isequal(numel(unique(A.tex)),numel(A.tex));
|
|||
return
|
||||
end
|
||||
|
||||
if ~isequal(A.dates,firstdate(A):firstdate(A)+A.nobs)
|
||||
if ~isequal(A.dates,firstdate(A):firstdate(A)+nobs(A))
|
||||
error_flag = 1;
|
||||
if nargout>1
|
||||
message = ['dseries: Wrong definition of the dates member in dseries object ''' inputname(1) '''!'];
|
||||
|
|
|
@ -34,7 +34,7 @@ if isempty(idx)
|
|||
error('dseries::cumprod: All the variables have NaNs. The cumulated product cannot be computed!')
|
||||
end
|
||||
|
||||
if ~isequal(idx(:),transpose(1:varargin{1}.vobs))
|
||||
if ~isequal(idx(:),transpose(1:vobs(varargin{1})))
|
||||
warning('dseries::cumprod: The cumulated product is not computed for some variables because they have NaNs!')
|
||||
end
|
||||
|
||||
|
@ -45,19 +45,19 @@ switch nargin
|
|||
% Perform the cumulated sum
|
||||
B.data(:,idx) = cumprod(B.data(:,idx));
|
||||
% Change the name of the variables
|
||||
for i=1:B.vobs
|
||||
for i=1:vobs(B)
|
||||
B.name(i) = {['cumprod(' B.name{i} ')']};
|
||||
B.tex(i) = {['\prod_t ' B.tex{i}]};
|
||||
end
|
||||
case 2
|
||||
if isdseries(varargin{2})
|
||||
if ~isequal(varargin{1}.vobs, varargin{2}.vobs)
|
||||
if ~isequal(vobs(varargin{1}), vobs(varargin{2}))
|
||||
error('dseries::cumprod: First and second input arguments must be dseries objects with the same number of variables!')
|
||||
end
|
||||
if ~isequal(varargin{1}.name, varargin{2}.name)
|
||||
warning('dseries::cumprod: First and second input arguments must be dseries objects do not have the same variables!')
|
||||
end
|
||||
if ~isequal(varargin{2}.nobs,1)
|
||||
if ~isequal(nobs(varargin{2}),1)
|
||||
error('dseries::cumprod: Second input argument must be a dseries object with only one observation!')
|
||||
end
|
||||
B = cumprod(varargin{1});
|
||||
|
@ -84,13 +84,13 @@ switch nargin
|
|||
if ~isdseries(varargin{3})
|
||||
error('dseries::cumprod: Third input argument must be a dseries object!')
|
||||
end
|
||||
if ~isequal(varargin{1}.vobs, varargin{3}.vobs)
|
||||
if ~isequal(vobs(varargin{1}), vobs(varargin{3}))
|
||||
error('dseries::cumprod: First and third input arguments must be dseries objects with the same number of variables!')
|
||||
end
|
||||
if ~isequal(varargin{1}.name, varargin{3}.name)
|
||||
warning('dseries::cumprod: First and third input arguments must be dseries objects do not have the same variables!')
|
||||
end
|
||||
if ~isequal(varargin{3}.nobs,1)
|
||||
if ~isequal(nobs(varargin{3}),1)
|
||||
error('dseries::cumprod: Third input argument must be a dseries object with only one observation!')
|
||||
end
|
||||
B = cumprod(varargin{1});
|
||||
|
|
|
@ -34,7 +34,7 @@ if isempty(idx)
|
|||
error('dseries::cumsum: All the variables have NaNs. The cumulated sum cannot be computed!')
|
||||
end
|
||||
|
||||
if ~isequal(idx(:),transpose(1:varargin{1}.vobs))
|
||||
if ~isequal(idx(:),transpose(1:vobs(varargin{1})))
|
||||
warning('dseries::cumsum: The cumulated sum is not computed for some variables because they have NaNs!')
|
||||
end
|
||||
|
||||
|
@ -45,19 +45,19 @@ switch nargin
|
|||
% Perform the cumulated sum
|
||||
B.data(:,idx) = cumsum(B.data(:,idx));
|
||||
% Change the name of the variables
|
||||
for i=1:B.vobs
|
||||
for i=1:vobs(B)
|
||||
B.name(i) = {['cumsum(' B.name{i} ')']};
|
||||
B.tex(i) = {['\sum_t ' B.tex{i}]};
|
||||
end
|
||||
case 2
|
||||
if isdseries(varargin{2})
|
||||
if ~isequal(varargin{1}.vobs, varargin{2}.vobs)
|
||||
if ~isequal(vobs(varargin{1}), vobs(varargin{2}))
|
||||
error('dseries::cumsum: First and second input arguments must be dseries objects with the same number of variables!')
|
||||
end
|
||||
if ~isequal(varargin{1}.name, varargin{2}.name)
|
||||
warning('dseries::cumsum: First and second input arguments must be dseries objects do not have the same variables!')
|
||||
end
|
||||
if ~isequal(varargin{2}.nobs,1)
|
||||
if ~isequal(nobs(varargin{2}),1)
|
||||
error('dseries::cumsum: Second input argument must be a dseries object with only one observation!')
|
||||
end
|
||||
B = cumsum(varargin{1});
|
||||
|
@ -83,13 +83,13 @@ switch nargin
|
|||
if ~isdseries(varargin{3})
|
||||
error('dseries::cumsum: Third input argument must be a dseries object!')
|
||||
end
|
||||
if ~isequal(varargin{1}.vobs, varargin{3}.vobs)
|
||||
if ~isequal(vobs(varargin{1}), vobs(varargin{3}))
|
||||
error('dseries::cumsum: First and third input arguments must be dseries objects with the same number of variables!')
|
||||
end
|
||||
if ~isequal(varargin{1}.name, varargin{3}.name)
|
||||
warning('dseries::cumsum: First and third input arguments must be dseries objects do not have the same variables!')
|
||||
end
|
||||
if ~isequal(varargin{3}.nobs,1)
|
||||
if ~isequal(nobs(varargin{3}),1)
|
||||
error('dseries::cumsum: Third input argument must be a dseries object with only one observation!')
|
||||
end
|
||||
B = cumsum(varargin{1});
|
||||
|
|
|
@ -30,9 +30,9 @@ if isnumeric(model)
|
|||
case 0
|
||||
data = demean(data);
|
||||
otherwise
|
||||
x = NaN(o.nobs, model+1);
|
||||
x(:,1) = ones(o.nobs, 1);
|
||||
x(:,2) = transpose(1:o.nobs);
|
||||
x = NaN(nobs(o), model+1);
|
||||
x(:,1) = ones(nobs(o), 1);
|
||||
x(:,2) = transpose(1:nobs(o));
|
||||
for c=3:model+1
|
||||
x(:,c) = x(:,c-1).*x(:,2);
|
||||
end
|
||||
|
|
|
@ -19,16 +19,16 @@ function disp(A)
|
|||
%! @end deftypefn
|
||||
%@eod:
|
||||
|
||||
separator = repmat(' | ',A.nobs+1,1);
|
||||
separator = repmat(' | ', nobs(A)+1,1);
|
||||
vspace = ' ';
|
||||
TABLE = ' ';
|
||||
for t=1:A.nobs
|
||||
for t=1:nobs(A)
|
||||
TABLE = char(TABLE, date2string(A.dates(t)));
|
||||
end
|
||||
for i = 1:A.vobs
|
||||
for i = 1:vobs(A)
|
||||
TABLE = horzcat(TABLE,separator);
|
||||
tmp = A.name{i};
|
||||
for t=1:A.nobs
|
||||
for t=1:nobs(A)
|
||||
tmp = char(tmp,num2str(A.data(t,i)));
|
||||
end
|
||||
TABLE = horzcat(TABLE, tmp);
|
||||
|
|
|
@ -21,16 +21,16 @@ function display(A)
|
|||
vspace = ' ';
|
||||
TABLE = ' ';
|
||||
|
||||
if A.vobs<=10
|
||||
if A.nobs<=40
|
||||
separator = repmat(' | ',A.nobs+1,1);
|
||||
for t=1:A.nobs
|
||||
if vobs(A)<=10
|
||||
if nobs(A)<=40
|
||||
separator = repmat(' | ', nobs(A)+1,1);
|
||||
for t=1:nobs(A)
|
||||
TABLE = char(TABLE, date2string(A.dates(t)));
|
||||
end
|
||||
for i = 1:A.vobs
|
||||
for i = 1:vobs(A)
|
||||
TABLE = horzcat(TABLE,separator);
|
||||
tmp = A.name{i};
|
||||
for t=1:A.nobs
|
||||
for t=1:nobs(A)
|
||||
tmp = char(tmp,num2str(A.data(t,i)));
|
||||
end
|
||||
TABLE = horzcat(TABLE, tmp);
|
||||
|
@ -42,17 +42,17 @@ if A.vobs<=10
|
|||
TABLE = char(TABLE, date2string(A.dates(t)));
|
||||
end
|
||||
TABLE = char(TABLE,vspace);
|
||||
for t = A.nobs-n:A.nobs
|
||||
for t = nobs(A)-n:nobs(A)
|
||||
TABLE = char(TABLE, date2string(A.dates(t)));
|
||||
end
|
||||
for i=1:A.vobs
|
||||
for i=1:vobs(A)
|
||||
TABLE = horzcat(TABLE,separator);
|
||||
tmp = A.name{i};
|
||||
for t=1:10
|
||||
tmp = char(tmp,num2str(A.data(t,i)));
|
||||
end
|
||||
tmp = char(tmp,vspace);
|
||||
for t=A.nobs-10:A.nobs
|
||||
for t=nobs(A)-10:nobs(A)
|
||||
tmp = char(tmp,num2str(A.data(t,i)));
|
||||
end
|
||||
TABLE = horzcat(TABLE, tmp);
|
||||
|
@ -60,24 +60,24 @@ if A.vobs<=10
|
|||
end
|
||||
else
|
||||
m = 4;
|
||||
if A.nobs<=40
|
||||
separator = repmat(' | ',A.nobs+1,1);
|
||||
for t=1:A.nobs
|
||||
if nobs(A)<=40
|
||||
separator = repmat(' | ', nobs(A)+1,1);
|
||||
for t=1:nobs(A)
|
||||
TABLE = char(TABLE, date2string(A.dates(t)));
|
||||
end
|
||||
for i = 1:m
|
||||
TABLE = horzcat(TABLE,separator);
|
||||
tmp = A.name{i};
|
||||
for t=1:A.nobs
|
||||
for t=1:nobs(A)
|
||||
tmp = char(tmp,num2str(A.data(t,i)));
|
||||
end
|
||||
TABLE = horzcat(TABLE, tmp);
|
||||
end
|
||||
TABLE = horzcat(TABLE, separator, repmat(' ... ', A.nobs+1,1));
|
||||
for i = A.vobs-m+1:A.vobs
|
||||
TABLE = horzcat(TABLE, separator, repmat(' ... ', nobs(A)+1,1));
|
||||
for i = vobs(A)-m+1:vobs(A)
|
||||
TABLE = horzcat(TABLE,separator);
|
||||
tmp = A.name{i};
|
||||
for t=1:A.nobs
|
||||
for t=1:nobs(A)
|
||||
tmp = char(tmp,num2str(A.data(t,i)));
|
||||
end
|
||||
TABLE = horzcat(TABLE, tmp);
|
||||
|
@ -89,7 +89,7 @@ else
|
|||
TABLE = char(TABLE, date2string(A.dates(t)));
|
||||
end
|
||||
TABLE = char(TABLE,vspace);
|
||||
for t = A.nobs-n:A.nobs
|
||||
for t = nobs(A)-n:nobs(A)
|
||||
TABLE = char(TABLE, date2string(A.dates(t)));
|
||||
end
|
||||
for i=1:m
|
||||
|
@ -99,20 +99,20 @@ else
|
|||
tmp = char(tmp,num2str(A.data(t,i)));
|
||||
end
|
||||
tmp = char(tmp,vspace);
|
||||
for t=A.nobs-10:A.nobs
|
||||
for t=nobs(A)-10:nobs(A)
|
||||
tmp = char(tmp,num2str(A.data(t,i)));
|
||||
end
|
||||
TABLE = horzcat(TABLE, tmp);
|
||||
end
|
||||
TABLE = horzcat(TABLE, separator, repmat(' ... ', 2*n+3,1));
|
||||
for i=A.vobs-m+1:A.vobs
|
||||
for i=vobs(A)-m+1:vobs(A)
|
||||
TABLE = horzcat(TABLE,separator);
|
||||
tmp = A.name{i};
|
||||
for t=1:10
|
||||
tmp = char(tmp,num2str(A.data(t,i)));
|
||||
end
|
||||
tmp = char(tmp,vspace);
|
||||
for t=A.nobs-10:A.nobs
|
||||
for t=nobs(A)-10:nobs(A)
|
||||
tmp = char(tmp,num2str(A.data(t,i)));
|
||||
end
|
||||
TABLE = horzcat(TABLE, tmp);
|
||||
|
|
|
@ -79,8 +79,6 @@ function ts = dseries(varargin) % --*-- Unitary tests --*--
|
|||
if nargin>0 && ischar(varargin{1}) && isequal(varargin{1},'initialize')
|
||||
ts = struct;
|
||||
ts.data = [];
|
||||
ts.nobs = 0;
|
||||
ts.vobs = 0;
|
||||
ts.name = {};
|
||||
ts.tex = {};
|
||||
ts.dates = dates();
|
||||
|
@ -137,9 +135,7 @@ switch nargin
|
|||
end
|
||||
ts.data = data;
|
||||
ts.name = varlist;
|
||||
ts.vobs = length(varlist);
|
||||
ts.nobs = size(data,1);
|
||||
ts.dates = init:init+(ts.nobs-1);
|
||||
ts.dates = init:init+(nobs(ts)-1);
|
||||
if isempty(tex)
|
||||
ts.tex = name2tex(varlist);
|
||||
else
|
||||
|
@ -147,10 +143,9 @@ switch nargin
|
|||
end
|
||||
elseif isnumeric(varargin{1}) && isequal(ndims(varargin{1}),2)
|
||||
ts.data = varargin{1};
|
||||
[ts.nobs, ts.vobs] = size(ts.data);
|
||||
ts.name = default_name(ts.vobs);
|
||||
ts.name = default_name(vobs(ts));
|
||||
ts.tex = name2tex(ts.name);
|
||||
ts.dates = dates(1,1):dates(1,1)+(ts.nobs-1);
|
||||
ts.dates = dates(1,1):dates(1,1)+(nobs(ts)-1);
|
||||
end
|
||||
case {2,3,4}
|
||||
if isequal(nargin,2) && ischar(varargin{1}) && isdates(varargin{2})
|
||||
|
@ -185,29 +180,26 @@ switch nargin
|
|||
end
|
||||
% Get data, number of observations and number of variables.
|
||||
ts.data = a;
|
||||
ts.nobs = size(a,1);
|
||||
ts.vobs = size(a,2);
|
||||
% Get the first date and set the frequency.
|
||||
if isempty(b)
|
||||
init = dates(1,1);
|
||||
elseif (isdates(b) && isequal(length(b),1))
|
||||
init = b;
|
||||
elseif isdate(b)% Weekly, Monthly, Quaterly or Annual data (string).
|
||||
elseif ischar(b) && isdate(b)% Weekly, Monthly, Quaterly or Annual data (string).
|
||||
init = dates(b);
|
||||
elseif (isnumeric(b) && isscalar(b) && isint(b)) % Yearly data.
|
||||
init = dates([num2str(b) 'Y']);
|
||||
elseif isdates(b) % Range of dates
|
||||
init = b(1);
|
||||
if ts.nobs>1 && ~isequal(b.ndat,ts.nobs)
|
||||
if nobs(ts)>1 && ~isequal(b.ndat,nobs(ts))
|
||||
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');
|
||||
message = char(message, ' has only one row.');
|
||||
skipline()
|
||||
disp(message);
|
||||
error(' ');
|
||||
elseif isequal(ts.nobs, 1)
|
||||
elseif isequal(nobs(ts), 1)
|
||||
ts.data = repmat(ts.data,b.ndat,1);
|
||||
ts.nobs = b.ndat;
|
||||
end
|
||||
ts.dates = b;
|
||||
elseif (isnumeric(b) && isint(b)) % Range of yearly dates.
|
||||
|
@ -220,19 +212,19 @@ switch nargin
|
|||
end
|
||||
% Get the names of the variables.
|
||||
if ~isempty(c)
|
||||
if ts.vobs==length(c)
|
||||
for i=1:ts.vobs
|
||||
if vobs(ts)==length(c)
|
||||
for i=1:vobs(ts)
|
||||
ts.name = vertcat(ts.name, c(i));
|
||||
end
|
||||
else
|
||||
error('dseries::dseries: The number of declared names does not match the number of variables!')
|
||||
end
|
||||
else
|
||||
ts.name = default_name(ts.vobs);
|
||||
ts.name = default_name(vobs(ts));
|
||||
end
|
||||
if ~isempty(d)
|
||||
if ts.vobs==length(d)
|
||||
for i=1:ts.vobs
|
||||
if vobs(ts)==length(d)
|
||||
for i=1:vobs(ts)
|
||||
ts.tex = vertcat(ts.tex, d(i));
|
||||
end
|
||||
else
|
||||
|
@ -246,7 +238,7 @@ switch nargin
|
|||
end
|
||||
|
||||
if isempty(ts.dates)
|
||||
ts.dates = init:init+(ts.nobs-1);
|
||||
ts.dates = init:init+(nobs(ts)-1);
|
||||
end
|
||||
|
||||
%@test:1
|
||||
|
@ -349,12 +341,12 @@ end
|
|||
%@test:6
|
||||
%$ t = zeros(8,1);
|
||||
%$
|
||||
%$ %try
|
||||
%$ try
|
||||
%$ ts = dseries(transpose(1:5),[]);
|
||||
%$ t(1) = 1;
|
||||
%$ %catch
|
||||
%$ % t = 0;
|
||||
%$ %end
|
||||
%$ catch
|
||||
%$ t = 0;
|
||||
%$ end
|
||||
%$
|
||||
%$ if length(t)>1
|
||||
%$ t(2) = dyn_assert(ts.freq,1);
|
||||
|
|
|
@ -18,4 +18,4 @@ function lastIndex = end(o, k, n)
|
|||
% along with Dynare. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
assert(k==1 && n==1, 'dseries::end: Wrong indexing!');
|
||||
lastIndex = o.vobs;
|
||||
lastIndex = vobs(o);
|
|
@ -37,13 +37,13 @@ if ~(isdseries(A) && isdseries(B))
|
|||
error('dseries::eq: Both input arguments must be dseries objects!')
|
||||
end
|
||||
|
||||
if ~isequal(A.nobs,B.nobs)
|
||||
if ~isequal(nobs(A), nobs(B))
|
||||
warning('dseries::eq: Both input arguments should have the same number of observations!')
|
||||
C = 0;
|
||||
return
|
||||
end
|
||||
|
||||
if ~isequal(A.vobs,B.vobs)
|
||||
if ~isequal(vobs(A), vobs(B))
|
||||
warning('dseries::eq: Both input arguments should have the same number of observations!')
|
||||
C = 0;
|
||||
return
|
||||
|
|
|
@ -46,7 +46,7 @@ function ts = exp(ts)
|
|||
|
||||
ts.data = exp(ts.data);
|
||||
|
||||
for i=1:ts.vobs
|
||||
for i=1:vobs(ts)
|
||||
ts.name(i) = {['exp(' ts.name{i} ')']};
|
||||
ts.tex(i) = {['\exp(' ts.tex{i} ')']};
|
||||
end
|
|
@ -126,8 +126,6 @@ end
|
|||
|
||||
A.data = B.data(:,idVariableName);
|
||||
A.dates = B.dates;
|
||||
A.nobs = B.nobs;
|
||||
A.vobs = length(idVariableName);
|
||||
A.name = B.name(idVariableName);
|
||||
A.tex = B.tex(idVariableName);
|
||||
|
||||
|
|
|
@ -68,41 +68,38 @@ function a = concatenate(b,c)
|
|||
a = dseries();
|
||||
end
|
||||
d_nobs_flag = 0;
|
||||
if ~isequal(b.nobs,c.nobs)
|
||||
if ~isequal(nobs(b),nobs(c))
|
||||
d_nobs_flag = 1;
|
||||
else
|
||||
a.nobs = b.nobs;
|
||||
end
|
||||
d_init_flag = 0;
|
||||
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.data = [b.data,c.data];
|
||||
a.dates = b.dates;
|
||||
else
|
||||
nobs_b = nobs(b);
|
||||
nobs_c = nobs(c);
|
||||
if firstdate(b)<=firstdate(c)
|
||||
if firstdate(b)<firstdate(c)
|
||||
c.data = [NaN(firstdate(c)-firstdate(b),c.vobs); c.data];
|
||||
c.data = [NaN(firstdate(c)-firstdate(b), vobs(c)); c.data];
|
||||
end
|
||||
else
|
||||
b_first_lines = firstdate(b)-firstdate(c);
|
||||
b.data = [NaN(firstdate(b)-firstdate(c),b.vobs); b.data];
|
||||
b.data = [NaN(firstdate(b)-firstdate(c), vobs(b)); b.data];
|
||||
end
|
||||
b_last_date = firstdate(b)+b.nobs;
|
||||
c_last_date = firstdate(c)+c.nobs;
|
||||
b_last_date = firstdate(b)+nobs_b;
|
||||
c_last_date = firstdate(c)+nobs_c;
|
||||
if b_last_date<c_last_date
|
||||
b.data = [b.data; NaN(c_last_date-b_last_date,b.vobs)];
|
||||
b.data = [b.data; NaN(c_last_date-b_last_date, vobs(b))];
|
||||
elseif b_last_date>c_last_date
|
||||
c.data = [c.data; NaN(b_last_date-c_last_date,c.vobs)];
|
||||
c.data = [c.data; NaN(b_last_date-c_last_date, vobs(c))];
|
||||
end
|
||||
a.data = [b.data, c.data];
|
||||
a.dates = unique([b.dates, c.dates]);
|
||||
end
|
||||
a.nobs = size(a.data,1);
|
||||
|
||||
%@test:1
|
||||
%$ % Define a data set.
|
||||
|
|
|
@ -36,7 +36,7 @@ else
|
|||
lambda = [];
|
||||
end
|
||||
|
||||
for i=1:ts.vobs
|
||||
for i=1:vobs(ts)
|
||||
ts.name(i) = {['hpcycle(' ts.name{i} ')']};
|
||||
ts.tex(i) = {['\text{hpcycle}(' ts.tex{i} ')']};
|
||||
end
|
||||
|
|
|
@ -36,7 +36,7 @@ else
|
|||
lambda = [];
|
||||
end
|
||||
|
||||
for i=1:ts.vobs
|
||||
for i=1:vobs(ts)
|
||||
ts.name(i) = {['hptrend(' ts.name{i} ')']};
|
||||
ts.tex(i) = {['\text{hptrend}(' ts.tex{i} ')']};
|
||||
end
|
||||
|
|
|
@ -74,11 +74,6 @@ for i=1:n
|
|||
id = id+1;
|
||||
end
|
||||
|
||||
% Update vobs member.
|
||||
ts.vobs = columns(ts.data);
|
||||
|
||||
|
||||
|
||||
%@test:1
|
||||
%$ % Define a datasets.
|
||||
%$ A = rand(10,3); B = rand(5,2);
|
||||
|
|
|
@ -36,5 +36,5 @@ function b = isempty(A)
|
|||
%
|
||||
% You should have received a copy of the GNU General Public License
|
||||
% along with Dynare. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
b = isempty(A.data) && isequal(A.nobs,0) && isequal(A.vobs,0);
|
||||
|
||||
b = isempty(A.data);
|
|
@ -34,12 +34,12 @@ if ~isdseries(B)
|
|||
error('dseries::isequal: Both input arguments must be dseries objects!')
|
||||
end
|
||||
|
||||
if ~isequal(A.nobs,B.nobs)
|
||||
if ~isequal(nobs(A), nobs(B))
|
||||
C = 0;
|
||||
return
|
||||
end
|
||||
|
||||
if ~isequal(A.vobs,B.vobs)
|
||||
if ~isequal(vobs(A), vobs(B))
|
||||
C = 0;
|
||||
return
|
||||
end
|
||||
|
|
|
@ -52,9 +52,9 @@ end
|
|||
us = ts;
|
||||
|
||||
% Update data member
|
||||
us.data = [NaN(p,ts.vobs); ts.data(1:end-p,:)];
|
||||
us.data = [NaN(p, vobs(ts)); ts.data(1:end-p,:)];
|
||||
|
||||
for i=1:ts.vobs
|
||||
for i=1:vobs(ts)
|
||||
us.name(i) = {[ 'lag(' ts.name{i} ',' int2str(p) ')']};
|
||||
us.tex(i) = {[ ts.tex{i} '_{-' int2str(p) '}']};
|
||||
end
|
||||
|
|
|
@ -52,9 +52,9 @@ end
|
|||
us = ts;
|
||||
|
||||
% Update data member
|
||||
us.data = [ ts.data(p+1:end,:); NaN(p,ts.vobs);];
|
||||
us.data = [ ts.data(p+1:end,:); NaN(p, vobs(ts));];
|
||||
|
||||
for i=1:ts.vobs
|
||||
for i=1:vobs(ts)
|
||||
us.name(i) = {[ 'lead(' ts.name{i} ',' int2str(p) ')']};
|
||||
us.tex(i) = {[ ts.tex{i} '_{+' int2str(p) '}']};
|
||||
end
|
||||
|
|
|
@ -47,7 +47,7 @@ if any(ts.data<eps)
|
|||
error('dseries::log: Input argument has to be strictly positive!')
|
||||
end
|
||||
|
||||
for i=1:ts.vobs
|
||||
for i=1:vobs(ts)
|
||||
ts.name(i) = {['log(' ts.name{i} ')']};
|
||||
ts.tex(i) = {['\log(' ts.tex{i} ')']};
|
||||
end
|
||||
|
|
|
@ -51,46 +51,45 @@ end
|
|||
A = dseries();
|
||||
[A.name, IBC, junk] = unique([B.name; C.name], 'last');
|
||||
tex = [B.tex; C.tex];
|
||||
A.tex = tex(IBC);
|
||||
A.vobs=length(IBC);
|
||||
A.tex = tex(IBC);
|
||||
|
||||
if B.nobs == 0
|
||||
if nobs(B) == 0
|
||||
A = C;
|
||||
elseif C.nobs == 0
|
||||
elseif nobs(C) == 0
|
||||
A = B;
|
||||
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];
|
||||
if A.nobs > B.nobs + diff
|
||||
Z1 = [Z1; NaN(A.nobs-(B.nobs + diff),B.vobs)];
|
||||
A_nobs = max(nobs(B) + diff, nobs(C));
|
||||
A.data = NaN(A_nobs, vobs(A));
|
||||
Z1 = [NaN(diff, vobs(B));B.data];
|
||||
if nobs(A) > nobs(B) + diff
|
||||
Z1 = [Z1; NaN(nobs(A)-(nobs(B) + diff), vobs(B))];
|
||||
end;
|
||||
Z2 = C.data;
|
||||
if A.nobs > C.nobs
|
||||
Z2 = [Z2; NaN(A.nobs - C.nobs,C.vobs)];
|
||||
if nobs(A) > nobs(C)
|
||||
Z2 = [Z2; NaN(nobs(A) - nobs(C), vobs(C))];
|
||||
end;
|
||||
Z = [Z1 Z2];
|
||||
A.data = Z(:,IBC);
|
||||
A_init = firstdate(C);
|
||||
else
|
||||
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];
|
||||
if A.nobs > C.nobs + diff
|
||||
Z1 = [Z1; NaN(A.nobs-(C.nobs + diff),C.vobs)];
|
||||
end;
|
||||
A_nobs = max(nobs(C) + diff, nobs(B));
|
||||
A.data = NaN(A_nobs, vobs(A));
|
||||
Z1 = [NaN(diff, vobs(C)); C.data];
|
||||
if nobs(A) > nobs(C) + diff
|
||||
Z1 = [Z1; NaN(nobs(A)-(nobs(C) + diff), vobs(C))];
|
||||
end
|
||||
Z2 = B.data;
|
||||
if A.nobs > B.nobs
|
||||
Z2 = [Z2; NaN(A.nobs - B.nobs,B.vobs)];
|
||||
if nobs(A) > nobs(B)
|
||||
Z2 = [Z2; NaN(nobs(A) - nobs(B), vobs(B))];
|
||||
end;
|
||||
Z = [Z2 Z1];
|
||||
A.data = Z(:,IBC);
|
||||
A_init = B.init;
|
||||
end
|
||||
|
||||
A.dates = A_init:A_init+(A.nobs-1);
|
||||
A.dates = A_init:A_init+(nobs(A)-1);
|
||||
|
||||
%@test:1
|
||||
%$ % Define a datasets.
|
||||
|
|
|
@ -58,18 +58,18 @@ if isnumeric(C) && (isscalar(C) || isvector(C))
|
|||
return
|
||||
end
|
||||
|
||||
if ~isequal(B.vobs,C.vobs) && ~(isequal(B.vobs,1) || isequal(C.vobs,1))
|
||||
if ~isequal(vobs(B), vobs(C)) && ~(isequal(vobs(B),1) || isequal(vobs(C),1))
|
||||
error(['dseries::minus: Cannot substract ' inputname(1) ' and ' inputname(2) ' (wrong number of variables)!'])
|
||||
else
|
||||
if B.vobs>C.vobs
|
||||
idB = 1:B.vobs;
|
||||
idC = ones(1:B.vobs);
|
||||
elseif B.vobs<C.vobs
|
||||
idB = ones(1,C.vobs);
|
||||
idC = 1:C.vobs;
|
||||
if vobs(B)>vobs(C)
|
||||
idB = 1:vobs(B);
|
||||
idC = ones(1:vobs(B));
|
||||
elseif vobs(B)<vobs(C)
|
||||
idB = ones(1,vobs(C));
|
||||
idC = 1:vobs(C);
|
||||
else
|
||||
idB = 1:B.vobs;
|
||||
idC = 1:C.vobs;
|
||||
idB = 1:vobs(B);
|
||||
idC = 1:vobs(C);
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -77,7 +77,7 @@ 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(firstdate(B),firstdate(C))
|
||||
if ~isequal(nobs(B), nobs(C)) || ~isequal(firstdate(B),firstdate(C))
|
||||
[B, C] = align(B, C);
|
||||
end
|
||||
|
||||
|
@ -94,11 +94,10 @@ end
|
|||
A = dseries();
|
||||
|
||||
A.dates = B.dates;
|
||||
A.nobs = max(B.nobs,C.nobs);
|
||||
A.vobs = max(B.vobs,C.vobs);
|
||||
A.name = cell(A.vobs,1);
|
||||
A.tex = cell(A.vobs,1);
|
||||
for i=1:A.vobs
|
||||
A_vobs = max(vobs(B), vobs(C));
|
||||
A.name = cell(A_vobs,1);
|
||||
A.tex = cell(A_vobs,1);
|
||||
for i=1:A_vobs
|
||||
A.name(i) = {['minus(' B.name{idB(i)} ',' C.name{idC(i)} ')']};
|
||||
A.tex(i) = {['(' B.tex{idB(i)} '-' C.tex{idC(i)} ')']};
|
||||
end
|
||||
|
|
|
@ -61,31 +61,27 @@ end
|
|||
if isdseries(B) && isnumeric(C) && isreal(C) && isscalar(C)
|
||||
A = dseries();
|
||||
A.dates = B.dates;
|
||||
A.nobs = B.nobs;
|
||||
A.vobs = B.vobs;
|
||||
A.name = cell(A.vobs,1);
|
||||
A.tex = cell(A.vobs,1);
|
||||
for i=1:A.vobs
|
||||
A.data = B.data.^C;
|
||||
A.name = cell(vobs(A),1);
|
||||
A.tex = cell(vobs(A),1);
|
||||
for i=1:vobs(A)
|
||||
A.name(i) = {['power(' B.name{i} ',' num2str(C) ')']};
|
||||
A.tex(i) = {[B.tex{i} '^' num2str(C) ]};
|
||||
end
|
||||
A.data = B.data.^C;
|
||||
return
|
||||
end
|
||||
|
||||
if isdseries(B) && isdseries(C)
|
||||
if isequal(B.nobs,C.nobs) && isequal(B.vobs,C.vobs) && isequal(frequency(B),frequency(C))
|
||||
if isequal(nobs(B),nobs(C)) && isequal(vobs(B), vobs(C)) && isequal(frequency(B),frequency(C))
|
||||
A = dseries();
|
||||
A.data = B.data.^C.data;
|
||||
A.dates = B.dates;
|
||||
A.nobs = B.nobs;
|
||||
A.vobs = B.vobs;
|
||||
A.name = cell(A.vobs,1);
|
||||
A.tex = cell(A.vobs,1);
|
||||
for i=1:A.vobs
|
||||
A.name = cell(vobs(A),1);
|
||||
A.tex = cell(vobs(A),1);
|
||||
for i=1:vobs(A)
|
||||
A.name(i) = {['power(' B.name{i} ',' C.name{i} ')']};
|
||||
A.tex(i) = {[B.tex{i} '^{' C.tex{i} '}']};
|
||||
end
|
||||
A.data = B.data.^C.data;
|
||||
else
|
||||
error('dseries::mpower: If both input arguments are dseries objects, they must have the same numbers of variables and observations and common frequency!')
|
||||
end
|
||||
|
|
|
@ -60,33 +60,32 @@ end
|
|||
|
||||
if isdseries(B) && isdseries(C)
|
||||
% Element by element divisions of two dseries object
|
||||
if ~isequal(B.vobs,C.vobs) && ~(isequal(B.vobs,1) || isequal(C.vobs,1))
|
||||
if ~isequal(vobs(B), vobs(C)) && ~(isequal(vobs(B),1) || isequal(vobs(C),1))
|
||||
error(['dseries::times: Cannot divide ' inputname(1) ' and ' inputname(2) ' (wrong number of variables)!'])
|
||||
else
|
||||
if B.vobs>C.vobs
|
||||
idB = 1:B.vobs;
|
||||
idC = ones(1:B.vobs);
|
||||
elseif B.vobs<C.vobs
|
||||
idB = ones(1,C.vobs);
|
||||
idC = 1:C.vobs;
|
||||
if vobs(B)>vobs(C)
|
||||
idB = 1:vobs(B);
|
||||
idC = ones(1:vobs(B));
|
||||
elseif vobs(B)<vobs(C)
|
||||
idB = ones(1,vobs(C));
|
||||
idC = 1:vobs(C);
|
||||
else
|
||||
idB = 1:B.vobs;
|
||||
idC = 1:C.vobs;
|
||||
idB = 1:vobs(B);
|
||||
idC = 1:vobs(C);
|
||||
end
|
||||
end
|
||||
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(firstdate(B),firstdate(C))
|
||||
if ~isequal(nobs(B), nobs(C)) || ~isequal(firstdate(B),firstdate(C))
|
||||
[B, C] = align(B, C);
|
||||
end
|
||||
A = dseries();
|
||||
A.dates = B.dates;
|
||||
A.nobs = max(B.nobs,C.nobs);
|
||||
A.vobs = max(B.vobs,C.vobs);
|
||||
A.name = cell(A.vobs,1);
|
||||
A.tex = cell(A.vobs,1);
|
||||
for i=1:A.vobs
|
||||
A_vobs = max(vobs(B),vobs(C));
|
||||
A.name = cell(A_vobs,1);
|
||||
A.tex = cell(A_vobs,1);
|
||||
for i=1:A_vobs
|
||||
A.name(i) = {['divide(' B.name{idB(i)} ',' C.name{idC(i)} ')']};
|
||||
A.tex(i) = {['(' B.tex{idB(i)} '/' C.tex{idC(i)} ')']};
|
||||
end
|
||||
|
|
|
@ -60,33 +60,32 @@ end
|
|||
|
||||
if isdseries(B) && isdseries(C)
|
||||
% Element by element multiplication of two dseries object
|
||||
if ~isequal(B.vobs,C.vobs) && ~(isequal(B.vobs,1) || isequal(C.vobs,1))
|
||||
if ~isequal(vobs(B), vobs(C)) && ~(isequal(vobs(B),1) || isequal(vobs(C),1))
|
||||
error(['dseries::times: Cannot multiply ' inputname(1) ' and ' inputname(2) ' (wrong number of variables)!'])
|
||||
else
|
||||
if B.vobs>C.vobs
|
||||
idB = 1:B.vobs;
|
||||
idC = ones(1:B.vobs);
|
||||
elseif B.vobs<C.vobs
|
||||
idB = ones(1,C.vobs);
|
||||
idC = 1:C.vobs;
|
||||
if vobs(B)>vobs(C)
|
||||
idB = 1:vobs(B);
|
||||
idC = ones(1:vobs(B));
|
||||
elseif vobs(B)<vobs(C)
|
||||
idB = ones(1,vobs(C));
|
||||
idC = 1:vobs(C);
|
||||
else
|
||||
idB = 1:B.vobs;
|
||||
idC = 1:C.vobs;
|
||||
idB = 1:vobs(B);
|
||||
idC = 1:vobs(C);
|
||||
end
|
||||
end
|
||||
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(firstdate(B),firstdate(C))
|
||||
if ~isequal(nobs(B), nobs(C)) || ~isequal(firstdate(B),firstdate(C))
|
||||
[B, C] = align(B, C);
|
||||
end
|
||||
A = dseries();
|
||||
A.dates = B.dates;
|
||||
A.nobs = max(B.nobs,C.nobs);
|
||||
A.vobs = max(B.vobs,C.vobs);
|
||||
A.name = cell(A.vobs,1);
|
||||
A.tex = cell(A.vobs,1);
|
||||
for i=1:A.vobs
|
||||
A_vobs = max(vobs(B),vobs(C));
|
||||
A.name = cell(A_vobs,1);
|
||||
A.tex = cell(A_vobs,1);
|
||||
for i=1:A_vobs
|
||||
A.name(i) = {['multiply(' B.name{idB(i)} ',' C.name{idC(i)} ')']};
|
||||
A.tex(i) = {['(' B.tex{idB(i)} '*' C.tex{idC(i)} ')']};
|
||||
end
|
||||
|
|
|
@ -37,13 +37,13 @@ if ~(isdseries(A) && isdseries(B))
|
|||
error('dseries::ne: Both input arguments must be dseries objects!')
|
||||
end
|
||||
|
||||
if ~isequal(A.nobs,B.nobs)
|
||||
if ~isequal(nobs(A), nobs(B))
|
||||
warning('dseries::ne: Both input arguments should have the same number of observations!')
|
||||
C = 1;
|
||||
return
|
||||
end
|
||||
|
||||
if ~isequal(A.vobs,B.vobs)
|
||||
if ~isequal(vobs(A), vobs(B))
|
||||
warning('dseries::ne: Both input arguments should have the same number of observations!')
|
||||
C = 1;
|
||||
return
|
||||
|
|
|
@ -0,0 +1,22 @@
|
|||
function s = nobs(ts)
|
||||
|
||||
% Returns the number of observations in a @dseries object.
|
||||
|
||||
% 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/>.
|
||||
|
||||
s = rows(ts.data);
|
|
@ -22,26 +22,26 @@ function h = plot(ts, varargin)
|
|||
% Get the number of dseries objects
|
||||
if isequal(nargin,1)
|
||||
ndseries = 1;
|
||||
nvariables = ts.vobs;
|
||||
nobservations = ts.nobs;
|
||||
nvariables = vobs(ts);
|
||||
nobservations = nobs(ts);
|
||||
else
|
||||
if isdseries(varargin{1})
|
||||
ndseries = 2;
|
||||
nvariables = ts.vobs;
|
||||
nobservations = ts.nobs;
|
||||
nvariables = vobs(ts);
|
||||
nobservations = nobs(ts);
|
||||
if nargin>2 && any(cellfun(@isdseries,varargin(2:end)))
|
||||
error('dseries::plot: You cannot pass more two dseries objects!')
|
||||
end
|
||||
if ~isequal(nvariables,varargin{1}.vobs)
|
||||
if ~isequal(nvariables, vobs(varargin{1}))
|
||||
error('dseries::plot: The two dseries objects must have the same number of variables!')
|
||||
end
|
||||
if ~isequal(nobservations,varargin{1}.nobs)
|
||||
if ~isequal(nobservations, nobs(varargin{1}))
|
||||
error('dseries::plot: The two dseries objects must have the same number of observations!')
|
||||
end
|
||||
else
|
||||
ndseries = 1;
|
||||
nvariables = ts.vobs;
|
||||
nobservations = ts.nobs;
|
||||
nvariables = vobs(ts);
|
||||
nobservations = nobs(ts);
|
||||
end
|
||||
end
|
||||
|
||||
|
|
|
@ -58,18 +58,18 @@ if isnumeric(C) && (isscalar(C) || isvector(C))
|
|||
return
|
||||
end
|
||||
|
||||
if ~isequal(B.vobs,C.vobs) && ~(isequal(B.vobs,1) || isequal(C.vobs,1))
|
||||
if ~isequal(vobs(B), vobs(C)) && ~(isequal(vobs(B), 1) || isequal(vobs(C), 1))
|
||||
error(['dseries::plus: Cannot add ' inputname(1) ' and ' inputname(2) ' (wrong number of variables)!'])
|
||||
else
|
||||
if B.vobs>C.vobs
|
||||
idB = 1:B.vobs;
|
||||
idC = ones(1,B.vobs);
|
||||
elseif B.vobs<C.vobs
|
||||
idB = ones(1,C.vobs);
|
||||
idC = 1:C.vobs;
|
||||
if vobs(B)>vobs(C)
|
||||
idB = 1:vobs(B);
|
||||
idC = ones(1,vobs(B));
|
||||
elseif vobs(B)<vobs(C)
|
||||
idB = ones(1,vobs(C));
|
||||
idC = 1:vobs(C);
|
||||
else
|
||||
idB = 1:B.vobs;
|
||||
idC = 1:C.vobs;
|
||||
idB = 1:vobs(B);
|
||||
idC = 1:vobs(C);
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -77,7 +77,7 @@ 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(firstdate(B),firstdate(C))
|
||||
if ~isequal(nobs(B), nobs(C)) || ~isequal(firstdate(B),firstdate(C))
|
||||
[B, C] = align(B, C);
|
||||
end
|
||||
|
||||
|
@ -93,19 +93,16 @@ end
|
|||
|
||||
A = dseries();
|
||||
|
||||
A.data = bsxfun(@plus,B.data,C.data);
|
||||
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);
|
||||
A.tex = cell(A.vobs,1);
|
||||
for i=1:A.vobs
|
||||
|
||||
A_vobs = max(vobs(B), vobs(C));
|
||||
A.name = cell(A_vobs,1);
|
||||
A.tex = cell(A_vobs,1);
|
||||
for i=1:A_vobs
|
||||
A.name(i) = {['plus(' B.name{idB(i)} ',' C.name{idC(i)} ')']};
|
||||
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);
|
||||
|
||||
%@test:1
|
||||
%$ % Define a datasets.
|
||||
|
|
|
@ -47,7 +47,7 @@ function [ts,id] = pop(ts,a) % --*-- Unitary tests --*--
|
|||
|
||||
if nargin<2
|
||||
% Removes the last variable
|
||||
id = ts.vobs;
|
||||
id = vobs(ts);
|
||||
else
|
||||
id = find(strcmp(a,ts.name));
|
||||
end
|
||||
|
@ -57,7 +57,6 @@ if isempty(id)
|
|||
return
|
||||
end
|
||||
|
||||
ts.vobs = ts.vobs-1;
|
||||
ts.data(:,id) = [];
|
||||
ts.name(id) = [];
|
||||
ts.tex(id) = [];
|
||||
|
|
|
@ -47,14 +47,14 @@ switch frequency(ts)
|
|||
case 4
|
||||
us.data(2:end,:) = ts.data(2:end,:)-ts.data(1:end-1,:);
|
||||
us.data(1,:) = NaN;
|
||||
for i = 1:ts.vobs
|
||||
for i = 1:vobs(ts)
|
||||
us.name(i) = {['qdiff(' us.name{i} ')']};
|
||||
us.tex(i) = {['\Delta ' us.tex{i}]};
|
||||
end
|
||||
case 12
|
||||
us.data(4:end,:) = ts.data(4:end,:)-ts.data(1:end-3,:);
|
||||
us.data(1:3,:) = NaN;
|
||||
for i = 1:ts.vobs
|
||||
for i = 1:vobs(ts)
|
||||
us.name(i) = {['qdiff(' us.name{i} ')']};
|
||||
us.tex(i) = {['\Delta_3 ' us.tex{i}]};
|
||||
end
|
||||
|
|
|
@ -47,14 +47,14 @@ switch frequency(ts)
|
|||
case 4
|
||||
us.data(2:end,:) = ts.data(2:end,:)./ts.data(1:end-1,:) - 1;
|
||||
us.data(1,:) = NaN;
|
||||
for i = 1:ts.vobs
|
||||
for i = 1:vobs(ts)
|
||||
us.name(i) = {['qgrowth(' us.name{i} ')']};
|
||||
us.tex(i) = {['\delta ' us.tex{i}]};
|
||||
end
|
||||
case 12
|
||||
us.data(4:end,:) = ts.data(4:end,:)./ts.data(1:end-3,:) - 1;
|
||||
us.data(1:3,:) = NaN;
|
||||
for i = 1:ts.vobs
|
||||
for i = 1:vobs(ts)
|
||||
us.name(i) = {['qgrowth(' us.name{i} ')']};
|
||||
us.tex(i) = {['\delta_3 ' us.tex{i}]};
|
||||
end
|
||||
|
|
|
@ -39,15 +39,15 @@ switch format
|
|||
fprintf(fid,'INIT__ = ''%s'';\n',date2string(firstdate(A)));
|
||||
fprintf(fid,'\n');
|
||||
fprintf(fid,'NAMES__ = {');
|
||||
for i=1:A.vobs
|
||||
for i=1:vobs(A)
|
||||
fprintf(fid,[ '''' A.name{i} '''']);
|
||||
if i<A.vobs
|
||||
if i<vobs(A)
|
||||
fprintf(fid,'; ');
|
||||
end
|
||||
end
|
||||
fprintf(fid,'};\n');
|
||||
str = 'TEX__ = {';
|
||||
for i=1:A.vobs-1
|
||||
for i=1:vobs(A)-1
|
||||
str = [str, '''%s''; '];
|
||||
end
|
||||
str = [str, '''%s''};'];
|
||||
|
@ -56,7 +56,7 @@ switch format
|
|||
str = regexprep(str, pattern, '$1\\\\_');
|
||||
fprintf(fid,str);
|
||||
fprintf(fid,'\n\n');
|
||||
for v=1:A.vobs
|
||||
for v=1:vobs(A)
|
||||
fprintf(fid,'%s = [\n', A.name{v});
|
||||
fprintf(fid,'%15.8g\n',A.data(1:end-1,v));
|
||||
fprintf(fid,'%15.8g];\n\n',A.data(end,v));
|
||||
|
@ -68,7 +68,7 @@ switch format
|
|||
NAMES__ = A.name;
|
||||
TEX__ = A.tex;
|
||||
str = [];
|
||||
for v=1:A.vobs
|
||||
for v=1:vobs(A)
|
||||
str = [str, A.name{v} ' = A.data(:,' num2str(v) ');' ];
|
||||
end
|
||||
eval(str);
|
||||
|
@ -83,7 +83,7 @@ switch format
|
|||
fid = fopen([basename, '.csv'],'w');
|
||||
fprintf(fid,',%s', A.name{:});
|
||||
fprintf(fid,'\n');
|
||||
for t=1:A.nobs
|
||||
for t=1:nobs(A)
|
||||
str = sprintf(', %15.8g',A.data(t,:));
|
||||
fprintf(fid, '%s%s\n',date2string(A.dates(t)),str);
|
||||
end
|
||||
|
|
|
@ -48,13 +48,13 @@ if ~isdseries(B)
|
|||
error(['dseries::rename: ' inputname(1) ' must be a dseries object!'])
|
||||
end
|
||||
|
||||
if ~isequal(B.vobs,n)
|
||||
if ~isequal(vobs(B),n)
|
||||
error(['dseries::rename: The number of variables in ' inputname(1) ' does not match the number of declared names!'])
|
||||
end
|
||||
|
||||
A = B;
|
||||
|
||||
for i=1:A.vobs
|
||||
for i=1:vobs(A)
|
||||
if ~isempty(varargin{i})
|
||||
A.name(i) = { varargin{i} };
|
||||
end
|
||||
|
|
|
@ -83,11 +83,11 @@ switch length(S)
|
|||
end
|
||||
return
|
||||
end
|
||||
if ~isequal(length(S(1).subs),B.vobs)
|
||||
if ~isequal(length(S(1).subs),vobs(B))
|
||||
error('dseries::subsasgn: Wrong syntax!')
|
||||
end
|
||||
if ~isequal(S(1).subs(:),B.name)
|
||||
for i = 1:B.vobs
|
||||
for i = 1:vobs(B)
|
||||
if ~isequal(S(1).subs{i},B.name{i})
|
||||
% Rename a variable.
|
||||
id = find(strcmp(S(1).subs{i},A.name));
|
||||
|
@ -106,13 +106,13 @@ switch length(S)
|
|||
case '.'
|
||||
if isequal(S(1).subs,'init') && isdates(B) && isequal(length(B),1)
|
||||
% Change the initial date (update dates member)
|
||||
A.dates = B:B+(A.nobs-1);
|
||||
A.dates = B:B+(nobs(A)-1);
|
||||
return
|
||||
elseif isequal(S(1).subs,'dates') && isdates(B)
|
||||
% Overwrite the dates member
|
||||
A.dates = B;
|
||||
return
|
||||
elseif ismember(S(1).subs,{'nobs','vobs','data','name','tex'})
|
||||
elseif ismember(S(1).subs,{'data','name','tex'})
|
||||
error(['dseries::subsasgn: You cannot overwrite ' S(1).subs ' member!'])
|
||||
elseif ~isequal(S(1).subs,B.name)
|
||||
% Single variable selection.
|
||||
|
@ -143,7 +143,7 @@ switch length(S)
|
|||
if isempty(tdy)
|
||||
error('dseries::subsasgn: Periods of the dseries objects on the left and right hand sides must intersect!')
|
||||
end
|
||||
if ~isequal(A.vobs,B.vobs)
|
||||
if ~isequal(vobs(A), vobs(B))
|
||||
error('dseries::subsasgn: Dimension error! The number of variables on the left and right hand side must match.')
|
||||
end
|
||||
A.data(tdx,:) = B.data(tdy,:);
|
||||
|
@ -166,28 +166,20 @@ switch length(S)
|
|||
if isnumeric(B)
|
||||
if isequal(rows(B),1)
|
||||
A.data = repmat(B,A.dates.ndat,1);
|
||||
A.nobs = rows(A.data);
|
||||
A.vobs = columns(A.data);
|
||||
elseif isequal(rows(B),A.dates.ndat)
|
||||
A.data = B;
|
||||
A.nobs = rows(A.data);
|
||||
A.vobs = columns(A.data);
|
||||
else
|
||||
error('dseries::subsasgn: Wrong syntax!')
|
||||
end
|
||||
if isempty(A.name)
|
||||
A.name = default_name(A.vobs);
|
||||
A.name = default_name(vobs(A));
|
||||
A.tex = name2tex(A.name);
|
||||
end
|
||||
elseif isdseries(B)
|
||||
if isequal(B.nobs,1)
|
||||
if isequal(nobs(B), 1)
|
||||
A.data = repmat(B.data,A.dates.ndat,1);
|
||||
A.nobs = rows(A.data);
|
||||
A.vobs = columns(A.data);
|
||||
elseif isequal(B.nobs,A.dates.ndat)
|
||||
elseif isequal(nobs(B), A.dates.ndat)
|
||||
A.data = B;
|
||||
A.nobs = rows(A.data);
|
||||
A.vobs = columns(A.data);
|
||||
else
|
||||
error('dseries::subsasgn: Wrong syntax!')
|
||||
end
|
||||
|
@ -211,7 +203,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(vobs(sA), vobs(B))) || (isnumeric(B) && isequal(vobs(sA),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)
|
||||
|
|
|
@ -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','dates'} % Public members.
|
||||
case {'data','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,12 @@ switch S(1).type
|
|||
if length(S)>1 && isequal(S(2).type,'()') && isempty(S(2).subs)
|
||||
S = shiftS(S,1);
|
||||
end
|
||||
case 'nobs'
|
||||
% Returns the number of observations.
|
||||
B = rows(A.data);
|
||||
case 'vobs'
|
||||
% Returns the number of variables.
|
||||
B = columns(A.data);
|
||||
case 'init'
|
||||
% Returns a dates object (first date).
|
||||
B = A.dates(1);
|
||||
|
@ -177,8 +183,6 @@ switch S(1).type
|
|||
B.name = A.name(ndx);
|
||||
B.tex = A.tex(ndx);
|
||||
B.tex = deblank(A.tex(ndx,:));
|
||||
B.nobs = A.nobs;
|
||||
B.vobs = 1;
|
||||
B.dates = A.dates;
|
||||
else
|
||||
error('dseries::subsref: Unknown public method, public member or variable!')
|
||||
|
@ -232,8 +236,6 @@ switch S(1).type
|
|||
B.data = A.data(tdx,:);
|
||||
B.name = A.name;
|
||||
B.tex = A.tex;
|
||||
B.nobs = length(tdx);
|
||||
B.vobs = A.vobs;
|
||||
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!');
|
||||
|
@ -245,15 +247,13 @@ switch S(1).type
|
|||
B = extract(A,S(1).subs{:});
|
||||
elseif isequal(length(S(1).subs),1) && all(isint(S(1).subs{1}))
|
||||
idx = S(1).subs{1};
|
||||
if max(idx)>A.vobs || min(idx)<1
|
||||
if max(idx)>size(A.data,2) || min(idx)<1
|
||||
error('dseries::subsref: Indices are out of bounds!')
|
||||
end
|
||||
B = dseries();
|
||||
B.data = A.data(:,idx);
|
||||
B.name = A.name(idx);
|
||||
B.tex = A.tex(idx);
|
||||
B.nobs = A.nobs;
|
||||
B.vobs = length(idx);
|
||||
B.dates = A.dates;
|
||||
else
|
||||
error('dseries::subsref: What the Hell are you tryin'' to do?!')
|
||||
|
|
|
@ -21,7 +21,7 @@ assert(nargin <= 3, 'dseries::tex_rename: accepts at most three args');
|
|||
|
||||
if nargin == 2
|
||||
newtexname = varargin{1};
|
||||
assert(ts.vobs == 1, ['dseries::tex_rename: with one argument, the dseries contain only one variable.']);
|
||||
assert(vobs(ts) == 1, ['dseries::tex_rename: with one argument, the dseries contain only one variable.']);
|
||||
else
|
||||
newtexname = varargin{2};
|
||||
name = varargin{1};
|
||||
|
|
|
@ -42,16 +42,15 @@ function A = uminus(B) % --*-- Unitary tests --*--
|
|||
|
||||
A = dseries();
|
||||
|
||||
A.nobs = B.nobs;
|
||||
A.vobs = B.vobs;
|
||||
A.data = -(B.data);
|
||||
A.dates = B.dates;
|
||||
A.name = cell(A.vobs,1);
|
||||
A.tex = cell(A.vobs,1);
|
||||
for i = 1:A.vobs
|
||||
|
||||
A.name = cell(vobs(A),1);
|
||||
A.tex = cell(vobs(A),1);
|
||||
for i = 1:vobs(A)
|
||||
A.name(i) = {[ '-' B.name{i}]};
|
||||
A.tex(i) = {[ '-' B.tex{i}]};
|
||||
end
|
||||
A.data = -(B.data);
|
||||
|
||||
%@test:1
|
||||
%$ % Define a datasets.
|
||||
|
|
|
@ -63,7 +63,7 @@ function d = vertcat_(b, c)
|
|||
if ~isequal(frequency(b), frequency(c))
|
||||
error('dseries::vertcat: Frequencies must be common!')
|
||||
end
|
||||
if ~isequal(b.vobs, c.vobs)
|
||||
if ~isequal(vobs(b), vobs(c))
|
||||
error('dseries::vertcat: Number of variables must be common!')
|
||||
end
|
||||
if ~isequal(b.name, c.name)
|
||||
|
@ -72,7 +72,6 @@ function d = vertcat_(b, c)
|
|||
d = b;
|
||||
d.data = [b.data; c.data];
|
||||
d.dates = [b.dates; c.dates];
|
||||
d.nobs = b.nobs+c.nobs;
|
||||
|
||||
%@test:1
|
||||
%$ % Define a data set.
|
||||
|
|
|
@ -0,0 +1,22 @@
|
|||
function s = vobs(ts)
|
||||
|
||||
% Returns the number of variables in a @dseries object.
|
||||
|
||||
% 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/>.
|
||||
|
||||
s = columns(ts.data);
|
|
@ -45,28 +45,28 @@ switch frequency(ts)
|
|||
case 1
|
||||
us.data(2:end,:) = ts.data(2:end,:)-ts.data(1:end-1,:);
|
||||
us.data(1,:) = NaN;
|
||||
for i = 1:ts.vobs
|
||||
for i = 1:vobs(ts)
|
||||
us.name(i) = {['ydiff(' us.name{i} ')']};
|
||||
us.tex(i) = {['\Delta ' us.tex{i}]};
|
||||
end
|
||||
case 4
|
||||
us.data(5:end,:) = ts.data(5:end,:)-ts.data(1:end-4,:);
|
||||
us.data(1:4,:) = NaN;
|
||||
for i = 1:ts.vobs
|
||||
for i = 1:vobs(ts)
|
||||
us.name(i) = {['ydiff(' us.name{i} ')']};
|
||||
us.tex(i) = {['\Delta_4 ' us.tex{i}]};
|
||||
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
|
||||
for i = 1:vobs(ts)
|
||||
us.name(i) = {['ydiff(' us.name{i} ')']};
|
||||
us.tex(i) = {['\Delta_{12} ' us.tex{i}]};
|
||||
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
|
||||
for i = 1:vobs(ts)
|
||||
us.name(i) = {['ydiff(' us.name{i} ')']};
|
||||
us.tex(i) = {['\Delta_{52} ' us.tex{i}]};
|
||||
end
|
||||
|
|
|
@ -45,28 +45,28 @@ switch frequency(ts)
|
|||
case 1
|
||||
us.data(2:end,:) = ts.data(2:end,:)./ts.data(1:end-1,:) - 1;
|
||||
us.data(1,:) = NaN;
|
||||
for i = 1:ts.vobs
|
||||
for i = 1:vobs(ts)
|
||||
us.name(i) = {['ygrowth(' us.name{i} ')']};
|
||||
us.tex(i) = {['\delta ' us.tex{i}]};
|
||||
end
|
||||
case 4
|
||||
us.data(5:end,:) = ts.data(5:end,:)./ts.data(1:end-4,:) - 1;
|
||||
us.data(1:4,:) = NaN;
|
||||
for i = 1:ts.vobs
|
||||
for i = 1:vobs(ts)
|
||||
us.name(i) = {['ygrowth(' us.name{i} ')']};
|
||||
us.tex(i) = {['\delta_4 ' us.tex{i}]};
|
||||
end
|
||||
case 12
|
||||
us.data(13:end,:) = ts.data(13:end,:)./ts.data(1:end-12,:) - 1;
|
||||
us.data(1:12,:) = NaN;
|
||||
for i = 1:ts.vobs
|
||||
for i = 1:vobs(ts)
|
||||
us.name(i) = {['ygrowth(' us.name{i} ')']};
|
||||
us.tex(i) = {['\delta_{12} ' us.tex{i}]};
|
||||
end
|
||||
case 52
|
||||
us.data(53:end,:) = ts.data(53:end,:)./ts.data(1:end-52,:) - 1;
|
||||
us.data(1:52,:) = NaN;
|
||||
for i = 1:ts.vobs
|
||||
for i = 1:vobs(ts)
|
||||
us.name(i) = {['ygrowth(' us.name{i} ')']};
|
||||
us.tex(i) = {['\delta_{52} ' us.tex{i}]};
|
||||
end
|
||||
|
|
Loading…
Reference in New Issue