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)Convert the wealth factor back to cumulative return:
Rt=Wt−1Here, 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.
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]
Maintain one running wealth value rather than adding returns.
Append wealth - 1 immediately after processing each return.
Sign in to take notes on this problem
Accepts: array
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)Convert the wealth factor back to cumulative return:
Rt=Wt−1Here, 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.
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]
Maintain one running wealth value rather than adding returns.
Append wealth - 1 immediately after processing each return.
Sign in to take notes on this problem
Accepts: array