Do a few classic portfolio optimizations using:
- CVXPY (paper), a modeling environment for convex optimization, supporting many back-end solvers.
- Data (mostly) from Prof. Aswath Damodaran and FRED
- Aswath Damodaran. See the FAQ tab in his XLS for details on individual asset returns.
- FRED
- Shiller data
- Ken French
- Macrotrends
Currently use Damodaran data for returns.
- Load asset return data from Damodaran website using
pd.read_excel
. - Load GDP data from FRED using
pandas_datareader
module. - Compute covariance matrix, long-only efficient frontier, and transition map using historical data (see above). Also compute same outputs for 1972-present (post-gold standard) and 1983-present (post-inflation era).
- Compute long-short efficient frontier and transition map, adding a random short asset with 5% annualized negative return and 90% correlation to S&P, and addig a 150% gross exposure constraint.
- Compute some allocations using hierarchical risk parity model for comparison.
- Compute an efficient frontier using a factor model, using a random set of returns for 1000 stocks and 10 random factor exposures and a random factor covariance matrix.
This mostly follows the cvxpy tutorial but uses real historical data, and visualizes the full efficient frontier and transition map.
- Gold adds some value for most portfolios, except in most disinflationary environment at higher risk tolerances.
- TIPS should be a more direct inflation hedge with a US government guaranteed real return but we don't have data back very far.
- If you can find good shorts and use leverage, you can supercharge returns.
-
git clone this repo, cd to repo directory
-
Install Anaconda
-
Create virtual environment
conda create -n portfolio_opt
conda activate portfolio_opt
pip install -r requirements.txt
or
conda env create -f environment.yaml
conda activate portfolio_opt
-
jupyter notebook
-
Run
Portfolio optimization.ipynb
Asset allocation books:
- David Swensen - Pioneering Portfolio Management: An Unconventional Approach to Institutional Investment
- Bernstein - The Intelligent Asset Allocator: How to Build Your Portfolio to Maximize Returns and Minimize Risk
- Kinlaw et al - Asset Allocation: From Theory to Practice and Beyond (Wiley Finance) 1st Edition
- Fabozzi and Markowitz, ed. - The Theory and Practice of Investment Management: Asset Allocation, Valuation, Portfolio Construction, and Strategies
- Muralidhar - Innovations in Pension Fund Management 1st Edition
- Ferri - All About Asset Allocation Paperback
- Faber - Global Asset Allocation: A Survey of the World's Top Asset Allocation Strategies