1function d = firstobservedperiod(o) % --*-- Unitary tests --*--
2
3% Returns the first period where all the variables are observed (first period without NaNs).
4%
5% INPUTS
6% - o [dseries]    with N variables and T periods.
7%
8% OUTPUTS
9% - d [dates]      First period where the N variables are observed (without NaNs).
10
11% Copyright (C) 2016-2017 Dynare Team
12%
13% This file is part of Dynare.
14%
15% Dynare is free software: you can redistribute it and/or modify
16% it under the terms of the GNU General Public License as published by
17% the Free Software Foundation, either version 3 of the License, or
18% (at your option) any later version.
19%
20% Dynare is distributed in the hope that it will be useful,
21% but WITHOUT ANY WARRANTY; without even the implied warranty of
22% MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
23% GNU General Public License for more details.
24%
25% You should have received a copy of the GNU General Public License
26% along with Dynare.  If not, see <http://www.gnu.org/licenses/>.
27
28b = ~isnan(o);
29c = find(prod(double(b), 2));
30
31if isempty(c)
32    error('No overlapping non-NaN data points found in dseries.');
33end
34
35d = firstdate(o)+(c(1)-1);
36
37%@test:1
38%$ try
39%$     ts = dseries([NaN, NaN; NaN, 1; 2, 2; 3, 3; 4, NaN; 5, 5]);
40%$     dd = ts.firstobservedperiod();
41%$     t(1) = true;
42%$ catch
43%$     t(1) = false;
44%$ end
45%$
46%$ if t(1)
47%$     t(2) = isequal(dd, dates('3Y'));
48%$ end
49%$
50%$ T = all(t);
51%@eof:1
52
53%@test:2
54%$ try
55%$     ts = dseries([0, 0; NaN, 1; 2, 2; 3, 3; 4, NaN; 5, 5]);
56%$     dd = ts.firstobservedperiod();
57%$     t(1) = true;
58%$ catch
59%$     t(1) = false;
60%$ end
61%$
62%$ if t(1)
63%$     t(2) = isequal(dd, dates('1Y'));
64%$ end
65%$
66%$ T = all(t);
67%@eof:2
68