Skip to content

druce/portfolio_optimization

Repository files navigation

Portfolio optimization with CVXPY

Do a few classic portfolio optimizations using:

Efficient Frontier

Optimal portfolio transition map

Steps

  1. Load asset return data from Damodaran website using pd.read_excel.
  2. Load gold and GDP data from FRED using pandas_datareader module.
  3. Manually fill in some missing data back to 1928.
  4. 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).
  5. 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 adding a 150% gross exposure constraint.
  6. 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 follows the cvxpy tutorial but uses real historical data, and visualizes the full efficient frontier and transition map.

Takeaways / blinding glimpses of the obvious:

  • Gold adds some value for most portfolios, except in most disinflationary environment at higher risk tolerances. (Of course TIPS may be a better inflation hedge but we don't have data back very far).
  • If you can find good shorts and use leverage, you can supercharge returns.

Setup

You should be able to run directly in Google Colab.

Or, to run locally

  1. git clone this repo, cd to repo directory

  2. Install Anaconda

  3. 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
  1. jupyter notebook

  2. Run Portfolio optimization.ipynb

About

Portfolio optimization with cvxopt

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published