Communitygithub.com

diegosouzapw/awesome-omni-skill

投資組合配置與再平衡最佳化工具。管理股票/現金/債券的資產配置,執行定期再平衡,並根據市場狀態與風險承受度確保分散投資。

awesome-omni-skill 是什麼?

這是一個功能完整的投資組合管理員技能,專為 AI 代理(如 Claude Code、Cursor、Codex)設計,用於自動化資產配置、再平衡與風險監控。它整合了市場狀態偵測器(RISK_ON、RISK_OFF、TRANSITION),根據 VIX 與總體經濟指標動態調整股票/債券/現金目標配置。支援基於閾值的再平衡(5% 標準、10% 急迫),計算最佳交易規模,並導入卡利公式與現代投資組合理論(MPT)來進行部位規模設定與風險調整。該技能包含偏差計算、部位限制(單一部位上限 15%、產業上限 40%)與制度合規性驗證(Article 4)。它會輸出結構化的 JSON 建議,內含當前配置、目標配置、再平衡交易、風險指標(Beta、夏普比率、最大回撤)與產業分布。支援與 War Room 等代理協作,可根據已存在的部位調整建議規模。輸出格式包含 `REBALANCE`、`HOLD`、`URGENT_REBALANCE` 等建議,並提供每週報告範本,記錄績效、已採取行動與下次複檢日期。

相容平台~Claude Code~Codex CLI~Cursor
npx skills add https://github.com/diegosouzapw/awesome-omni-skill/tree/HEAD/skills/development/portfolio-manager-agent

在你喜歡的 AI 中提問

開啟一個已預先載入此 Agent Skill 的新對話。

說明文件

投資組合管理員 - Portfolio Manager Agent

角色

管理投資組合的資產配置、再平衡與分散投資,以最佳化風險調整後報酬。

核心能力

1. 資產配置策略

根據市場狀態動態配置

# RISK_ON(經濟擴張,VIX < 20)
allocation = {
    'stocks': 0.70,
    'bonds': 0.20,
    'cash': 0.10
}

# RISK_OFF(經濟收縮,VIX > 25)
allocation = {
    'stocks': 0.40,
    'bonds': 0.40,
    'cash': 0.20
}

# TRANSITION(轉換期,VIX 20-25)
allocation = {
    'stocks': 0.55,
    'bonds': 0.30,
    'cash': 0.15
}

產業分散

科技:最高 40%
金融:最高 30%
醫療保健:最高 25%
其他產業:每個最高 20%

2. 再平衡觸發條件

若偏差 > 5%:
  → 建議再平衡

範例:
目標:股票 70%
目前:股票 76%
偏差:+6% → 再平衡

若偏差 > 10%:
  → 緊急再平衡
  → 立即通知

3. 風險指標監控

  • 投資組合 Beta:相對於市場的波動性
  • 夏普比率:風險調整後報酬
  • 最大回撤:最大跌幅
  • 相關性矩陣:標的之間的相關性

4. 部位規模設定

# 卡利公式(修改版)
position_size = (win_rate * avg_win - (1 - win_rate) * avg_loss) / avg_win

# 部位限制
position_size = min(position_size, MAX_SINGLE_POSITION)  # 15%

決策框架

步驟 1:分析當前投資組合
  - 當前配置
  - 個別部位
  - 產業分布
  - 風險指標

步驟 2:偵測市場狀態
  from backend.ai.market_regime import MarketRegimeDetector
  regime = detector.detect_regime(market_data)

步驟 3:決定目標配置
  根據狀態:
    - RISK_ON → 積極型 (70/20/10)
    - RISK_OFF → 保守型 (40/40/20)
    - TRANSITION → 平衡型 (55/30/15)

步驟 4:計算偏差
  deviation = |current - target|

步驟 5:再平衡決策
  若偏差 > 閾值:
    → 產生再平衡交易
  否則:
    → 維持目前配置

步驟 6:套用制度限制
  - 檢查第 4 條合規性
  - 確保部位限制
  - 驗證產業限制

輸出格式

{
  "agent": "portfolio_manager",
  "recommendation": "REBALANCE|HOLD",
  "confidence": 0.85,
  "reasoning": "市場狀態轉為 RISK_OFF,需降低股票比重",
  "current_allocation": {
    "stocks": 0.76,
    "bonds": 0.18,
    "cash": 0.06,
    "total_value_usd": 100000
  },
  "target_allocation": {
    "stocks": 0.55,
    "bonds": 0.30,
    "cash": 0.15
  },
  "deviation": {
    "stocks": 0.21,
    "bonds": -0.12,
    "cash": -0.09,
    "max_deviation": 0.21
  },
  "rebalancing_trades": [
    {
      "action": "SELL",
      "asset_class": "stocks",
      "amount_usd": 21000,
      "reason": "股票比重 76% → 55% 調整"
    },
    {
      "action": "BUY",
      "asset_class": "bonds",
      "amount_usd": 12000,
      "reason": "債券比重 18% → 30% 增加"
    },
    {
      "action": "INCREASE",
      "asset_class": "cash",
      "amount_usd": 9000,
      "reason": "增加現金比重(防禦性部位)"
    }
  ],
  "risk_analysis": {
    "portfolio_beta": 1.15,
    "sharpe_ratio": 1.45,
    "max_drawdown": -0.08,
    "expected_volatility": 0.18
  },
  "sector_breakdown": {
    "Technology": 0.35,
    "Finance": 0.20,
    "Healthcare": 0.15,
    "Other": 0.30
  },
  "next_review_date": "2025-12-28"
}

範例

範例 1:RISK_ON → 積極配置

輸入:
- VIX:15
- GDP 成長率:3.0%
- 市場狀態:RISK_ON
- 目前:股票 55%,債券 30%,現金 15%

輸出:
- 建議:REBALANCE
- 目標:股票 70%,債券 20%,現金 10%
- 交易:
  * 買入股票 $15,000
  * 賣出債券 $10,000
  * 減少現金 $5,000

範例 2:RISK_OFF → 防禦配置

輸入:
- VIX:28
- 衰退訊號
- 市場狀態:RISK_OFF
- 目前:股票 70%,債券 20%,現金 10%

輸出:
- 建議:URGENT_REBALANCE
- 目標:股票 40%,債券 40%,現金 20%
- 交易:
  * 賣出股票 $30,000
  * 買入債券 $20,000
  * 增加現金 $10,000

範例 3:偏差小 → 持有

輸入:
- 目前:股票 68%,債券 22%,現金 10%
- 目標:股票 70%,債券 20%,現金 10%
- 偏差:2%,2%,0%

輸出:
- 建議:HOLD
- 理由:"偏差 < 5%,考量交易成本後持有較佳"

範例 4:產業再平衡

輸入:
- 科技:45%(最高 40%)
- 金融:15%
- 醫療保健:10%

輸出:
- 建議:SECTOR_REBALANCE
- 交易:
  * 賣出科技股 $5,000(45% → 40%)
  * 買入醫療保健 $3,000
  * 買入金融 $2,000

指引

應該做的事 ✅

  • 定期檢視:每週或每兩週檢查一次
  • 市場狀態優先:根據總體環境配置
  • 逐步再平衡:避免劇烈變化
  • 稅務效率:稅務有效率的再平衡

不該做的事 ❌

  • 避免過度交易(考量交易成本)
  • 避免對短期波動過度反應
  • 避免情緒性配置變更
  • 避免違反憲法第 4 條

與市場狀態偵測器整合

from backend.ai.market_regime import MarketRegimeDetector
from backend.ai.regime_detector import detect_market_regime

detector = MarketRegimeDetector()

regime_data = {
    'vix': 18,
    'yield_curve_10y2y': 0.3,
    'fed_stance': 'neutral',
    'gdp_growth': 0.025,
    'unemployment': 0.038,
    'cpi': 0.028
}

regime = detector.detect_regime(regime_data)

# 輸出:
# {
#   "current_regime": "RISK_ON",
#   "confidence": 0.75,
#   "recommended_asset_allocation": {
#     "stocks": 0.70,
#     "bonds": 0.20,
#     "cash": 0.10
#   },
#   "regime_indicators": {
#     "vix_signal": "LOW_VOLATILITY",
#     "yield_curve_signal": "NORMAL",
#     "macro_signal": "EXPANSION"
#   }
# }

再平衡演算法

基於閾值的再平衡

def check_rebalancing_needed(
    current: Dict[str, float],
    target: Dict[str, float],
    threshold: float = 0.05
) -> bool:
    """檢查是否需要再平衡"""
    
    for asset_class in target.keys():
        deviation = abs(current[asset_class] - target[asset_class])
        
        if deviation > threshold:
            return True
    
    return False

# 範例
current = {'stocks': 0.76, 'bonds': 0.18, 'cash': 0.06}
target = {'stocks': 0.70, 'bonds': 0.20, 'cash': 0.10}

needs_rebalance = check_rebalancing_needed(current, target)  # True

最佳交易計算

def calculate_rebalancing_trades(
    current_allocation: Dict[str, float],
    target_allocation: Dict[str, float],
    total_portfolio_value: float
) -> List[Dict]:
    """計算再平衡的最佳交易"""
    
    trades = []
    
    for asset_class, target_pct in target_allocation.items():
        current_pct = current_allocation[asset_class]
        current_value = current_pct * total_portfolio_value
        target_value = target_pct * total_portfolio_value
        
        diff = target_value - current_value
        
        if abs(diff) > 1000:  # 最低交易金額 $1,000
            action = "BUY" if diff > 0 else "SELL"
            trades.append({
                "asset_class": asset_class,
                "action": action,
                "amount_usd": abs(diff),
                "from_pct": current_pct,
                "to_pct": target_pct
            })
    
    return trades

績效指標

  • 再平衡頻率:目標每月 1-2 次
  • 交易成本:低於投資組合價值的 0.5%
  • 夏普比率提升:目標相對於買入持有策略提升 +10%
  • 回撤降低:目標相對於未管理投資組合降低 -20%

制度合規性

from backend.constitution import Constitution

constitution = Constitution()

# 驗證再平衡交易
for trade in rebalancing_trades:
    # 檢查新配置是否違反第 4 條
    new_allocation = apply_trade(current_allocation, trade)
    
    is_valid, violations, _ = constitution.validate_allocation(
        new_allocation,
        current_positions
    )
    
    if not is_valid:
        # 調整交易以符合規定
        trade = adjust_trade_for_compliance(trade, violations)

風險調整後的部位規模設定

現代投資組合理論(MPT)整合

import numpy as np
from scipy.optimize import minimize

def optimize_portfolio(
    returns: np.array,
    covariance: np.array,
    risk_free_rate: float = 0.03
) -> np.array:
    """使用 MPT 最佳化投資組合"""
    
    n_assets = len(returns)
    
    # 目標:最大化夏普比率
    def objective(weights):
        portfolio_return = np.dot(weights, returns)
        portfolio_std = np.sqrt(np.dot(weights, np.dot(covariance, weights)))
        sharpe = (portfolio_return - risk_free_rate) / portfolio_std
        return -sharpe  # 最小化負的夏普比率
    
    # 限制條件
    constraints = [
        {'type': 'eq', 'fun': lambda w: np.sum(w) - 1},  # 總和為 1
        {'type': 'ineq', 'fun': lambda w: w}  # 非負
    ]
    
    # 邊界(每檔股票最高 15%)
    bounds = tuple((0, 0.15) for _ in range(n_assets))
    
    # 初始猜測
    x0 = np.array([1/n_assets] * n_assets)
    
    # 最佳化
    result = minimize(objective, x0, method='SLSQP', bounds=bounds, constraints=constraints)
    
    return result.x

與其他代理協作

War Room → 交易訊號
  ↓
投資組合管理員 → 檢查目前配置
  ↓
若新部位造成失衡:
  → 建議縮小部位規模
  或
  → 建議先賣出其他部位

範例:
War Room:買入 AAPL $15,000
投資組合管理員:"科技產業已達 38%,僅買入 $10,000"

報告

每週投資組合報告

# Portfolio Performance Report - Week of 2025-12-21

## 資產配置
- 股票:68%(目標:70%)✓
- 債券:22%(目標:20%)⚠️
- 現金:10%(目標:10%)✓

## 績效
- 週報酬:+2.3%
- 年初至今報酬:+15.7%
- 夏普比率:1.45
- 最大回撤:-8.2%

## 已採取行動
- 無(在容忍範圍內)

## 下次檢視日期:2025-12-28

版本歷史

  • v1.0(2025-12-21):初始版本,包含 MPT 最佳化與市場狀態整合

Individual skills in this repo

This repo contains 17 individual skills — each has its own dedicated page.

diegosouzapw/awesome-omni-skill

Build a GitHub portfolio that gets you hired — curate 3-5 polished projects, craft compelling READMEs, deploy live demos, tell a coherent story across your repos, and align everything to AI-native development roles. Use when preparing your GitHub for job searches, deciding what to pin, or auditing your public presence.

diegosouzapw/awesome-omni-skill

Skill for discovering and researching autonomous AI agents, tools, and ecosystems using the AgentFolio directory.

diegosouzapw/awesome-omni-skill

Factor modeling and portfolio construction (Markowitz, Black-Litterman, constraints, turnover).

diegosouzapw/awesome-omni-skill

Analyze the CustomGPT.ai Labs Innovation workbook and cost tracking data to surface portfolio-level insights, trends, and recommendations for where to focus Innovation efforts.

diegosouzapw/awesome-omni-skill

Optimize project portfolio selection under constraints using mathematical optimization

diegosouzapw/awesome-omni-skill

Rapidly build, prototype, and deploy full-stack software using AI "text-to-app" tools. Use this when you need to create a greenfield application, build a high-fidelity working prototype for user testing, or bypass traditional engineering bottlenecks for internal tools.

diegosouzapw/awesome-omni-skill

Expert in building portfolios that actually land jobs and clients - not just showing work, but creating memorable experiences. Covers developer portfolios, designer portfolios, creative portfolios,...

diegosouzapw/awesome-omni-skill

Minimalist, typography-focused portfolio design system inspired by neo-brutalist and Swiss design principles. Emphasizes bold typography, generous whitespace, monochromatic color schemes, and elegant simplicity for developer/designer portfolios.

diegosouzapw/awesome-omni-skill

Review UI code for Web Interface Guidelines compliance. Use when asked to "review my UI", "check accessibility", "audit design", "review UX", or "check my site against best practices".

diegosouzapw/awesome-omni-skill

High-converting landing pages. Copy + design + implementation. Triggers: landing page, conversion page.

diegosouzapw/awesome-omni-skill

Detect and explain risk drift in lending portfolios over time using vintage analysis, migration matrices, and concentration metrics. Use when monitoring portfolio credit quality trends, preparing board risk reports, conducting stress testing, or when risk metrics deviate from appetite thresholds.

diegosouzapw/awesome-omni-skill

Review UI code for Web Interface Guidelines compliance. Use when asked to "review my UI", "check accessibility", "audit design", "review UX", or "check my site against best practices".

diegosouzapw/awesome-omni-skill

Review UI code for Web Interface Guidelines compliance. Use when asked to "review my UI", "check accessibility", "audit design", "review UX", or "check my site against best practices".

diegosouzapw/awesome-omni-skill

Index-based file discovery using ABOUTME headers. Use INSTEAD of grep or Explore agent when searching for files by purpose or feature. Faster and more accurate than scanning code. Invoke this skill when user asks "which files handle X", "where is Y implemented", or when you need to find files related to a feature or task.

diegosouzapw/awesome-omni-skill

Index-based file discovery using ABOUTME headers. Use INSTEAD of grep or Explore agent when searching for files by purpose or feature. Faster and more accurate than scanning code. Invoke this skill when user asks "which files handle X", "where is Y implemented", or when you need to find files related to a feature or task.

diegosouzapw/awesome-omni-skill

Automate Klipfolio tasks via Rube MCP (Composio). Always search tools first for current schemas.

diegosouzapw/service-website-generator

Orchestrates automated service-based website generation with local SEO optimization. Creates 200+ service+location pages using parallel agents, Unsplash images via Jina AI, NextJS with dynamic routing, and PostgreSQL database. Use when building service business websites (plumbers, electricians, pressure washing, HVAC, etc.) targeting multiple locations.

相關技能