Communitygithub.com

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

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

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

風險投資組合管理器是一個系統性的風險管理層,位於訊號生成與交易執行之間。它使用數據驅動的方法來優化部位規模、管理投資組合風險並自動化防禦行動。該技能支援所有平台(Claude Code、Cursor、Codex 等),並透過擷取交易、風險模型和市場資料來運作。核心功能包括:基於凱利公式和風險調整矩陣的部位規模引擎、即時投資組合風險儀表板(含 VaR、夏普比率、相關性矩陣、集中度風險)、動態再平衡(當偏離目標超過 5% 或相關性過高時觸發)、自動化防禦行動(如停損、暫停交易、緊急清算),以及壓力測試場景分析。它與其他技能(如 memes-trader、memes-executor)無縫整合,以確保所有決策都經過風險評估。

相容平台✓Claude Code~Codex CLI~Cursor
npx skills add https://github.com/majiayu000/claude-skill-registry-data/tree/HEAD/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%(處於歷史高點)
├─ 夏普比率(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)- 在限制範圍內
├─ 前三大部位: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. 賣出 BONK 部位的 15%(630 美元)→ USDC
2. 賣出 WIF 部位的 20%(500 美元)→ USDC
3. 賣出 SOL 部位的 10%(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 偵測檢查不得進行部位規模設定 </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-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

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

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

相關技能