Reputation: 947
So I am trying to go from cumulative returns given by
hist_data = (hist_data - hist_data.iloc[0]) / hist_data.iloc[0]
And I am trying to go from this cumulative return to daily returns but am blanking on how to do this effectively. Any ideas? I thought this might work if I subtract by one
(hist_data[1:] - hist_data[:-1]) / hist_data[:-1]
Upvotes: 1
Views: 929
Reputation: 2574
If hist_data
contains the cumulative returns, then this is a common shortcut for computing daily returns. Assuming hist_data
is a vector of return percentages, you will need to add 1.0
to hist_data, as I have done below. This way we have a vector of return ratios instead of return percentages.
import numpy as np
daily_returns = np.exp(np.log(hist_data + 1.0).diff())
Here we are simply using the property of natural logs (ln
) that says
ln(a/b) = ln(a) - ln(b)
a/b = exp(ln(a) - ln(b))
Upvotes: 5