Communitygithub.com

diegosouzapw/awesome-omni-skill

投资组合配置与再平衡优化器。管理股票/现金/债券等资产配置,根据市场状态和风险承受能力执行定期再平衡,确保多元化投资。

awesome-omni-skill 是什么?

Portfolio Manager Agent 是一款专注于投资组合资产配置、再平衡和多样化的智能工具,旨在优化风险调整后收益。该技能支持动态资产配置策略,根据市场机制(如 RISK_ON、RISK_OFF、TRANSITION)自动调整股票、债券和现金的比例,并结合行业分散化限制(如科技股上限 40%)来控制集中度风险。它基于偏差阈值(5% 常规再平衡、10% 紧急再平衡)触发再平衡操作,并输出包含当前/目标配置、偏差、交易建议和风险指标(Beta、夏普比率、最大回撤)的详细 JSON 结果。该技能可集成市场机制检测器(MarketRegimeDetector),利用 VIX、GDP 增长等宏观数据判断市场状态,并通过凯利公式和现代投资组合理论(MPT)优化仓位大小。它还能与其他代理(如 War Room)协作,在交易信号导致配置失衡时提供建议,确保符合宪章约束(如 Article 4 限制)。支持 Cursor、Claude Code、Codex 等平台,适用于需要系统化、纪律性投资组合管理的开发者和量化交易者。

兼容平台~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 = |当前 - 目标|

步骤 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%

输出:
- 建议:再平衡
- 目标:股票 70%,债券 20%,现金 10%
- 交易:
  * 买入股票 15,000 美元
  * 卖出债券 10,000 美元
  * 减少现金 5,000 美元

示例 2:RISK_OFF → 防御配置

输入:
- VIX:28
- 衰退信号
- 市场机制:RISK_OFF
- 当前:股票 70%,债券 20%,现金 10%

输出:
- 建议:紧急再平衡
- 目标:股票 40%,债券 40%,现金 20%
- 交易:
  * 卖出股票 30,000 美元
  * 买入债券 20,000 美元
  * 增加现金 10,000 美元

示例 3:偏差较小 → 维持

输入:
- 当前:股票 68%,债券 22%,现金 10%
- 目标:股票 70%,债券 20%,现金 10%
- 偏差:2%,2%,0%

输出:
- 建议:维持
- 理由:“偏差 < 5%,考虑交易成本后维持更有利”

示例 4:行业再平衡

输入:
- 科技:45%(最高 40%)
- 金融:15%
- 医疗:10%

输出:
- 建议:行业再平衡
- 交易:
  * 卖出科技股 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

与其他代理的协作

战斗室 → 交易信号
  ↓
投资组合管理器 → 检查当前配置
  ↓
如果新仓位导致失衡:
  → 建议部分仓位规模
  或
  → 建议先卖出其他仓位

示例:
战斗室:买入 AAPL 15,000 美元
投资组合管理器:“科技行业已达 38%,仅买入 10,000 美元”

报告

每周投资组合报告

# 投资组合表现报告 - 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.

相关技能