liveBook · Manning

Capital asset pricing model

As explained in Build a Robo-Advisor with Python (From Scratch)

The capital asset pricing model is a financial model that estimates an asset's expected return from the risk-free rate, market expected return, and the asset's sensitivity to market returns.

Asset allocation requires expected returns for individual assets. CAPM provides an alternative to averaging historical returns by relating an asset’s forecasted return to the risk-free rate, the market’s expected return, and the asset’s beta. section 3.3 section 3.0

The CAPM equation is E[r] = r_f + β(E[r_m] − r_f). Beta measures sensitivity to market returns: the market has beta 1, less-sensitive stocks have beta below 1, and more-sensitive stocks have beta above 1. section 3.1.2

A practical CAPM workflow uses:

  • Three-month Treasury Bill rates as a short-term risk-free-rate proxy, converted from percentage yields to decimal monthly rates. section 3.1.2
  • SPY historical prices as a proxy for market returns, combined with monthly stock prices. section 3.1.2
  • An ordinary least-squares regression of stock excess returns on market excess returns to estimate beta. section 3.1.2

Comparing CAPM estimates

Using a 5.27% risk-free rate and an 8.0741% annualized market return, the resulting CAPM estimates are AAPL: beta 1.3187 and expected return 8.96%; FE: beta 0.2958 and 6.10%; WMT: beta 0.4907 and 6.64%. Historical returns differ substantially, especially for AAPL. section 3.1.2

Listing 3.3 Regressing stock returns on market returns to get beta
import statsmodels.api as sm

stock_prices_monthly = stock_prices.resample('MS').first()  #1
mkt_prices_monthly = mkt_prices.resample('MS').first()
aapl_returns_monthly = stock_prices_monthly['AAPL'].pct_change()  #2

mkt_returns_monthly = mkt_prices_monthly.pct_change()
y = (aapl_returns_monthly - rf['TB3MS']/100/12).dropna()  #3
X = (mkt_returns_monthly - rf['TB3MS']/100/12).dropna()  #4
model = sm.OLS(y,X)  #5
results = model.fit()  #6
print(results.summary())  #7

Inspect the executable regression that prepares monthly excess returns, fits the OLS model, and prints the estimated beta. section 3.1.2

How Build a Robo-Advisor with Python (From Scratch) covers it

How deep it goes
Works from formula through rate downloads and excess-return regression, then compares CAPM estimates with historical returns.
Examples
Uses AAPL, FE, WMT, SPY, three-month T-Bills, and a Python OLS regression to produce beta and expected-return estimates.
What it assumes
Requires asset-price and market data while teaching the risk-free rate, market return, beta, and their preparation.
What you can do after
Apply it via pandas-datareader, yfinance, and statsmodels to estimate beta and CAPM expected returns.
How it connects
Connects expected returns with beta, risk-free rates, market returns, historical returns, and covariance matrices.

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Build a Robo-Advisor with Python (From Scratch). The section links point to the parts of the book it draws on.