---
title: "13 The Capital Asset Pricing Model"
format:
  html:
    self-contained: TRUE
---

## Part 1: CAPM Basics

The **Capital Asset Pricing Model** is a simple idea in finance that says: if a stock earns higher returns compared to the market on average, it's because that stock is *riskier* than the market. And if a stock earns lower returns than the market on average, it's because that stock is *less risky* than the market. Why? People are risk-averse, so they demand compensation (in expectation) for holding a risky asset.

The elements of the model:

- $r_f$: the "risk-free" rate. It's the expected return on an extremely safe investment, like the guaranteed interest in a bank savings account, or more commonly, the yield on a U.S. 10-year Treasury note (around 4.4% annually right now).
- $r_m$: the expected return of the market as a whole. Since 1957, the S&P 500 has had an average annual return of about 10.4%.
- $\beta$: a measure of how much a certain stock moves with the market as a whole. Let's say Apple has a $\beta$ of 0.99 (when the market goes up, Apple goes up by 99% as much; when the market goes down, Apple goes down by 99% as much). Therefore, Apple is just a little bit *safer* an asset compared to the market in general. But take another stock: let's say Facebook has a $\beta$ of 1.2. That means when the market goes up, Facebook goes up even more. And when the market goes down, Facebook goes down by even more: it's *riskier* than the market.

CAPM says that stocks with higher $\beta$ earn higher returns on average than the market as a whole because investors demand to be compensated for bearing the extra risk.

![](https://media.wallstreetprep.com/uploads/2021/09/11224111/CAPM-Graph.jpg)

The market as a whole has a $\beta$ of exactly 1, by definition. The CAPM is the line:

$$r_a = r_f + \beta \times (r_m - r_f)$$

where $r_a$ refers to the return for an asset with risk $\beta$.

**Question 1:** According to the CAPM, if stock A has a $\beta$ of 0.9 and stock B has a $\beta$ of 1.3, which stock should you expect will earn a higher return, and why?

**Question 2:** Calculate the CAPM expected return for a stock with $\beta = 1$, given a risk-free rate of .044 and a market rate of .104.

**Question 3:** Calculate the CAPM expected return for a stock with $\beta = 0.9$, given a risk-free rate of .044 and a market rate of .104. Fill in the blanks: because this asset is (more/less) risky than the market as a whole, its returns are expected to be (higher/lower).

## Part 2: Estimating Beta

```{r, message = F}
library(quantmod)
library(tidyverse)
```

```{r, eval = F}
# Run this to download the FRED series
# called "TB3MS": 3-Month treasury bill
# secondary rate. This is a commonly
# used proxy for the risk-free interest
# rate. We'll download this rate for
# every month from January, 2000 to 
# December, 2024.

getSymbols("TB3MS", src = "FRED")

TB3MS %>% 
  fortify.zoo() %>% 
  as_tibble() %>% 
  rename(
    date = Index,
    annual_rf_percent = TB3MS
  ) %>% 
  filter(date >= "2000-01-01",
         date <= "2024-12-31") %>% 
  mutate(
    annual_rf = annual_rf_percent / 100,
    rf_return = (1 + annual_rf)^(1/12) - 1
  ) %>%
  write_csv("risk_free_rate.csv")
```

```{r}
risk_free <- read_csv("risk_free_rate.csv")

# Then use `stocks.csv` and `sp500_index.csv`
# from the Chapter 8 assignment on Building
# Portfolios.
stocks <- read_csv("stocks.csv")
sp500 <- read_csv("sp500_index.csv") %>%
  select(date, sp500_ret = ret)
```

**Question 4:** What is $r_f$ and $r_m$, the average risk-free rate and the average market rate (average S&P 500 return)?

```{r}
sp500 %>% summarize(____)
risk_free %>% summarize(____)
```

I'll join stocks, sp500, and risk_free to create `joined_data` that has, for each stock and each date, the market rate and the risk-free rate.

```{r}
joined_data <- stocks %>%
  left_join(sp500, join_by(date)) %>%
  mutate(date = ceiling_date(date, unit = "month")) %>%
  left_join(risk_free, join_by(date)) %>%
  select(permno, date, ret, comnam, sp500_ret, rf_return)
```

```{r}
# Question 5: What is Apple's average monthly return (permno 14593)?

joined_data %>%
  filter(permno == 14593) %>%
  summarize(____)

# Question 6: Finish the code below to estimate 
# Apple's CAPM beta. The CAPM regression is
# ret_a ~ ret_m, where ret_a is Apple's return
# in excess of the risk-free rate, and ret_m
# is the market's return in excess of the risk-free
# rate.

joined_data %>%
  filter(____) %>%
  mutate(
    ret_a = ____, 
    ret_m = ____
    ) %>%
  lm(ret_a ~ ret_m, data = .) %>%
  broom::tidy()

# Apple's beta is: ____, which indicates it's 
# (more/less) risky than the market as a whole.

# Question 7: Visualize a time series of Apple's
# returns on top of the returns for the S&P 500.
# Does your beta estimate make sense from the
# previous question?

joined_data %>%
  filter(permno == 14593) %>%
  mutate(ret_a = ____, ret_m = ____) %>%
  ggplot(aes(x = ____, y = ret_a)) +
  geom_line(color = "red") +
  geom_line(aes(x = ____, y = ret_m), color = "blue")

# Fill in the blanks: Apple is (more/less) risky 
# than the market overall, and earns a (higher/lower)
# return, which (supports/does not support) the
# CAPM theory.
```

**Question 8:** Analyze the average return and beta for each of these stocks. Which stock is riskiest out of this list? Do any *not* support the CAPM theory (if beta is higher than 1, mean(return) is higher than the S&P 500 average)? Use map() on a vector of permnos to do this task.

| comnam    | permno | mean(return) | beta |
|-----------|--------|--------------|------|
| Microsoft | 10107  |              |      |
| Amazon    | 84788  |              |      |
| Tesla     | 93436  |              |      |
| NVIDIA    | 86580  |              |      |
| Facebook  | 13407  |              |      |
| McDonalds | 43449  |              |      |
| Coca Cola | 11995  |              |      |
| Netflix   | 89393  |              |      |
| Nike      | 57665  |              |      |
| Walmart   | 55976  |              |      |
| Costco    | 87055  |              |      |
| Starbucks | 77702  |              |      |
| GameStop  | 89301  |              |      |

```{r}
map(
  .x = c(10107, 84788, 93436, ____________),
  .f = function(p) {
    # Average returns
    r <- joined_data %>%
      filter(permno == ___) %>%
      summarize(
        mean_ret = mean(___, na.rm = T), 
        mean_sp500 = mean(___, na.rm = T)
        )
    
    # CAPM beta
    joined_data %>%
      filter(permno == ___) %>%
      mutate(
        r_a = ___, 
        r_m = ___
        ) %>%
      lm(___, data = .) %>%
      broom::tidy() %>%
      slice(___) %>%
      select(beta = estimate) %>%
      bind_cols(r) %>%
      mutate(permno = p) %>%
      select(permno, mean_ret, mean_sp500, beta)
  }
) %>%
  bind_rows()
```

## Part 3: Alpha

The CAPM says that a stock's return should be completely explained by its exposure to market risk, measured by $\beta$.

But what if a stock tends to earn *more* than the CAPM predicts? Or *less* than the CAPM predicts? That extra return is called $\alpha$, and in the linear regression, it will be captured by a nonzero intercept.

```{r}
# Question 9: Does Apple earn returns in excess of
# what the CAPM predicts, given its risk relative to
# the market? Run the CAPM regression and evaluate
# whether you can reject the null hypothesis that
# the intercept is 0.

joined_data %>%
  filter(permno == 14593) %>%
  mutate(
    ret_a = ____, 
    ret_m = ____
    ) %>%
  lm(ret_a ~ ret_m, data = .) %>%
  broom::tidy()
```

**If a stock's alpha is not zero, that suggests a failure of the CAPM model.** Under CAPM, a stock's expected return should be completely explained by its exposure to market risk, measured by $\beta$. If a stock consistently earns returns above or below what CAPM predicts, then the model is missing something.

Possible reasons for $\alpha > 0$ include:

- genuinely exceptional management that continually performs better than investors expect
- valuable patents, technology, or other advantages that investors consistently underestimate
- other reasons for investors undervaluing the asset for long periods
- pure luck or random chance
- exposure to other types of risk that CAPM does not include, such as size, value, or momentum risk factors

Out of this list, the last reason is the one we tend to believe in general.

**Question 10:** Out of the stocks we analyzed in question 8, which stock has the highest alpha? What about the lowest alpha? How many stocks had evidence that alpha was not zero (failure of the CAPM model)?

## Part 4: Omitted Variable Bias in the CAPM

Let's return to this explanation for a nonzero $\alpha$: "exposure to other kinds of risk not included in the CAPM". The CAPM assumes that the only important kind of risk is market risk. But what if stocks are exposed to *other* systematic risks besides the market overall? There can be risks to factors like:

- small-company risk
- technology-sector risk
- oil price risk
- interest rate risk
- momentum risk (risk to companies whose stocks are currently having momentum)
- recession risk

**Question 11:** Suppose technology companies tend to earn unusually high returns because they are exposed to *innovation risk*. Fill in the blank: innovation risk is strongly correlated with overall market risk, innovation risk is correlated with __________, and therefore if we estimate CAPM, leaving innovation risk out of the model, it will create omitted variable bias and lead us to incorrectly estimate both $\alpha$ and $\beta$.


**Question 12:** Explain why omitting a company's exposure to oil price risk would create OVB in the CAPM.



Given this omitted variable bias issue, CAPM is no longer considered a complete description of stock returns. Economists have found many patterns in returns that cannot be fully explained by market beta alone.

In the rest of the course, we'll study several ways researchers test and extend asset pricing models:

- the Fama-MacBeth approach for testing whether certain stock characteristics predict returns
- anomalies like the price-earnings effect, where some stocks appear to systematically outperform CAPM predictions
- the Fama-French three-factor model, which adds additional sources of risk beyond the market
- papers like DellaVigna and Pollet (2009), which explore how investor behavior and limited attention can affect prices

These approaches suggest that stock returns may depend on multiple kinds of risk, firm characteristics, and investor behavior, not just market exposure alone.

## Download this assignment

Here's a [link](downloads/CW13-CAPM.qmd) to download this assignment. Turn in your finished work to Canvas (one copy per group).

