1function d = lastobservedperiod(o) % --*-- Unitary tests --*-- 2 3% Returns the last period where all the variables are observed (last period without NaNs). 4% 5% INPUTS 6% - o [dseries] with N variables and T periods. 7% 8% OUTPUTS 9% - b [dates] Last period where the N variables are observed (without NaNs). 10 11% Copyright (C) 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)); 30if isempty(c) 31 error('No overlapping non-NaN data points found in dseries.'); 32end 33d = firstdate(o)+(c(end)-1); 34 35%@test:1 36%$ try 37%$ ts = dseries([NaN, NaN; NaN, 1; 2, 2; 3, 3; 4, NaN; 5, 5]); 38%$ dd = ts.lastobservedperiod(); 39%$ t(1) = true; 40%$ catch 41%$ t(1) = false; 42%$ end 43%$ 44%$ if t(1) 45%$ t(2) = isequal(dd, dates('6Y')); 46%$ end 47%$ 48%$ T = all(t); 49%@eof:1 50 51%@test:2 52%$ try 53%$ ts = dseries([0, 0; NaN, 1; 2, 2; 3, 3; 4, NaN; 5, NaN]); 54%$ dd = ts.lastobservedperiod(); 55%$ t(1) = true; 56%$ catch 57%$ t(1) = false; 58%$ end 59%$ 60%$ if t(1) 61%$ t(2) = isequal(dd, dates('4Y')); 62%$ end 63%$ 64%$ T = all(t); 65%@eof:2 66