Commit 08b514f5 authored by Stéphane Adjemian's avatar Stéphane Adjemian

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

parent a8b572a6
Pipeline #2652 failed with stage
in 2 minutes and 36 seconds
......@@ -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
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