You have a series of period-by-period returns and want to know how you're doing overall. The tempting move is to add them up. That's wrong, and the error compounds along with the returns.
Returns multiply. Each period scales your position by (1 + r), so after several periods:
Task: write cumulative_returns(returns) returning the cumulative return after each period, each rounded to 4 decimal places.
returns[t] is that period's return as a fraction: 0.1 is a 10% gain, -0.05 a 5% loss.1.0, multiply by (1 + r) each period, and report growth - 1.The - 1 at the end converts a factor back into a return: a growth factor of 1.21 is a 21% gain. Mixing up the two is the most common bug here — report the factor and all your numbers are off by exactly 1.
Two 10% gains make the point: additively that's 20%, but multiplicatively 1.1 × 1.1 = 1.21, a 21% gain. The extra 1% is the second period's gain on the first period's gain, and over many periods that gap becomes the whole story.