Graphing CAPM
The equation function:
def CAPM(rf,market,beta):
return rf+(beta*(market-rf))
The graphing:
import matplotlib.pyplot as plt
betas = []
returns = []
beta = 0
rf = .02
market = .08
for x in range(31):
betas+=[beta]
r = CAPM(rf,market,beta)
returns +=[r]
beta+=.1
plt.plot(betas,returns,"blue")
betas = []
returns = []
beta = 0
rf = .04
market = .08
for x in range(31):
betas+=[beta]
r = CAPM(rf,market,beta)
returns +=[r]
beta+=.1
plt.plot(betas,returns,"red")
betas = []
returns = []
beta = 0
rf = .02
market = .12
for x in range(31):
betas+=[beta]
r = CAPM(rf,market,beta)
returns +=[r]
beta+=.1
plt.plot(betas,returns,"black")
plt.xlabel("Beta")
plt.ylabel("Return")
plt.title("Capital Asset Pricing Model")
plt.legend(["Baseline","Higher Risk Free","Higher Risk Premium"])
plt.show()
Source Code
For the graphing, I chose to show three different cases. The first is a base case, as you can see it is a linear function with regards to beta. The second equation is the case where the risk free rate is 2% higher, as you can see it shifts the line upwards everything by 2%. The third equation is one with higher market return, it shifts the slope of the equation up.
This line is called the security market line.