Answers for "python pandas cumulative return"

2

python pandas cumulative return

#We calculate and plot the cumulative return of a given dataframe called data
r = data.pct_change()  
r_plus_one = r.add(1)
cumulative_return = r_plus_one.cumprod().sub(1)
cumulative_return.mul(100).plot()
plt.ylabel('Percent')
plt.legend(['Cumulative Return'])
plt.show()
Posted by: Guest on September-15-2021

Code answers related to "python pandas cumulative return"

Python Answers by Framework

Browse Popular Code Answers by Language