Fixed bug (incorrect results) in backcast method.

parent 923eadce
Pipeline #2840 failed with stage
in 2 minutes and 38 seconds
......@@ -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.
%
......
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);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment