Introduction to Portfolio Analysis in Python
Charlotte Werger
Data Scientist
$$
$ $
$ R_{pf} = \alpha + \beta_m MKT + \beta_s SMB + \beta_h HML $
MKT is the excess return of the market, i.e. $R_m - R_f$
import statsmodels.api as sm
# Define the model
model = sm.OLS(factor_data['sp500'],
factor_data[['momentum','value']]).fit()
# Get the model predictions
predictions = model.predict(factor_data[['momentum','value']])
b1, b2 = model.params
# Print out the summary statistics
model.summary()
# Get just beta coefficients from linear regression model
b1, b2 = regression.linear_model.OLS(df['returns'],
df[['F1', 'F2']]).fit().params
# Print the coefficients
print 'Sensitivities of active returns to factors:
\nF1: %f\nF2: %f' % (b1, b2)
Sensitivities of active returns to factors:
F1: -0.0381
F2: 0.9858
Introduction to Portfolio Analysis in Python