All problems
Cumulative Return
Problem
Compute the simple cumulative return over a price path: prices[-1] / prices[0] - 1.
Return 0.0 when there are fewer than two prices or the first price is 0.0.
Hint
Only the first and last prices matter.
Test cases
case 1
in: [[100,150]]
expected: 0.5
case 2
in: [[100,50]]
expected: -0.5
case 3
in: [[10]]
expected: 0
case 4
in: [[2,4,8]]
expected: 3
Starter codePython
def cumulative_return(prices):
# Your code here
pass4 test cases · run your code against them in the editor