Communitygithub.com

風險投資組合管理器 - AI 驅動的風險控制

AI 驅動的投資組合風險管理與優化。用於部位規模計算、投資組合配置管理、風險指標(VaR、夏普比率)計算、再平衡以及實施防禦策略。涵蓋:部位規模化、相關性分析、回撤管理、動態再平衡、緊急停止開關。

風險投資組合管理器 - AI 驅動的風險控制 是什麼?

這項技能提供了一個系統性的風險管理層,位於信號生成與交易執行之間。它採用數據驅動的方法來優化部位規模、管理投資組合風險,並自動化防禦性行動。該技能支援計算關鍵風險指標,如 Value at Risk (VaR)、夏普比率、索提諾比率和最大回撤;執行動態再平衡以將偏離目標配置的程度降至最低;並配備一個緊急停止開關系統,用於在超出每日/每週損失限額或回撤閾值時自動暫停交易、減少曝險或進行緊急平倉。此外,它還包含情境分析功能,可對各種市場壓力事件(如崩盤、板塊輪動或黑天鵝事件)進行壓力測試。該技能是為 Claude Code 等 AI 代理設計的,並提供 CLI 腳本用於執行部位規模計算、風險指標計算、再平衡建議、壓力測試和緊急停止開關狀態檢查。

相容平台✓Claude Code~Codex CLI~Cursor
npx skills add https://github.com/majiayu000/claude-skill-registry/tree/HEAD/skills/analysis/risk-portfolio-manager-dreamineering-meme-times-2

在你喜歡的 AI 中提問

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

說明文件

風險投資組合管理器 - AI 驅動的風險控制 是做什麼的?

系統性風險管理層,位於信號生成與交易執行之間。使用數據驅動的方法來優化部位規模、管理投資組合風險,並自動化防禦性行動。

核心原則

部位規模與風險管理決定長期生存。沒有任何單一交易應危及整個投資組合。

觸發條件

核心能力

1. 部位規模計算引擎

<position_sizing> 規模計算方法:

interface PositionSizeRequest {
  signal_strength: number;    // 0-1,來自 meme-trader
  token_risk_score: number;   // 1-10,來自 rug detection
  current_portfolio: Portfolio;
  market_regime: 'bull' | 'bear' | 'sideways' | 'volatile';
  risk_tolerance: 'conservative' | 'moderate' | 'degen';
}

interface PositionSizeResult {
  recommended_size_pct: number;  // 佔投資組合的百分比
  recommended_size_usd: number;
  max_allowed_size: number;
  reasoning: string[];
  risk_warnings: string[];
}

凱利準則(修正版):

最佳規模 = (勝率 * 平均獲利 - (1 - 勝率) * 平均虧損) / 平均獲利
調整後規模 = 凱利值 * 分數乘數 (為安全起見取 0.25-0.5)

風險調整後的規模矩陣:

風險承受度基礎規模最大單一部位最大相關曝險
保守0.5-1%2%5%
溫和1-2%4%10%
激進2-5%10%25%

基於信號的調整:

最終規模 = 基礎規模 * 信號強度 * (1 - 代幣風險 / 20) * 市場乘數

其中:
- 信號強度:0.5-1.5(弱到強)
- 代幣風險:1-10(越低越安全)
- 市場乘數:0.5(波動)到 1.2(趨勢)

輸出格式:

部位規模建議

代幣:$MEME
信號強度:8/10
代幣風險評分:4/10
市場狀態:多頭

建議規模:
├─ 百分比:投資組合的 2.3%
├─ 金額:$460 (基於 $20,000 的投資組合)
├─ 最大允許:$800(4% 限制)
└─ 風險調整後:在限制內

理由:
1. 強信號(8/10)支持高於平均的規模
2. 中低風險代幣(4/10)允許全額配置
3. 多頭市場狀態允許積極的規模設定
4. 與現有持倉無相關性

警告:
- 考慮分批進場(3 批)而非一次性進入
- 設置停損於 -25%(最大虧損 $345)

</position_sizing>

2. 投資組合風險指標

<risk_metrics> 即時投資組合儀表板:

投資組合風險儀表板
═══════════════════════════════════════

持倉(5 個活躍):
代幣      | 規模    | 損益      | 風險  | 權重
$BONK      | $4,200  | +$840    | 5/10  | 21%
$MEME      | $3,100  | +$620    | 4/10  | 15.5%
$DOGE      | $2,800  | -$140    | 3/10  | 14%
$WIF       | $2,500  | +$1,250  | 6/10  | 12.5%
SOL        | $7,400  | +$2,220  | 2/10  | 37%
───────────────────────────────────────
總計      | $20,000 | +$4,790  |       | 100%

風險指標:
├─ 每日 VaR(95%):-$1,240(-6.2%)
├─ 最大回撤(30 天):-18.3%
├─ 當前回撤:0%(處於歷史高點)
├─ 夏普比率(30 天):2.14
├─ 索提諾比率:2.87
├─ Beta 對 SOL:1.34

相關性矩陣:
        BONK   MEME   DOGE   WIF    SOL
BONK    1.00   0.82   0.71   0.78   0.65
MEME    0.82   1.00   0.68   0.85   0.61
DOGE    0.71   0.68   1.00   0.59   0.54
WIF     0.78   0.85   0.59   1.00   0.72
SOL     0.65   0.61   0.54   0.72   1.00

集中度風險:
├─ 最大倉位:37%(SOL) - 在限制內
├─ 前 3 大倉位:72.5% - 高
├─ 赫芬達爾指數:0.23 - 中等
└─ Meme 曝險:63% - 高

警報:
⚠️ MEME 和 WIF 之間高度相關(0.85)
⚠️ Meme 板塊集中度超過 50%

風險計算:

interface PortfolioRisk {
  // 風險價值
  var_95: number;       // 95% 信心水準的每日 VaR
  var_99: number;       // 99% 信心水準的每日 VaR
  cvar_95: number;      // 條件 VaR(預期虧損)

  // 績效風險
  sharpe_ratio: number;
  sortino_ratio: number;
  max_drawdown: number;
  current_drawdown: number;

  // 相關性風險
  avg_correlation: number;
  max_correlation: number;
  correlation_cluster: string[]; // 高度相關的群組

  // 集中度風險
  herfindahl_index: number;
  top_position_pct: number;
  sector_concentrations: Record<string, number>;
}

function calculateVaR(
  positions: Position[],
  confidence: number = 0.95,
  horizon_days: number = 1
): number {
  // 使用過去 30 天的報酬率計算歷史 VaR
  const returns = getHistoricalReturns(positions, 30);
  const portfolio_returns = calculatePortfolioReturns(returns, positions);
  const sorted = portfolio_returns.sort((a, b) => a - b);
  const index = Math.floor((1 - confidence) * sorted.length);
  return sorted[index] * getPortfolioValue(positions) * Math.sqrt(horizon_days);
}

</risk_metrics>

3. 動態再平衡

目標配置框架:

interface AllocationTarget {
  core_holdings: {
    SOL: { target: 30, min: 20, max: 50 };
    stablecoins: { target: 20, min: 10, max: 40 };
  };
  satellite_holdings: {
    memes: { target: 30, min: 0, max: 50 };
    defi: { target: 15, min: 0, max: 30 };
    other: { target: 5, min: 0, max: 15 };
  };
  rebalance_threshold: 5; // 觸發再平衡的偏離百分比
}

再平衡輸出:

再平衡建議

當前配置 vs 目標配置:
類別       | 當前   | 目標   | 偏離   | 行動
SOL        | 37%    | 30%    | +7%    | 賣出 $1,400
Memes      | 63%    | 50%    | +13%   | 賣出 $2,600
穩定幣    | 0%     | 20%    | -20%   | 買入 $4,000

建議交易:
1. 賣出 15% 的 BONK 部位 ($630) → USDC
2. 賣出 20% 的 WIF 部位 ($500) → USDC
3. 賣出 10% 的 SOL 部位 ($740) → USDC
4. 保留 MEME 和 DOGE 部位
5. 將銷售所得轉換為 USDC 穩定幣緩衝

再平衡後預測:
├─ SOL:31%(目標:30%)
├─ Memes:48%(目標:50%)
├─ 穩定幣:21%(目標:20%)
└─ VaR 降低:-18%(風險狀況改善)

4. 自動化防禦性行動

<defensive_actions> 緊急停止開關系統:

interface KillSwitchConfig {
  daily_loss_limit: number;      // 佔投資組合的百分比
  weekly_loss_limit: number;     // 佔投資組合的百分比
  position_loss_limit: number;   // 每部位的百分比
  drawdown_limit: number;        // 從高點回撤的百分比
  correlation_spike_action: 'alert' | 'reduce' | 'exit';
  auto_execute: boolean;
}

const defaultKillSwitch: KillSwitchConfig = {
  daily_loss_limit: 10,      // 日虧損達 -10% 時暫停新交易
  weekly_loss_limit: 20,     // 週虧損達 -20% 時暫停所有活動
  position_loss_limit: 30,   // 部位虧損達 -30% 時自動平倉
  drawdown_limit: 25,        // 從高點回撤 -25% 時進入緊急模式
  correlation_spike_action: 'alert',
  auto_execute: false,       // 在第一階段需要確認
};

觸發的行動:

觸發條件行動嚴重程度
部位 -25%停損警告中等
部位 -30%自動平倉(若啟用)高
每日 -10%暫停新交易高
每週 -20%退出至穩定幣嚴重
回撤 -25%緊急清算嚴重
相關性 > 0.95減少一個部位中等

警報輸出:

🚨 風險警報:接近每日損失限額

當日損益:-8.7%($-1,740)
每日限額:-10%($-2,000)
剩餘緩衝:$260

觸發的行動:
1. ⏸️ 新交易執行已暫停
2. ⚠️ 審查所有未平倉部位
3. 📊 增加監控頻率

建議:
- 審查表現最差的部位(WIF:-15%)
- 如果趨勢持續,考慮部分退出
- 請勿攤平成本

輸入 RESUME 以重新啟用交易
輸入 EXIT_ALL 以清算所有部位

</defensive_actions>

5. 情境分析

<scenario_analysis> 壓力測試:

interface StressScenario {
  name: string;
  market_move: {
    sol: number;      // 百分比變動
    memes: number;    // 相對於 SOL 的百分比變動
    correlation_shift: number;
  };
  probability: number;
}

const stressScenarios: StressScenario[] = [
  {
    name: 'SOL -30% 閃電崩跌',
    market_move: { sol: -30, memes: -50, correlation_shift: 0.2 },
    probability: 0.05,
  },
  {
    name: 'Meme 資金輪出',
    market_move: { sol: 0, memes: -40, correlation_shift: -0.1 },
    probability: 0.10,
  },
  {
    name: '多頭行情延續',
    market_move: { sol: 50, memes: 100, correlation_shift: 0 },
    probability: 0.15,
  },
  {
    name: '黑天鵝事件',
    market_move: { sol: -60, memes: -80, correlation_shift: 0.3 },
    probability: 0.01,
  },
];

壓力測試輸出:

壓力測試結果

當前投資組合價值:$20,000

情境                        | 投資組合影響 | 機率
SOL -30% 閃電崩跌            | -$7,200(-36%)  | 5%
Meme 資金輪出               | -$5,040(-25%)  | 10%
多頭行情延續                | +$14,600(+73%) | 15%
黑天鵝事件                  | -$12,400(-62%) | 1%

預期投資組合價值:
├─ 基準情況:$20,000
├─ 預期(機率加權):$22,340(+11.7%)
├─ 最壞情況(99%):-$12,400(-62%)
└─ VaR(95%,30 天):-$4,800(-24%)

風險評估:
⚠️ 對 Meme 資金輪出高度敏感(-25% 情境)
⚠️ 黑天鵝曝險顯著(-62%)
✓ 基準情境下預期價值為正
✓ 多頭情況的上漲潛力巨大(+73%)

建議:
考慮使用 SOL 賣權對沖 Meme 曝險,或將 Meme 配置減少 10-15% 以改善風險狀況。

</scenario_analysis>

整合點

風險管理器提供給:

  • meme-executor:已核准的部位規模、停損水準
  • meme-trader:部位限制、可用資金
  • 所有技能:投資組合狀態、風險警報

CLI 使用方式

# 計算部位規模
npx tsx .claude/skills/risk-portfolio-manager/scripts/position-sizer.ts \
  --signal 8 \
  --risk-score 4 \
  --portfolio-file ./portfolio.json \
  --risk-mode moderate

# 取得投資組合風險指標
npx tsx .claude/skills/risk-portfolio-manager/scripts/risk-metrics.ts \
  --portfolio-file ./portfolio.json \
  --include-correlation \
  --var-confidence 95

# 再平衡建議
npx tsx .claude/skills/risk-portfolio-manager/scripts/rebalancer.ts \
  --portfolio-file ./portfolio.json \
  --target-allocation ./targets.json \
  --threshold 5

# 執行壓力測試
npx tsx .claude/skills/risk-portfolio-manager/scripts/stress-test.ts \
  --portfolio-file ./portfolio.json \
  --scenarios default \
  --output-format detailed

# 檢查緊急停止開關狀態
npx tsx .claude/skills/risk-portfolio-manager/scripts/kill-switch.ts \
  --portfolio-file ./portfolio.json \
  --check-status

品質閘門

<validation_rules>

  • 部位規模計算需要價格資料的品質評分 >= 85%
  • VaR 計算需要 30 天以上的乾淨歷史數據
  • 相關性矩陣需要同步的價格數據
  • 所有建議都包含信心水準
  • 未經 rug detection 檢查,不得進行部位規模計算 </validation_rules>

錯誤處理

<error_recovery>

  • 缺少價格數據:使用最後已知數據並附上過時警告
  • 計算錯誤:保守回退(最小規模)
  • 緊急停止開關衝突:安全優先(暫停 > 繼續)
  • 數據品質不足:拒絕規模計算,請求刷新 </error_recovery>

<see_also>

  • references/risk-models.md - 數學公式
  • references/allocation-templates.md - 目標投資組合
  • scripts/position-sizer.ts - 規模計算引擎
  • scripts/risk-metrics.ts - 風險計算
  • scripts/kill-switch.ts - 自動化安全 </see_also>

Individual skills in this repo

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

majiayu000/claude-skill-registry

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".

majiayu000/claude-skill-registry

Edit existing BMAD agents while maintaining compliance

majiayu000/claude-skill-registry

Edit existing BMAD agents while maintaining compliance

majiayu000/claude-skill-registry

Edit existing BMAD modules while maintaining coherence

majiayu000/claude-skill-registry

Edit existing BMAD modules while maintaining coherence

majiayu000/claude-skill-registry

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

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

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

Portfolio allocation and rebalancing optimizer. Manages asset allocation across stocks/cash/bonds, performs periodic rebalancing, and ensures diversification according to market regime and risk tolerance.

majiayu000/claude-skill-registry

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

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

majiayu000/claude-skill-registry

BlockRun works with Claude Code and Google Antigravity.

majiayu000/claude-skill-registry

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

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

majiayu000/claude-skill-registry

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

CRITICAL: Use for MolyKit AI chat toolkit. Triggers on: BotClient, OpenAI, SSE streaming, AI chat, molykit, PlatformSend, spawn(), ThreadToken, cross-platform async, Chat widget, Messages, PromptInput, Avatar, LLM

majiayu000/claude-skill-registry

AI and machine learning workflow covering LLM application development, RAG implementation, agent architecture, ML pipelines, and AI-powered features.

majiayu000/claude-skill-registry

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

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

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

相關技能