In this study, the daily returns of the US Industry and the daily returns of the Fama-French 3 factor were compared and the betas of the US industry were calculated and these values were tried to be shown with graphs. And, I try to explain with some questions so This study should be looks like a assignment.
You can download the Fama-French daily factors for US Stocks from the following website: https://mba.tuck.dartmouth.edu/pages/faculty/ken.french/data_library.html
> website: All exercises based on the R program language¶
library(data.table)
library(readr)
#setwd('')
industry_portfolios = na.omit(read.csv('US_Industry_Portfolios_Daily.csv'))
factors = na.omit(read.csv('F-F_Research_Data_Factors_daily.csv'))
colnames(factors)[1] = 'Date'
factors = factors[20113:25419,]
industry_portfolios$Date = NULL
factors$Date = NULL
betas = list()
alphas = list()
r_squares = list()
t_stats = list()
for(i in 1:ncol(industry_portfolios)){
model1 = coef(lm(industry_portfolios[,i]-factors$RF ~ factors$Mkt.RF+factors$SMB+factors$HML))[2:4]
betas[[i]] = model1
names(betas)[i] = colnames(industry_portfolios)[i]
model2 = coef(lm(industry_portfolios[,i]-factors$RF ~ factors$Mkt.RF+factors$SMB+factors$HML))[1]*252 # Yearly alpha.
alphas[[i]] = model2
names(alphas)[i] = colnames(industry_portfolios)[i]
model3 = summary(lm(industry_portfolios[,i]-factors$RF ~ factors$Mkt.RF+factors$SMB+factors$HML))$r.squared
r_squares[[i]] = model3
names(r_squares)[i] = colnames(industry_portfolios)[i]
model4 = summary(lm(industry_portfolios[,i]-factors$RF ~ factors$Mkt.RF+factors$SMB+factors$HML))$coefficients[2:4,3]
t_stats[[i]] = model4
names(t_stats)[i] = colnames(industry_portfolios)[i]
}
The code I provided performs a regression analysis on US industry portfolio data using the Fama-French three-factor model and momentum factor. The analysis aims to estimate the beta coefficients, annualized alpha, R-squared, and t-statistics for each industry portfolio, as well as to create bar plots to visualize the results.
betas = transpose(as.data.frame(betas))
rownames(betas)= colnames(industry_portfolios)
colnames(betas) = c('MKT_RF','SMB','HML')
alphas = transpose(as.data.frame(alphas))
rownames(alphas) = colnames(industry_portfolios)
colnames(alphas) = 'Yearly Alphas'
r_squares = transpose(as.data.frame(r_squares))
rownames(r_squares) = colnames(industry_portfolios)
colnames(r_squares) = 'R_Squares'
t_stats = transpose(as.data.frame(t_stats))
rownames(t_stats) = colnames(industry_portfolios)
colnames(t_stats) = c('Tstat_MKT_RF','Tstat_SMB','Tstat_HML')
stats = cbind(betas,alphas,r_squares,t_stats)
MKT = stats[order(stats$MKT_RF,decreasing = FALSE),]
barplot(x1$MKT_RF,horiz = T,cex.names = 0.7,col = 'blue4',las = 1,names.arg =rownames(x1) ,main = 'Market Betas',xlim = c(0,1.5))
SMB = stats[order(stats$SMB,decreasing = FALSE),]
barplot(x2$SMB,horiz = T,cex.names = 0.7,col = 'blue4',las = 1,names.arg =rownames(x2) ,main = 'Size Betas',xlim = c(-0.3,1))
HML = stats[order(stats$HML,decreasing = FALSE),]
barplot(x3$HML,horiz = T,cex.names = 0.7,col = 'blue4',las = 1,names.arg =rownames(x3) ,main = 'Value Betas')
Based on the I provided data, it appears that the t-statistics for both SMB and HML are statistically significant, The t-stats for SMB and HML are 2.955801 and 8.36437267, respectively. These values indicate that both factors are statistically significant at a high level of confidence, suggesting that they are priced factors. Beta and alpha are commonly used measures in finance to assess the risk and return characteristics of an investment, So this beta and alpha is high and we can say that it is significant and this values have a correlation.. Therefore, we can we so few insdustries have without priced size and value factors. finance,retail same sectors not statistically significant and they not have a correlation.
# Read in data and format
mom_factors = na.omit(read.csv('F-F_Momentum_Factor_daily.csv')) # Read in momentum factor data and remove missing values
colnames(mom_factors)[1] = 'Date' # Rename the first column to "Date"
mom_factors = mom_factors[20012:25318,] # Subset to only the dates we need
mom_factors$Date = NULL # Remove the "Date" column
# Initialize output lists
betas = list() # For storing beta coefficients
alphas = list() # For storing alphas
r_squares = list() # For storing R-squared values
t_stats = list() # For storing t-statistics
# Loop over each industry portfolio
for(i in 1:ncol(industry_portfolios)){
# Estimate regression model and store results in output lists
model1 = coef(lm(industry_portfolios[,i]-factors$RF ~ factors$Mkt.RF+factors$SMB+factors$HML+mom_factors$Mom))[2:5] # Store beta coefficients
betas[[i]] = model1
names(betas)[i] = colnames(industry_portfolios)[i]
model2 = coef(lm(industry_portfolios[,i]-factors$RF ~ factors$Mkt.RF+factors$SMB+factors$HML+mom_factors$Mom))[1]*252 # Store annualized alpha
alphas[[i]] = model2
names(alphas)[i] = colnames(industry_portfolios)[i]
model3 = summary(lm(industry_portfolios[,i]-factors$RF ~ factors$Mkt.RF+factors$SMB+factors$HML+mom_factors$Mom))$r.squared # Store R-squared value
r_squares[[i]] = model3
names(r_squares)[i] = colnames(industry_portfolios)[i]
model4 = summary(lm(industry_portfolios[,i]-factors$RF ~ factors$Mkt.RF+factors$SMB+factors$HML+mom_factors$Mom))$coefficients[2:5,3] # Store t-statistics
t_stats[[i]] = model4
names(t_stats)[i] = colnames(industry_portfolios)[i]
}
I provided a block of R code that estimates several regression models for each of the industry portfolios in the Fama-French-Carhart data set. The regression models include the Fama-French factors (Mkt.RF, SMB, HML) and a momentum factor (Mom), and the output includes estimates of the beta coefficients for each factor, the alpha (annualized), the R-squared value, and the t-statistics for each factor.
betas = transpose(as.data.frame(betas))
rownames(betas)= colnames(industry_portfolios)
colnames(betas) = c('MKT_RF','SMB','HML','WML')
alphas = transpose(as.data.frame(alphas))
rownames(alphas) = colnames(industry_portfolios)
colnames(alphas) = 'Yearly Alphas'
r_squares = transpose(as.data.frame(r_squares))
rownames(r_squares) = colnames(industry_portfolios)
colnames(r_squares) = 'R_Squares'
t_stats = transpose(as.data.frame(t_stats))
rownames(t_stats) = colnames(industry_portfolios)
colnames(t_stats) = c('Tstat_MKT_RF','Tstat_SMB','Tstat_HML','Tstat_WML')
stats = cbind(betas,alphas,r_squares,t_stats)
Market = stats[order(stats$MKT_RF,decreasing = FALSE),]
barplot(x1$MKT_RF,horiz = T,cex.names = 0.7,col = 'blue4',las = 1,names.arg =rownames(x1) ,main = 'Market Betas',xlim = c(0,1.5))
Size = stats[order(stats$SMB,decreasing = FALSE),]
barplot(x2$SMB,horiz = T,cex.names = 0.7,col = 'blue4',las = 1,names.arg =rownames(x2) ,main = 'Size Betas',xlim = c(-0.3,1))
Value = stats[order(stats$HML,decreasing = FALSE),]
barplot(x3$HML,horiz = T,cex.names = 0.7,col = 'blue4',las = 1,names.arg =rownames(x3) ,main = 'Value Betas')
Momentum = stats[order(stats$WML,decreasing = FALSE),]
barplot(x4$WML,horiz = T,cex.names = 0.7,col = 'blue4',las = 1,names.arg =rownames(x4) ,main = 'Momentum Betas')
it appears that the precious metals industry is positively affected by the momentum factor, while the banking industry is negatively affected. However, the R-squared value for the relationship between the momentum factor and the precious metals industry is low, which means that only a small portion of the variation in the precious metals industry can be explained by the momentum factor.
Additionally, the momentum factor seems to have a statistically significant effect on several industries, including construction materials, aircraft, business services, measuring and control equipment, steel, coal, paper, rubber, personal services, retail, construction, and meals (although not statistically significant).
it is noted that adding the momentum factor to the model did not significantly change the ordering of the market betas and another betas. This suggests that the momentum factor may not be a dominant factor in explaining the returns of these industries, but rather one of several factors that contribute to their performance.