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

Online data

Currently use Damodaran data for returns.

Steps

  1. Load asset return data from Damodaran website using pd.read_excel.
  2. Load GDP data from FRED using pandas_datareader module.
  3. 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).
  4. 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.
  5. Compute some allocations using hierarchical risk parity model for comparison.
  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 mostly follows the cvxpy tutorial but uses real historical data, and visualizes the full efficient frontier and transition map.

Takeaways

  • 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.

Setup

  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

Further reading

Asset allocation books:

About

Portfolio optimization with cvxopt

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published