...
 
Commits (2)
......@@ -13,7 +13,7 @@ function q = backcast(o, p, diff) % --*-- Unitary tests --*--
% The two dseries objects must have common frequency and the same number of variables. Also the
% two samples must overlap.
% Copyright (C) 2019 Dynare Team
% Copyright © 2019-2020 Dynare Team
%
% This file is part of Dynare.
%
......@@ -31,7 +31,12 @@ function q = backcast(o, p, diff) % --*-- Unitary tests --*--
% along with Dynare. If not, see <http://www.gnu.org/licenses/>.
q = copy(o);
q.backcast_(p);
if nargin>2
q.backcast_(p, diff);
else
q.backcast_(p);
end
return
......
function o = backcast_(o, p, diff) % --*-- Unitary tests --*--
% Copyright (C) 2019 Dynare Team
% Copyright © 2019-2020 Dynare Team
%
% This file is part of Dynare.
%
......@@ -43,11 +43,11 @@ idp = find(o.dates(1)==p.dates);
if diff
FirstDifference = p.data(2:idp,:)-p.data(1:idp-1,:);
CumulatedDifferences = rcumsum(FirstDifference);
o.data = [bsxfun(@minus, o.data(1:end), CumulatedDifferences); o.data];
o.data = [bsxfun(@minus, o.data(1), CumulatedDifferences); o.data];
else
GrowthFactor = p.data(2:idp,:)./p.data(1:idp-1,:);
CumulatedGrowthFactors = rcumprod(GrowthFactor);
o.data = [bsxfun(@rdivide, o.data(1:end), CumulatedGrowthFactors); o.data];
o.data = [bsxfun(@rdivide, o.data(1), CumulatedGrowthFactors); o.data];
end
o.dates = firstdate(p):lastdate(o);
......