TensorTonicTensorTonic
Problems
Study PlansProjectsNewInterviewPricingFeedback
Problems
Loading...
1 / 1

Cumulative Returns

Time Series
Easy

Returns across multiple periods compound multiplicatively. Begin with a wealth factor of 1.0 and update it after each period:

Wt=Wt−1(1+rt)W_t = W_{t-1}(1+r_t)Wt​=Wt−1​(1+rt​)

Convert the wealth factor back to cumulative return:

Rt=Wt−1R_t = W_t - 1Rt​=Wt​−1

Here, r_t is the return for period t, W_t is wealth relative to the starting value, and R_t is cumulative return. Return R_t after every period.

Loading visualization...

Examples

Input: returns = [0.1, 0.05, -0.02]

Output: [0.1, 0.155, 0.1319]

Explanation: The wealth factors become 1.1, 1.155, and 1.1319 after compounding.

Input: returns = [-0.5, 1.0]

Output: [-0.5, 0.0]

Hint 1

Maintain one running wealth value rather than adding returns.

Hint 2

Append wealth - 1 immediately after processing each return.

Requirements

  • Begin with a wealth factor of 1.0.
  • Multiply the running wealth by 1 + r for each period.
  • Append the running wealth minus 1 after every update.
  • Return a list with the same length as returns.

Constraints

  • returns is nonempty.
  • Every return is greater than -1.
  • Time limit: 300 ms.
Try Similar Problems
Percent ChangeDifferencingExponential Moving AverageSimple Moving AverageLag Features

Sign in to take notes on this problem

Case 1
Case 2

Accepts: array

You must run your code first.
PrevNext

Cumulative Returns

Time Series
Easy

Returns across multiple periods compound multiplicatively. Begin with a wealth factor of 1.0 and update it after each period:

Wt=Wt−1(1+rt)W_t = W_{t-1}(1+r_t)Wt​=Wt−1​(1+rt​)

Convert the wealth factor back to cumulative return:

Rt=Wt−1R_t = W_t - 1Rt​=Wt​−1

Here, r_t is the return for period t, W_t is wealth relative to the starting value, and R_t is cumulative return. Return R_t after every period.

Loading visualization...

Examples

Input: returns = [0.1, 0.05, -0.02]

Output: [0.1, 0.155, 0.1319]

Explanation: The wealth factors become 1.1, 1.155, and 1.1319 after compounding.

Input: returns = [-0.5, 1.0]

Output: [-0.5, 0.0]

Hint 1

Maintain one running wealth value rather than adding returns.

Hint 2

Append wealth - 1 immediately after processing each return.

Requirements

  • Begin with a wealth factor of 1.0.
  • Multiply the running wealth by 1 + r for each period.
  • Append the running wealth minus 1 after every update.
  • Return a list with the same length as returns.

Constraints

  • returns is nonempty.
  • Every return is greater than -1.
  • Time limit: 300 ms.
Try Similar Problems
Percent ChangeDifferencingExponential Moving AverageSimple Moving AverageLag Features

Sign in to take notes on this problem

Case 1
Case 2

Accepts: array

You must run your code first.