Introduction
The relationship between return and risk has long been a popular topic for research. Investors have been seeking financial models that quantify risk and use it to estimate the expected return on equity. The Fama French five-factor model, improved from the Fama French three-factor model, is one of the most classic models (Fama and French, 2015). In this post, we will discuss this model and develop a stock-picking strategy based on it.
Method
The Fama French five-factor model was proposed in 2014 and is adapted from the Fama French three-factor model (Fama and French, 2015). It builds upon the dividend discount model which states that the value of stocks today is dependent upon future dividends. Fama and French add two factors, investment and profitability, to the dividend discount model to better capture the relationship between risk and return. The model is as follows
\[\begin{equation} \begin{aligned} R = \alpha & + \beta_m MKT + \beta_s SMB \\ & + \beta_h HML + \beta_r RMW \\ & + \beta_c CMA \end{aligned} \end{equation}\]
where
- \(MKT\) is the excess return of the market. It is the return on the value-weighted market portfolio.
- \(SMB\) is the return on a diversified portfolio of small-cap stocks minus the return on a diversified portfolio of big-cap stocks.
- \(HML\) is the difference between the returns on diversified portfolios of stocks with high and low Book-to-Market ratios.
- \(RMW\) is the difference between the returns on diversified portfolios of stocks with robust (high and steady) and weak (low) profitability.
- \(CMA\) is the difference between the returns on diversified portfolios of the stocks of low and high investment firms, which we call conservative and aggressive. Here, low/high investment means reinvestment ratio is low/high.
Taking inspiration from the Fama French five-factor model, we can develop a multi-factor stock selection strategy that focuses on five factors: size, value, quality, profitability, and investment pattern.
First, we run a Coarse Selection to drop Equities which have no fundamental data or have too low prices. Then we select those with the highest dollar volume.
Note that a useful technique is used here: we can use Universe.UNCHANGED
to remain the same universe when there is no necessary change, which greatly speeds up the backtest.
def coarse_selection_function(self, coarse):
'''Drop securities which have no fundamental data or have too low prices.
Select those with highest by dollar volume'''
if self.time < self.next_liquidate:
return Universe.UNCHANGED
selected = sorted([x for x in coarse if x.has_fundamental_data and x.price > 5],
key=lambda x: x.dollar_volume, reverse=True)
return [x.symbol for x in selected[:self.num_coarse]]
Secondly, in Fine Selection, we use the terms TotalEquity
, BookValuePerShare
, OperationProfitMargin
, ROE
, and TotalAssetsGrowth
to account for the five factors, respectively. We then calculate a custom ranking metric for each stock using these five terms. Our algorithm will go long in the five stocks with the highest scores and short the five stocks with the lowest scores.
def fine_selection_function(self, fine):
'''Select securities with highest score on Fama French 5 factors'''
# Select stocks with these 5 factors:
# MKT -- Book value per share: Value
# SMB -- TotalEquity: Size
# HML -- Operation profit margin: Quality
# RMW -- ROE: Profitability
# CMA -- TotalAssetsGrowth: Investment Pattern
filtered = [x for x in fine if x.valuation_ratios.book_value_per_share
and x.financial_statements.balance_sheet.total_equity
and x.operation_ratios.operation_margin.value
and x.operation_ratios.ROE
and x.operation_ratios.total_assets_growth]
# Sort by factors
sorted_by_mkt = sorted(filtered, key=lambda x: x.valuation_ratios.book_value_per_share, reverse=True)
sorted_by_smb = sorted(filtered, key=lambda x: x.financial_statements.balance_sheet.total_equity.value, reverse=True)
sorted_by_hml = sorted(filtered, key=lambda x: x.operation_ratios.operation_margin.value, reverse=True)
sorted_by_rmw = sorted(filtered, key=lambda x: x.operation_ratios.ROE.value, reverse=True)
sorted_by_cma = sorted(filtered, key=lambda x: x.operation_ratios.total_assets_growth.value, reverse=False)
stock_by_symbol = {}
# Get the rank based on 5 factors for every stock
for index, stock in enumerate(sorted_by_mkt):
mkt_rank = self.beta_m * index
smb_rank = self.beta_s * sorted_by_smb.index(stock)
hml_rank = self.beta_h * sorted_by_hml.index(stock)
rmw_rank = self.beta_r * sorted_by_rmw.index(stock)
cma_rank = self.beta_c * sorted_by_cma.index(stock)
avg_rank = np.mean([mkt_rank,smb_rank,hml_rank,rmw_rank,cma_rank])
stock_by_symbol[stock.symbol] = avg_rank
sorted_dict = sorted(stock_by_symbol.items(), key = lambda x: x[1], reverse = True)
symbols = [x[0] for x in sorted_dict]
# Pick the stocks with the highest scores to long
self.long_symbols= symbols[:self.num_long]
# Pick the stocks with the lowest scores to short
self.short_symbols = symbols[-self.num_short:]
return self.long_symbols + self.short_symbols
Results
In this example, the portfolio is rebalanced every 30 days and the backtest period runs from Jan 2010 to Aug 2019. You can improve upon this strategy by changing the fundamental factors, the weight of each factor, and the rebalance frequency.
The Fama French five-factor model provides a scientific way to measure asset pricing. For the five aspects that Fama and French mentioned, we used one possible combination in our backtest. We can see from the results that it achieves an annual rate of return around 6.8% with a max drawdown of 19.8% over 8 years. These factors perhaps cannot capture a sufficient amount of information on the assets' pricing, and therefore, there are still many aspects can be improved (e.g. the weights of factors, a different set of factors for different kinds of Equities,etc.) We encourage you to explore and create better algorithms upon this tutorial!
Derek Melchin
See the attached backtest for an updated version of the algorithm in PEP8 style.
The material on this website is provided for informational purposes only and does not constitute an offer to sell, a solicitation to buy, or a recommendation or endorsement for any security or strategy, nor does it constitute an offer to provide investment advisory services by QuantConnect. In addition, the material offers no opinion with respect to the suitability of any security or specific investment. QuantConnect makes no guarantees as to the accuracy or completeness of the views expressed in the website. The views are subject to change, and may have become unreliable for various reasons, including changes in market conditions or economic circumstances. All investments involve risk, including loss of principal. You should consult with an investment professional before making any investment decisions.
Daniel Chen
The material on this website is provided for informational purposes only and does not constitute an offer to sell, a solicitation to buy, or a recommendation or endorsement for any security or strategy, nor does it constitute an offer to provide investment advisory services by QuantConnect. In addition, the material offers no opinion with respect to the suitability of any security or specific investment. QuantConnect makes no guarantees as to the accuracy or completeness of the views expressed in the website. The views are subject to change, and may have become unreliable for various reasons, including changes in market conditions or economic circumstances. All investments involve risk, including loss of principal. You should consult with an investment professional before making any investment decisions.
To unlock posting to the community forums please complete at least 30% of Boot Camp.
You can continue your Boot Camp training progress from the terminal. We hope to see you in the community soon!