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