1function o = qdiff_(o) % --*-- Unitary tests --*--
2
3% Computes quaterly 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    error('dseries::qdiff: I cannot compute quaterly differences from yearly data!')
31  case 4
32    o.data(2:end,:) = o.data(2:end,:)-o.data(1:end-1,:);
33    o.data(1,:) = NaN;
34  case 12
35    o.data(4:end,:) = o.data(4:end,:)-o.data(1:end-3,:);
36    o.data(1:3,:) = NaN;
37  case 52
38    error('dseries::qdiff: I do not know yet how to compute quaterly differences from weekly data!')
39  otherwise
40    error(['dseries::qdiff: object ' inputname(1) ' has unknown frequency']);
41end
42
43for i = 1:vobs(o)
44    if isempty(o.ops{i})
45        o.ops(i) = {['qdiff(' o.name{i} ')']};
46    else
47        o.ops(i) = {['qdiff(' o.ops{i} ')']};
48    end
49end
50
51%@test:1
52%$ try
53%$     data = transpose(0:1:50);
54%$     ts = dseries(data,'1950Q1');
55%$     ts.qdiff_;
56%$     t(1) = 1;
57%$ catch
58%$     t(1) = 0;
59%$ end
60%$
61%$ if t(1)
62%$     DATA = NaN(1,ts.vobs);
63%$     DATA = [DATA; ones(ts.nobs-1,ts.vobs)];
64%$     t(2) = dassert(ts.data,DATA,1e-15);
65%$ end
66%$
67%$ T = all(t);
68%@eof:1
69
70%@test:2
71%$ try
72%$     data = transpose(0:1:80);
73%$     ts = dseries(data,'1950M1');
74%$     ts.qdiff_;
75%$     t(1) = 1;
76%$ catch
77%$     t(1) = 0;
78%$ end
79%$
80%$ if t(1)
81%$     DATA = NaN(3,ts.vobs);
82%$     DATA = [DATA; 3*ones(ts.nobs-3,ts.vobs)];
83%$     t(2) = dassert(ts.data,DATA,1e-15);
84%$ end
85%$
86%$ T = all(t);
87%@eof:2
88