When dealing with multiple assets over the same timeframe
When you make calculations about a single asset over time
import numpy as np
from pandas_datareader import data as wb
import matplotlib.pyplot as plt
PG = wb.DataReader('PG', data_source='yahoo', start='1995-1-1')
PG.head()
PG['simple_return'] = (PG['Adj Close'] / PG['Adj Close'].shift(1)) - 1
PG['simple_return'].head()
PG['simple_return'].plot(figsize=(8,5))
plt.show()
# daily
avg_returns_d = PG['simple_return'].mean()
avg_returns_d
# annually
avg_returns_a = PG['simple_return'].mean()*250
avg_returns_a
print (str(round(avg_returns_a,5)*100)+' %')
PG.head()
PG['log_return'] = np.log(PG['Adj Close'] / PG['Adj Close'].shift(1))
PG['log_return'].head()
PG['log_return'].plot(figsize=(8,5))
plt.show()
# daily
log_return_d = PG['log_return'].mean()
log_return_d
# annually
log_return_a = PG['log_return'].mean() * 250
log_return_a
print (str(round(log_return_a,5)*100)+' %')