I am trying to create a DataFrame
with a rolling cumulative percentage change. I would like to show the percentage change of the stock from the initial buy date (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
Thank you @EdChum
What I was looking for was...
PriceChange = cvs.diff().cumsum()
PercentageChange = PriceChange / cvs.iloc[0]
How about this:
(cvs.iloc[-1] - cvs.iloc[0]) / cvs.iloc[0] * 100
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With