You should use this chunk for renew memory.
# Define a function to encapsulate your code
run_analysis <- function() {
# Check if there are open graphics devices and close them
if (!is.null(dev.list())) {
dev.off()
}
# Clear the console
cat("\014")
# Remove all objects from the global environment
rm(list = ls(all = TRUE))
}
# Call the function to execute your analysis
run_analysis()
Hey there! Today, I want to dive into a fascinating topic on my website: the Capital Assets Pricing Model (CAPM). This model essentially explores how the expected returns of a financial asset relate to the level of risk it carries. It’s like peering into the crystal ball of investments! CAPM is like the Swiss Army knife of finance – it’s super handy for companies trying to figure out how much their investments might cost them. By using tools like Excel and R, I’ve been delving into the nitty-gritty of this model, uncovering insights that help me understand the ins and outs of financial markets. It’s like solving a puzzle with numbers, and it’s pretty darn exciting!
Firstly, please see Basic Econometrics textbook for more information.
Briefly, CAPM of modern portfolio theory is shown as follows:
\[ (ER_{i}-r_{f})=\beta_{i}(ER_{m}-r_{f}) \] where
\[ ER_{i}=\text{expected rate of return on security} \ i \\ ER_{m}=\text{expected rate of return on the market portfolio e.g. S&P500} \\ r_{f}=\text{risk-free rate of return, say, the return on 90-day Treasury bills}\\ \beta_{i}=\text{the Beta coefficient, a measure of systematic risk} \] \(\beta_{i}\) is also a measure of the extent to which the \(i\)-th security’s rate of return moves with the market.Here is the interpretation of \(\beta_{i}\):
\[ \beta_{i}>1: \text{A volatile or aggressive security} \\ \beta_{i}<1: \text{A defensive security} \\ \]
Table 6.1 presents information regarding the excess returns \(Y_{t}\) (%) from a portfolio comprising 104 stocks in the cyclical consumer goods sector, and the excess returns \(X_{t}\) (%) from the entire stock market index in the U.K. This data is based on monthly observations spanning the period from 1980 to 1999, totaling 240 observations. Excess return denotes the return surpassing that of a risk-less asset.
# Load libraries and suppress messages and warnings
suppressMessages({
library(readxl)
library(forecast)
library(seastests)
library(xts)
library(zoo)
library(stats)
library(graphics)
library(utils)
library(RJDemetra)
library(fpp2)
library(reshape2)
library(ggplot2)
})
I prepared a sample excel file that comprise Table 6.1 in Basic Econometrics textbook, page 151, You can find it in my github page:
https://github.com/busragndz/Data
and
https://github.com/busragndz/Data/blob/main/Table6_1.xlsx
after that I run this:
# Read the Excel file into R
data <- read_excel("Table6_1.xlsx", sheet = "Sheet1")
Let’s remember what are the definitions of the variables:
\(Y_{t}\):(%) Excess return of an index of 104 stocks in the sector of cyclical consumer goods and
\(X_{t}\) (%) Excess return of the overall stock market index in the U.K.
This data is monthly and from 1980-1990. Due to time series structure of the data, I use line graph:
# Convert sample_data from wide form to long form
data_final <- melt(data, id.vars = "t")
# Plot the final data
ggplot(data_final,
aes(x = t,
y = value,
col = variable)) + geom_line()
Comparison of the two lines enables an analysis of the relative
performance of cyclical consumer goods stocks against the broader
market. Should the red line (\(Y_{t}\)
%) surpass the blue line (X_{t} %) at any juncture, it indicates that
cyclical consumer goods stocks outperformed the market during that
period.
Volatility is evident from the significant fluctuations in both lines, indicating considerable volatility in both sector-specific and overall market returns. This volatility may stem from diverse economic cycles, prevailing market conditions, and other external factors influencing stock performance.
Covering a substantial time frame from 1980 to 1999, the data encapsulates various economic cycles, facilitating a comprehensive examination of long-term trends and patterns.
Historically, CAPM model was expressed as
\[ Y_{t} = \beta_{1}X_{t}+\varepsilon_{t} \] From this point of perspective, I fit CAPM model via using regression approach through origin
# Fit a linear regression model and remove constant term via -1
model_origin <- lm(data$Y ~ data$X-1)
# Print the summary of the model
summary(model_origin)
##
## Call:
## lm(formula = data$Y ~ data$X - 1)
##
## Residuals:
## Min 1Q Median 3Q Max
## -20.8053 -3.9760 -0.2102 3.0745 14.7680
##
## Coefficients:
## Estimate Std. Error t value Pr(>|t|)
## data$X 1.1555 0.0744 15.53 <2e-16 ***
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
##
## Residual standard error: 5.549 on 239 degrees of freedom
## Multiple R-squared: 0.5023, Adjusted R-squared: 0.5003
## F-statistic: 241.2 on 1 and 239 DF, p-value: < 2.2e-16
As indicated by these findings, the slope coefficient, also known as the Beta coefficient, holds high significance, as evidenced by its exceptionally small p-value. The interpretation suggests that a 1 percentage point increase in the excess market rate corresponds to approximately a 1.15 percentage point increase in the excess return on the consumer goods sector index. Moreover, not only is the slope coefficient statistically significant, but it also notably exceeds 1. When the Beta coefficient surpasses 1, the security (in this case, a portfolio of 104 stocks) is considered volatile, meaning it fluctuates more than proportionately with the overall stock market index. However, this outcome shouldn’t come as a surprise, given that we are examining stocks from the cyclical consumer goods sector, which includes items such as household durables, automobiles, textiles, and sports equipment, all prone to market fluctuations.
In accordance with Basic Econometrics text book by Gujarati, omitting the constant term in a regression model can lead to biased estimates, inaccurate predictions, violation of assumptions, loss of interpretability, and reduced model fit. It is generally advisable to include the constant term in regression models to avoid these issues and ensure the validity of the results.
Alternatively, I fit the model with constant term.
Here’s the background
\[ Y_{t} = \alpha_{1}+\beta_{1}X_{t}+\varepsilon_{t} \]
# Fit a linear regression model with constant
model <- lm(data$Y ~ data$X)
# Print the summary of the model
summary(model)
##
## Call:
## lm(formula = data$Y ~ data$X)
##
## Residuals:
## Min 1Q Median 3Q Max
## -20.4122 -3.5274 0.2316 3.4774 15.1150
##
## Coefficients:
## Estimate Std. Error t value Pr(>|t|)
## (Intercept) -0.44748 0.36294 -1.233 0.219
## data$X 1.17113 0.07539 15.535 <2e-16 ***
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
##
## Residual standard error: 5.543 on 238 degrees of freedom
## Multiple R-squared: 0.5035, Adjusted R-squared: 0.5014
## F-statistic: 241.3 on 1 and 238 DF, p-value: < 2.2e-16
Based on these findings, it’s evident that the intercept doesn’t significantly differ from zero, whereas the slope coefficient (the Beta coefficient) holds high statistical significance. This implies that the regression-through-the-origin model effectively captures the data. Furthermore, there’s no statistical distinction in the slope coefficient values between the two models. It’s worth noting that the standard error of the slope coefficient in the regression-through-the-origin model is marginally lower compared to the intercept-present model. Despite this, the slope coefficient remains statistically greater than 1, reaffirming the volatility of returns on cyclical consumer goods sector stocks.
I also prepare an Excel file in my github page, so you do not have to deal with defining time series data in R. With the VBA codes I have written in this Excel file, you can easily run and compare both models by simply inputting your data. You do not also have to determine the range of your data.
For excel file:
https://github.com/busragndz/Data
and
https://github.com/busragndz/Data/blob/main/CAPM%20regression%20tool.xlsx
Good luck!!!