How to calculate the cumulative percentage change since the beginning of the period

I am trying to create a DataFrame with a rolling cumulative percentage change. I would like to show the percentage change in the stock from the start date of the purchase (2014-09-05).

 import pandas as pd import pandas.io.data as web cvs = web.get_data_yahoo('cvs', '2014-09-05')['Adj Close'] cvsChange = cvs[1:] / cvs.shift(1) - 1 
+4
source share
2 answers

Thanks @EdChum

What I was looking for was ...

 PriceChange = cvs.diff().cumsum() PercentageChange = PriceChange / cvs.iloc[0] 
+5
source

How about this:

 (cvs.iloc[-1] - cvs.iloc[0]) / cvs.iloc[0] * 100 
+2
source

All Articles