Four ways to mix eight funds, rebalanced each month from past data only, with a report on what each one earned and how far each one fell.
Download daily adjusted closes since 2006 for eight US-listed ETFs that cover stocks, bonds, gold and property (for example SPY, EFA, EEM, IEF, TLT, LQD, GLD and VNQ), and FRED's 3-month Treasury bill rate (DTB3).
At each month end, estimate the covariance matrix from the past 252 days, once as the plain sample and once with scikit-learn's LedoitWolf shrinkage.
Build four long-only portfolios from them (equal weight, minimum variance on each matrix, and risk parity), and hold each one for the next month.
Report each one's yearly return, volatility, Sharpe ratio, maximum drawdown, and historical 95% one-day VaR and expected shortfall.
Stress each one: its loss from September 2008 to February 2009 and in March 2020, and its VaR with every correlation set to 0.9.
Check that each month's weights use only earlier prices, and that each ETF carries an equal share of the risk parity portfolio's risk.
How you'll know it worksA table of the four portfolios with every number above, from the months after each rebalance only, and each ETF's share of risk parity's risk within one percentage point of 12.5% every month.
Python with NumPy, pandas, SciPy and scikit-learn. You download the price CSVs yourself from a free source such as Stooq or Yahoo Finance; FRED's rates are free. Uses lessons 01 to 11.
Project: A risk report for an ETF portfolio
From insideout, Portfolio and Risk: Four ways to mix eight funds, rebalanced each month from past data only, with a report on what each one earned and how far each one fell.
Steps:
1. Download daily adjusted closes since 2006 for eight US-listed ETFs that cover stocks, bonds, gold and property (for example SPY, EFA, EEM, IEF, TLT, LQD, GLD and VNQ), and FRED's 3-month Treasury bill rate (DTB3).
2. At each month end, estimate the covariance matrix from the past 252 days, once as the plain sample and once with scikit-learn's LedoitWolf shrinkage.
3. Build four long-only portfolios from them (equal weight, minimum variance on each matrix, and risk parity), and hold each one for the next month.
4. Report each one's yearly return, volatility, Sharpe ratio, maximum drawdown, and historical 95% one-day VaR and expected shortfall.
5. Stress each one: its loss from September 2008 to February 2009 and in March 2020, and its VaR with every correlation set to 0.9.
6. Check that each month's weights use only earlier prices, and that each ETF carries an equal share of the risk parity portfolio's risk.
How you'll know it works: A table of the four portfolios with every number above, from the months after each rebalance only, and each ETF's share of risk parity's risk within one percentage point of 12.5% every month.
Runs on: Python with NumPy, pandas, SciPy and scikit-learn. You download the price CSVs yourself from a free source such as Stooq or Yahoo Finance; FRED's rates are free.
Help me build this on my machine, one step at a time. Ask what I've tried first, give hints before full answers, and check my work against "How you'll know it works".