Follow these steps to implement the four- and five-factor models in Python.
- Import the libraries:
import pandas as pdimport yfinance as yfimport statsmodels.formula.api as smfimport pandas_datareader.data as web
- Specify the risky asset and the time horizon:
RISKY_ASSET = 'AMZN'START_DATE = '2013-12-31'END_DATE = '2018-12-31'
- Download the risk factors from prof. French's website:
# three factors df_three_factor = web.DataReader('F-F_Research_Data_Factors', 'famafrench', start=START_DATE)[0]df_three_factor.index = df_three_factor.index.format()# momentum factordf_mom = web.DataReader('F-F_Momentum_Factor', 'famafrench', start=START_DATE)[0]df_mom.index = df_mom.index.format()# five factorsdf_five_factor = web.DataReader('F-F_Research_Data_5_Factors_2x3', ...