Monday, June 26, 2023

x̄ - > Fama-French three-factor model R

 The Fama-French three-factor model is a widely used financial model that extends the traditional Capital Asset Pricing Model (CAPM) by incorporating additional risk factors. This model helps explain the variation in expected returns of securities based on three factors: market risk, size risk, and value risk. While implementing the full Fama-French model involves data analysis and regression techniques, I can provide you with an example in R that demonstrates the basic concepts.


To begin, we'll need historical stock price and market data for a set of securities. For this example, we'll use the "quantmod" package in R to retrieve stock price data and the "FamaFrench" package to calculate the Fama-French factors.


```R

# Install and load required packages

install.packages(c("quantmod", "FamaFrench"))

library(quantmod)

library(FamaFrench)


# Define the stock symbols and the time period

symbols <- c("AAPL", "MSFT", "GOOG")  # Example stock symbols

start_date <- "2018-01-01"

end_date <- "2022-12-31"


# Retrieve stock price data

getSymbols(symbols, from = start_date, to = end_date)


# Extract adjusted close prices

prices <- merge(Ad(get(symbols[1])), Ad(get(symbols[2])), Ad(get(symbols[3])))


# Calculate daily returns

returns <- dailyReturn(prices)


# Retrieve Fama-French factors data

ff_factors <- FamaFrenchFactors()


# Merge returns and factors data

data <- merge(returns, ff_factors)


# Run linear regression to estimate factor loadings

model <- lm(returns ~ MktRF + SMB + HML, data = data)


# Extract factor loadings and intercept

factor_loadings <- coef(model)[-1]

intercept <- coef(model)[1]


# Output the factor loadings and intercept

cat("Factor Loadings:\n")

print(factor_loadings)

cat("\nIntercept:", intercept, "\n")

```


FOOD CATEGORY

In this example, we consider three stocks (Apple, Microsoft, and Google) and retrieve their adjusted close prices using the `quantmod` package. We calculate the daily returns of these stocks using the `dailyReturn` function. We then retrieve the Fama-French factors data using the `FamaFrenchFactors` function from the `FamaFrench` package. By merging the returns and factors data, we create a dataset suitable for regression analysis.


Next, we use linear regression (`lm` function) to estimate the factor loadings and intercept. The dependent variable is the returns, and the independent variables are the Fama-French factors (MktRF, SMB, HML). The resulting regression model provides us with the estimated factor loadings and intercept.


Finally, we output the factor loadings and intercept to examine the relationship between the stock returns and the Fama-French factors. Please note that this example is simplified, and in practice, it's important to perform thorough data analysis, evaluate model assumptions, and interpret the results appropriately.


No comments:

Meet the Authors
Zacharia Maganga’s blog features multiple contributors with clear activity status.
Active ✔
πŸ§‘‍πŸ’»
Zacharia Maganga
Lead Author
Active ✔
πŸ‘©‍πŸ’»
Linda Bahati
Co‑Author
Active ✔
πŸ‘¨‍πŸ’»
Jefferson Mwangolo
Co‑Author
Inactive ✖
πŸ‘©‍πŸŽ“
Florence Wavinya
Guest Author
Inactive ✖
πŸ‘©‍πŸŽ“
Esther Njeri
Guest Author
Inactive ✖
πŸ‘©‍πŸŽ“
Clemence Mwangolo
Guest Author

Followers

Support This Blog
Tap Donate now here to donate or go to donate on top menu to scan QR and support this site.
Donate Now