Skip to content
Snippets Groups Projects

Compare revisions

Changes are shown as if the source revision was being merged into the target revision. Learn more about comparing revisions.

Source

Select target project
No results found

Target

Select target project
  • giovanma/dynare
  • giorgiomas/dynare
  • Vermandel/dynare
  • Dynare/dynare
  • normann/dynare
  • MichelJuillard/dynare
  • wmutschl/dynare
  • FerhatMihoubi/dynare
  • sebastien/dynare
  • lnsongxf/dynare
  • rattoma/dynare
  • CIMERS/dynare
  • FredericKarame/dynare
  • SumuduK/dynare
  • MinjeJeon/dynare
  • camilomrch/dynare
  • DoraK/dynare
  • avtishin/dynare
  • selma/dynare
  • claudio_olguin/dynare
  • jeffjiang07/dynare
  • EthanSystem/dynare
  • stepan-a/dynare
  • wjgatt/dynare
  • JohannesPfeifer/dynare
  • gboehl/dynare
  • chskcau/dynare-doc-fixes
27 results
Show changes
Showing
with 322 additions and 118 deletions
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
...@@ -51,14 +51,21 @@ end ...@@ -51,14 +51,21 @@ end
function a = concatenate(b,c) function a = concatenate(b,c)
[n,message] = common_strings_in_cell_arrays(b.name,c.name); [n,message] = common_strings_in_cell_arrays(b.name,c.name);
if isempty(b)
a = c;
return
end
if isempty(c)
a = b;
return
end
if n if n
error(['dseries::horzcat: I cannot concatenate dseries objects with common variable names (' message ')!']) error(['dseries::horzcat: I cannot concatenate dseries objects with common variable names (' message ')!'])
end end
if ~isequal(b.freq,c.freq) if ~isequal(frequency(b),frequency(c))
error('dseries::horzcat: All time series objects must have common frequency!') error('dseries::horzcat: All time series objects must have common frequency!')
else else
a = dseries(); a = dseries();
a.freq = b.freq;
end end
d_nobs_flag = 0; d_nobs_flag = 0;
if ~isequal(b.nobs,c.nobs) if ~isequal(b.nobs,c.nobs)
...@@ -67,29 +74,26 @@ function a = concatenate(b,c) ...@@ -67,29 +74,26 @@ function a = concatenate(b,c)
a.nobs = b.nobs; a.nobs = b.nobs;
end end
d_init_flag = 0; d_init_flag = 0;
if ~isequal(b.init,c.init) if ~isequal(firstdate(b),firstdate(c))
d_init_flag = 1; d_init_flag = 1;
end end
a.vobs = b.vobs+c.vobs; a.vobs = b.vobs+c.vobs;
a.name = vertcat(b.name,c.name); a.name = vertcat(b.name,c.name);
a.tex = vertcat(b.tex,c.tex); a.tex = vertcat(b.tex,c.tex);
if ~( d_nobs_flag(1) || d_init_flag(1) ) if ~( d_nobs_flag(1) || d_init_flag(1) )
a.init = b.init;
a.data = [b.data,c.data]; a.data = [b.data,c.data];
a.dates = b.dates; a.dates = b.dates;
else else
if b.init<=c.init if firstdate(b)<=firstdate(c)
a.init = b.init; if firstdate(b)<firstdate(c)
if b.init<c.init c.data = [NaN(firstdate(c)-firstdate(b),c.vobs); c.data];
c.data = [NaN(c.init-b.init,c.vobs); c.data];
end end
else else
a.init = c.init; b_first_lines = firstdate(b)-firstdate(c);
b_first_lines = b.init-c.init; b.data = [NaN(firstdate(b)-firstdate(c),b.vobs); b.data];
b.data = [NaN(b.init-c.init,b.vobs); b.data];
end end
b_last_date = b.init+b.nobs; b_last_date = firstdate(b)+b.nobs;
c_last_date = c.init+c.nobs; c_last_date = firstdate(c)+c.nobs;
if b_last_date<c_last_date 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,b.vobs)];
elseif b_last_date>c_last_date elseif b_last_date>c_last_date
...@@ -289,3 +293,28 @@ function a = concatenate(b,c) ...@@ -289,3 +293,28 @@ function a = concatenate(b,c)
%$ %$
%$ T = t; %$ T = t;
%@eof:6 %@eof:6
%@test:7
%$ % Define X
%$ X = randn(30,2);
%$
%$ % Instantiate two time series objects.
%$ ts1 = dseries();
%$ ts2 = dseries(randn(30,2),'1950Q2');
%$
%$ % Call the tested method.
%$ try
%$ ts3 = [ts1,ts2];
%$ t = 1;
%$ catch
%$ t = 0;
%$ end
%$
%$ if t(1)
%$ t(2) = dyn_assert(ts3.freq,4);
%$ t(3) = dyn_assert(ts3.data,X);
%$ t(4) = dyn_assert(isequal(ts3.dates(1),dates('1950Q2')),1);
%$ end
%$
%$ T = t;
%@eof:7
...@@ -52,7 +52,7 @@ if n ...@@ -52,7 +52,7 @@ if n
error(['dseries::insert: Variable(s) ' message ' already exist in ''' inputname(1) '''!']) error(['dseries::insert: Variable(s) ' message ' already exist in ''' inputname(1) '''!'])
end 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!']) error(['dseries::insert: ''' inputname(1) ''' and ''' inputname(2) ''' dseries objects must have common frequencies!'])
end end
......
...@@ -44,12 +44,12 @@ if ~isequal(A.vobs,B.vobs) ...@@ -44,12 +44,12 @@ if ~isequal(A.vobs,B.vobs)
return return
end end
if ~isequal(A.freq,B.freq) if ~isequal(frequency(A),frequency(B))
C = 0; C = 0;
return return
end end
if ~isequal(A.init,B.init) if ~isequal(A.dates,B.dates)
C = 0; C = 0;
return return
end end
......
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
...@@ -44,12 +44,11 @@ if ~isdseries(C) ...@@ -44,12 +44,11 @@ if ~isdseries(C)
error('dseries::merge: Both inputs must be dseries objects!') error('dseries::merge: Both inputs must be dseries objects!')
end 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)!']) error(['dseries::merge: Cannot merge ' inputname(1) ' and ' inputname(2) ' (frequencies are different)!'])
end end
A = dseries(); A = dseries();
A.freq = B.freq;
[A.name, IBC, junk] = unique([B.name; C.name], 'last'); [A.name, IBC, junk] = unique([B.name; C.name], 'last');
tex = [B.tex; C.tex]; tex = [B.tex; C.tex];
A.tex = tex(IBC); A.tex = tex(IBC);
...@@ -59,8 +58,8 @@ if B.nobs == 0 ...@@ -59,8 +58,8 @@ if B.nobs == 0
A = C; A = C;
elseif C.nobs == 0 elseif C.nobs == 0
A = B; A = B;
elseif B.init >= C.init elseif firstdate(B) >= firstdate(C)
diff = B.init - C.init; diff = firstdate(B) - firstdate(C);
A.nobs = max(B.nobs + diff, C.nobs); A.nobs = max(B.nobs + diff, C.nobs);
A.data = NaN(A.nobs, A.vobs); A.data = NaN(A.nobs, A.vobs);
Z1 = [NaN(diff,B.vobs);B.data]; Z1 = [NaN(diff,B.vobs);B.data];
...@@ -68,14 +67,14 @@ elseif B.init >= C.init ...@@ -68,14 +67,14 @@ elseif B.init >= C.init
Z1 = [Z1; NaN(A.nobs-(B.nobs + diff),B.vobs)]; Z1 = [Z1; NaN(A.nobs-(B.nobs + diff),B.vobs)];
end; end;
Z2 = C.data; Z2 = C.data;
if A.nobs > C.nobs if A.nobs > C.nobs
Z2 = [Z2; NaN(A.nobs - C.nobs,C.vobs)]; Z2 = [Z2; NaN(A.nobs - C.nobs,C.vobs)];
end; end;
Z = [Z1 Z2]; Z = [Z1 Z2];
A.data = Z(:,IBC); A.data = Z(:,IBC);
A.init = C.init; A_init = firstdate(C);
else else
diff = C.init - B.init; diff = firstdate(C) - firstdate(B);
A.nobs = max(C.nobs + diff, B.nobs); A.nobs = max(C.nobs + diff, B.nobs);
A.data = NaN(A.nobs, A.vobs); A.data = NaN(A.nobs, A.vobs);
Z1 = [NaN(diff,C.vobs);C.data]; Z1 = [NaN(diff,C.vobs);C.data];
...@@ -88,10 +87,10 @@ else ...@@ -88,10 +87,10 @@ else
end; end;
Z = [Z2 Z1]; Z = [Z2 Z1];
A.data = Z(:,IBC); A.data = Z(:,IBC);
A.init = B.init; A_init = B.init;
end end
A.dates = A.init:A.init+(A.nobs-1); A.dates = A_init:A_init+(A.nobs-1);
%@test:1 %@test:1
%$ % Define a datasets. %$ % Define a datasets.
......
...@@ -73,11 +73,11 @@ else ...@@ -73,11 +73,11 @@ else
end end
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)!']) error(['dseries::plus: Cannot substract ' inputname(1) ' and ' inputname(2) ' (frequencies are different)!'])
end 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); [B, C] = align(B, C);
end end
...@@ -93,8 +93,6 @@ end ...@@ -93,8 +93,6 @@ end
A = dseries(); A = dseries();
A.freq = B.freq;
A.init = B.init;
A.dates = B.dates; A.dates = B.dates;
A.nobs = max(B.nobs,C.nobs); A.nobs = max(B.nobs,C.nobs);
A.vobs = max(B.vobs,C.vobs); A.vobs = max(B.vobs,C.vobs);
......
...@@ -40,10 +40,26 @@ function A = mpower(B,C) % --*-- Unitary tests --*-- ...@@ -40,10 +40,26 @@ function A = mpower(B,C) % --*-- Unitary tests --*--
% You should have received a copy of the GNU General Public License % You should have received a copy of the GNU General Public License
% along with Dynare. If not, see <http://www.gnu.org/licenses/>. % along with Dynare. If not, see <http://www.gnu.org/licenses/>.
if isdseries(B) && isnumeric(C) && isreal(C) && isscalar(C) if isnumeric(B) && isvector(B) && length(B)>1
if ~isdseries(C)
error('dseries::mpower: Second input argument must be a dseries object!')
end
A = C;
A.data = bsxfun(@power,C.data,B);
return;
end
if isnumeric(C) && isvector(C) && length(C)>1
if ~isdseries(B)
error('dseries::mpower: First input argument must be a dseries object!')
end
A = B;
A.data = bsxfun(@power,B.data,C);
return
end
if isdseries(B) && isnumeric(C) && isreal(C) && isscalar(C)
A = dseries(); A = dseries();
A.freq = B.freq;
A.init = B.init;
A.dates = B.dates; A.dates = B.dates;
A.nobs = B.nobs; A.nobs = B.nobs;
A.vobs = B.vobs; A.vobs = B.vobs;
...@@ -58,10 +74,8 @@ if isdseries(B) && isnumeric(C) && isreal(C) && isscalar(C) ...@@ -58,10 +74,8 @@ if isdseries(B) && isnumeric(C) && isreal(C) && isscalar(C)
end end
if isdseries(B) && isdseries(C) 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 = dseries();
A.freq = B.freq;
A.init = B.init;
A.dates = B.dates; A.dates = B.dates;
A.nobs = B.nobs; A.nobs = B.nobs;
A.vobs = B.vobs; A.vobs = B.vobs;
...@@ -133,4 +147,26 @@ error(['dseries::mpower: Wrong calling sequence!']) ...@@ -133,4 +147,26 @@ error(['dseries::mpower: Wrong calling sequence!'])
%$ t(6) = dyn_assert(ts3.tex,{'A1^2';'A2^2'}); %$ t(6) = dyn_assert(ts3.tex,{'A1^2';'A2^2'});
%$ end %$ end
%$ T = all(t); %$ T = all(t);
%@eof:2 %@eof:2
\ No newline at end of file
%@test:3
%$ % Define a dseries object
%$ ts1=dseries([1 1;2 2;3 3], '1999y', {'MyVar1','MyVar2'});
%$
%$ % Use the power
%$ try
%$ ts2 = ts1^transpose(1:3);
%$ t = 1;
%$ catch
%$ t = 0;
%$ end
%$
%$ if t(1)
%$ t(2) = dyn_assert(ts2.vobs,2);
%$ t(3) = dyn_assert(ts2.nobs,3);
%$ t(4) = dyn_assert(ts2.data,bsxfun(@power,ts1.data,transpose(1:3)),1e-15);
%$ t(5) = dyn_assert(ts2.name,{'MyVar1';'MyVar2'});
%$ t(6) = dyn_assert(ts2.tex,{'MyVar1';'MyVar2'});
%$ end
%$ T = all(t);
%@eof:3
\ No newline at end of file
...@@ -74,15 +74,13 @@ if isdseries(B) && isdseries(C) ...@@ -74,15 +74,13 @@ if isdseries(B) && isdseries(C)
idC = 1:C.vobs; idC = 1:C.vobs;
end end
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)!']) error(['dseries::times: Cannot divide ' inputname(1) ' and ' inputname(2) ' (frequencies are different)!'])
end 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); [B, C] = align(B, C);
end end
A = dseries(); A = dseries();
A.freq = B.freq;
A.init = B.init;
A.dates = B.dates; A.dates = B.dates;
A.nobs = max(B.nobs,C.nobs); A.nobs = max(B.nobs,C.nobs);
A.vobs = max(B.vobs,C.vobs); A.vobs = max(B.vobs,C.vobs);
......
...@@ -74,15 +74,13 @@ if isdseries(B) && isdseries(C) ...@@ -74,15 +74,13 @@ if isdseries(B) && isdseries(C)
idC = 1:C.vobs; idC = 1:C.vobs;
end end
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)!']) error(['dseries::times: Cannot multiply ' inputname(1) ' and ' inputname(2) ' (frequencies are different)!'])
end 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); [B, C] = align(B, C);
end end
A = dseries(); A = dseries();
A.freq = B.freq;
A.init = B.init;
A.dates = B.dates; A.dates = B.dates;
A.nobs = max(B.nobs,C.nobs); A.nobs = max(B.nobs,C.nobs);
A.vobs = max(B.vobs,C.vobs); A.vobs = max(B.vobs,C.vobs);
......
...@@ -38,35 +38,35 @@ if ~(isdseries(A) && isdseries(B)) ...@@ -38,35 +38,35 @@ if ~(isdseries(A) && isdseries(B))
end end
if ~isequal(A.nobs,B.nobs) 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; C = 1;
return return
end end
if ~isequal(A.vobs,B.vobs) 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; C = 1;
return return
end end
if ~isequal(A.freq,B.freq) if ~isequal(frequency(A),frequency(B))
warning('dseries::eq: Both input arguments should have the same frequencies!') warning('dseries::ne: Both input arguments should have the same frequencies!')
C = 1; C = 1;
return return
end 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!') warning('dseries::ne: Both input arguments should have the same initial period!')
C = 1; C = 1;
return return
end end
if ~isequal(A.name,B.name) 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 end
if ~isequal(A.tex,B.tex) 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 end
C = ne(A.data, B.data); C = ne(A.data, B.data);
......
...@@ -73,11 +73,11 @@ else ...@@ -73,11 +73,11 @@ else
end end
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)!']) error(['dseries::plus: Cannot add ' inputname(1) ' and ' inputname(2) ' (frequencies are different)!'])
end 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); [B, C] = align(B, C);
end end
...@@ -93,8 +93,9 @@ end ...@@ -93,8 +93,9 @@ end
A = dseries(); A = dseries();
A.freq = B.freq; A.dates = B.dates;
A.init = B.init; %A.freq = B.freq;
%A.init = B.init;
A.nobs = max(B.nobs,C.nobs); A.nobs = max(B.nobs,C.nobs);
A.vobs = max(B.vobs,C.vobs); A.vobs = max(B.vobs,C.vobs);
A.name = cell(A.vobs,1); A.name = cell(A.vobs,1);
...@@ -104,7 +105,7 @@ for i=1:A.vobs ...@@ -104,7 +105,7 @@ for i=1:A.vobs
A.tex(i) = {['(' B.tex{idB(i)} '+' C.tex{idC(i)} ')']}; A.tex(i) = {['(' B.tex{idB(i)} '+' C.tex{idC(i)} ')']};
end end
A.data = bsxfun(@plus,B.data,C.data); 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 %@test:1
%$ % Define a datasets. %$ % Define a datasets.
......
...@@ -41,7 +41,7 @@ function us = qdiff(ts) % --*-- Unitary tests --*-- ...@@ -41,7 +41,7 @@ function us = qdiff(ts) % --*-- Unitary tests --*--
us = ts; us = ts;
switch ts.freq switch frequency(ts)
case 1 case 1
error('dseries::qgrowth: I cannot compute quaterly differences from yearly data!') error('dseries::qgrowth: I cannot compute quaterly differences from yearly data!')
case 4 case 4
......
...@@ -41,7 +41,7 @@ function us = qgrowth(ts) % --*-- Unitary tests --*-- ...@@ -41,7 +41,7 @@ function us = qgrowth(ts) % --*-- Unitary tests --*--
us = ts; us = ts;
switch ts.freq switch frequency(ts)
case 1 case 1
error('dseries::qgrowth: I cannot compute quaterly growth rates from yearly data!') error('dseries::qgrowth: I cannot compute quaterly growth rates from yearly data!')
case 4 case 4
......
function ts = remove(ts,a) % --*-- Unitary tests --*--
% Removes a variable from a dseries object (alias for the pop method).
%@info:
%! @deftypefn {Function File} {@var{ts} =} pop (@var{ts}, @var{a})
%! @anchor{dseries/pop}
%! @sp 1
%! Remove method for the dseries class. Removes a variable from a dseries object.
%! @sp 2
%! @strong{Inputs}
%! @sp 1
%! @table @ @var
%! @item ts
%! Object instantiated by @ref{dseries}.
%! @item a
%! String, name of the variable to be removed.
%! @end table
%! @sp 2
%! @strong{Outputs}
%! @sp 1
%! @table @ @var
%! @item ts
%! Object instantiated by @ref{dseries}, without variable (@var{a}).
%! @end table
%! @end deftypefn
%@eod:
% 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/>.
ts = pop(ts, a);
%@test:1
%$ % Define a datasets.
%$ A = rand(10,3);
%$
%$ % Define names
%$ A_name = {'A1';'A2';'A3'};
%$
%$ t = zeros(4,1);
%$
%$ % Instantiate a time series object.
%$ try
%$ ts1 = dseries(A,[],A_name,[]);
%$ ts2 = remove(ts1,'A2');
%$ t(1) = 1;
%$ catch
%$ t = 0;
%$ end
%$
%$ if length(t)>1
%$ t(2) = dyn_assert(ts2.vobs,2);
%$ t(3) = dyn_assert(ts2.nobs,10);
%$ t(4) = dyn_assert(ts2.data,[A(:,1), A(:,3)],1e-15);
%$ end
%$ T = all(t);
%@eof:1
%@test:2
%$ % Define a datasets.
%$ A = rand(10,3);
%$
%$ % Define names
%$ A_name = {'A1';'A2';'A3'};
%$
%$ t = zeros(4,1);
%$
%$ % Instantiate a time series object.
%$ try
%$ ts1 = dseries(A,[],A_name,[]);
%$ ts2 = ts1.remove('A2');
%$ t(1) = 1;
%$ catch
%$ t = 0;
%$ end
%$
%$ if length(t)>1
%$ t(2) = dyn_assert(ts2.vobs,2);
%$ t(3) = dyn_assert(ts2.nobs,10);
%$ t(4) = dyn_assert(ts2.data,[A(:,1), A(:,3)],1e-15);
%$ end
%$ T = all(t);
%@eof:2
\ No newline at end of file
...@@ -35,8 +35,8 @@ switch format ...@@ -35,8 +35,8 @@ switch format
fid = fopen([basename, '.m'],'w'); fid = fopen([basename, '.m'],'w');
fprintf(fid,'%% File created on %s.\n',datestr(now)); fprintf(fid,'%% File created on %s.\n',datestr(now));
fprintf(fid,'\n'); fprintf(fid,'\n');
fprintf(fid,'FREQ__ = %s;\n',num2str(A.freq)); fprintf(fid,'FREQ__ = %s;\n',num2str(frequency(A)));
fprintf(fid,'INIT__ = '' %s'';\n',date2string(A.init)); fprintf(fid,'INIT__ = '' %s'';\n',date2string(firstdate(A)));
fprintf(fid,'\n'); fprintf(fid,'\n');
fprintf(fid,'NAMES__ = {'); fprintf(fid,'NAMES__ = {');
for i=1:A.vobs for i=1:A.vobs
...@@ -61,8 +61,8 @@ switch format ...@@ -61,8 +61,8 @@ switch format
end end
fclose(fid); fclose(fid);
case 'mat' case 'mat'
FREQ__ = A.freq; FREQ__ = frequency(A);
INIT__ = date2string(A.init); INIT__ = date2string(firstdate(A));
NAMES__ = A.name; NAMES__ = A.name;
TEX__ = A.tex; TEX__ = A.tex;
str = []; str = [];
......
...@@ -25,7 +25,7 @@ function A = subsasgn(A,S,B) % --*-- Unitary tests --*-- ...@@ -25,7 +25,7 @@ function A = subsasgn(A,S,B) % --*-- Unitary tests --*--
% You should have received a copy of the GNU General Public License % You should have received a copy of the GNU General Public License
% along with Dynare. If not, see <http://www.gnu.org/licenses/>. % along with Dynare. If not, see <http://www.gnu.org/licenses/>.
merge_dseries_objects = 1; merge_dseries_objects = 1;
switch length(S) switch length(S)
case 1 case 1
...@@ -77,6 +77,12 @@ switch length(S) ...@@ -77,6 +77,12 @@ switch length(S)
end end
end end
end end
if isempty(B)
for i=1:length(S(1).subs)
A = remove(A,S(1).subs{i});
end
return
end
if ~isequal(length(S(1).subs),B.vobs) if ~isequal(length(S(1).subs),B.vobs)
error('dseries::subsasgn: Wrong syntax!') error('dseries::subsasgn: Wrong syntax!')
end end
...@@ -99,20 +105,14 @@ switch length(S) ...@@ -99,20 +105,14 @@ switch length(S)
end end
case '.' case '.'
if isequal(S(1).subs,'init') && isdates(B) && isequal(length(B),1) if isequal(S(1).subs,'init') && isdates(B) && isequal(length(B),1)
% Overwrite the init member... % Change the initial date (update dates member)
A.init = B; A.dates = B:B+(A.nobs-1);
% ... and update freq and time members.
A.freq = A.init.freq;
A.dates = A.init:A.init+(A.nobs-1);
return return
elseif isequal(S(1).subs,'dates') && isdates(B) elseif isequal(S(1).subs,'dates') && isdates(B)
% Overwrite the time member... % Overwrite the dates member
A.dates = B; A.dates = B;
% ... and update the freq and init members.
A.init = B(1);
A.freq = A.init.freq;
return 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!']) error(['dseries::subsasgn: You cannot overwrite ' S(1).subs ' member!'])
elseif ~isequal(S(1).subs,B.name) elseif ~isequal(S(1).subs,B.name)
% Single variable selection. % Single variable selection.
...@@ -211,7 +211,7 @@ switch length(S) ...@@ -211,7 +211,7 @@ switch length(S)
else else
sA = extract(A,S(1).subs); sA = extract(A,S(1).subs);
end 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}) if isdates(S(2).subs{1})
[junk, tdx] = intersect(sA.dates.time,S(2).subs{1}.time,'rows'); [junk, tdx] = intersect(sA.dates.time,S(2).subs{1}.time,'rows');
if isdseries(B) if isdseries(B)
...@@ -278,8 +278,8 @@ end ...@@ -278,8 +278,8 @@ end
%$ t(1) = 1; %$ t(1) = 1;
%$ catch %$ catch
%$ t(1) = 0; %$ t(1) = 0;
%$ end %$ end
%$ %$
%$ % Instantiate a time series object. %$ % Instantiate a time series object.
%$ if t(1) %$ if t(1)
%$ t(2) = dyn_assert(ts1.vobs,3); %$ t(2) = dyn_assert(ts1.vobs,3);
...@@ -440,8 +440,8 @@ end ...@@ -440,8 +440,8 @@ end
%$ t(1) = 1; %$ t(1) = 1;
%$ catch %$ catch
%$ t(1) = 0; %$ t(1) = 0;
%$ end %$ end
%$ %$
%$ % Instantiate a time series object. %$ % Instantiate a time series object.
%$ if t(1) %$ if t(1)
%$ t(2) = dyn_assert(ts1.vobs,4); %$ t(2) = dyn_assert(ts1.vobs,4);
...@@ -469,8 +469,8 @@ end ...@@ -469,8 +469,8 @@ end
%$ t(1) = 1; %$ t(1) = 1;
%$ catch %$ catch
%$ t(1) = 0; %$ t(1) = 0;
%$ end %$ end
%$ %$
%$ % Instantiate a time series object. %$ % Instantiate a time series object.
%$ if t(1) %$ if t(1)
%$ t(2) = dyn_assert(ts1.vobs,4); %$ t(2) = dyn_assert(ts1.vobs,4);
...@@ -499,8 +499,8 @@ end ...@@ -499,8 +499,8 @@ end
%$ t(1) = 1; %$ t(1) = 1;
%$ catch %$ catch
%$ t(1) = 0; %$ t(1) = 0;
%$ end %$ end
%$ %$
%$ % Instantiate a time series object. %$ % Instantiate a time series object.
%$ if t(1) %$ if t(1)
%$ t(2) = dyn_assert(ts1.vobs,4); %$ t(2) = dyn_assert(ts1.vobs,4);
...@@ -845,7 +845,7 @@ end ...@@ -845,7 +845,7 @@ end
%$ T = all(t); %$ T = all(t);
%@eof:21 %@eof:21
%@test:21 %@test:22
%$ % Define a datasets. %$ % Define a datasets.
%$ A = rand(1,3); %$ A = rand(1,3);
%$ %$
...@@ -867,4 +867,28 @@ end ...@@ -867,4 +867,28 @@ end
%$ t(4) = dyn_assert(ts.data,repmat(A,4,1),1e-15); %$ t(4) = dyn_assert(ts.data,repmat(A,4,1),1e-15);
%$ end %$ end
%$ T = all(t); %$ T = all(t);
%@eof:21 %@eof:22
\ No newline at end of file
%@test:23
%$ % Instantiate a dseries object.
%$ ts0 = dseries(randn(10,6), '1999y');
%$
%$ % Try to remove Variable_2 and Variable_3
%$ try
%$ ts0{'Variable_@2,3@'} = [];
%$ t(1) = 1;
%$ catch
%$ t(1) = 0;
%$ end
%$
%$ if t(1)
%$ % Try to display Variable_2 and Variable_3 again (should fail because already removed)
%$ try
%$ ts0{'Variable_@2,3@'};
%$ t(2) = 0;
%$ catch
%$ t(2) = 1;
%$ end
%$ end
%$ T = all(t);
%@eof:23
\ No newline at end of file
...@@ -65,7 +65,7 @@ function B = subsref(A, S) % --*-- Unitary tests --*-- ...@@ -65,7 +65,7 @@ function B = subsref(A, S) % --*-- Unitary tests --*--
switch S(1).type switch S(1).type
case '.' case '.'
switch S(1).subs 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) 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!']) error(['dseries::subsref: ' S(1).subs ' is not a method but a member!'])
end end
...@@ -75,6 +75,15 @@ switch S(1).type ...@@ -75,6 +75,15 @@ switch S(1).type
if length(S)>1 && isequal(S(2).type,'()') && isempty(S(2).subs) if length(S)>1 && isequal(S(2).type,'()') && isempty(S(2).subs)
S = shiftS(S,1); S = shiftS(S,1);
end 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. case {'lag','lead','hptrend','hpcycle','chain'} % Methods with less than two arguments.
if length(S)>1 && isequal(S(2).type,'()') if length(S)>1 && isequal(S(2).type,'()')
if isempty(S(2).subs) if isempty(S(2).subs)
...@@ -90,7 +99,7 @@ switch S(1).type ...@@ -90,7 +99,7 @@ switch S(1).type
else else
B = feval(S(1).subs,A); B = feval(S(1).subs,A);
end end
case {'cumsum','insert','pop','cumprod'} % Methods with less than three argument. case {'cumsum','insert','pop','cumprod','remove'} % Methods with less than three argument.
if length(S)>1 && isequal(S(2).type,'()') if length(S)>1 && isequal(S(2).type,'()')
if isempty(S(2).subs) if isempty(S(2).subs)
B = feval(S(1).subs,A); B = feval(S(1).subs,A);
...@@ -170,8 +179,6 @@ switch S(1).type ...@@ -170,8 +179,6 @@ switch S(1).type
B.tex = deblank(A.tex(ndx,:)); B.tex = deblank(A.tex(ndx,:));
B.nobs = A.nobs; B.nobs = A.nobs;
B.vobs = 1; B.vobs = 1;
B.freq = A.freq;
B.init = A.init;
B.dates = A.dates; B.dates = A.dates;
else else
error('dseries::subsref: Unknown public method, public member or variable!') error('dseries::subsref: Unknown public method, public member or variable!')
...@@ -227,29 +234,9 @@ switch S(1).type ...@@ -227,29 +234,9 @@ switch S(1).type
B.tex = A.tex; B.tex = A.tex;
B.nobs = length(tdx); B.nobs = length(tdx);
B.vobs = A.vobs; B.vobs = A.vobs;
B.freq = A.freq;
B.init = A.init+(tdx(1)-1);
B.dates = A.dates(tdx); B.dates = A.dates(tdx);
elseif isvector(S(1).subs{1}) && all(isint(S(1).subs{1})) elseif isvector(S(1).subs{1}) && all(isint(S(1).subs{1}))
% Extract a subsample using a vector of integers (observation index). error('dseries::subsref: It is not possible to select observations with a vector of integers. You have to index with a dates object instead!');
% Note that this does not work if S(1).subs is an integer scalar... In which case S(1).subs is interpreted as a lead/lag operator (as in the Dynare syntax).
% To extract one observation, a dates with one element input must be used.
if all(S(1).subs{1}>0) && all(S(1).subs{1}<=A.nobs)
if size(A.data,2)>1
S(1).subs = [S(1).subs, ':'];
end
B = dseries();
B.data = builtin('subsref', A.data, S(1));
B.nobs = size(B.data,1);
B.vobs = A.vobs;
B.freq = A.freq;
B.dates = A.dates(S(1).subs{1});
B.init = B.dates(1);
B.name = A.name;
B.tex = A.tex;
else
error('dseries::subsref: Indices are out of bounds!')
end
else else
error('dseries::subsref: I have no idea of what you are trying to do!') error('dseries::subsref: I have no idea of what you are trying to do!')
end end
...@@ -267,8 +254,6 @@ switch S(1).type ...@@ -267,8 +254,6 @@ switch S(1).type
B.tex = A.tex(idx); B.tex = A.tex(idx);
B.nobs = A.nobs; B.nobs = A.nobs;
B.vobs = length(idx); B.vobs = length(idx);
B.freq = A.freq;
B.init = A.init;
B.dates = A.dates; B.dates = A.dates;
else else
error('dseries::subsref: What the Hell are you tryin'' to do?!') error('dseries::subsref: What the Hell are you tryin'' to do?!')
...@@ -293,7 +278,7 @@ end ...@@ -293,7 +278,7 @@ end
%$ ts1 = dseries(A,[],A_name,[]); %$ ts1 = dseries(A,[],A_name,[]);
%$ %$
%$ % Call the tested method. %$ % Call the tested method.
%$ a = ts1(2:9); %$ a = ts1(ts1.dates(2:9));
%$ %$
%$ % Expected results. %$ % Expected results.
%$ e.data = [transpose(2:9),2*transpose(2:9)]; %$ e.data = [transpose(2:9),2*transpose(2:9)];
...@@ -653,7 +638,7 @@ end ...@@ -653,7 +638,7 @@ end
%@test:15 %@test:15
%$ try %$ try
%$ ds = dseries(transpose(1:5)); %$ ds = dseries(transpose(1:5));
%$ ts = ds(2:3); %$ ts = ds(ds.dates(2:3));
%$ t(1) = 1; %$ t(1) = 1;
%$ catch %$ catch
%$ t(1) = 0; %$ t(1) = 0;
...@@ -670,7 +655,7 @@ end ...@@ -670,7 +655,7 @@ end
%@test:16 %@test:16
%$ try %$ try
%$ ds = dseries(transpose(1:5)); %$ ds = dseries(transpose(1:5));
%$ ts = ds(2:6); %$ ts = ds(ds.dates(2:6));
%$ t(1) = 0; %$ t(1) = 0;
%$ catch %$ catch
%$ t(1) = 1; %$ t(1) = 1;
......
...@@ -42,10 +42,8 @@ function A = uminus(B) % --*-- Unitary tests --*-- ...@@ -42,10 +42,8 @@ function A = uminus(B) % --*-- Unitary tests --*--
A = dseries(); A = dseries();
A.freq = B.freq;
A.nobs = B.nobs; A.nobs = B.nobs;
A.vobs = B.vobs; A.vobs = B.vobs;
A.init = B.init;
A.dates = B.dates; A.dates = B.dates;
A.name = cell(A.vobs,1); A.name = cell(A.vobs,1);
A.tex = cell(A.vobs,1); A.tex = cell(A.vobs,1);
......
...@@ -60,7 +60,7 @@ end ...@@ -60,7 +60,7 @@ end
function d = vertcat_(b, c) function d = vertcat_(b, c)
d = NaN; d = NaN;
if ~isequal(b.freq, c.freq) if ~isequal(frequency(b), frequency(c))
error('dseries::vertcat: Frequencies must be common!') error('dseries::vertcat: Frequencies must be common!')
end end
if ~isequal(b.vobs, c.vobs) if ~isequal(b.vobs, c.vobs)
......