Problems
Loading...
1 / 1

Cumulative Returns

Time Series
Easy

Cumulative return measures the total return of an investment over multiple periods. Unlike simple addition, returns compound multiplicatively: a 10% gain followed by a 10% loss does not return to the starting point (you end up at 0.99, not 1.0). This compounding effect is critical for portfolio tracking, performance attribution, and backtesting trading strategies.

Given a list of period returns (as fractions, e.g., 0.05 for 5%), compute the cumulative return at each time step.

Algorithm

Starting with a wealth factor of 1.0, multiply by (1 + r_t) at each step:

Wt=i=0t(1+ri)cumulative_returnt=Wt1W_t = \prod_{i=0}^{t}(1 + r_i) \\ \text{cumulative\_return}_t = W_t - 1
Loading visualization...

Examples

Input:

returns = [0.1, 0.05, -0.02]

Output:

[0.1, 0.155, 0.1319]

After 10% gain: 1.1 (cum=0.1). After 5% gain: 1.11.05=1.155 (cum=0.155). After 2% loss: 1.1550.98=1.1319 (cum=0.1319).

Input:

returns = [-0.5, 1.0]

Output:

[-0.5, 0.0]

A 50% loss followed by a 100% gain: 0.5 * 2.0 = 1.0. The cumulative return is 0.0 - you only break even, not profit.

Hint 1

Start with a wealth factor of 1.0. At each step, multiply by (1 + return). The cumulative return at each step is the current wealth factor minus 1.

Hint 2

cum = 1.0; for each r, do cum *= (1 + r) and append (cum - 1) to the result list.

Requirements

  • Compound returns multiplicatively using (1 + r) factors
  • At each step, cumulative return = running product - 1
  • Return a list of floats with the same length as the input

Constraints

  • returns is non-empty
  • Each return is > -1 (no total loss)
  • Return a list of floats
  • Time limit: 300 ms
Try Similar Problems