5QQMN534: Algorithmic Finance
Tutorial 9 – Statistical Analysis: CAPM and Factor Models
Question1: CAPM & OLS Regression
a) Using Yahoo Finance library download the two time series
from start_date = “1985-03-13” until end_date = 2022-01-01.
i. risky_asset = “MSFT” (Microsoft)
ii. market_benchmark = “^GSPC” (S&P 500)
b) Resample this daily adjusted close data to a monthly time
series. Save this variable called X. Make a deepcopy of X and
call it X_v2
c) Calculate the Beta between MSFT and S&P500 using the
covariance approach.
d) Implement a OLS regression. The risky_asset is the dependent
variable and the market_benchmark is the independent
variable. Print the model regression results.
2
Question1: CAPM & OLS Regression
e) Save each model results to separate DataFrame variables.
(There are 3 tables possible). Print to screen.
f) Extract the below statistics
i. Alpha co-efficient
ii. Beta co-efficient
iii. R Squared
iv. P values
g) Check the Beta from 1c is the same as 1f ii). Note rounding difference issue.
Fix to 12 dp. See below.
h) Save model summary as excel csv file. Make sure each regression value is in a
separate cell
i) Add 1,5 & 10% significance stars to the coefficients using summary_col functi
on. See below
j) Plot the regression. (See right)
3
Question 2: Downloading Factor Data
From the Fama/French Data Library accessible here:
[Link] using pandas
DataReader library from Week 6 Part 2 Extra.
a) Download the full history data for:
i. Fama/French 3 Factor Data (details on right)
ii. Fama/French 5 Factor (2x3) Data (See next slide for details)
Note start and end dates are different for each dataset
Hint: Identify the dataset wanted via the list of datasets function.
b) For each dataset, save the DESCR Description of the dataset to a variable and print
to screen.
c) For each dataset extract table position table zero to a separate dataframe. Print the
.head, .tail, .info and .describe functions.
4
Fama/French 5 Factor Description
5
Question 3: Estimating Fama / French 3 Factor Model
a) Use the Fama/French Daily 3 Factor Data acquired from Question 2ai.
b) Rename columns, correct index and filter for risky asset dates. Then convert
to correct numeric values.
c) Reuse the returns on the risky asset MSFT from question 1b and resample to
monthly. Make sure sort out date index to same format as part a.
d) Merge the factor data from part a and monthly risky asset data from part c
and calculate the excess return.
e) Define and estimate the three- factor regression model. Note: excess return is
the dependent variable.
f) Save each model results to separate DataFrames. There are 3 tables possible.
g) Extract the below statistics. Print results and round to 4 dp and display right
justified.
i. Alpha co-efficient (intercept)
ii. Beta co-efficient for each factor (mkt, smb, hml)
iii. Aic
iv. Bic
v. F-statistic
vi. Coefficient's t values
vii. Durbin Watson Statistic
viii. Jacque Bera Statistic
h) Briefly interpret the regression results
i) Coefficients
ii) t value and probability of t significance
iii) confidence intervals
iv) r squared
v) F-stat and probability of f-stat
vi) Durbin Watson Stat 6
vii) Jacque Bera Stat
Fama / French Academic papers Additional Resources
• See Fama and French, 1993, "Common Risk Factors in the Returns on Stocks and Bonds," Journal of Financial Economics:
[Link]
• Fama and French, 2014, "A Five-Factor Asset Pricing Model" for a complete description of the factor returns:
[Link]