Commit bf79dbce authored by Stéphane Adjemian's avatar Stéphane Adjemian Committed by Stéphane Adjemian

Rewrote headers + Cosmetic changes.

parent dacdb39f
function us = lag(ts,p) % --*-- Unitary tests --*-- function q = lag(o, p) % --*-- Unitary tests --*--
%@info: % Returns a lagged time series
%! @deftypefn {Function File} {@var{us} =} lag (@var{ts}) %
%! @anchor{lag} % INPUTS
%! @sp 1 % - o [dseries]
%! Computes lagged time series. % - p [integer] Number of lags
%! @sp 2 %
%! @strong{Inputs} % OUTPUTS
%! @sp 1 % - o [dseries]
%! @table @var %
%! @item ts % EXAMPLE
%! Dynare time series object, instantiated by @ref{dseries} % Define a dseries object as follows:
%! @end table %
%! @sp 2 % >> o = dseries(transpose(1:5))
%! @strong{Outputs} %
%! @sp 1 % then o.lag(1) returns
%! @table @var %
%! @item us % | lag(Variable_1,1)
%! Dynare time series object with transformed data field. % 1Y | NaN
%! @end table % 2Y | 1
%! @end deftypefn % 3Y | 2
%@eod: % 4Y | 3
% 5Y | 4
% Copyright (C) 2013 Dynare Team % Copyright (C) 2013-2015 Dynare Team
% %
% This file is part of Dynare. % This file is part of Dynare.
% %
...@@ -44,19 +45,24 @@ if nargin<2 ...@@ -44,19 +45,24 @@ if nargin<2
p = 1; p = 1;
end end
% Check second input argument
if p<=0 if p<=0
error('dseries::lag: Second input argument must be strictly positive! Use lead method instead.') error('dseries:WrongInputArguments','Second input argument must be strictly positive! Use lead method instead.')
end
if ~isint(p)
error('dseries:WrongInputArguments','Second input argument must be an integer!')
end end
% Copy of ts dseries object % Copy of ts dseries object
us = ts; q = copy(o);
% Update data member % Update data member
us.data = [NaN(p, vobs(ts)); ts.data(1:end-p,:)]; q.data = [NaN(p, vobs(o)); q.data(1:end-p,:)];
for i=1:vobs(ts) for i=1:vobs(o)
us.name(i) = {[ 'lag(' ts.name{i} ',' int2str(p) ')']}; q.name(i) = {[ 'lag(' o.name{i} ',' int2str(p) ')']};
us.tex(i) = {[ ts.tex{i} '_{-' int2str(p) '}']}; q.tex(i) = {[ o.tex{i} '_{-' int2str(p) '}']};
end end
%@test:1 %@test:1
...@@ -68,12 +74,12 @@ end ...@@ -68,12 +74,12 @@ end
%$ a = ts.lag; %$ a = ts.lag;
%$ b = ts.lag.lag; %$ b = ts.lag.lag;
%$ c = lag(ts,2); %$ c = lag(ts,2);
%$ t(1) = 1; %$ t(1) = true;
%$ catch %$ catch
%$ t = 0; %$ t(1) = false;
%$ end %$ end
%$ %$
%$ if length(t)>1 %$ if t(1)
%$ DATA = [NaN(1,ts.vobs); transpose(0:1:49)]; %$ DATA = [NaN(1,ts.vobs); transpose(0:1:49)];
%$ t(2) = dassert(a.data,DATA,1e-15); %$ t(2) = dassert(a.data,DATA,1e-15);
%$ DATA = [NaN(2,ts.vobs); transpose(0:1:48)]; %$ DATA = [NaN(2,ts.vobs); transpose(0:1:48)];
......
function us = lead(ts,p) % --*-- Unitary tests --*-- function q = lead(o, p) % --*-- Unitary tests --*--
%@info: % Returns a lagged time series
%! @deftypefn {Function File} {@var{us} =} lead (@var{ts}) %
%! @anchor{lag} % INPUTS
%! @sp 1 % - o [dseries]
%! Computes leaded time series. % - p [integer] Number of leads
%! @sp 2 %
%! @strong{Inputs} % OUTPUTS
%! @sp 1 % - o [dseries]
%! @table @var %
%! @item ts % EXAMPLE
%! Dynare time series object, instantiated by @ref{dseries} % Define a dseries object as follows:
%! @end table %
%! @sp 2 % >> o = dseries(transpose(1:5))
%! @strong{Outputs} %
%! @sp 1 % then o.lag(1) returns
%! @table @var %
%! @item us % | lead(Variable_1,1)
%! Dynare time series object with transformed data field. % 1Y | 2
%! @end table % 2Y | 3
%! @end deftypefn % 3Y | 4
%@eod: % 4Y | 5
% 5Y | NaN
% Copyright (C) 2013 Dynare Team % Copyright (C) 2013-2015 Dynare Team
% %
% This file is part of Dynare. % This file is part of Dynare.
% %
...@@ -44,41 +45,45 @@ if nargin<2 ...@@ -44,41 +45,45 @@ if nargin<2
p = 1; p = 1;
end end
% Check second input argument
if p<=0 if p<=0
error('dseries::lead: Second input argument must be strictly positive! Use lag method instead.') error('dseries:WrongInputArguments','Second input argument must be strictly positive! Use lag method instead.')
end
if ~isint(p)
error('dseries:WrongInputArguments','Second input argument must be an integer!')
end end
% Copy of ts dseries object % Copy of ts dseries object
us = ts; q = copy(o);
% Update data member % Update data member
us.data = [ ts.data(p+1:end,:); NaN(p, vobs(ts));]; q.data = [ o.data(p+1:end,:); NaN(p, vobs(o));];
for i=1:vobs(ts) for i=1:vobs(o)
us.name(i) = {[ 'lead(' ts.name{i} ',' int2str(p) ')']}; q.name(i) = {[ 'lead(' q.name{i} ',' int2str(p) ')']};
us.tex(i) = {[ ts.tex{i} '_{+' int2str(p) '}']}; q.tex(i) = {[ q.tex{i} '_{+' int2str(p) '}']};
end end
%@test:1 %@test:1
%$ t = zeros(4,1);
%$
%$ try %$ try
%$ data = transpose(0:1:50); %$ data = transpose(1:50);
%$ ts = dseries(data,'1950Q1'); %$ ts = dseries(data,'1950Q1');
%$ a = ts.lead; %$ a = ts.lead;
%$ b = ts.lead.lead; %$ b = ts.lead.lead;
%$ c = lead(ts,2); %$ c = lead(ts,2);
%$ t(1) = 1; %$ t(1) = true;
%$ catch %$ catch
%$ t = 0; %$ t(1) = false;
%$ end %$ end
%$ %$
%$ if length(t)>1 %$ if t(1)
%$ DATA = [transpose(1:50); NaN(1,ts.vobs)]; %$
%$ t(2) = dassert(a.data,DATA,1e-15); %$ DATA = [data(2:end); NaN(1)];
%$ DATA = [transpose(2:50); NaN(2,ts.vobs)]; %$ t(2) = dassert(a.data, DATA, 1e-15);
%$ t(3) = dassert(b.data,DATA,1e-15); %$ DATA = [data(3:end); NaN(2,1)];
%$ t(4) = dassert(b.data,c.data,1e-15); %$ t(3) = dassert(b.data, DATA, 1e-15);
%$ t(4) = dassert(c.data, DATA, 1e-15);
%$ end %$ end
%$ %$
%$ T = all(t); %$ T = all(t);
......
function A = minus(B,C) % --*-- Unitary tests --*-- function q = minus(o, p) % --*-- Unitary tests --*--
%@info: % Overloads the minus operator for dseries objects.
%! @deftypefn {Function File} {@var{A} =} minus (@var{B},@var{C}) %
%! @anchor{@dseries/minus} % INPUTS
%! @sp 1 % - o [dseries]
%! Overloads the minus method for the Dynare time series class (@ref{dseries}). % - p [dseries]
%! @sp 2 %
%! @strong{Inputs} % OUTPUTS
%! @sp 1 % - q [dseries]
%! @table @ @var %
%! @item B % EXAMPLE
%! Dynare time series object instantiated by @ref{dseries}. % Define a dseries object:
%! @item C %
%! Dynare time series object instantiated by @ref{dseries}. % >> a = dseries(transpose(1:5));
%! @end table %
%! @sp 1 % Then we have
%! @strong{Outputs} %
%! @sp 1 % >> a-a
%! @table @ @var %
%! @item A % ans is a dseries object:
%! Dynare time series object. %
%! @end deftypefn % | minus(Variable_1;Variable_1)
%@eod: % 1Y | 0
% 2Y | 0
% Copyright (C) 2012-2014, Dynare Team % 3Y | 0
% 4Y | 0
% 5Y | 0
% Copyright (C) 2012-2015, Dynare Team
% %
% This file is part of Dynare. % This file is part of Dynare.
% %
...@@ -40,68 +44,68 @@ function A = minus(B,C) % --*-- Unitary tests --*-- ...@@ -40,68 +44,68 @@ function A = minus(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 isnumeric(B) && (isscalar(B) || isvector(B)) if isnumeric(o) && (isscalar(o) || isvector(o))
if ~isdseries(C) if ~isdseries(p)
error('dseries::minus: Second input argument must be a dseries object!') error('dseries:WrongInputArguments', 'Second input argument must be a dseries object!')
end end
A = C; q = copy(p);
A.data = bsxfun(@minus,B,C.data); q.data = bsxfun(@minus, o, p.data);
return; return;
end end
if isnumeric(C) && (isscalar(C) || isvector(C)) if isnumeric(p) && (isscalar(p) || isvector(p))
if ~isdseries(B) if ~isdseries(o)
error('dseries::minus: First input argument must be a dseries object!') error('dseries::minus: First input argument must be a dseries object!')
end end
A = B; q = copy(o);
A.data = bsxfun(@minus,B.data,C); q.data = bsxfun(@minus,o.data,p);
return return
end end
if ~isequal(vobs(B), vobs(C)) && ~(isequal(vobs(B),1) || isequal(vobs(C),1)) if ~isequal(vobs(o), vobs(p)) && ~(isequal(vobs(o),1) || isequal(vobs(p),1))
error(['dseries::minus: Cannot substract ' inputname(1) ' and ' inputname(2) ' (wrong number of variables)!']) error('dseries:WrongInputArguments', 'Cannot substract %s and %s (wrong number of variables)!', inputname(1), inputname(2))
else else
if vobs(B)>vobs(C) if vobs(o)>vobs(p)
idB = 1:vobs(B); ido = 1:vobs(o);
idC = ones(1:vobs(B)); idp = ones(1:vobs(o));
elseif vobs(B)<vobs(C) elseif vobs(o)<vobs(p)
idB = ones(1,vobs(C)); ido = ones(1,vobs(p));
idC = 1:vobs(C); idp = 1:vobs(p);
else else
idB = 1:vobs(B); ido = 1:vobs(o);
idC = 1:vobs(C); idp = ido;
end end
end end
if ~isequal(frequency(B),frequency(C)) if ~isequal(frequency(o),frequency(p))
error(['dseries::plus: Cannot substract ' inputname(1) ' and ' inputname(2) ' (frequencies are different)!']) error('dseries:WrongInputArguments', 'Cannot substract %s and %s (frequencies are different)!', inputname(1), inputname(2))
end end
if ~isequal(nobs(B), nobs(C)) || ~isequal(firstdate(B),firstdate(C)) if ~isequal(nobs(o), nobs(p)) || ~isequal(firstdate(o),firstdate(p))
[B, C] = align(B, C); [o, p] = align(o, p);
end end
if isempty(B) if isempty(o)
A = -C; q = -copy(p);
return return
end end
if isempty(C) if isempty(p)
A = B; q = copy(o);
return return
end end
A = dseries(); q = dseries();
A.dates = B.dates; q.dates = o.dates;
A_vobs = max(vobs(B), vobs(C)); q_vobs = max(vobs(o), vobs(p));
A.name = cell(A_vobs,1); q.name = cell(q_vobs,1);
A.tex = cell(A_vobs,1); q.tex = cell(q_vobs,1);
for i=1:A_vobs for i=1:q_vobs
A.name(i) = {['minus(' B.name{idB(i)} ';' C.name{idC(i)} ')']}; q.name(i) = {['minus(' o.name{ido(i)} ';' p.name{idp(i)} ')']};
A.tex(i) = {['(' B.tex{idB(i)} '-' C.tex{idC(i)} ')']}; q.tex(i) = {['(' o.tex{ido(i)} '-' p.tex{idp(i)} ')']};
end end
A.data = bsxfun(@minus,B.data,C.data); q.data = bsxfun(@minus, o.data, p.data);
%@test:1 %@test:1
%$ % Define a datasets. %$ % Define a datasets.
......
function A = mpower(B,C) % --*-- Unitary tests --*-- function q = mpower(o, p) % --*-- Unitary tests --*--
%@info: % Overloads the power (^) operator for dseries objects.
%! @deftypefn {Function File} {@var{A} =} mpower (@var{B},@var{C}) %
%! @anchor{@dseries/mpower} % INPUTS
%! @sp 1 % - o [dseries] A dseries object with T observations and N variables.
%! Overloads the mpower method for the Dynare time series class (@ref{dseries}). % - p [real] A real scalar.
%! @sp 2 %
%! @strong{Inputs} % OUTPUTS
%! @sp 1 % - q [dseries] A dseries object with T observations and N variables.
%! @table @ @var
%! @item B
%! Dynare time series object instantiated by @ref{dseries}, with T observations and N variables.
%! @item C
%! Real scalar or a dseries object with T observations and N variables.
%! @end table
%! @sp 1
%! @strong{Outputs}
%! @sp 1
%! @table @ @var
%! @item A
%! dseries object with T observations and N variables.
%! @end deftypefn
%@eod:
% Copyright (C) 2013 Dynare Team % Copyright (C) 2013-2015 Dynare Team
% %
% This file is part of Dynare. % This file is part of Dynare.
% %
...@@ -40,55 +26,55 @@ function A = mpower(B,C) % --*-- Unitary tests --*-- ...@@ -40,55 +26,55 @@ 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 isnumeric(B) && isvector(B) && length(B)>1 if isnumeric(o) && isvector(o) && length(o)>1
if ~isdseries(C) if ~isdseries(p)
error('dseries::mpower: Second input argument must be a dseries object!') error('dseries:WrongInputArguments', 'Second input argument must be a dseries object!')
end end
A = C; q = copy(p);
A.data = bsxfun(@power,C.data,B); q.data = bsxfun(@power, p.data, o);
return; return;
end end
if isnumeric(C) && isvector(C) && length(C)>1 if isnumeric(p) && isvector(p) && length(p)>1
if ~isdseries(B) if ~isdseries(o)
error('dseries::mpower: First input argument must be a dseries object!') error('dseries:WrongInputArguments', 'First input argument must be a dseries object!')
end end
A = B; q = copy(o);
A.data = bsxfun(@power,B.data,C); q.data = bsxfun(@power, o.data, p);
return return
end end
if isdseries(B) && isnumeric(C) && isreal(C) && isscalar(C) if isdseries(o) && isnumeric(p) && isreal(p) && isscalar(p)
A = dseries(); q = dseries();
A.dates = B.dates; q.dates = o.dates;
A.data = B.data.^C; q.data = o.data.^p;
A.name = cell(vobs(A),1); q.name = cell(vobs(q),1);
A.tex = cell(vobs(A),1); q.tex = cell(vobs(q),1);
for i=1:vobs(A) for i=1:vobs(q)
A.name(i) = {['power(' B.name{i} ';' num2str(C) ')']}; q.name(i) = {['power(' o.name{i} ';' num2str(p) ')']};
A.tex(i) = {[B.tex{i} '^' num2str(C) ]}; q.tex(i) = {[o.tex{i} '^' num2str(p) ]};
end end
return return
end end
if isdseries(B) && isdseries(C) if isdseries(o) && isdseries(p)
if isequal(nobs(B),nobs(C)) && isequal(vobs(B), vobs(C)) && isequal(frequency(B),frequency(C)) if isequal(nobs(o),nobs(p)) && isequal(vobs(o), vobs(p)) && isequal(frequency(o),frequency(p))
A = dseries(); q = dseries();
A.data = B.data.^C.data; q.data = (o.data).^p.data;
A.dates = B.dates; q.dates = o.dates;
A.name = cell(vobs(A),1); q.name = cell(vobs(q),1);
A.tex = cell(vobs(A),1); q.tex = cell(vobs(q),1);
for i=1:vobs(A) for i=1:vobs(q)
A.name(i) = {['power(' B.name{i} ';' C.name{i} ')']}; q.name(i) = {['power(' o.name{i} ';' p.name{i} ')']};
A.tex(i) = {[B.tex{i} '^{' C.tex{i} '}']}; q.tex(i) = {[o.tex{i} '^{' p.tex{i} '}']};
end end
else else
error('dseries::mpower: If both input arguments are dseries objects, they must have the same numbers of variables and observations and common frequency!') error('dseries:WrongInputArguments', 'If both input arguments are dseries objects, they must have the same numbers of variables and observations and common frequency!')
end end
return return
end end
error(['dseries::mpower: Wrong calling sequence!']) error('dseries:WrongInputArguments', 'Wrong calling sequence! Please check the manual.')
%@test:1 %@test:1
%$ % Define a datasets. %$ % Define a datasets.
...@@ -103,9 +89,9 @@ error(['dseries::mpower: Wrong calling sequence!']) ...@@ -103,9 +89,9 @@ error(['dseries::mpower: Wrong calling sequence!'])
%$ ts1 = dseries(A,[],A_name,[]); %$ ts1 = dseries(A,[],A_name,[]);
%$ ts2 = dseries(B,[],B_name,[]); %$ ts2 = dseries(B,[],B_name,[]);
%$ ts3 = ts1^ts2; %$ ts3 = ts1^ts2;
%$ t = 1; %$ t(1) = true;
%$ catch %$ catch
%$ t = 0; %$ t(1) = false;
%$ end %$ end
%$ %$
%$ if t(1) %$ if t(1)
...@@ -130,9 +116,9 @@ error(['dseries::mpower: Wrong calling sequence!']) ...@@ -130,9 +116,9 @@ error(['dseries::mpower: Wrong calling sequence!'])
%$ try %$ try
%$ ts1 = dseries(A,[],A_name,[]); %$ ts1 = dseries(A,[],A_name,[]);
%$ ts3 = ts1^2; %$ ts3 = ts1^2;
%$ t = 1; %$ t(1) = true;
%$ catch %$ catch
%$ t = 0; %$ t(1) = false;
%$ end %$ end
%$ %$
%$ if t(1) %$ if t(1)
...@@ -152,9 +138,9 @@ error(['dseries::mpower: Wrong calling sequence!']) ...@@ -152,9 +138,9 @@ error(['dseries::mpower: Wrong calling sequence!'])
%$ % Use the power %$ % Use the power
%$ try %$ try
%$ ts2 = ts1^transpose(1:3); %$ ts2 = ts1^transpose(1:3);
%$ t = 1; %$ t(1) = true;
%$ catch %$ catch
%$ t = 0; %$ t(1) = false;
%$ end %$ end
%$ %$
%$ if t(1) %$ if t(1)
......
function A = plus(B,C) % --*-- Unitary tests --*-- function q = plus(o, p) % --*-- Unitary tests --*--
%@info: % Overloads the plus (+) operator for dseries objects.
%! @deftypefn {Function File} {@var{A} =} plus (@var{B},@var{C}) %
%! @anchor{@dseries/plus} % INPUTS
%! @sp 1 % - o [dseries, real]
%! Overloads the plus method for the Dynare time series class (@ref{dseries}). % - p [dseries, real]
%! @sp 2 %
%! @strong{Inputs} % OUTPUTS
%! @sp 1 % - q [dseries]
%! @table @ @var
%! @item B
%! Dynare time series object instantiated by @ref{dseries}.
%! @item C
%! Dynare time series object instantiated by @ref{dseries}.
%! @end table
%! @sp 1
%! @strong{Outputs}
%! @sp 1
%! @table @ @var
%! @item A
%! Dynare time series object.
%! @end deftypefn
%@eod:
% Copyright (C) 2011-2014 Dynare Team % Copyright (C) 2011-2015 Dynare Team
% %
% This file is part of Dynare. % This file is part of Dynare.
% %
...@@ -40,68 +26,68 @@ function A = plus(B,C) % --*-- Unitary tests --*-- ...@@ -40,68 +26,68 @@ function A = plus(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 isnumeric(B) && (isscalar(B) || isvector(B)) if isnumeric(o) && (isscalar(o) || isvector(o))
if ~isdseries(C) if ~isdseries(p)
error('dseries::plus: Second input argument must be a dseries object!') error('dseries::plus: Second input argument must be a dseries object!')
end end
A = C; q = copy(p);
A.data = bsxfun(@plus,C.data,B); q.data = bsxfun(@plus, q.data, o);
return; return
end end
if isnumeric(C) && (isscalar(C) || isvector(C)) if isnumeric(p) && (isscalar(p) || isvector(p))
if ~isdseries(B) if ~isdseries(o)