1function o = mgrowth_(o) % --*-- Unitary tests --*-- 2 3% Computes monthly growth rates. 4% 5% INPUTS 6% - o [dseries] 7% 8% OUTPUTS 9% - o [dseries] 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 28switch frequency(o) 29 case 1 30 error('dseries::mgrowth: I cannot compute monthly growth rates from yearly data!') 31 case 4 32 error('dseries::mgrowth: I cannot compute monthly growth rates from quaterly data!') 33 case 12 34 o.data(2:end,:) = o.data(2:end,:)./o.data(1:end-1,:) - 1; 35 o.data(1,:) = NaN; 36 otherwise 37 error(['dseries::mgrowth: object ' inputname(1) ' has unknown frequency']); 38end 39 40for i = 1:vobs(o) 41 if isempty(o.ops{i}) 42 o.ops(i) = {['mgrowth(' o.name{i} ')']}; 43 else 44 o.ops(i) = {['mgrowth(' o.ops{i} ')']}; 45 end 46end 47 48%@test:1 49%$ try 50%$ data = (1+.01).^transpose(0:1:50); 51%$ ts = dseries(data,'1950Q1'); 52%$ ts.mgrowth_; 53%$ t(1) = 0; 54%$ catch 55%$ t(1) = 1; 56%$ end 57%$ 58%$ T = all(t); 59%@eof:1 60 61%@test:2 62%$ try 63%$ data = (1+.01).^transpose(0:1:80); 64%$ ts = dseries(data, '1950M1'); 65%$ ts.mgrowth_; 66%$ t(1) = 1; 67%$ catch 68%$ t(1) = 0; 69%$ end 70%$ 71%$ if t(1) 72%$ DATA = NaN(1,ts.vobs); 73%$ DATA = [DATA; (1.01-1)*ones(ts.nobs-1, ts.vobs)]; 74%$ t(2) = dassert(ts.data, DATA, 1e-15); 75%$ end 76%$ 77%$ T = all(t); 78%@eof:2 79