Python for Finance: Part II: 5 The Capital Asset Pricing Model
The Capital Asset Pricing Model (CAPM)
According to Markowitz, in the CAPM investors are:
– risk-averse
– prefer higher returns
– willing to buy the optimal portfolio
The market portfolio:
– a combination of all the possible investments in the world.
The risk-free asset:
– the CAPM assumes the existence of a risk-free asset.
– an investment with zero risk.
– Why should we assume the risk-free rate has a lower expected rate of return?
=> In efficient markets, investors are only compensated for the added risk they are willing to bear.
The Capital Market Line
– investors will allocate their money between the risk-free and the market portfolio
In the CAPM, investors will invest in:
– depending on their risk preferences, they will choose to buy more of the risk-free asset or more of the market portfolio.
Beta
β = Cov(rx, rm) / σm2
– measures the market risk that cannot be avoided through diversification.
β = 0: No relationship
β < 1: Defensive (Walmart)
β > 1: Aggressive (Ford)
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 |
import numpy as np import pandas as pd from pandas_datareader import data as wb tickers = ['AMZN','S&P 500'] data = pd.DataFrame() for t in tickers: data[t] = wb.DataReader(t, data_source='google', start='2012-1-1',end='2016-12-31')['Close'] sec_returns = np.log(data/data.shift(1)) cov = sec_returns.cov() * 250 cov cov_with_market = cov.iloc[0,1] cov_with_market // 0.0039599527224196103 market_var = sec_returns['S&P 500'].var() * 250 market_var // 0.02393760982543131 // Beta: AMZN_beta = cov_with_market / market_var AMZN_beta // 0.16542807537169221 |
The Capital Asset Pricing Model
ri = rf + βim(rm – rf)
rf: risk-free
βim: beta between the stock and the market
rm: market return
Risk-free: Approximate with 10-year US government bond yield: 2.5%
Beta: Approximate the market portfolio with the S&P500: 0.62
Equity Risk Premium: Historically, it has been between 4.5% and 5.5%
r(i) = 2.5% + 0.62 * 5% = 5.6%
1 2 3 4 |
// Calculate the expected return of AMZN(CAPM): AMZN_er = 0.025 + AMZN_beta * 0.05 AMZN_er // 0.033271403768584611 |
Sharpe Ratio
William Sharpe
Sharpe Ratio = (ri – rf) / σi
rf: risk-free rate
ri: rate of return of the stock “i”
σi: standard deviation of the stock “i”
1 2 3 4 |
// Sharpe ratio: Sharpe = (AMZN_er - 0.025) / (sec_returns['AMZN'].std() * 250 ** 0.5) Sharpe // 0.02701837714000498 |
Alpha
The Capital Asset Pricing Model:
ri = α + rf + βim(rm – rf)
– The standard CAPM setting assumes an alpha equal to 0.
– We can only compare the alpha of investments with a similar risk profile.