import pandas as pd
import edhec_risk_kit as erk
import numpy as np
import statsmodels.api as sm
ind_rets = erk.get_ind_file('returns', n_inds=49)
fff = erk.get_fff_returns()
What is the market beta for Healthcare industry stocks from 1970 to 2015?
hlth_excess = ind_rets.loc['1970':'2015', ['Hlth']] - fff.loc['1970':'2015', ['RF']].values
mkt_excess = fff.loc['1970':'2015', ['Mkt-RF']]
exp_var = mkt_excess.copy()
exp_var['Constant'] = 1
lm = sm.OLS(hlth_excess, exp_var).fit()
lm.summary()
The market beta for healthcare stocks is the coefficient on the Mkt-RF variable in the model. In this case, it is 1.1222. This tells us that the expected excess return for healthcare stocks is 1.1222 times the excess return of the market
industries = list(ind_rets.columns)
betas = []
for ind in industries:
ind_excess = ind_rets.loc['1970':'2015 ', [ind]] - fff.loc['1970':'2015', ['RF']].values
lm = sm.OLS(ind_excess, exp_var).fit()
betas.append(lm.params['Mkt-RF'])
beta_df = pd.DataFrame({'Beta':betas},
index = industries)
print(beta_df['Beta'].idxmax(), 'had a market beta of', np.round(beta_df['Beta'].max(),2))
print(beta_df['Beta'].idxmin(), 'had a market beta of', np.round(beta_df['Beta'].min(),2))