home / skills / louloulin / claude-agent-sdk / kelly-position

kelly-position skill

/.claude/skills/kelly-position

This skill computes optimal position sizing using the Kelly criterion and provides safe, actionable recommendations for portfolio allocation.

npx playbooks add skill louloulin/claude-agent-sdk --skill kelly-position

Review the files below or copy the command above to add this skill to your agents.

Files (5)
SKILL.md
1.4 KB
---
name: kelly-position
description: 使用Kelly公式科学计算投资仓位大小。当用户询问仓位、资金分配、position sizing或Kelly公式时使用。支持完整Kelly、分数Kelly和组合优化。
version: 1.0.0
author: InvestIntel AI Team
tags:
  - position-sizing
  - kelly-criterion
  - risk-management
  - portfolio-optimization
---

# Kelly仓位计算

使用Kelly公式计算最优投资仓位,平衡长期增长与风险控制。

## 核心公式

**完整Kelly**: `f* = (bp - q) / b`
- `b` = 盈亏比 (平均盈利/平均亏损)
- `p` = 胜率, `q` = 败率 (1-p)
- `f*` = 最优仓位比例

**简化Kelly**: `f = μ / σ²` (基于期望收益μ和方差σ²)

## 实践建议

1. **分数Kelly**: 使用1/4或1/2 Kelly降低波动
2. **仓位上限**: 单只股票≤25%(Munger原则)
3. **最小仓位**: Kelly<2%时不建仓
4. **组合管理**: 多只股票时需归一化总仓位

## 使用方式

当用户提供胜率和盈亏比时,计算完整Kelly并应用1/4分数:

```rust
let kelly = (b * p - (1.0 - p)) / b;
let safe_kelly = (kelly * 0.25).min(0.25).max(0.0);
```

## 输出内容

- Kelly最优仓位
- 推荐仓位(1/4或1/2 Kelly)
- 风险等级评估
- 仓位限制说明
- 建议理由

## 工具和详细文档

- 📁 [详细计算方法](./detailed-calculation.md)
- 📁 [Rust实现参考](./reference-implementation.md)
- 🔧 [kelly_calculator.py](./scripts/kelly_calculator.py) - 命令行工具

Overview

This skill calculates position sizes using the Kelly criterion to balance long-term growth against drawdown risk. It supports full Kelly, fractional Kelly (e.g., 1/2 or 1/4 Kelly), and portfolio-level normalization to keep total exposure within limits. Implemented for integration in Rust-based agents, it returns clear numerical recommendations and risk context.

How this skill works

Given inputs like win rate (p), win/loss payoff ratio (b), or statistical estimates (expected return μ and variance σ²), the skill computes the optimal Kelly fraction using the core formulas: full Kelly f* = (b p - q) / b and simplified f = μ / σ². It then applies fractional scaling, enforces configurable min/max position caps, and normalizes across multiple positions for portfolio sizing. The output includes the raw Kelly value, recommended traded fraction, a risk grade, and an explanation of limits.

When to use it

  • When deciding position size for a single trade or strategy after estimating win rate and payoff ratio
  • When you have statistical estimates of expected return and variance and want a variance-based size
  • When you need conservative sizing via fractional Kelly to reduce volatility
  • When managing multiple positions and requiring normalized total exposure
  • When wanting automated, reproducible position-sizing recommendations in a Rust agent

Best practices

  • Prefer fractional Kelly (1/4 or 1/2) for live trading to limit volatility and estimation error
  • Set a hard per-position cap (commonly 20–25%) to avoid concentration risk
  • Treat Kelly < 2% as a signal to skip opening a new position
  • Normalize recommended fractions so portfolio total exposure respects your risk budget
  • Regularly update p, b, μ and σ² with fresh data; estimation error materially affects Kelly outputs

Example use cases

  • Compute full and 1/4-Kelly for a strategy with 60% win rate and 1.5 reward/risk
  • Turn statistical backtest μ and σ² into a variance-based position fraction for automated sizing
  • Normalize individual Kelly recommendations across ten signals to keep total exposure ≤ 50%
  • Automatically enforce minimum size thresholds and per-trade caps before sending orders
  • Provide decision support in a trading assistant implemented in Rust

FAQ

What inputs does the skill require?

Either win rate (p) and payoff ratio (b), or expected return μ and variance σ². You can also provide custom min/max caps and a fractional multiplier.

How should I pick a fractional Kelly multiplier?

Use 1/4 for conservative live trading and 1/2 for moderate risk tolerance. Lower fractions reduce volatility but also reduce long-term growth.

How does portfolio normalization work?

Individual Kelly fractions are scaled so their sum meets your total exposure limit, preserving relative weights while enforcing the cap.