In [2]:
import numpy as np
import pandas as pd
from pandas_datareader import data as wb
import matplotlib.pyplot as plt
In [18]:
tickers = ['PG', 'BRK']
sec_data = pd.DataFrame()
for t in tickers:
sec_data[t] = wb.DataReader(t, data_source='google', start='2007-1-1')['Close']
In [19]:
sec_data.tail()
Out[19]:
In [20]:
sec_returns = np.log(sec_data / sec_data.shift(1))
In [21]:
sec_returns
Out[21]:
In [10]:
sec_returns['PG'].mean() # Daily average return
Out[10]:
In [11]:
sec_returns['PG'].mean() * 250 # Anually average return
Out[11]:
In [12]:
sec_returns['PG'].std() # standard deviation
Out[12]:
In [13]:
sec_returns['PG'].std() * 250 ** 0.5 # volatility or risk
Out[13]:
In [14]:
sec_returns['BRK'].mean()
Out[14]:
In [15]:
sec_returns['BRK'].mean() * 250
Out[15]:
In [16]:
sec_returns['BRK'].std()
Out[16]:
In [17]:
sec_returns['BRK'].std() * 250 ** 0.5
Out[17]:
In [22]:
sec_returns[['PG', 'BRK']].std() * 250 ** 0.5 # comparing
Out[22]:
According to this analysis, BRK is riskier than PG.
In [ ]: