Markets don't announce regime changes. By the time a recession is declared, portfolios are already down 20–40%. This project builds the early-warning system — reading 12 macro signals monthly to detect the shift before it hits prices, then rotating automatically.
No black boxes. Every decision is traceable to a data point.
12 Federal Reserve (FRED) indicators updated monthly: yield curve shape, credit spreads, unemployment, inflation, industrial output, money supply, and more.
A 3-state Hidden Markov Model processes the signals and assigns probabilities: Expansion / Stagnation / Contraction. Output is probabilistic — not a binary switch.
Probability-weighted allocation across 6 ETFs (stocks, bonds, gold, credit, cash). Rebalances only when drift exceeds 2% — minimising unnecessary transaction costs.
| Asset | Expansion 📈 | Stagnation ⚠️ | Contraction 🛡️ |
|---|---|---|---|
| SPY — US Stocks | 60% | 30% | 10% |
| TLT — Long Bonds | 10% | 25% | 40% |
| GLD — Gold | 5% | 15% | 25% |
| LQD — IG Credit | 15% | 15% | 5% |
| HYG — High Yield | 10% | 5% | 0% |
| BIL — Cash | 0% | 10% | 20% |
Trained on 1991–2005. Tested blind on 2006–2026 — including three major crises.
The deliberate trade-off: SPY earned more in absolute dollars — $779 vs $510 on $100 invested. The strategy traded ~2% of annual return for 60% less drawdown, faster recovery, and +3.4% during the 2008 financial crisis while SPY fell 46%. That's not underperformance — it's a different objective function.
| Strategy | CAGR | Volatility | Max Loss | Sharpe | Sortino | Recovery |
|---|---|---|---|---|---|---|
|
Regime Strategy
|
8.45% | 9.13% | -21.0% | 0.937 | 1.357 | 31 mo |
|
S&P 500 Buy & Hold
|
10.56% | 14.70% | -50.8% | 0.760 | 1.050 | 57 mo |
|
60/40 Portfolio
|
8.56% | 9.81% | -28.5% | 0.890 | 1.115 | 35 mo |
|
Equal Weight
|
6.32% | 7.09% | -16.9% | 0.902 | 1.298 | 29 mo |
A portfolio that drops 50% spends years just getting back to flat — not compounding. Every year in recovery is a year of missed growth. Avoiding catastrophic drawdowns is a return strategy.
The model never saw these crises during training. These are genuine out-of-sample results.
12 publicly available government data series from the US Federal Reserve. No proprietary data needed.
10Y minus 2Y Treasury spread. Inversion has predicted every US recession since 1970 — typically 12–18 months early. The single most predictive feature.
Extra yield on corporate vs government bonds. Widens sharply when fear rises — credit markets flash red before equities react.
Unemployment rate (monthly) + initial jobless claims (weekly). Claims spike fast at turning points — early warning before unemployment data confirms.
Industrial production (monthly) and real GDP YoY (quarterly, ALFRED vintage). Uses numbers as published — no revision bias.
High CPI locks the Fed into hiking even as growth stalls — the stagflation trap. 2022 is the textbook case: stocks and bonds fell simultaneously.
Policy rate stance and M2 growth. Aggressive hiking cycles precede every major recession; M2 contraction (rare) signals severe credit tightening.
Return alone is incomplete. These metrics show the quality of the return.
Most portfolios are built for one regime and left to survive all others. This project builds a system that reads the economic environment monthly and adjusts exposure accordingly — the same logic that institutional allocators apply with full research teams, automated from public data alone.
The goal was never to beat SPY in a bull market. It was to build something that holds up when it matters most — and to prove it on 20 years of out-of-sample data, not a backfit curve.