Simple rate of return

$\frac{\text{ending price}\: - \:\text{beginning price}}{\text{beginning price}}$

When dealing with multiple assets over the same timeframe

Logarithmic rate of return

$\log \frac{\text{ending price}}{\text{beginning price}} = \log \text{ending price} - \log \text{beginning price}$

When you make calculations about a single asset over time

Annual return

$\text{annual return} = [(\text{daily return} + 1)^{365}] \times 100 $

In [1]:
import numpy as np
from pandas_datareader import data as wb
import matplotlib.pyplot as plt
In [2]:
PG = wb.DataReader('PG', data_source='yahoo', start='1995-1-1')

Simple rate of return

$\frac{P_1 - P_0}{P_0}=\frac{P_1}{P_0}-1$

In [3]:
PG.head()
Out[3]:
High Low Open Close Volume Adj Close
Date
1995-01-03 15.62500 15.43750 15.46875 15.59375 3318400.0 6.320252
1995-01-04 15.65625 15.31250 15.53125 15.46875 2218800.0 6.269589
1995-01-05 15.43750 15.21875 15.37500 15.25000 2319600.0 6.180927
1995-01-06 15.40625 15.15625 15.15625 15.28125 3438000.0 6.193593
1995-01-09 15.40625 15.18750 15.34375 15.21875 1795200.0 6.168259
In [4]:
PG['simple_return'] = (PG['Adj Close'] / PG['Adj Close'].shift(1)) - 1
PG['simple_return'].head()
Out[4]:
Date
1995-01-03         NaN
1995-01-04   -0.008016
1995-01-05   -0.014142
1995-01-06    0.002049
1995-01-09   -0.004090
Name: simple_return, dtype: float64
In [5]:
PG['simple_return'].plot(figsize=(8,5))
plt.show()
In [6]:
# daily
avg_returns_d = PG['simple_return'].mean()
avg_returns_d
Out[6]:
0.0005616927968466187
In [7]:
# annually
avg_returns_a = PG['simple_return'].mean()*250
avg_returns_a
Out[7]:
0.14042319921165466
In [8]:
print (str(round(avg_returns_a,5)*100)+' %')
14.041999999999998 %

Logarithmic rate of return

$ln \left ( \frac{P_t}{P_{t-1}} \right )$

In [9]:
PG.head()
Out[9]:
High Low Open Close Volume Adj Close simple_return
Date
1995-01-03 15.62500 15.43750 15.46875 15.59375 3318400.0 6.320252 NaN
1995-01-04 15.65625 15.31250 15.53125 15.46875 2218800.0 6.269589 -0.008016
1995-01-05 15.43750 15.21875 15.37500 15.25000 2319600.0 6.180927 -0.014142
1995-01-06 15.40625 15.15625 15.15625 15.28125 3438000.0 6.193593 0.002049
1995-01-09 15.40625 15.18750 15.34375 15.21875 1795200.0 6.168259 -0.004090
In [10]:
PG['log_return'] = np.log(PG['Adj Close'] / PG['Adj Close'].shift(1))
PG['log_return'].head()
Out[10]:
Date
1995-01-03         NaN
1995-01-04   -0.008048
1995-01-05   -0.014243
1995-01-06    0.002047
1995-01-09   -0.004099
Name: log_return, dtype: float64
In [11]:
PG['log_return'].plot(figsize=(8,5))
plt.show()
In [12]:
# daily
log_return_d = PG['log_return'].mean()
log_return_d
Out[12]:
0.00045771481720173555
In [13]:
# annually
log_return_a = PG['log_return'].mean() * 250
log_return_a
Out[13]:
0.11442870430043389
In [14]:
print (str(round(log_return_a,5)*100)+' %')
11.443 %