Communitygithub.com

投资组合管理器代理

优化投资组合的资产配置、再平衡和多元化,根据市场状态和风险承受能力管理股票、现金和债券的分配。

投资组合管理器代理 是什么?

该技能实现了一个智能的投资组合管理器代理,专注于自动化的资产配置、再平衡和风险管理。它支持多种市场状态(RISK_ON、RISK_OFF、TRANSITION),并根据VIX指数、宏观数据等动态调整目标配置比例。该代理的核心功能包括偏差检测(超过5%建议再平衡,超过10%紧急再平衡)、基于凯利公式和现代投资组合理论(MPT)的仓位计算、以及行业分散化约束检查。输出格式为标准化的JSON,包含当前/目标配置、交易建议、风险指标(Beta、夏普比率、最大回撤)和下次审查日期。该技能适用于Claude Code等支持工具使用的AI代理平台,可通过结合市场状态检测器和宪法合规检查来实现稳健的决策流程。

兼容平台✓Claude Code~Codex CLI~Cursor
npx skills add https://github.com/majiayu000/claude-skill-registry-data/tree/HEAD/agent/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. 再平衡触发条件

IF 偏差 > 5%:
  → 建议再平衡

示例:
目标:股票 70%
当前:股票 76%
偏差:+6% → 再平衡

IF 偏差 > 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步:再平衡决策
  IF 偏差 > 阈值:
    → 生成再平衡交易
  ELSE:
    → 维持当前配置

第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

与其他代理的协作

War Room → 交易信号
  ↓
投资组合管理器 → 检查当前配置
  ↓
IF 新仓位导致失衡:
  → 建议部分仓位
  或
  → 建议先卖出其他仓位

示例:
War Room:买入 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 20 individual skills — each has its own dedicated page.

majiayu000/claude-skill-registry-data

Edit existing BMAD agents while maintaining compliance

majiayu000/claude-skill-registry-data

Edit existing BMAD agents while maintaining compliance

majiayu000/claude-skill-registry-data

Edit existing BMAD modules while maintaining coherence

majiayu000/claude-skill-registry-data

Edit existing BMAD modules while maintaining coherence

majiayu000/claude-skill-registry-data

Analyzes current state and user query to answer BMad questions or recommend the next workflow or agent. Use when user says what should I do next, what do I do now, or asks a question about BMad

majiayu000/claude-skill-registry-data

Build AI agents with Google ADK Python (Agent Development Kit). Use for multi-agent systems, workflow agents (sequential/parallel/loop), Vertex AI deployment, tool integration, human-in-the-loop.

majiayu000/claude-skill-registry-data

Build AI agents with Google ADK Python (Agent Development Kit). Use for multi-agent systems, workflow agents (sequential/parallel/loop), Vertex AI deployment, tool integration, human-in-the-loop.

majiayu000/claude-skill-registry-data

Create a hilarious and ultra-realistic video of an anthropomorphic animal acting like a human vlogger in a real-world setting.

majiayu000/claude-skill-registry-data

Speech-to-text transcription and translation via OpenAI Audio API -- models, response formats, timestamps, prompting, streaming, chunking, and diarization

majiayu000/claude-skill-registry-data

This skill should be used when the user asks about libraries, frameworks, API references, or needs code examples. Activates for setup questions, code generation involving libraries, or mentions of specific frameworks like React, Vue, Next.js, Prisma, Supabase, etc.

majiayu000/claude-skill-registry-data

小省导购员数字人带货版即梦视频提示词生成系统,基于四大智能体协同(提示词生成师、质量管控师、知识库运维师、跨环节适配师),按照"主体+运动+场景+(镜头语言+光影+氛围)"公式输出中英文双版提示词,适配5s短视频。确保人物一致性、视觉连贯性、情绪连贯性,支持知识库智能复用和跨工具适配(Suno音乐、AI绘画),为数字人带货视频提供高质量提示词生成服务。

majiayu000/claude-skill-registry-data

Upload and manage files using Google Gemini File API via scripts/. Use for uploading images, audio, video, PDFs, and other files for use with Gemini models. Supports file upload, status checking, and file management. Triggers on "upload file", "file API", "upload image", "upload PDF", "upload video", "file management".

majiayu000/claude-skill-registry-data

Analyze images/audio/video with Gemini API (better vision than Claude). Generate images (Imagen 4), videos (Veo 3). Use for vision analysis, transcription, OCR, design extraction, multimodal AI.

majiayu000/claude-skill-registry-data

Analyze images/audio/video with Gemini API (better vision than Claude). Generate images (Imagen 4), videos (Veo 3). Use for vision analysis, transcription, OCR, design extraction, multimodal AI.

majiayu000/claude-skill-registry-data

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

majiayu000/claude-skill-registry-data

Conduct domain and industry research. Use when the user says "lets create a research report on [domain or industry]

majiayu000/claude-skill-registry-data

Conduct market research on competition and customers. Use when the user says "create a market research report about [business idea]".

majiayu000/claude-skill-registry-data

Conduct technical research on technologies and architecture. Use when the user says "create a technical research report on [topic]".

majiayu000/claude-skill-registry-data

Understand an existing codebase through systematic exploration

majiayu000/claude-skill-registry-data

Builds, edit or validate Agent Skill through conversational discovery. Use when the user requests to "Create an Agent", "Optimize an Agent" or "Edit an Agent".

相关技能