1function o = ydiff_(o) % --*-- Unitary tests --*--
2
3% Computes yearly differences.
4%
5% INPUTS
6% - o   [dseries]
7%
8% OUTPUTS
9% - o   [dseries]
10
11% Copyright (C) 2012-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
28switch frequency(o)
29  case 1
30    o.data(2:end,:) = o.data(2:end,:)-o.data(1:end-1,:);
31    o.data(1,:) = NaN;
32  case 4
33    o.data(5:end,:) = o.data(5:end,:)-o.data(1:end-4,:);
34    o.data(1:4,:) = NaN;
35  case 12
36    o.data(13:end,:) = o.data(13:end,:)-o.data(1:end-12,:);
37    o.data(1:12,:) = NaN;
38  case 52
39    o.data(53:end,:) = o.data(53:end,:)-o.data(1:end-52,:);
40    o.data(1:52,:) = NaN;
41  otherwise
42    error(['dseries::ydiff: object ' inputname(1) ' has unknown frequency']);
43end
44
45for i = 1:vobs(o)
46    if isempty(o.ops{i})
47        o.ops(i) = {['ydiff(' o.name{i} ')']};
48    else
49        o.ops(i) = {['ydiff(' o.ops{i} ')']};
50    end
51end
52
53%@test:1
54%$ try
55%$     data = transpose(1:100);
56%$     ts = dseries(data,'1950Q1',{'A1'},{'A_1'});
57%$     ts.ydiff_;
58%$     t(1) = true;
59%$ catch
60%$     t(1) = false;
61%$ end
62%$
63%$
64%$ if t(1)
65%$     DATA = NaN(4,ts.vobs);
66%$     DATA = [DATA; 4*ones(ts.nobs-4,ts.vobs)];
67%$     t(2) = dassert(ts.data,DATA);
68%$     t(3) = dassert(ts.ops{1},['ydiff(A1)']);
69%$ end
70%$
71%$ T = all(t);
72%@eof:1
73
74%@test:2
75%$ try
76%$     data = transpose(1:100);
77%$     ts = dseries(data,'1950M1',{'A1'},{'A_1'});
78%$     ts.ydiff_;
79%$     t(1) = true;
80%$ catch
81%$     t(1) = false;
82%$ end
83%$
84%$
85%$ if t(1)
86%$     DATA = NaN(12,ts.vobs);
87%$     DATA = [DATA; 12*ones(ts.nobs-12,ts.vobs)];
88%$     t(2) = dassert(ts.data,DATA);
89%$     t(3) = dassert(ts.ops{1},['ydiff(A1)']);
90%$ end
91%$
92%$ T = all(t);
93%@eof:2
94
95%@test:3
96%$ try
97%$     data = transpose(1:100);
98%$     ts = dseries(data,'1950W1',{'A1'},{'A_1'});
99%$     ts.ydiff_;
100%$     t(1) = true;
101%$ catch
102%$     t(1) = false;
103%$ end
104%$
105%$ if t(1)
106%$     DATA = NaN(52,ts.vobs);
107%$     DATA = [DATA; 52*ones(ts.nobs-52,ts.vobs)];
108%$     t(2) = dassert(ts.data,DATA);
109%$     t(3) = dassert(ts.ops{1},['ydiff(A1)']);
110%$ end
111%$
112%$ T = all(t);
113%@eof:3
114
115%@test:4
116%$ try
117%$     data = transpose(1:100);
118%$     ts = dseries(data,'1950Y',{'A1'},{'A_1'});
119%$     ts.ydiff_;
120%$     t(1) = true;
121%$ catch
122%$     t(1) = false;
123%$ end
124%$
125%$
126%$ if t(1)
127%$     DATA = NaN(1,ts.vobs);
128%$     DATA = [DATA; ones(ts.nobs-1,ts.vobs)];
129%$     t(2) = dassert(ts.data,DATA);
130%$     t(3) = dassert(ts.ops{1},['ydiff(A1)']);
131%$ end
132%$
133%$ T = all(t);
134%@eof:4
135