https://github.com/hvass-labs/financeops
Research in investment finance with Python Notebooks
https://github.com/hvass-labs/financeops
finance investing portfolio-optimization python stocks
Last synced: 10 months ago
JSON representation
Research in investment finance with Python Notebooks
- Host: GitHub
- URL: https://github.com/hvass-labs/financeops
- Owner: Hvass-Labs
- License: mit
- Created: 2018-07-22T08:14:46.000Z (over 7 years ago)
- Default Branch: master
- Last Pushed: 2022-02-12T16:04:25.000Z (almost 4 years ago)
- Last Synced: 2025-04-12T23:40:14.020Z (10 months ago)
- Topics: finance, investing, portfolio-optimization, python, stocks
- Language: Jupyter Notebook
- Homepage:
- Size: 39.4 MB
- Stars: 983
- Watchers: 47
- Forks: 224
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# FinanceOps
[Original repository on GitHub](https://github.com/Hvass-Labs/FinanceOps)
Original author is [Magnus Erik Hvass Pedersen](http://www.hvass-labs.org)
## Introduction
This is a collection of research papers on long-term investing, portfolio
optimization, etc. They are written as Python Notebooks so they can easily be
modified and run again.
## Python Package
The [InvestOps](https://github.com/Hvass-Labs/InvestOps) Python package
contains the main results and algorithms from this research, making it
very easy to use in your own Python projects.
## Papers
The following Python Notebooks produce the plots and statistics for some of my
"normal" research papers which can be downloaded from
[SSRN](http://papers.ssrn.com/sol3/cf_dev/AbsByAuth.cfm?per_id=1993051)
and [GitHub](https://github.com/Hvass-Labs/Finance-Papers).
- Long-Term Stock Forecasting
([PDF](https://ssrn.com/abstract=3750775))
([Video](https://www.youtube.com/watch?v=L8OtWNCQAAs))
([Notebook](https://github.com/Hvass-Labs/FinanceOps/blob/master/Paper_Long-Term_Stock_Forecasting.ipynb))
([Google Colab](https://colab.research.google.com/github/Hvass-Labs/FinanceOps/blob/master/Paper_Long-Term_Stock_Forecasting.ipynb))
- Simple Portfolio Optimization That Works!
([PDF](https://ssrn.com/abstract=3942552))
([Video](https://www.youtube.com/watch?v=5--5Ydtbu1Y))
([Notebook](https://github.com/Hvass-Labs/FinanceOps/blob/master/Paper_Simple_Portfolio_Optimization.ipynb))
([Google Colab](https://colab.research.google.com/github/Hvass-Labs/FinanceOps/blob/master/Paper_Simple_Portfolio_Optimization.ipynb))
- Fast Portfolio Diversification
([PDF](https://ssrn.com/abstract=4009041))
([Video](https://www.youtube.com/watch?v=5--5Ydtbu1Y))
([Notebook](https://github.com/Hvass-Labs/FinanceOps/blob/master/Paper_Fast_Portfolio_Diversification.ipynb))
([Google Colab](https://colab.research.google.com/github/Hvass-Labs/FinanceOps/blob/master/Paper_Fast_Portfolio_Diversification.ipynb))
- Portfolio Group Constraints
([PDF](https://ssrn.com/abstract=4033243))
([Notebook](https://github.com/Hvass-Labs/FinanceOps/blob/master/Paper_Portfolio_Group_Constraints.ipynb))
([Google Colab](https://colab.research.google.com/github/Hvass-Labs/FinanceOps/blob/master/Paper_Portfolio_Group_Constraints.ipynb))
- Does Volatility Harvesting Really Work?
([PDF](https://ssrn.com/abstract=3847692))
([Video](https://www.youtube.com/watch?v=t0AxhyQRRvM))
([Notebook](https://github.com/Hvass-Labs/FinanceOps/blob/master/Paper_Volatility_Harvesting.ipynb))
([Google Colab](https://colab.research.google.com/github/Hvass-Labs/FinanceOps/blob/master/Paper_Volatility_Harvesting.ipynb))
## Other Research
The following Python Notebooks contain stand-alone research without "normal" papers.
1. Basic Long-Term Stock Forecasting ([Notebook](https://github.com/Hvass-Labs/FinanceOps/blob/master/01_Forecasting_Long-Term_Stock_Returns.ipynb)) ([Google Colab](https://colab.research.google.com/github/Hvass-Labs/FinanceOps/blob/master/01_Forecasting_Long-Term_Stock_Returns.ipynb))
1-B. Better Long-Term Stock Forecasts ([Notebook](https://github.com/Hvass-Labs/FinanceOps/blob/master/01B_Better_Long-Term_Stock_Forecasts.ipynb)) ([Google Colab](https://colab.research.google.com/github/Hvass-Labs/FinanceOps/blob/master/01B_Better_Long-Term_Stock_Forecasts.ipynb))
1-C. Theory of Long-Term Stock Forecasting ([Notebook](https://github.com/Hvass-Labs/FinanceOps/blob/master/01C_Theory_of_Long-Term_Stock_Forecasting.ipynb)) ([Google Colab](https://colab.research.google.com/github/Hvass-Labs/FinanceOps/blob/master/01C_Theory_of_Long-Term_Stock_Forecasting.ipynb))
1-D. Testing the Stock Forecasting Model ([Notebook](https://github.com/Hvass-Labs/FinanceOps/blob/master/01D_Testing_the_Stock_Forecasting_Model.ipynb)) ([Google Colab](https://colab.research.google.com/github/Hvass-Labs/FinanceOps/blob/master/01D_Testing_the_Stock_Forecasting_Model.ipynb))
1-E. Forecasting U.S. Stock Indices ([Notebook](https://github.com/Hvass-Labs/FinanceOps/blob/master/01E_Forecasting_US_Stock_Indices.ipynb)) ([Google Colab](https://colab.research.google.com/github/Hvass-Labs/FinanceOps/blob/master/01E_Forecasting_US_Stock_Indices.ipynb))
1-F. Forecasting International Stock Indices ([Notebook](https://github.com/Hvass-Labs/FinanceOps/blob/master/01F_Forecasting_Int_Stock_Indices.ipynb)) ([Google Colab](https://colab.research.google.com/github/Hvass-Labs/FinanceOps/blob/master/01F_Forecasting_Int_Stock_Indices.ipynb))
1-G. Forecasting House Price Index ([Notebook](https://github.com/Hvass-Labs/FinanceOps/blob/master/01G_Forecasting_House_Price_Index.ipynb)) ([Google Colab](https://colab.research.google.com/github/Hvass-Labs/FinanceOps/blob/master/01G_Forecasting_House_Price_Index.ipynb))
2. Comparing Stock Indices ([Notebook](https://github.com/Hvass-Labs/FinanceOps/blob/master/02_Comparing_Stock_Indices.ipynb)) ([Google Colab](https://colab.research.google.com/github/Hvass-Labs/FinanceOps/blob/master/02_Comparing_Stock_Indices.ipynb))
3. Portfolio Optimization Using Signals ([Notebook](https://github.com/Hvass-Labs/FinanceOps/blob/master/03_Portfolio_Optimization_Using_Signals.ipynb)) ([Google Colab](https://colab.research.google.com/github/Hvass-Labs/FinanceOps/blob/master/03_Portfolio_Optimization_Using_Signals.ipynb))
4. Multi-Objective Portfolio Optimization ([Notebook](https://github.com/Hvass-Labs/FinanceOps/blob/master/04_Multi-Objective_Portfolio_Optimization.ipynb)) ([Google Colab](https://colab.research.google.com/github/Hvass-Labs/FinanceOps/blob/master/04_Multi-Objective_Portfolio_Optimization.ipynb))
5. Forecasting the P/Sales Ratio ([Notebook](https://github.com/Hvass-Labs/FinanceOps/blob/master/05_Forecasting_PSales_Ratio.ipynb)) ([Google Colab](https://colab.research.google.com/github/Hvass-Labs/FinanceOps/blob/master/05_Forecasting_PSales_Ratio.ipynb))
6. Forecasting Sales Growth ([Notebook](https://github.com/Hvass-Labs/FinanceOps/blob/master/06_Forecasting_Sales_Growth.ipynb)) ([Google Colab](https://colab.research.google.com/github/Hvass-Labs/FinanceOps/blob/master/06_Forecasting_Sales_Growth.ipynb))
7. Forecasting Dividends ([Notebook](https://github.com/Hvass-Labs/FinanceOps/blob/master/07_Forecasting_Dividends.ipynb)) ([Google Colab](https://colab.research.google.com/github/Hvass-Labs/FinanceOps/blob/master/07_Forecasting_Dividends.ipynb))
## Videos
There is a [YouTube video](https://www.youtube.com/playlist?list=PL9Hr9sNUjfsmlHaWuVxIA0pKL1yjryR0Z) for each research paper.
## Downloading
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.
### Git
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:
git pull
### Zip-File
You can also [download](https://github.com/Hvass-Labs/FinanceOps/archive/master.zip)
the contents of the GitHub repository as a Zip-file and extract it manually.
## Installation
If you want to run these tutorials on your own computer, then it is best
to use a virtual environment when installing the required packages,
so you can easily delete the environment again.
The following command creates a virtual environment named `financeops`:
virtualenv financeops
Or you can use [Anaconda](https://www.anaconda.com/download) instead of a virtualenv:
conda create --name financeops python=3
Then you switch to the virtual environment and install the required packages:
source activate financeops
pip install -r requirements.txt
When you are done working on the project you can deactivate the virtualenv:
source deactivate
## How To Run
Once you have installed the required Python packages in a virtual environment,
you run the following commands from the `FinanceOps` directory to view, edit
and run the Notebooks:
source activate financeops
jupyter notebook
If you want to edit the other source-code then you may use the free version of
[PyCharm](https://www.jetbrains.com/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](https://colab.research.google.com).
You 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, and installs all the
required Python packages:
# Clone the repository from GitHub to Google Colab's temporary drive.
import os
work_dir = "/content/FinanceOps/"
if not os.path.exists(work_dir):
!git clone https://github.com/Hvass-Labs/FinanceOps.git
os.chdir(work_dir)
# Install the required Python packages.
!pip install -r requirements.txt
Note that you will need to run this every time you login to Google Colab.
### Run in Docker
Because many of these Notebooks and some of the Python packages also read/write
data on the local disk, you would need to create so-called Docker volumes to
enable persistent data-storage on your local disk. The instructions for setting
this up would be complicated, and it seems much easier to run the Notebooks
using one of the other methods above.
## Data Sources
- Recent share-price and fundamental data from [SimFin](https://github.com/SimFin/simfin).
- Older share-price data from [Yahoo Finance](https://finance.yahoo.com/quote/%5EGSPC/history?p=%5EGSPC).
- Intraday share-price data from [Alpha Vantage](https://www.alphavantage.co/)
- Financial data for some individual stocks collected manually by the author from the 10-K Forms filed with the [U.S. SEC](http://www.sec.gov/cgi-bin/browse-edgar?company=&match=&CIK=jnj&filenum=&State=&Country=&SIC=&owner=exclude&Find=Find+Companies&action=getcompany).
- Newer S&P 500 data from the [S&P Earnings & Estimates Report](http://www.spindices.com/documents/additional-material/sp-500-eps-est.xlsx) and older data from the research staff at S&P and Compustat (some older data is approximated by their research staff).
- Financial data for Exchange Traded Funds (ETF) from Morningstar Direct.
- U.S. Government Bond yield for 1-year constant maturity. From the [U.S. Federal Reserve](https://www.federalreserve.gov/datadownload/Choose.aspx?rel=H15).
- The inflation index is: All Items Consumer Price Index for All Urban Consumers (CPI-U), U.S. City Average.
[Data](https://beta.bls.gov/dataQuery/find?fq=survey:%5Bcu%5D&s=popularity:D&q=CUUR0000SA0)
from the [US Department of Labor, Bureau of Labor Statistics](http://www.bls.gov/cpi/data.htm).
## License (MIT)
These Python Notebooks and source-code are published under the [MIT License](https://github.com/Hvass-Labs/FinanceOps/blob/master/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](https://github.com/Hvass-Labs/FinanceOps).
The financial data is **not** covered by the MIT license and may have limitations on commercial redistribution, etc.