Communitygithub.com

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

以 AI 驅動的投資組合風險管理與最佳化。適用於持倉規模計算、投資組合配置管理、風險指標(VaR、Sharpe)計算、再平衡或實施防禦策略。涵蓋:持倉規模、相關性分析、回撤管理、動態再平衡、緊急止損。

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

這是一個系統性的風險管理層,位於信號生成與交易執行之間。它採用數據驅動的方法來優化持倉規模、管理投資組合風險,並自動執行防禦性動作,例如止損和緊急平倉。此技能支援多種平台(如 Claude Code、Cursor 等),並整合了凱利準則、風險調整後的規模計算矩陣、VaR 和 Sharpe 比率等風險指標,以及動態再平衡和壓力測試功能。其主要價值在於透過嚴格的風險規則,防止單一交易對整體投資組合造成毀滅性打擊,並能根據市場狀態(牛市、熊市、震盪、波動)和用戶的風險偏好(保守、穩健、激進)提供個人化的建議。

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

在你喜歡的 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%(歷史新高)
├─ Sharpe 比率 (30天):2.14
├─ Sortino 比率: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) - 在限制內
├─ 前三大持倉:72.5% - 高
├─ Herfindahl 指數:0.23 - 中等
└─ 迷因幣曝險:63% - 高

警報:
⚠️ MEME 和 WIF 之間相關性高 (0.85)
⚠️ 迷因幣板塊集中度超過 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; // 觸發再平衡的偏離百分比
}

再平衡輸出:

再平衡建議

目前與目標配置:
類別       | 目前   | 目標   | 偏離   | 動作
SOL        | 37%     | 30%    | +7%    | 賣出 $1,400
迷因幣     | 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%)
├─ 迷因幣: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: '迷因幣資金流出',
    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%
迷因幣資金流出           | -$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%)

風險評估:
⚠️ 對迷因幣資金流出的敏感度很高(-25% 情境)
⚠️ 黑天鵝曝險顯著(-62%)
✓ 基本情境下預期價值為正
✓ 牛市情況下上漲潛力巨大(+73%)

建議:
考慮使用 SOL 賣權對沖迷因幣曝險,或者
將迷因幣配置減少 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 檢測檢查,不得進行持倉規模計算 </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.

相關技能