Fama French Multifactor Model in Python


Factor modelling is everywhere these days. I wrote about smart beta here. It is good to quantify performance drivers but the usual caveats apply to quantitative studies utilizing backward looking data, “past performance does not guarantee future results”.

I wanted to share a little exercise I did in Python comparing a fund, stock, or anything with a ticker available on Yahoo Finance with the Fama French 3 factor model – Market Returns, Size, and Book Value. Eugene Fama also graciously publishes the factors monthly on his website for free. The script automatically pulls the monthly data from the website and aligns it with the corresponding dates from Yahoo Finance. Obviously any fund information can be compared as well or new factors should you have access to the returns.

Here is the Tweedy, Browne Global Value Fund from 1993 to 2016:

OLS FF3factor

R^2 ~ .67 so 67% of the performance is explained by the 3 factors. About .65 beta shown as MKT-RF coefficient with P value of 0

We can also plot the excess returns versus the factors to get a visual representation:

OLS FF3factor2.JPG

You can get the code on my *Github Page. Factor away!

* I had a hard time initially figuring out Github and how to post code from my local drive. It is a tool designed for collaboration and version control which I didn’t really have a need for. I just wanted a place to upload and share simple code instead of linking to text files. If anyone else had these issues, you have company. Here is how I handled it:
  1. Open an account on Github.com and create a new repository.
  2. Download the Github Desktop application and install.
  3. In the Desktop app, ‘CLONE’ the repository by clicking on the ‘+’ icon in the top left and selecting the ‘CLONE’ tab.
  4. This creates a directory on your local drive, perhaps something like Documents\Github\ExampleRepository ; Add your *.ipynb files to this directory, most likely in Documents\Ipython Notebooks.
  5. Now click on ‘CHANGES’ tab in the top middle, add a summary and description and select ‘COMMIT’
  6. Click ‘SYNC’ on the top right of the app. The file should now be on Github.com

Be the first to comment on "Fama French Multifactor Model in Python"

Leave a comment

Your email address will not be published.