1function o = chain_(o, p) % --*-- Unitary tests --*-- 2 3% Copyright (C) 2014-2017 Dynare Team 4% 5% This file is part of Dynare. 6% 7% Dynare is free software: you can redistribute it and/or modify 8% it under the terms of the GNU General Public License as published by 9% the Free Software Foundation, either version 3 of the License, or 10% (at your option) any later version. 11% 12% Dynare is distributed in the hope that it will be useful, 13% but WITHOUT ANY WARRANTY; without even the implied warranty of 14% MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15% GNU General Public License for more details. 16% 17% You should have received a copy of the GNU General Public License 18% along with Dynare. If not, see <http://www.gnu.org/licenses/>. 19 20noinputname = false; 21 22if isempty(inputname(1)) 23 % If method is called with dot notation (eg o.chain_(p) insteady of chain(o, p)), input names 24 % are not defined. 25 noinputname = true; 26end 27 28if vobs(o)-vobs(p) 29 if noinputname 30 error(['dseries::chain: dseries objects must have the same number of variables!']) 31 else 32 error(['dseries::chain: dseries objects ' inputname(1) ' and ' inputname(2) ' must have the same number of variables!']) 33 end 34end 35 36if frequency(o)-frequency(p) 37 if noinputname 38 error(['dseries::chain: dseries objects must have common frequencies!']) 39 else 40 error(['dseries::chain: dseries objects ' inputname(1) ' and ' inputname(2) ' must have common frequencies!']) 41 end 42end 43 44if lastdate(o)<firstdate(p) 45 if noinputname 46 error(['dseries::chain: The last date in first dseries object (' date2string(o.dates(end)) ') must not preceed the first date in the second dseries object (' date2string(p.dates(1)) ')!']) 47 else 48 error(['dseries::chain: The last date in ' inputname(1) ' (' date2string(o.dates(end)) ') must not preceed the first date in ' inputname(2) ' (' date2string(p.dates(1)) ')!']) 49 end 50end 51 52tdx = find(sum(bsxfun(@eq, p.dates.time, o.dates.time(end,:)),2)==2); 53GrowthFactor = p.data(tdx+1:end,:)./p.data(tdx:end-1,:); 54CumulatedGrowthFactors = cumprod(GrowthFactor); 55 56o.data = [o.data; bsxfun(@times,CumulatedGrowthFactors, o.data(end,:))]; 57 58o.dates = firstdate(o):firstdate(o)+nobs(o); 59 60for i=1:o.vobs 61 if isempty(o.ops{i}) 62 if noinputname 63 o.ops(i) = {sprintf('chain(%s, %s)', o.name{i}, p.name{i})}; 64 else 65 o.ops(i) = {sprintf('chain(%s, %s.%s)', o.name{i}, inputname(2), p.name{i})}; 66 end 67 else 68 if noinputname 69 o.ops(i) = {sprintf('chain(%s, %s)', o.ops{i}, p.name{i})}; 70 else 71 o.ops(i) = {sprintf('chain(%s, %s.%s)', o.ops{i}, inputname(2), p.name{i})}; 72 end 73 end 74end 75 76 77%@test:1 78%$ try 79%$ ts = dseries([1; 2; 3; 4],dates('1950Q1')) ; 80%$ us = dseries([3; 4; 5; 6],dates('1950Q3')) ; 81%$ ts.chain_(us); 82%$ t(1) = 1; 83%$ catch 84%$ t(1) = 0; 85%$ end 86%$ 87%$ if t(1) 88%$ t(2) = dassert(ts.freq,4); 89%$ t(3) = dassert(ts.init.freq,4); 90%$ t(4) = dassert(ts.init.time,[1950, 1]); 91%$ t(5) = dassert(ts.vobs,1); 92%$ t(6) = dassert(ts.nobs,6); 93%$ t(7) = isequal(ts.data,transpose(1:6)); 94%$ end 95%$ 96%$ T = all(t); 97%@eof:1