I. Introduction

In this assignment we aim to estimate a CAPM model using a simple OLS regression and using time-varying coefficeints from a Kalman filter. Ideally we want to see if the assumption that alphas and betas are constant is a safe assumption. If the estimates from the Kalman filter are relatively close to that of the OLS estimates then we fail to reject the null hypothesis, which is that alphas and betas produced from the CAPM are constant.

II. The Data

We download the monthly time series for the closing price of the S&P 500 index, the closing price of IBM stock, and the annualized 3 month Treasury bill rate. The S&P 500 returns will proxy as our market return. The IBM stock will be the asset for which we are trying to price using the capital asset pricing model. The Treasury bill rate is a proxy for the risk free rate. Below is the code that we use to download the data.

data.SP500.closing.price <- Quandl("YAHOO/INDEX_GSPC/CLOSE", type = 'zoo', collapse = "monthly")
data.IBM.closing.price <- Quandl("GOOG/NYSE_IBM/CLOSE", type = 'zoo', collapse = "monthly")
data.3.month.T.bill <- Quandl("FRED/TB3MS", type = 'zoo')

We will want to use returns in order to simplify our CAPM model, therefore we will transform the price data we downloaded into returns. We will also divide the 3 month Treasury bill rate by 12 in order to convert the rate into a monthly instead of annualized return. Mathematically we do this as:

\[r_t^{SP500} = 100\Delta\log SP500_t\] \[r_t^{IBM} = 100\Delta\log IBM_t\] \[r_t^{TB3MS}=TBSMS_t/12\]

where \(SP500_t\) is the closing price of the S&P500, \(IBM_t\) is the closing price of IBM stock, and \(TBSMS_t\) is the 3 month Treasury bill rate annualized. We calculate these time series in R using the following code:

r1.market <- 100*diff(log(data.SP500.closing.price), differences = 1)
r2.IBM <- 100*diff(log(data.IBM.closing.price), differences = 1)
r3.riskfree <- data.3.month.T.bill / 12

For convience we plot the time series of each variable below:

Since the data do not align in time, we restrict all three variables over the window from April 1981 to April 2017. We calculate these variables using the following code and also plot these time series below.

reg.r1.market <- window(r1.market, start = 1981 + 3/12, end = 2017 + 3/12)
reg.r2.IBM <- window(r2.IBM, start = 1981 + 3/12, end = 2017 + 3/12)
reg.r3.riskfree <- window(r3.riskfree, start = 1981 + 3/12, end = 2017 + 3/12)

III. Estimating CAPM - OLS

In this section we will be estimating the CAPM using the ordinary least squares method. In other words we will be estimating the following regression:

\[r_t^{IBM} - r_t^{TB3MS} = \alpha + \beta (r_t^{SP500}-r_t^{TB3MS}) + \varepsilon_t\] We estimate this model in R using the following code:

reg.excess.IBM.return <- reg.r2.IBM - reg.r3.riskfree
reg.excess.market.return <- reg.r1.market - reg.r3.riskfree

simple.OLS <- lm(reg.excess.IBM.return  ~ reg.excess.market.return)

The main point of the OLS estimated CAPM is that we are assuming alpha and beta (the coefficients) to be constant across time. We capture these coefficients using the following code:

alpha.OLS <- simple.OLS$coefficients[1]
beta.OLS <- simple.OLS$coefficients[2]

We then plot this OLS line in the plot below along with a scatterplot of all of the excess IBM-market return pairs.

IV. Estimating CAPM - KFS

In this section we will now be estimating the CAPM using Kalman filter. In other words we will want to estimate a CAPM model with time-varying alphas and beta. Below is the code we use to run the Kalman filter:

# SS stands for State-Space
SS.excess.market.return <- as.ts(reg.excess.market.return)
SS.excess.IBM.return <- as.ts(reg.excess.IBM.return)

# get number of observatons
T <- length(SS.excess.market.return)

# construct system matrices for state-space model - CAPM with time variable alpha and beta
Zt <- array(rbind(rep(1,T), SS.excess.market.return), dim=c(1,2,T))
Ht <- matrix(NA)
Tt <- diag(2)
Rt <- diag(2)
Qt <- matrix(c(NA,0,0,NA), 2,2)

# use diffuse prior
a1 <- matrix(c(0, 1), 2, 1)
P1 <- matrix(0, 2, 2)
P1inf <- diag(2)

# define state-space CAPM model
y.SS <- SSModel(SS.excess.IBM.return ~ -1 + SSMcustom(Z=Zt, T=Tt, R=Rt, Q=Qt, a1=a1, P1=P1, P1inf=P1inf), H=Ht)

# estimate variances of innovations using maximum likelihood
y.SS.ML <- fitSSM(y.SS, inits = c(0.001,0.001,0.001), method="BFGS")

# Kalman filtering and smoothing, with parameters in Q and H set to maximum likelihood estimates
y.SS.KFS <- KFS(y.SS.ML$model)

To extract the time-varying coefficients from this model we use:

alpha.KFS <- ts( cbind(y.SS.KFS$a[,1], y.SS.KFS$alphahat[,1]), start=c(1981,4), frequency=12)
beta.KFS <- ts( cbind(y.SS.KFS$a[,2], y.SS.KFS$alphahat[,2]), start=c(1981,4), frequency=12)

Note: plot of alpha and beta are shown in section V.

V. Comparing OLS CAPM to KFS CAPM

We now want to compare the alpha and beta estimates from the CAPM estimated using ordinary least squares and the CAPM estimated using the Kalman filter. We first compare the OLS estimates to the mean of the time series of the fitted and smoothed KFS estimates.

           (Intercept) reg.excess.market.return
OLS        -0.09956639                0.9250887
KFS Fitted -0.06942577                0.9198105
KFS Smooth -0.07471126                0.9228255

The KFS and OLS beta estimates are nearly identical; however, the alpha from the OLS estimate is smaller (more largely negative) than the KFS estimate. To get a better look at the difference between the two we plot a time series of the smoothed alpha and beta estimates from the KFS estimates of the CAPM. We also include a flat line showing the alpha and beta estimates from the OLS estimate of the CAPM.

We then show a plot for the smoothed states of alpha and beta over time. We also include a flat line to show

We confirm what we have already seen. The smoothed state alpha from the KFS estimation are all much higher at every point in time than the OLS estimation of alpha. However, the smoothed state beta seems to fluctuate around the estimated beta from the OLS model. It is more clear, though, that a smoothed state beta is a better representation of how the IBM stock covaries with the excess market return because there are clear periods where IBM stock is less risky than the market and more risky than the market as shown by the fluctuating beta. It therefore seems inappropriate to use a constant beta or alpha when using the CAPM.

VI. Conclusion

The above analysis shows that it may not be a good idea to assume that beta and alpha are constant across time. We have shown that one way to estiamte the time-varying alpha and beta coefficients for the CAPM is to use a Kalman filter. However we must be aware that the S&P500 index may not be a good proxy for the market portfolio. Therefore, we could be capturing time-varying coefficients due to a mis-specified market portfolio. We would need to try other proxies for the market portfolio to at least mitigate this concern. Furthermore, the risk free rate could be better proxied by the one month Treasury bill rather than the three month rate. Lastly, when estimating the CAPM, it is not a good idea to use a single asset, even though theoretically the model should hold. Rather, the literature has shown that it is better to use a portfolio of assets to determine the validity of the CAPM and its assumptions.

OVerall, we have shown some evidence that time-varying coefficients may be needed, however, we cannot rule out the possibilty of having a mis-specified model and it is therefore possible that the CAPM with constant coefficients is still true.