1function o = detrend(o, model) % --*-- Unitary tests --*--
2
3% Detrends a dseries object with a polynomial of order model.
4%
5% INPUTS
6% - o       [dseries]   time series to be detrended.
7% - model   [integer]   scalar, order of the fitted polynomial.
8%
9% OUTPUTS
10% - o       [dseries]   detrended time series.
11
12% Copyright (C) 2014-2017 Dynare Team
13%
14% This file is part of Dynare.
15%
16% Dynare is free software: you can redistribute it and/or modify
17% it under the terms of the GNU General Public License as published by
18% the Free Software Foundation, either version 3 of the License, or
19% (at your option) any later version.
20%
21% Dynare is distributed in the hope that it will be useful,
22% but WITHOUT ANY WARRANTY; without even the implied warranty of
23% MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
24% GNU General Public License for more details.
25%
26% You should have received a copy of the GNU General Public License
27% along with Dynare.  If not, see <http://www.gnu.org/licenses/>.
28
29% Set default for the order of the polynomial trend (constant).
30if nargin<2
31    model = 0;
32end
33
34o = copy(o);
35o.detrend_(model);
36
37%@test:1
38%$ % Define a dataset.
39%$ A = ones(3,1);
40%$ a = dseries(A);
41%$
42%$ try
43%$   b = a.detrend();
44%$   t(1) = 1;
45%$ catch
46%$   t(1) = 0;
47%$ end
48%$
49%$ if t(1)
50%$   t(2) = max(max(abs(a.data-A)))<1e-12;
51%$ end
52%$
53%$ T = all(t);
54%@eof:1