Original author is Magnus Erik Hvass Pedersen
This is a small collection of research papers on investing. They are written as Python Notebooks so they can easily be modified and run again.
- Forecasting Long-Term Stock Returns (Notebook) (Google Colab)
- Comparing Stock Indices (Notebook) (Google Colab)
- Portfolio Optimization Using Signals (Notebook) (Google Colab)
There is a YouTube video for each research paper.
The Python Notebooks use source-code located in different files to allow for easy re-use across multiple Notebooks. It is therefore recommended that you download the whole repository from GitHub, instead of just downloading the individual Python Notebooks.
The easiest way to download and install this is by using git from the command-line:
git clone https://github.com/Hvass-Labs/FinanceOps.git
This creates the directory
FinanceOps and downloads all the files to it.
This also makes it easy to update the files, simply by executing this command inside that directory:
You can also download the contents of the GitHub repository as a Zip-file and extract it manually.
How To Run
If you want to edit and run the Notebooks on your own computer, then it is
suggested that you use the Anaconda
distribution of Python 3.6 (or later) because it has all the required packages
already installed. Once you have installed Anaconda, you run the following
command from the
FinanceOps directory to view and edit the Notebooks:
If you want to edit the other source-code then you may use the free version of PyCharm.
Run in Google Colab
If you do not want to install anything on your own computer, then the Notebooks can be viewed, edited and run entirely on the internet by using Google Colab. You can click the "Google Colab"-link next to the research papers listed above. You can view the Notebook on Colab but in order to run it you need to login using your Google account. Then you need to execute the following commands at the top of the Notebook, which clones FinanceOps to your work-directory on Colab.
import os work_dir = "/content/FinanceOps/" if os.getcwd() != work_dir: !git clone https://github.com/Hvass-Labs/FinanceOps.git os.chdir(work_dir)
- Price data from Yahoo Finance.
- Financial data for individual stocks collected manually by the author from the 10-K Forms filed with the U.S. SEC.
- Newer S&P 500 data from the S&P Earnings & Estimates Report and older data from the research staff at S&P and Compustat (some older data is approximated by their research staff).
- U.S. Government Bond yield for 1-year constant maturity. From the U.S. Federal Reserve.
- The inflation index is: All Items Consumer Price Index for All Urban Consumers (CPI-U), U.S. City Average. From the US Department of Labor, Bureau of Labor Statistics.
These Python Notebooks and source-code are published under the MIT License which allows very broad use for both academic and commercial purposes.
You are very welcome to modify and use the source-code in your own project. Please keep a link to the original repository.
The financial data is not covered by the MIT license and may have limitations on commercial redistribution, etc.