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
Select Git revision
  • dynare-4.6
  • dynare-5.x
  • dynare-6.x
  • master
  • master-dist
  • master-with-fame-io
  • old-oop-style
  • path_setting
8 results

Target

Select target project
  • Dynare/dseries
  • sebastien/dseries
  • houtanb/dseries
  • DoraK/dseries
  • wmutschl/dseries
  • JohannesPfeifer/dseries
6 results
Select Git revision
  • dynare-4.6
  • dynare-4.7
  • fractional_ticks
  • master
  • master-dist
  • master-with-fame-io
  • old-oop-style
  • path_setting
  • xls_range
9 results
Show changes
Showing
with 237 additions and 104 deletions
function l = exist(o, varname) % --*-- Unitary tests --*--
function l = exist(o, varname)
% Tests if a variable exists in dseries object o.
%
......@@ -9,7 +9,7 @@ function l = exist(o, varname) % --*-- Unitary tests --*--
% OUTPUTS
% - l [logical], equal to 1 (true) iff varname is a variable in dseries object o.
% Copyright © 2014-2021 Dynare Team
% Copyright © 2014-2023 Dynare Team
%
% This file is part of Dynare.
%
......@@ -28,7 +28,7 @@ function l = exist(o, varname) % --*-- Unitary tests --*--
if ~ischar(varname)
if isempty(inputname(2))
error(['dseries::exist: Input argument (variable name) has to be string!'])
error('dseries::exist: Input argument (variable name) has to be string!')
else
error(['dseries::exist: Second input argument ''' inputname(2) ''' has to be string!'])
end
......@@ -36,7 +36,7 @@ end
l = ~isempty(strmatch(varname, o.name, 'exact'));
return
return % --*-- Unit tests --*--
%@test:1
% Define a datasets.
......
function o = exp(o) % --*-- Unitary tests --*--
function o = exp(o)
% Apply the exponential to all the variables in a dseries object (without in place modification).
%
......@@ -8,7 +8,7 @@ function o = exp(o) % --*-- Unitary tests --*--
% OUTPUTS
% - o [dseries]
% Copyright © 2011-2021 Dynare Team
% Copyright © 2011-2023 Dynare Team
%
% This file is part of Dynare.
%
......@@ -28,7 +28,7 @@ function o = exp(o) % --*-- Unitary tests --*--
o = copy(o);
o.exp_();
return
return % --*-- Unit tests --*--
%@test:1
% Define a dates object
......@@ -79,4 +79,4 @@ if t(1)
end
T = all(t);
%@eof:2
\ No newline at end of file
%@eof:2
function o = exp_(o) % --*-- Unitary tests --*--
function o = exp_(o)
% Apply the exponential to all the variables in a dseries object (in place modification).
%
......@@ -8,7 +8,7 @@ function o = exp_(o) % --*-- Unitary tests --*--
% OUTPUTS
% - o [dseries]
% Copyright © 2015-2021 Dynare Team
% Copyright © 2015-2023 Dynare Team
%
% This file is part of Dynare.
%
......@@ -35,7 +35,7 @@ for i=1:vobs(o)
end
end
return
return % --*-- Unit tests --*--
%@test:1
% Define a dates object
......@@ -93,4 +93,4 @@ if t(1)
end
T = all(t);
%@eof:2
\ No newline at end of file
%@eof:2
function p = extract(o, varargin) % --*-- Unitary tests --*--
function p = extract(o, varargin)
% Extract some variables from a database.
% Copyright © 2012-2021 Dynare Team
% Copyright © 2012-2023 Dynare Team
%
% This file is part of Dynare.
%
......@@ -99,7 +99,7 @@ p.name = o.name(idVariableName);
p.tex = o.tex(idVariableName);
p.ops = o.ops(idVariableName);
return
return % --*-- Unit tests --*--
%@test:1
% Define a data set.
......@@ -189,4 +189,4 @@ if t(1)
end
T = all(t);
%@eof:3
\ No newline at end of file
%@eof:3
function o = fill_(o, name, value)
% Fills a dseries object.
%
% INPUTS
% - o [dseries]
% - name [char, cell] row char arry or cell of row char arrays.
% - value [double] scalar, vector or matrix.
% Copyright © 2023 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 <https://www.gnu.org/licenses/>.
if ischar(name)
name = {name};
end
if iscell(name) & (rows(name)==1 || columns(name)==1)
for i=1:length(name)
id = find(strcmp(name{i}, o.name));
if isempty(id)
error('dseries::fill: Variable %s is unknown.', name{i})
else
if isscalar(value)
o.data(:,id) = value;
elseif isvector(value) && length(value)==length(name)
o.data(:,id) = value(i);
elseif ismatrix(value) && columns(value)==length(name) && rows(value)==nobs(o)
o.data(:,id) = value(:,i);
else
error('dseries::fill: dimension of the last argument is not correct.')
end
end
end
else
error('dseries::fill: Argument must be a row char array or a cell array of row char arrays')
end
return % --*-- Unit tests --*--
%@test:1
% Define a dates object
o = dseries(randn(10,5));
% Call the tested routine.
try
o.fill_('Variable_1', NaN);
t(1) = true;
catch
t(1) = false;
end
if t(1)
t(2) = all(isnan(o.data(:,1)));
end
T = all(t);
%@eof:1
%@test:2
% Define a dates object
o = dseries(randn(10,5));
% Call the tested routine.
try
o.fill_({'Variable_1' 'Variable_3'}, NaN);
t(1) = true;
catch
t(1) = false;
end
if t(1)
t(2) = all(isnan(o.data(:,1)));
t(3) = all(isnan(o.data(:,3)));
end
T = all(t);
%@eof:2
%@test:3
% Define a dates object
o = dseries(randn(10,5));
% Call the tested routine.
try
o.fill_({'Variable_1' 'Variable_3'}, [1 2]);
t(1) = true;
catch
t(1) = false;
end
if t(1)
t(2) = all(o.data(:,1)==1);
t(3) = all(o.data(:,3)==2);
end
T = all(t);
%@eof:3
%@test:4
% Define a dates object
o = dseries(randn(10,5));
% Call the tested routine.
try
o.fill_({'Variable_1' 'Variable_3'}, [ones(10,1) zeros(10,1)]);
t(1) = true;
catch
t(1) = false;
end
if t(1)
t(2) = all(o.data(:,1)==1);
t(3) = all(o.data(:,3)==0);
end
T = all(t);
%@eof:4
function f = firstdate(o) % --*-- Unitary tests --*--
function f = firstdate(o)
% Copyright © 2014-2021 Dynare Team
% Copyright © 2014-2023 Dynare Team
%
% This file is part of Dynare.
%
......@@ -19,7 +19,7 @@ function f = firstdate(o) % --*-- Unitary tests --*--
f = o.dates(1);
return
return % --*-- Unit tests --*--
%@test:1
try
......
function d = firstobservedperiod(o) % --*-- Unitary tests --*--
function d = firstobservedperiod(o)
% Returns the first period where all the variables are observed (first period without NaNs).
%
......@@ -8,7 +8,7 @@ function d = firstobservedperiod(o) % --*-- Unitary tests --*--
% OUTPUTS
% - d [dates] First period where the N variables are observed (without NaNs).
% Copyright © 2016-2021 Dynare Team
% Copyright © 2016-2023 Dynare Team
%
% This file is part of Dynare.
%
......@@ -34,7 +34,7 @@ end
d = firstdate(o)+(c(1)-1);
return
return % --*-- Unit tests --*--
%@test:1
try
......
function o = flip(o) % --*-- Unitary tests --*--
function o = flip(o)
% Flips the rows in the data member (without changing the
% periods order)
......@@ -9,7 +9,7 @@ function o = flip(o) % --*-- Unitary tests --*--
% OUTPUTS
% - o [dseries]
% Copyright © 2020 Dynare Team
% Copyright © 2020-2023 Dynare Team
%
% This file is part of Dynare.
%
......@@ -29,7 +29,8 @@ function o = flip(o) % --*-- Unitary tests --*--
o = copy(o);
o.flip_;
return
return % --*-- Unit tests --*--
%@test:1
% Define a dates object
data = transpose(1:3);
......@@ -50,4 +51,4 @@ if t(1)
end
T = all(t);
%@eof:1
\ No newline at end of file
%@eof:1
function o = flip_(o) % --*-- Unitary tests --*--
function o = flip_(o)
% Flips the rows in the data member (without changing the
% periods order)
......@@ -9,7 +9,7 @@ function o = flip_(o) % --*-- Unitary tests --*--
% OUTPUTS
% - o [dseries]
% Copyright © 2020 Dynare Team
% Copyright © 2020-2023 Dynare Team
%
% This file is part of Dynare.
%
......@@ -36,7 +36,8 @@ end
o.data = flipud(o.data);
return
return % --*-- Unit tests --*--
%@test:1
% Define a dates object
data = [transpose(1:3) transpose(4:6)];
......@@ -67,35 +68,35 @@ T = all(t);
%@eof:1
%@test:2
%$ % Define a dates object
%$ data = [ones(10,1), -ones(10,1)];
%$ o = dseries(data);
%$ q = o;
%$ r = copy(o);
%$
%$ % Call the tested routine.
%$ try
%$ o.abs_();
%$ t(1) = true;
%$ catch
%$ t(1) = false;
%$ end
%$
%$ if t(1)
%$ t(2) = dassert(length(o.name), 2);
%$ t(3) = dassert(o.name{1},'Variable_1');
%$ t(4) = dassert(o.name{2},'Variable_2');
%$ t(5) = dassert(q.name{1},'Variable_1');
%$ t(6) = dassert(q.name{2},'Variable_2');
%$ t(7) = dassert(r.name{1},'Variable_1');
%$ t(8) = dassert(r.name{2},'Variable_2');
%$ t(9) = dassert(o.ops{1},'abs(Variable_1)');
%$ t(10) = dassert(o.ops{2},'abs(Variable_2)');
%$ t(11) = dassert(q.ops{1},'abs(Variable_1)');
%$ t(12) = dassert(q.ops{2},'abs(Variable_2)');
%$ t(13) = isempty(r.ops{1});
%$ t(14) = isempty(r.ops{2});
%$ end
%$
%$ T = all(t);
%@eof:2
\ No newline at end of file
% Define a dates object
data = [ones(10,1), -ones(10,1)];
o = dseries(data);
q = o;
r = copy(o);
% Call the tested routine.
try
o.abs_();
t(1) = true;
catch
t(1) = false;
end
if t(1)
t(2) = dassert(length(o.name), 2);
t(3) = dassert(o.name{1},'Variable_1');
t(4) = dassert(o.name{2},'Variable_2');
t(5) = dassert(q.name{1},'Variable_1');
t(6) = dassert(q.name{2},'Variable_2');
t(7) = dassert(r.name{1},'Variable_1');
t(8) = dassert(r.name{2},'Variable_2');
t(9) = dassert(o.ops{1},'abs(Variable_1)');
t(10) = dassert(o.ops{2},'abs(Variable_2)');
t(11) = dassert(q.ops{1},'abs(Variable_1)');
t(12) = dassert(q.ops{2},'abs(Variable_2)');
t(13) = isempty(r.ops{1});
t(14) = isempty(r.ops{2});
end
T = all(t);
%@eof:2
......@@ -8,7 +8,7 @@ function f = frequency(o)
% OUPUTS
% - f [integer] 1 (annual), 4 (quarterly), 12 (monthly)
% Copyright (C) 2014-2017 Dynare Team
% Copyright © 2014-2017 Dynare Team
%
% This file is part of Dynare.
%
......
function l = ge(varargin) % --*-- Unitary tests --*--
function l = ge(varargin)
% Overloads the >= operator for dseries objects.
% Copyright © 2021 Dynare Team
% Copyright © 2021-2023 Dynare Team
%
% This code is free software: you can redistribute it and/or modify
% it under the terms of the GNU General Public License as published by
......@@ -25,4 +25,4 @@ elseif isdseries(varargin{1}) && isdseries(varargin{2})
l = varargin{1}.data>=varargin{2}.data;
else
error('dseries::ge: wrong types.')
end
\ No newline at end of file
end
function l = gt(varargin) % --*-- Unitary tests --*--
function l = gt(varargin)
% Overloads the > operator for dseries objects.
% Copyright © 2021 Dynare Team
% Copyright © 2021-2023 Dynare Team
%
% This code is free software: you can redistribute it and/or modify
% it under the terms of the GNU General Public License as published by
......@@ -25,4 +25,4 @@ elseif isdseries(varargin{1}) && isdseries(varargin{2})
l = varargin{1}.data>varargin{2}.data;
else
error('dseries::gt: wrong types.')
end
\ No newline at end of file
end
function o = hdiff(o) % --*-- Unitary tests --*--
function o = hdiff(o)
% Computes bi-annual differences.
%
......@@ -8,7 +8,7 @@ function o = hdiff(o) % --*-- Unitary tests --*--
% OUTPUTS
% - o [dseries]
% Copyright © 2020-2021 Dynare Team
% Copyright © 2020-2023 Dynare Team
%
% This file is part of Dynare.
%
......@@ -28,7 +28,7 @@ function o = hdiff(o) % --*-- Unitary tests --*--
o = copy(o);
o.hdiff_();
return
return % --*-- Unit tests --*--
%@test:1
try
......@@ -48,4 +48,4 @@ if t(1)
end
T = all(t);
%@eof:1
\ No newline at end of file
%@eof:1
function o = hdiff_(o) % --*-- Unitary tests --*--
function o = hdiff_(o)
% Computes bi-annual differences.
%
......@@ -8,7 +8,7 @@ function o = hdiff_(o) % --*-- Unitary tests --*--
% OUTPUTS
% - o [dseries]
% Copyright © 2020-2021 Dynare Team
% Copyright © 2020-2023 Dynare Team
%
% This file is part of Dynare.
%
......@@ -53,7 +53,7 @@ for i = 1:vobs(o)
end
end
return
return % --*-- Unit tests --*--
%@test:1
try
......@@ -70,7 +70,7 @@ if t(1)
DATA = NaN(2,ts.vobs);
DATA = [DATA; 2*ones(ts.nobs-2,ts.vobs)];
t(2) = dassert(ts.data,DATA);
t(3) = dassert(ts.ops{1},['hdiff(H1)']);
t(3) = dassert(ts.ops{1},'hdiff(H1)');
end
T = all(t);
......@@ -91,7 +91,7 @@ if t(1)
DATA = NaN(6,ts.vobs);
DATA = [DATA; 6*ones(ts.nobs-6,ts.vobs)];
t(2) = dassert(ts.data,DATA);
t(3) = dassert(ts.ops{1},['hdiff(H1)']);
t(3) = dassert(ts.ops{1},'hdiff(H1)');
end
T = all(t);
......@@ -137,8 +137,8 @@ if t(1)
DATA = NaN(1,ts.vobs);
DATA = [DATA; ones(ts.nobs-1,ts.vobs)];
t(2) = dassert(ts.data,DATA);
t(3) = dassert(ts.ops{1},['hdiff(H1)']);
t(3) = dassert(ts.ops{1},'hdiff(H1)');
end
T = all(t);
%@eof:5
\ No newline at end of file
%@eof:5
function o = hgrowth(o) % --*-- Unitary tests --*--
function o = hgrowth(o)
% Computes bi-annual growth rates.
%
......@@ -8,7 +8,7 @@ function o = hgrowth(o) % --*-- Unitary tests --*--
% OUTPUTS
% - o [dseries]
% Copyright © 2020-2021 Dynare Team
% Copyright © 2020-2023 Dynare Team
%
% This file is part of Dynare.
%
......@@ -28,7 +28,7 @@ function o = hgrowth(o) % --*-- Unitary tests --*--
o = copy(o);
o.hgrowth_();
return
return % --*-- Unit tests --*--
%@test:1
t = zeros(2,1);
......@@ -51,4 +51,4 @@ if length(t)>1
end
T = all(t);
%@eof:1
\ No newline at end of file
%@eof:1
function o = hgrowth_(o) % --*-- Unitary tests --*--
function o = hgrowth_(o)
% Computes bi-annual growth rates.
%
......@@ -8,7 +8,7 @@ function o = hgrowth_(o) % --*-- Unitary tests --*--
% OUTPUTS
% - o [dseries]
% Copyright © 2020-2021 Dynare Team
% Copyright © 2020-2023 Dynare Team
%
% This file is part of Dynare.
%
......@@ -53,7 +53,7 @@ for i = 1:vobs(o)
end
end
return
return % --*-- Unit tests --*--
%@test:1
try
......
function o = horzcat(varargin) % --*-- Unitary tests --*--
function o = horzcat(varargin)
% Overloads horzcat method for dseries objects.
%
......@@ -20,7 +20,7 @@ function o = horzcat(varargin) % --*-- Unitary tests --*--
% REMARKS
% o o1, o2, ... must not have common variables.
% Copyright © 2011-2021 Dynare Team
% Copyright © 2011-2023 Dynare Team
%
% This file is part of Dynare.
%
......@@ -136,7 +136,7 @@ else
a.dates = sort(unique(hd));
end
return
return % --*-- Unit tests --*--
%@test:1
% Define a data set.
......
function o = hpcycle(o, lambda) % --*-- Unitary tests --*--
function o = hpcycle(o, lambda)
% Extracts the cycle component from a dseries object using Hodrick Prescott filter.
%
......@@ -9,7 +9,7 @@ function o = hpcycle(o, lambda) % --*-- Unitary tests --*--
% OUTPUTS
% - o [dseries] Cyclical component of the original time series.
% Copyright © 2013-2021 Dynare Team
% Copyright © 2013-2023 Dynare Team
%
% This file is part of Dynare.
%
......@@ -28,7 +28,7 @@ function o = hpcycle(o, lambda) % --*-- Unitary tests --*--
if nargin>1
if lambda<=0
error(['dseries::hpcycle: Lambda must be a positive integer!'])
error('dseries::hpcycle: Lambda must be a positive integer!')
end
else
lambda = [];
......@@ -37,7 +37,7 @@ end
o = copy(o);
o.hpcycle_(lambda);
return
return % --*-- Unit tests --*--
%@test:1
d = randn(100,1);
......@@ -55,4 +55,4 @@ if t(1)
end
T = all(t);
%@eof:1
\ No newline at end of file
%@eof:1
function o = hpcycle_(o, lambda) % --*-- Unitary tests --*--
function o = hpcycle_(o, lambda)
% Extracts the cycle component from a dseries object using Hodrick Prescott filter.
%
......@@ -9,7 +9,7 @@ function o = hpcycle_(o, lambda) % --*-- Unitary tests --*--
% OUTPUTS
% - o [dseries] Cyclical component of the original time series.
% Copyright © 2013-2021 Dynare Team
% Copyright © 2013-2023 Dynare Team
%
% This file is part of Dynare.
%
......@@ -28,7 +28,7 @@ function o = hpcycle_(o, lambda) % --*-- Unitary tests --*--
if nargin>1
if lambda<=0
error(['dseries::hpcycle: Lambda must be a positive integer!'])
error('dseries::hpcycle: Lambda must be a positive integer!')
end
else
lambda = [];
......@@ -53,7 +53,7 @@ for i=1:vobs(o)
end
end
return
return % --*-- Unit tests --*--
%@test:1
plot_flag = false;
......@@ -104,4 +104,4 @@ if plot_flag
end
T = all(t);
%@eof:1
\ No newline at end of file
%@eof:1
function o = hptrend(o, lambda) % --*-- Unitary tests --*--
function o = hptrend(o, lambda)
% Extracts the trend component from a dseries object using Hodrick Prescott filter.
%
......@@ -9,7 +9,7 @@ function o = hptrend(o, lambda) % --*-- Unitary tests --*--
% OUTPUTS
% - o [dseries] Trend component of the original time series.
% Copyright © 2013-2021 Dynare Team
% Copyright © 2013-2023 Dynare Team
%
% This file is part of Dynare.
%
......@@ -28,7 +28,7 @@ function o = hptrend(o, lambda) % --*-- Unitary tests --*--
if nargin>1
if lambda<=0
error(['dseries::hptrend: Lambda must be a positive integer!'])
error('dseries::hptrend: Lambda must be a positive integer!')
end
else
lambda = [];
......@@ -37,7 +37,7 @@ end
o = copy(o);
o.hptrend_(lambda);
return
return % --*-- Unit tests --*--
%@test:1
d = randn(100,1);
......@@ -55,4 +55,4 @@ if t(1)
end
T = all(t);
%@eof:1
\ No newline at end of file
%@eof:1