1function o = lead_(o, p) % --*-- Unitary tests --*--
2
3% Returns a leaded time series
4%
5% INPUTS
6% - o [dseries]
7% - p [integer]   Number of leads
8%
9% OUTPUTS
10% - o [dseries]
11%
12% EXAMPLE
13% Define a dseries object as follows:
14%
15% >> o = dseries(transpose(1:5))
16%
17% then o.lag(1) returns
18%
19%       | lead(Variable_1,1)
20%    1Y | 2
21%    2Y | 3
22%    3Y | 4
23%    4Y | 5
24%    5Y | NaN
25
26% Copyright (C) 2013-2017 Dynare Team
27%
28% This file is part of Dynare.
29%
30% Dynare is free software: you can redistribute it and/or modify
31% it under the terms of the GNU General Public License as published by
32% the Free Software Foundation, either version 3 of the License, or
33% (at your option) any later version.
34%
35% Dynare is distributed in the hope that it will be useful,
36% but WITHOUT ANY WARRANTY; without even the implied warranty of
37% MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
38% GNU General Public License for more details.
39%
40% You should have received a copy of the GNU General Public License
41% along with Dynare.  If not, see <http://www.gnu.org/licenses/>.
42
43% Set default number of leads
44if nargin<2
45    p = 1;
46end
47
48% Check second input argument
49if p<0
50    error('dseries:WrongInputArguments','Second input argument must be non negative! Use lag method instead.')
51end
52
53% Check that p is an integer
54if ~isint(p)
55    error('dseries:WrongInputArguments','Second input argument must be an integer!')
56end
57
58% Return without changing anything if p==0
59if ~p
60    return
61end
62
63% Update data member
64o.data = [  o.data(p+1:end,:); NaN(p, vobs(o));];
65
66for i=1:vobs(o)
67    if isempty(o.ops)
68        o.ops(i) = {sprintf('lead(%s, %s)', o.name{i}, int2str(p))};
69    else
70        if isempty(o.ops{i})
71            o.ops(i) = {sprintf('lead(%s)', int2str(p))};
72        else
73            o.ops(i) = {sprintf('lead(%s, %s)', o.ops{i}, int2str(p))};
74        end
75    end
76end
77
78%@test:1
79%$ try
80%$     data = transpose(1:50);
81%$     ts = dseries(data,'1950Q1');
82%$     ts.lead_;
83%$     t(1) = true;
84%$ catch
85%$     t(1) = false;
86%$ end
87%$
88%$ if t(1)
89%$     DATA = [data(2:end); NaN(1)];
90%$     t(2) = dassert(ts.data, DATA, 1e-15);
91%$ end
92%$
93%$ T = all(t);
94%@eof:1
95
96%@test:2
97%$ try
98%$     data = transpose(1:50);
99%$     ts = dseries(data,'1950Q1');
100%$     ts.lead_.lead_;
101%$     t(1) = true;
102%$ catch
103%$     t(1) = false;
104%$ end
105%$
106%$ if t(1)
107%$     t(2) = all(isnan(ts.data(end-1:end))) && isequal(ts.data(1:end-2), data(3:end));
108%$ end
109%$
110%$ T = all(t);
111%@eof:2
112
113%@test:3
114%$ try
115%$     data = transpose(0:1:50);
116%$     ts = dseries(data,'1950Q1');
117%$     ts.lead_(0);
118%$     t(1) = 1;
119%$ catch
120%$     t(1) = 0;
121%$ end
122%$
123%$ if t(1)
124%$     t(2) = dassert(ts.data,data,1e-15);
125%$     t(3) = isempty(ts.ops{1});
126%$ end
127%$
128%$ T = all(t);
129%@eof:3