-
Compound Interest Part 1 6
-
Lecture1.1
-
Lecture1.2
-
Lecture1.3
-
Lecture1.4
-
Lecture1.5
-
Lecture1.6
-
-
Compound Interest Part 2 3
-
Lecture2.1
-
Lecture2.2
-
Lecture2.3
-
-
Present Value 4
-
Lecture3.1
-
Lecture3.2
-
Lecture3.3
-
Lecture3.4
-
-
Annuities 6
-
Lecture4.1
-
Lecture4.2
-
Lecture4.3
-
Lecture4.4
-
Lecture4.5
-
Lecture4.6
-
-
Perpetuities 2
-
Lecture5.1
-
Lecture5.2
-
-
Bonds 6
-
Lecture6.1
-
Lecture6.2
-
Lecture6.3
-
Lecture6.4
-
Lecture6.5
-
Lecture6.6
-
-
Dividend Discount Model 3
-
Lecture7.1
-
Lecture7.2
-
Lecture7.3
-
-
Risk 8
-
Lecture8.1
-
Lecture8.2
-
Lecture8.3
-
Lecture8.4
-
Lecture8.5
-
Lecture8.6
-
Lecture8.7
-
Lecture8.8
-
-
Capital Asset Pricing Model 6
-
Lecture9.1
-
Lecture9.2
-
Lecture9.3
-
Lecture9.4
-
Lecture9.5
-
Lecture9.6
-
Correlation and Beta
Correlation¶
The correlation is a number between -1 and 1 which represents how closely related two assets are. A correlation of 1 means that for every change in one asset the second one will have the same change times some constant c (so it could be that for every percent return in asset 1, asset 2 returns twice that exactly). A negative correlation would mean that the other asset gets some sort of an opposite reaction. The formula to find correlation is:
$$ \rho = \frac{COV(X, Y)}{\sigma_X \sigma_Y}$$
where
$$ \rho = \text{Correlation} $$$$ COV(X, Y) = \text{Covariance between X and Y} $$$$ \sigma_X = \text{The standard deviation of X} $$$$ \sigma_Y = \text{The standard deviation of Y} $$
There are two ways that we could find the correlation, either dividing covariance by both standard deviations or by getting the correlation matrix.
corr = np.cov(market_returns,stock_returns, ddof=0)[0][1] / (np.std(market_returns, ddof=0) * np.std(stock_returns, ddof=0))
print(corr)
corr = np.corrcoef(market_returns, stock_returns)[0,1]
print(corr)
0.8326633246824368
0.8326633246824369
Beta¶
Beta is a measure of how reactive a stock's returns are going to be market returns. A stock with a beta of one would mean that on average when there is a 1% return in the market, we expect that the stock will go up by 1% on average. A .5 beta would mean we expect the stock might go up by .5% on average, and 2 would imply a 2% return on average.
Beta can be found with the following formula:
$$ \beta = \frac{COV(S, M)}{\sigma^2_M} $$
where
$$ \beta = \text{Beta} $$$$ COV(S, M) = \text{The covariance between the stock and market} $$$$ \sigma^2_M = \text{The variance of the market} $$
Now we can find the beta.
#To calculate Beta
beta = np.cov(market_returns, stock_returns, ddof=0)[0][1] / np.var(market_returns, ddof=0)
print(beta)
0.7845586152744413
We are able to break down volatility into two measures if we want: the market risk and the idiosyncratic risk. The market risk is the risk that comes from general market exposure and then there is idiosyncratic risk which is the rest of the risk that is unrelated to general market risk conditions. Variance can be broken down as the following:
$$ \sigma^2_A = \beta_A^2 \sigma^2_M + \sigma^2_{A-I} $$
where
$ \sigma^2_A = \text{Variance of asset A} $
$ \beta_A = \text{Beta of asset A} $
$ \sigma^2_M = \text{Variance of market} $
$ \sigma^2_{A-I} = \text{Variance of the idiosnycratic part of asset A's returns} $
The first term on the right hand side is the variance from the market, and the second term is what is left over as risk unrelated to the market.
#Calculate volatility that comes from the market
market_vol = beta**2*np.var(market_returns)
print(market_vol)
0.0002405378996400538
#Calculate volatility from idiosyncratic risk
idio_vol = np.var(stock_returns)-market_vol
print(idio_vol)
0.00010639432579484973
The calculations above show that a large amount of the risk in this stock is coming from the market. More than 2/3 of the risk can be attributed to its relationship to the market, the rest is risk specific to the stock.
You can ignore the code below as it will just be for setting up our data mmoving foward.
np.random.seed(3)
betas = np.random.normal(1, .15, 100)
vols = np.random.normal(.03, .005, 100)
stock_returns = [market_returns * beta + np.random.normal(0, vol, 500) for beta, vol in zip(betas, vols)]
We have stock returns now which is 100 different stock returns. As a first step, let's find the average volatility of each random stock versus the volatility of the market. We will see below that picking a random stock leads to a much bigger volatility on average than the volatility of the market.
print(np.mean([np.std(x) for x in stock_returns]))
print(np.std(market_returns))
0.0356430155025617
0.019768165185653
We may also be interested in seeing the computed betas (if you understood the code that generates the data, you will notice the betas are not exactly the same, don't worry this is normal because noise can distort the true measures).
#Get the betas of our stock
betas = [np.cov(market_returns, r, ddof=0)[0][1] / np.var(market_returns, ddof=0) for r in stock_returns]
#Plot the betas
plt.hist(betas)
plt.xlabel("Beta")
plt.ylabel("Frequency")
plt.title("Frequency of Betas")
plt.show()