--- name: portfolio-review description: "Portfolio health check — optimization, correlation, risk parity, clustering, similarity analysis. Use when user asks about portfolio allocation, diversification, rebalancing, or finding similar stocks." user-invocable: true metadata: { "openclaw": { "emoji": "💼", "requires": { "bins": ["curl"] } } } --- # Portfolio Review Professional portfolio analysis. Think like a portfolio manager at a wealth management firm. **Trigger**: User mentions portfolio, allocation, diversification, rebalancing, "how should I weight", or "find stocks like X". ## Mode A: Portfolio Health Check When user provides holdings or references MEMORY.md portfolio: ```bash BASE=https://invest-api.k8s.home # Rule-engine analysis (BUY_MORE/HOLD/SELL per holding with confidence) curl -sk -X POST "$BASE/api/v1/portfolio/analyze" \ -H "Content-Type: application/json" \ -d '{"holdings": [{"symbol": "AAPL", "shares": 100, "buy_in_price": 150.0}, ...]}' # HRP optimal weights (Hierarchical Risk Parity) curl -sk -X POST "$BASE/api/v1/portfolio/optimize" \ -H "Content-Type: application/json" \ -d '{"symbols": ["AAPL", "MSFT", "GOOGL", ...], "days": 365}' # Correlation matrix (identify hidden correlations) curl -sk -X POST "$BASE/api/v1/portfolio/correlation" \ -H "Content-Type: application/json" \ -d '{"symbols": ["AAPL", "MSFT", "GOOGL", ...], "days": 365}' # Risk parity weights (equal risk contribution) curl -sk -X POST "$BASE/api/v1/portfolio/risk-parity" \ -H "Content-Type: application/json" \ -d '{"symbols": ["AAPL", "MSFT", "GOOGL", ...], "days": 365}' # Cluster analysis (which stocks behave similarly) curl -sk -X POST "$BASE/api/v1/portfolio/cluster" \ -H "Content-Type: application/json" \ -d '{"symbols": ["AAPL", "MSFT", "GOOGL", ...], "days": 180}' # Per-stock risk metrics for SYMBOL in AAPL MSFT GOOGL; do curl -sk "$BASE/api/v1/stock/$SYMBOL/performance?days=365" done ``` ### Report Structure ``` ## Portfolio Review — {date} ### Holdings Summary | Symbol | Shares | Cost | Current | P&L | P&L% | Signal | |--------|--------|------|---------|-----|-------|--------| | {sym} | {n} | ${cost} | ${current} | ${pnl} | {%} | {BUY_MORE/HOLD/SELL} | ### Total Portfolio - Total value: ${sum} - Total P&L: ${sum} ({%}) - Positions: {count} ### Diversification Analysis - Correlation highlights: - Highest pair: {A} ↔ {B} = {r} — ⚠️ if >0.8 = redundant exposure - Lowest pair: {A} ↔ {B} = {r} — ✅ good diversification - Clusters found: {n} groups - Cluster 1: [{symbols}] — {interpretation, e.g. "tech megacap"} - Cluster 2: [{symbols}] — {interpretation} - Diversification score: [well-diversified / concentrated / sector-heavy] ### Optimal Allocation | Symbol | Current Weight | HRP Weight | Risk Parity | Action | |--------|---------------|------------|-------------|--------| | {sym} | {%} | {%} | {%} | [increase/decrease/hold] | ### Risk Metrics per Holding | Symbol | Sharpe | Volatility | Max DD | Beta | |--------|--------|-----------|--------|------| | {sym} | {val} | {%} | {%} | {val} | ### Recommendations 1. {Top priority action with reasoning} 2. {Second action} 3. {Third action} ### ⚠️ Alerts - {Any BUY_MORE or SELL signals from rule engine} - {Highly correlated pairs that should be reduced} - {Overweight positions vs optimal} ``` ## Mode B: Find Similar/Different Stocks When user asks "find stocks like X" or "what's similar to X": ```bash # Find most similar stocks curl -sk -X POST "$BASE/api/v1/portfolio/similar" \ -H "Content-Type: application/json" \ -d '{"symbol": "{TICKER}", "universe": ["AAPL","MSFT","GOOGL","AMZN","META","NVDA","TSLA","JPM","V","WMT","JNJ","PG","XOM","CVX","HD"], "days": 180, "top_n": 5}' # Cluster the target with potential alternatives curl -sk -X POST "$BASE/api/v1/portfolio/cluster" \ -H "Content-Type: application/json" \ -d '{"symbols": ["{TICKER}","AAPL","MSFT","GOOGL","AMZN","META","NVDA","TSLA","JPM","V","WMT","JNJ"], "days": 180}' ``` ### Report Structure ``` ## Stocks Similar to {TICKER} ### Most Similar (by return correlation) | Rank | Symbol | Correlation | Why Similar | |------|--------|-------------|-------------| | 1 | {sym} | {r} | {interpretation} | ### Most Different (diversification candidates) | Rank | Symbol | Correlation | Why Different | |------|--------|-------------|---------------| | 1 | {sym} | {r} | {interpretation} | ### Recommendation - To add exposure like {TICKER}: consider {top similar} - To hedge {TICKER}: consider {most different} ``` ## Rules - Always read MEMORY.md for existing holdings before analysis - Correlation > 0.8 = redundant — flag for reduction - Correlation < 0.2 = good diversification pair - HRP is generally better than equal-weight for risk-adjusted returns - Risk parity = each position contributes equal risk (good for conservative portfolios) - Keep under 500 words