The code below calculates the Compounding values starting from 100 and the percentage gains gains. I want to write a code that goes start off with the entirety of the gains array [20,3,4,55,6.5] resulting in 212.19 at the end and then takes off the first index and recalculates the compounding value [3,4,55,6.5] resulting in 176.82., It would do this until the end of the gains array [6.5]. how would I be able to implement this to the code below and get the expected output?
import numpy as np
Amount = 100
def moneyrisk(array):
for counter,iterator in enumerate(array):
Compounding = Amount * np.cumprod(array / 100 + 1)
return Compounding
gains= np.array([20,3,4,55,6.5])
print(moneyrisk(gains))
Expected output:
[212.194008, 176.82834, 171.678, 165.075, 106.5]