Original link:tecdat.cn/?p=20031
Original source:Open end data tribes
Introduction to the
The Capital Asset Pricing Model (CAPM) is used to determine whether an investment in a particular asset is worthwhile. In essence, the question is: “Are the returns on the asset worth investing in?” In this tutorial, we will apply the CAPM model, using multiple regression models to see if a particular stock is worth investing in.
CAPM: formula
Economics is about trade-offs. The CAPM formula basically compares stocks, or any type of asset class, with relatively risk-free assets (usually government bonds) because the probability of default is very low. The CAPM formula is as follows
- E (Ri) is the expected rate of return.
- Rf is a risk-free asset, usually a government bond.
- The β I coefficient reflects the correlation between a single security and the overall market portfolio and is used to measure the risk of a single security.
- E (Rm) -RF is considered a risk premium.
We can graphically represent the CAPM model using the following figure
An efficient portfolio on the securities market line (SML) is either a single risk-free asset or a combination of a risk-free asset and a market portfolio. Therefore, the capital market line cannot explain the relationship between the expected return rate and risk of all single securities or only portfolios of risky securities.
Our goal is to find the value of β I using linear regression.
data
We will use the data to find the beta of each stock.
kable(head(capm, 11), format = 'html')
Copy the code
1st Qu.:-0.043638 1st Qu.:-0.032974 1st Qu.:-0.032974 1st Qu.:-0.076167 ## Median: 0.002240 | Median: -0.002240 | Median: -0.002240 | Median: -0.002240 ## Mean: 0.002240 | Median: -0.002240 0.001361 Mean :-0.009081 ## 3rd Qu.: 0.047858 3rd Qu.: 0.040096 3rd Qu.: 0.068138 ## Max. : 0.241453 Max. : 0.192392 Max. : 0.276619 ## IBM MSFT XOM ## Min. :-0.226453 Min. :-0.343529 Min. :-0.116462 ## 1st Qu.:-0.038707 1st Qu.:-0.056052 1st Qu.: -0.022464 ## Median: 0.006482 Median: 0.003996 Median: 0.003309 ## Mean: 0.008332 Median: 0.008557 Median: 0.010488 ## 3rd Qu.: 0.051488 3rd Qu.: 0.056916 3rd Qu.: 0.041534 ## Max. : 0.353799 Max. : 0.407781 Max. : ## MKT RiskFree ## m.: -2.224745 Min. : 0.00224744 ## Median: 0.00224744 0.010952 Median :0.002870 ## Mean: 0.002570 ## Median :0.002675 ## 3rd Qu.: 0.037875 3rd Qu.:0.003904 ## Max. : 0.083925 Max. : 0.005195Copy the code
According to our data, we have six stocks that we have to decide if they are worth investing in. Unfortunately, since we must first convert the data to formula (1), we cannot just fit the regression model. We will have to calculate the new variable from the existing variable.
We need to calculate the risk premium E (Rm) -rf for each stock.
risk.premium <- mkt -riskfree
Copy the code
Let’s look at the scatter chart of stocks (MSFT).
Ggplot (AES (y = MSFT, x = risk. Premium)) + GEOM_point (col='blue') + xlab(' risk premium ') +Copy the code
It is worth noting that the higher the risk premium, the greater the expected return should be. Otherwise, it is not wise to invest in risky assets with low expected returns, which can lead to losses.
Fitting model
Now we can begin to fit our regression model. First, we must divide the data into training sets and test sets.
# We will need to create regression models for all six stocks. Dis. fit < -lm (dis ~ riskFree + risk. Premium, data = capm) # build table kable(df, format = 'HTML ') %>%Copy the code
How do we explain the value of the risk premium? The higher the risk premium, the more volatile or risky the asset, so investors should receive returns that justify the risk of the asset to compensate for losses.
Now that we have estimated beta, we can use Formula (1) to calculate the expected return for each stock.
Capm $dis.predict < -dis.predictCopy the code
Fit the regression line
ggplot aes(y = dis.predict, x = risk.premium) +
geom_smooth(col='tomato2', method='lm') +
Copy the code
Most welcome insight
1.R language multiple Logistic Logistic regression application case
2. Panel smooth transfer regression (PSTR) analysis case implementation
3. Partial least squares regression (PLSR) and principal component regression (PCR) in MATLAB
4.R language Poisson regression model analysis cases
5. Hosmer-lemeshow goodness of fit test in R language regression
6. Implementation of LASSO regression, Ridge regression and Elastic Net model in R language
7. Realize Logistic Logistic regression in R language
8. Python predicts stock prices using linear regression
9. How to calculate IDI and NRI indices for R language in survival analysis and Cox regression