Skip to content
Snippets Groups Projects
Commit 08b514f5 authored by Stéphane Adjemian's avatar Stéphane Adjemian
Browse files

Fixed backcast method for older versions of Matlab and for Octave.

parent a8b572a6
No related branches found
No related tags found
No related merge requests found
Pipeline #2652 failed
......@@ -42,11 +42,11 @@ idp = find(o.dates(1)==p.dates);
if diff
FirstDifference = p.data(2:idp,:)-p.data(1:idp-1,:);
CumulatedDifferences = cumsum(FirstDifference, 'reverse');
CumulatedDifferences = rcumsum(FirstDifference);
o.data = [bsxfun(@minus, o.data(1:end), CumulatedDifferences); o.data];
else
GrowthFactor = p.data(2:idp,:)./p.data(1:idp-1,:);
CumulatedGrowthFactors = cumprod(GrowthFactor, 'reverse');
CumulatedGrowthFactors = rcumprod(GrowthFactor);
o.data = [bsxfun(@rdivide, o.data(1:end), CumulatedGrowthFactors); o.data];
end
......
function Y = rcumprod(X)
% Returns the cumulated product of X from bottom to top (reversed order
% compared to cumprod, emulate the `reverse` option).
%
% INPUTS
% - X [double] T×N array
%
% OUTPUTS
% - Y [double] T×N array
Y = flip(cumprod(flip(X)));
\ No newline at end of file
function Y = rcumsum(X)
% Returns the cumulated sum of X from bottom to top (reversed order
% compared to cumsum, emulate the `reverse` option).
%
% INPUTS
% - X [double] T×N array
%
% OUTPUTS
% - Y [double] T×N array
Y = flip(cumsum(flip(X)));
\ No newline at end of file
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment