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

Target

Select target project
  • Dynare/dseries
  • sebastien/dseries
  • houtanb/dseries
  • DoraK/dseries
  • wmutschl/dseries
  • JohannesPfeifer/dseries
6 results
Select Git revision
Show changes
Commits on Source (52)
Showing
with 533 additions and 232 deletions
......@@ -27,7 +27,7 @@ function [a,b] = align(a, b) % --*-- Unitary tests --*--
%! @end deftypefn
%@eod:
% Copyright (C) 2013 Dynare Team
% Copyright (C) 2013-2017 Dynare Team
%
% This file is part of Dynare.
%
......
......@@ -19,7 +19,7 @@ function ts = baxter_king_filter(ts, high_frequency, low_frequency, K) % --*-- U
% This filter use a (symmetric) moving average smoother, so that K observations at the beginning and at the end of the
% sample are lost in the computation of the filter.
% Copyright (C) 2013 Dynare Team
% Copyright (C) 2013-2017 Dynare Team
%
% This file is part of Dynare.
%
......
function o = center(o, geometric) % --*-- Unitary tests --*--
% Centers @dseries object o around its mean (arithmetic or geometric).
%
% INPUTS
% o o dseries object [mandatory].
% o geometric logical [default is false], if true returns the geometric mean.
%
% OUTPUTS
% o o o
% Copyright (C) 2016-2017 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 <http://www.gnu.org/licenses/>.
if nargin<2
geometric = false;
end
if geometric
o = o/mean(o, true);
else
o = o-mean(o, false);
end
%@test:1
%$ % Define a dataset.
%$ A = repmat([1.005, 1.05], 10, 1);
%$
%$ % Instantiate a time series object and compute the mean.
%$ try
%$ ts = dseries(A);
%$ ts = center(ts, true);
%$ t(1) = 1;
%$ catch
%$ t = 0;
%$ end
%$
%$ if t(1)
%$ t(2) = all(all(abs(ts.data-ones(10,2))<1e-12));
%$ end
%$ T = all(t);
%@eof:1
......@@ -10,7 +10,7 @@ function B = cumprod(varargin) % --*-- Unitary tests --*--
% OUTPUTS
% o B dseries object.
% Copyright (C) 2014 Dynare Team
% Copyright (C) 2014-2017 Dynare Team
%
% This file is part of Dynare.
%
......@@ -27,15 +27,24 @@ function B = cumprod(varargin) % --*-- Unitary tests --*--
% You should have received a copy of the GNU General Public License
% along with Dynare. If not, see <http://www.gnu.org/licenses/>.
% Get indices of the columns without NaNs
idx = find(~any(isnan(varargin{1}.data)));
% Get the firt observation number where all the variables are observed (ie without NaNs)
idx = find(all(~isnan(varargin{1}.data), 2),1);
if isempty(idx)
error('dseries::cumprod: All the variables have NaNs. The cumulated product cannot be computed!')
idx = 0;
end
if ~isequal(idx(:),transpose(1:vobs(varargin{1})))
warning('dseries::cumprod: The cumulated product is not computed for some variables because they have NaNs!')
% Is the first period where variables are observed common?
common_first_period_witout_nan = true;
if ~idx
if any(~isnan(varargin{1}.data(:)))
common_first_period_witout_nan = false;
end
else
if idx>1
if any(any(~isnan(varargin{1}.data(1:idx-1,:))))
common_first_period_witout_nan = false;
end
end
end
switch nargin
......@@ -43,7 +52,15 @@ switch nargin
% Initialize the output.
B = varargin{1};
% Perform the cumulated sum
B.data(:,idx) = cumprod(B.data(:,idx));
if isequal(idx, 1)
B.data = cumprod(B.data);
else
if common_first_period_witout_nan
B.data(idx:end,:) = cumprod(B.data(idx:end,:));
else
B.data = cumprodnan(B.data);
end
end
% Change the name of the variables
for i=1:vobs(B)
B.name(i) = {['cumprod(' B.name{i} ')']};
......@@ -226,3 +243,18 @@ end
%$ t(1) = dassert(ts3.data,ts4.data);
%$ T = all(t);
%@eof:5
%@test:6
%$ % Define a data set.
%$ A = [NaN, NaN; 1 NaN; 1 1; 1 1; 1 NaN];
%$
%$ % Instantiate a time series object.
%$ ts0 = dseries(A);
%$
%$ % Call the tested method.
%$ ts0 = ts0.cumprod();
%$
%$ % Check the results.
%$ t(1) = dassert(ts0.data, A);
%$ T = all(t);
%@eof:6
\ No newline at end of file
......@@ -10,7 +10,7 @@ function B = cumsum(varargin) % --*-- Unitary tests --*--
% OUTPUTS
% o B dseries object.
% Copyright (C) 2013 Dynare Team
% Copyright (C) 2013-2017 Dynare Team
%
% This file is part of Dynare.
%
......@@ -27,15 +27,24 @@ function B = cumsum(varargin) % --*-- Unitary tests --*--
% You should have received a copy of the GNU General Public License
% along with Dynare. If not, see <http://www.gnu.org/licenses/>.
% Get indices of the columns without NaNs
idx = find(~any(isnan(varargin{1}.data)));
% Get the firt observation number where all the variables are observed (ie without NaNs)
idx = find(all(~isnan(varargin{1}.data), 2),1);
if isempty(idx)
error('dseries::cumsum: All the variables have NaNs. The cumulated sum cannot be computed!')
idx = 0;
end
if ~isequal(idx(:),transpose(1:vobs(varargin{1})))
warning('dseries::cumsum: The cumulated sum is not computed for some variables because they have NaNs!')
% Is the first period where variables are observed common?
common_first_period_witout_nan = true;
if ~idx
if any(~isnan(varargin{1}.data(:)))
common_first_period_witout_nan = false;
end
else
if idx>1
if any(any(~isnan(varargin{1}.data(1:idx-1,:))))
common_first_period_witout_nan = false;
end
end
end
switch nargin
......@@ -43,7 +52,15 @@ switch nargin
% Initialize the output.
B = varargin{1};
% Perform the cumulated sum
B.data(:,idx) = cumsum(B.data(:,idx));
if isequal(idx, 1)
B.data = cumsum(B.data);
else
if common_first_period_witout_nan
B.data(idx:end,:) = cumsum(B.data(idx:end,:));
else
B.data = cumsumnan(B.data);
end
end
% Change the name of the variables
for i=1:vobs(B)
B.name(i) = {['cumsum(' B.name{i} ')']};
......@@ -213,3 +230,21 @@ end
%$ t(1) = dassert(ts3.data,ts4.data);
%$ T = all(t);
%@eof:5
%@test:6
%$ % Define a data set.
%$ A = [NaN, NaN; 1 NaN; 1 1; 1 1; 1 NaN];
%$
%$ % Instantiate a time series object.
%$ ts0 = dseries(A);
%$
%$ % Call the tested method.
%$ ts0 = ts0.cumsum();
%$
%$ % Expected results.
%$ A = [NaN NaN; 1 NaN; 2 1; 3 2; 4 NaN];
%$
%$ % Check the results.
%$ t(1) = dassert(ts0.data, A);
%$ T = all(t);
%@eof:6
\ No newline at end of file
......@@ -59,7 +59,7 @@ function ts = dseries(varargin) % --*-- Unitary tests --*--
%! @end deftypefn
%@eod:
% Copyright (C) 2011-2013 Dynare Team
% Copyright (C) 2011-2017 Dynare Team
%
% This file is part of Dynare.
%
......@@ -423,12 +423,21 @@ end
%@test:9
%$ try
%$ if isoctave()
%$ [strfile, status] = urlwrite('http://www.dynare.org/Datasets/dseries/dynseries_test_data-1.xlsx','dynseries_test_data-1.xlsx');
%$ else
%$ [strfile, status] = urlwrite('http://www.dynare.org/Datasets/dseries/dynseries_test_data-1.xls','dynseries_test_data-1.xls');
%$ end
%$ if ~status
%$ error()
%$ end
%$ if isoctave()
%$ ts = dseries('dynseries_test_data-1.xlsx');
%$ delete('dynseries_test_data-1.xlsx');
%$ else
%$ ts = dseries('dynseries_test_data-1.xls');
%$ delete('dynseries_test_data-1.xls');
%$ end
%$ t(1) = 1;
%$ catch
%$ t(1) = 0;
......@@ -449,12 +458,21 @@ end
%@test:10
%$ try
%$ if isoctave()
%$ [strfile, status] = urlwrite('http://www.dynare.org/Datasets/dseries/dynseries_test_data-2.xlsx','dynseries_test_data-2.xlsx');
%$ else
%$ [strfile, status] = urlwrite('http://www.dynare.org/Datasets/dseries/dynseries_test_data-2.xls','dynseries_test_data-2.xls');
%$ end
%$ if ~status
%$ error()
%$ end
%$ if isoctave()
%$ ts = dseries('dynseries_test_data-2.xlsx');
%$ delete('dynseries_test_data-2.xlsx');
%$ else
%$ ts = dseries('dynseries_test_data-2.xls');
%$ delete('dynseries_test_data-2.xls');
%$ end
%$ t(1) = 1;
%$ catch
%$ t(1) = 0;
......@@ -475,12 +493,21 @@ end
%@test:11
%$ try
%$ if isoctave()
%$ [strfile, status] = urlwrite('http://www.dynare.org/Datasets/dseries/dynseries_test_data-3.xlsx','dynseries_test_data-3.xlsx');
%$ else
%$ [strfile, status] = urlwrite('http://www.dynare.org/Datasets/dseries/dynseries_test_data-3.xls','dynseries_test_data-3.xls');
%$ end
%$ if ~status
%$ error()
%$ end
%$ if isoctave()
%$ ts = dseries('dynseries_test_data-3.xlsx');
%$ delete('dynseries_test_data-3.xlsx');
%$ else
%$ ts = dseries('dynseries_test_data-3.xls');
%$ delete('dynseries_test_data-3.xls');
%$ end
%$ t(1) = 1;
%$ catch
%$ t(1) = 0;
......@@ -501,12 +528,21 @@ end
%@test:12
%$ try
%$ if isoctave()
%$ [strfile, status] = urlwrite('http://www.dynare.org/Datasets/dseries/dynseries_test_data-4.xlsx','dynseries_test_data-4.xlsx');
%$ else
%$ [strfile, status] = urlwrite('http://www.dynare.org/Datasets/dseries/dynseries_test_data-4.xls','dynseries_test_data-4.xls');
%$ end
%$ if ~status
%$ error()
%$ end
%$ if isoctave()
%$ ts = dseries('dynseries_test_data-4.xlsx');
%$ delete('dynseries_test_data-4.xlsx');
%$ else
%$ ts = dseries('dynseries_test_data-4.xls');
%$ delete('dynseries_test_data-4.xls');
%$ end
%$ t(1) = 1;
%$ catch
%$ t(1) = 0;
......@@ -570,7 +606,7 @@ end
%@test:15
%$ try
%$ ts = dseries([1; 2],dates('1990Q1'):dates('1990Q4'));
%$ evalc('dseries([1; 2],dates(''1990Q1''):dates(''1990Q4''));');
%$ t = 0;
%$ catch
%$ t = 1;
......
......@@ -12,7 +12,7 @@ function C = eq(A,B) % --*-- Unitary tests --*--
% REMARKS
% If the number of variables, the number of observations or the frequencies are different in A and B, the function returns a zero scalar.
% Copyright (C) 2013 Dynare Team
% Copyright (C) 2013-2017 Dynare Team
%
% This file is part of Dynare.
%
......
......@@ -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 (C) 2014 Dynare Team
% Copyright (C) 2014-2017 Dynare Team
%
% This file is part of Dynare.
%
......
......@@ -2,7 +2,7 @@ function A = extract(B,varargin) % --*-- Unitary tests --*--
% Extract some variables from a database.
% Copyright (C) 2012-2013 Dynare Team
% Copyright (C) 2012-2017 Dynare Team
%
% This file is part of Dynare.
%
......@@ -25,87 +25,26 @@ A = dseries();
VariableName_ = {};
for i=1:nargin-1
VariableName = varargin{i};
% Implicit loop.
idArobase = strfind(VariableName,'@');
if mod(length(idArobase),2)
error('dseries::extract: (Implicit loops) The number of @ symbols must be even!')
end
% Regular expression
idBracket.open = strfind(VariableName,'[');
idBracket.close = strfind(VariableName,']');
if ~isequal(length(idBracket.open),length(idBracket.open))
error('dseries::extract: (Matlab/Octave''s regular expressions) Check opening and closing square brackets!')
end
if length(idArobase)
NumberOfImplicitLoops = .5*length(idArobase);
idComma = cell(NumberOfImplicitLoops,1);
expressions = cell(NumberOfImplicitLoops,1);
for i=0:NumberOfImplicitLoops-1
idComma(i+1) = { strfind(VariableName(idArobase(2*i+1)+1:idArobase(2*i+2)-1),',') };
expressions(i+1) = { VariableName(idArobase(2*i+1)+1:idArobase(2*i+2)-1) };
end
if any(cellfun(@isempty,idComma))
error('dseries::extract: (Implicit loops) Wrong syntax!')
end
switch NumberOfImplicitLoops
case 1
expression = expressions{1};
idVariables_ = [];
while ~isempty(expression)
[token, expression] = strtok(expression,',');
candidate = [VariableName(1:idArobase(1)-1), token, VariableName(idArobase(2)+1:end)];
id = find(strcmp(candidate,B.name));
if isempty(id)
error(['dseries::extract: (Implicit loops) Variable ''' candidate ''' does not exist in dseries object ''' inputname(1) '''!'])
else
idVariables_ = [idVariables_; id];
end
end
VariableName = B.name(idVariables_);
case 2
idVariables_ = [];
expression_1 = expressions{1};
while ~isempty(expression_1)
[token_1, expression_1] = strtok(expression_1,',');
expression_2 = expressions{2};
while ~isempty(expression_2)
[token_2, expression_2] = strtok(expression_2,',');
candidate = [VariableName(1:idArobase(1)-1), token_1, VariableName(idArobase(2)+1:idArobase(3)-1), token_2, VariableName(idArobase(4)+1:end)];
id = find(strcmp(candidate,B.name));
if isempty(id)
error(['dseries::extract: (Implicit loops) Variable ''' candidate ''' does not exist in dseries object ''' inputname(1) '''!'])
else
idVariables_ = [idVariables_; id];
end
end
end
VariableName = B.name(idVariables_);
otherwise
error('dseries::extract: (Implicit loops) Cannot unroll more than two implicit loops!')
% Loops and regular expressions are not compatible
if length(idArobase) && length(idBracket.open)
error(['dseries::extract: You cannot use implicit loops and regular expressions in the same rule!'])
end
VariableName_ = vertcat(VariableName_,VariableName);
% Update the list of variables.
if length(idArobase)
VariableName_ = build_list_of_variables_with_loops(B.name, idArobase, VariableName, VariableName_);
elseif length(idBracket.open)
% Matlab/Octave's regular expressions.
first_block_id = 0;
last_block_id = 0;
idVariables = find(isnotempty_cell(regexp(B.name,VariableName,'match')));
if isempty(idVariables)
error(['dseries::extract: Can''t find any variable matching ' VariableName ' pattern!'])
end
idVariables_ = [];
for j = 1:length(idVariables)
first_block_flag = 0;
if (first_block_id && strcmp(B.name{idVariables(j)}(1:first_block_id),VariableName(1:first_block_id))) || ~first_block_id
first_block_flag = 1;
end
last_block_flag = 0;
if (last_block_id && strcmp(B.name{idVariables(j)}(end-last_block_id:end),VariableName(end-last_block_id:end))) || ~last_block_id
last_block_flag = 1;
end
if first_block_flag && last_block_flag
idVariables_ = [idVariables_; idVariables(j)];
end
end
VariableName = B.name(idVariables_);
VariableName_ = vertcat(VariableName_,VariableName);
VariableName_ = build_list_of_variables_with_regexp(B.name, idBracket, VariableName, VariableName_);
else
VariableName_ = varargin(:);
end
......@@ -129,15 +68,6 @@ A.dates = B.dates;
A.name = B.name(idVariableName);
A.tex = B.tex(idVariableName);
function b = isnotempty_cell(CellArray)
CellArrayDimension = size(CellArray);
b = NaN(CellArrayDimension);
for i=1:CellArrayDimension(1)
for j = 1:CellArrayDimension(2)
b(i,j) = ~isempty(CellArray{i,j});
end
end
%@test:1
%$ % Define a data set.
......
function f = firstdate(o)
function f = firstdate(o) % --*-- Unitary tests --*--
% Copyright (C) 2014 Dynare Team
% Copyright (C) 2014-2016 Dynare Team
%
% This file is part of Dynare.
%
......@@ -18,3 +18,19 @@ function f = firstdate(o)
% along with Dynare. If not, see <http://www.gnu.org/licenses/>.
f = o.dates(1);
%@test:1
%$ try
%$ ts = dseries(randn(10, 3),'1938Q3');
%$ dd = ts.firstdate();
%$ t(1) = true;
%$ catch
%$ t(1) = false;
%$ end
%$
%$ if t(1)
%$ t(2) = isequal(dd, dates('1938Q3'));
%$ end
%$
%$ T = all(t);
%@eof:1
function d = firstobservedperiod(o) % --*-- Unitary tests --*--
% Returns the first period where all the variables are observed (first period without NaNs).
%
% INPUTS
% - o [dseries] with N variables and T periods.
%
% OUTPUTS
% - b [dates] First period where the N variables are observed (without NaNs).
% Copyright (C) 2016-2017 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 <http://www.gnu.org/licenses/>.
b = ~isnan(o);
c = find(prod(b, 2));
if isempty(c)
error('No overlapping non-NaN data points found in dseries.');
end
d = firstdate(o)+(c(1)-1);
%@test:1
%$ try
%$ ts = dseries([NaN, NaN; NaN, 1; 2, 2; 3, 3; 4, NaN; 5, 5]);
%$ dd = ts.firstobservedperiod();
%$ t(1) = true;
%$ catch
%$ t(1) = false;
%$ end
%$
%$ if t(1)
%$ t(2) = isequal(dd, dates('3Y'));
%$ end
%$
%$ T = all(t);
%@eof:1
%@test:2
%$ try
%$ ts = dseries([0, 0; NaN, 1; 2, 2; 3, 3; 4, NaN; 5, 5]);
%$ dd = ts.firstobservedperiod();
%$ t(1) = true;
%$ catch
%$ t(1) = false;
%$ end
%$
%$ if t(1)
%$ t(2) = isequal(dd, dates('1Y'));
%$ end
%$
%$ T = all(t);
%@eof:2
......@@ -20,7 +20,7 @@ function B = horzcat(varargin) % --*-- Unitary tests --*--
% REMARKS
% o A1, A2, ... must not have common variables.
% Copyright (C) 2011-2013 Dynare Team
% Copyright (C) 2011-2017 Dynare Team
%
% This file is part of Dynare.
%
......@@ -97,8 +97,23 @@ function a = concatenate(b,c)
elseif b_last_date>c_last_date
c.data = [c.data; NaN(b_last_date-c_last_date, vobs(c))];
end
fillerdates = dates();
if max(c.dates) < min(b.dates)
fillerdates = max(c.dates):min(b.dates);
end
if max(b.dates) < min(c.dates)
fillerdates = max(b.dates):min(c.dates);
end
if isempty(fillerdates)
hd = [b.dates, c.dates];
else
hd = [b.dates, fillerdates, c.dates];
end
a.data = [b.data, c.data];
a.dates = sort(unique([b.dates, c.dates]));
a.dates = sort(unique(hd));
end
%@test:1
......
......@@ -11,7 +11,7 @@ function ts = hpcycle(ts, lambda) % --*-- Unitary tests --*--
% OUTPUTS
% o ts dseries object, with time series replaced by the cyclical component of the original time series.
% Copyright (C) 2013 Dynare Team
% Copyright (C) 2013-2017 Dynare Team
%
% This file is part of Dynare.
%
......
......@@ -11,7 +11,7 @@ function ts = hptrend(ts, lambda) % --*-- Unitary tests --*--
% OUTPUTS
% o ts dseries object, with time series replaced by the trend component of the original time series.
% Copyright (C) 2013 Dynare Team
% Copyright (C) 2013-2017 Dynare Team
%
% This file is part of Dynare.
%
......
......@@ -29,7 +29,7 @@ function ts = insert(ts,us,id) % --*-- Unitary tests --*--
%! @end deftypefn
%@eod:
% Copyright (C) 2013 Dynare Team
% Copyright (C) 2013-2017 Dynare Team
%
% This file is part of Dynare.
%
......
......@@ -10,7 +10,7 @@ function C = isequal(A, B, tol)
% OUTPUTS
% o C Integer scalar equal to zero or one.
% Copyright (C) 2013 Dynare Team
% Copyright (C) 2013-2017 Dynare Team
%
% This file is part of Dynare.
%
......
function b = isnan(o) % --*-- Unitary tests --*--
% Returns an array of logicals (true/false). Element (t,i) is true iff the i-th variable at
% period number t is not a NaN.
%
% INPUTS
% - o [dseries] with N variables and T periods.
%
% OUTPUTS
% - b [logical] T*N array of logicals.
% Copyright (C) 2016-2017 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 <http://www.gnu.org/licenses/>.
b = isnan(o.data);
%@test:1
%$ try
%$ data = randn(100, 10);
%$ cnan = randi(10, 50, 1);
%$ rnan = randi(100, 50, 1);
%$ for i=1:50, data(rnan(i),cnan(i)) = NaN; end
%$ inan = isnan(data);
%$ ts = dseries(data);
%$ dd = ts.isnan();
%$ t(1) = true;
%$ catch
%$ t(1) = false;
%$ end
%$
%$ if t(1)
%$ t(2) = isequal(dd, inan);
%$ end
%$
%$ T = all(t);
%@eof:1
......@@ -44,7 +44,7 @@ if nargin<2
p = 1;
end
if p<=0
if p<0
error('dseries::lag: Second input argument must be strictly positive! Use lead method instead.')
end
......
function d = lastobservedperiod(o) % --*-- Unitary tests --*--
% Returns the last period where all the variables are observed (last period without NaNs).
%
% INPUTS
% - o [dseries] with N variables and T periods.
%
% OUTPUTS
% - b [dates] Last period where the N variables are observed (without NaNs).
% Copyright (C) 2017 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 <http://www.gnu.org/licenses/>.
b = ~isnan(o);
c = find(prod(b, 2));
if isempty(c)
error('No overlapping non-NaN data points found in dseries.');
end
d = firstdate(o)+(c(end)-1);
%@test:1
%$ try
%$ ts = dseries([NaN, NaN; NaN, 1; 2, 2; 3, 3; 4, NaN; 5, 5]);
%$ dd = ts.lastobservedperiod();
%$ t(1) = true;
%$ catch
%$ t(1) = false;
%$ end
%$
%$ if t(1)
%$ t(2) = isequal(dd, dates('6Y'));
%$ end
%$
%$ T = all(t);
%@eof:1
%@test:2
%$ try
%$ ts = dseries([0, 0; NaN, 1; 2, 2; 3, 3; 4, NaN; 5, NaN]);
%$ dd = ts.lastobservedperiod();
%$ t(1) = true;
%$ catch
%$ t(1) = false;
%$ end
%$
%$ if t(1)
%$ t(2) = isequal(dd, dates('4Y'));
%$ end
%$
%$ T = all(t);
%@eof:2
......@@ -44,7 +44,7 @@ if nargin<2
p = 1;
end
if p<=0
if p<0
error('dseries::lead: Second input argument must be strictly positive! Use lag method instead.')
end
......