In [1]:
import numpy as np
import pandas as pd
import pandas_datareader.data as wb
import matplotlib.pyplot as plt
In [3]:
BRK = wb.DataReader('BRK-A', data_source='google', start='1995-1-1')
In [4]:
BRK.head()
Out[4]:
In [5]:
BRK.tail()
Out[5]:
Adj Close is "Adjusted close price", adjusted by dividends and other events at the close of the market at that date.
In [7]:
BRK['simple_return'] = (BRK['Close'] / BRK['Close'].shift(1)) - 1
print(BRK['simple_return'])
In [8]:
BRK['simple_return'].plot(figsize=(8,5))
plt.show()
In [12]:
avg_returns_d = BRK['simple_return'].mean()
avg_returns_d
Out[12]:
In [13]:
avg_returns_a = avg_returns_d * 250 # multiply by the average number of business days per year
print(str(round(avg_returns_a, 5) * 100) + ' %')
In [14]:
BRK.head()
Out[14]:
In [10]:
BRK['log_return'] = np.log(BRK['Close'] / BRK['Close'].shift(1))
print(BRK['log_return'])
In [17]:
BRK['log_return'].plot(figsize=(8, 5))
plt.show()
In [18]:
log_return_d = BRK['log_return'].mean()
log_return_d
Out[18]:
In [19]:
log_return_a = BRK['log_return'].mean() * 250
log_return_a
Out[19]:
In [21]:
print(str(round(log_return_a, 5) * 100) + ' %')
In [ ]: