cumprod.m 2.25 KB
Newer Older
1
function o = cumprod(varargin) % --*-- Unitary tests --*--
2 3 4 5

% Overloads matlab's cumprod function for dseries objects.
%
% INPUTS
6 7 8
% - A     dseries object [mandatory].
% - d     dates object [optional]
% - v     dseries object with one observation [optional]
9 10
%
% OUTPUTS
11
% - B     dseries object.
12

13
% Copyright (C) 2014-2017 Dynare Team
14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29
%
% 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/>.

30
o = copy(varargin{1});
31

32 33
if nargin<2
    o.cumprod_();
34
else
35 36 37 38 39
    if isoctave
        o = cumprod_(o, varargin{2:end});
    else
        o.cumprod_(varargin{2:end});
    end
40 41 42 43 44 45 46 47 48 49 50 51 52 53
end

%@test:1
%$ % Define a data set.
%$ A = 2*ones(4,1);
%$
%$ % Define names
%$ A_name = {'A1'};
%$
%$ % Instantiate a time series object.
%$ ts = dseries(A,[],A_name,[]);
%$
%$ % Call the tested method.
%$ try
54
%$     ds = cumprod(ts);
55 56 57 58 59 60
%$     t(1) = 1;
%$ catch
%$     t(1) = 0;
%$ end
%$
%$ if t(1)
61
%$     t(2) = isequal(ds.data, cumprod(A));
62 63 64 65 66
%$     t(3) = isequal(ds.name{1}, 'A1');
%$     t(4) = isequal(ds.ops{1}, 'cumprod(A1)');
%$     t(5) = isequal(ts.data, A);
%$     t(6) = isequal(ts.name{1}, 'A1');
%$     t(7) = isempty(ts.ops{1});
67 68 69 70 71 72 73
%$ end
%$
%$ T = all(t);
%@eof:1

%@test:2
%$ % Define a data set.
74
%$ A = 2*ones(7,1);
75 76 77 78 79
%$
%$ % Define names
%$ A_name = {'A1'};
%$
%$ % Instantiate a time series object.
80 81
%$ ts1 = dseries(A, [], A_name, []);
%$ ts2 = dseries(pi, [], A_name, []);
82 83 84
%$
%$ % Call the tested method.
%$ try
85 86
%$   ts3 = ts1.cumprod(dates('3Y'),ts2);
%$   t(1) = 1;
87
%$ catch
88
%$   t(1) = 0;
89 90 91 92 93 94
%$ end
%$
%$ % Expected results.
%$ ts4 = dseries([.25; .5; 1; 2; 4; 8; 16]*pi, [], A_name, []);
%$
%$ % Check the results.
95 96 97 98
%$ if t(1)
%$   t(2) = dassert(ts3.data, ts4.data);
%$   t(3) = dassert(ts1.data, A);
%$ end
99
%$ T = all(t);
100
%@eof:2