Kelly Formula Crypto
🎯 Kelly Formula 仓位管理器 - 凯利公式加密货币仓位计算工具
MIT-0 · Free to use, modify, and redistribute. No attribution required.
⭐ 0 · 21 · 0 current installs · 0 all-time installs
MIT-0
Security Scan
OpenClaw
Suspicious
medium confidencePurpose & Capability
Name, README, SKILL.md, and the included Python script all implement Kelly-formula position sizing and related helpers; the code matches the described functionality.
Instruction Scope
The SKILL.md exposes an external endpoint (https://kelly-formula-crypto.vercel.app/api/calculate) and documents an x402 payment flow to api.x402.dev/pay. The instructions do not ask the agent to read local secrets or unrelated files. However, they do assume the agent will call an external paid API and (per docs) 'automatically' initiate a 0.01 USDC payment when invoked — this is outside pure calculation and is material to user cost/privacy expectations.
Install Mechanism
No install spec is provided (instruction-only with an included utility script). Nothing is downloaded from arbitrary URLs and there are no installers that would write code to disk during installation.
Credentials
The skill requests no environment variables or credentials. It does include a public recipient wallet address and references the x402 payment endpoint; this is proportionate for a paid skill. There is no request for private keys or other sensitive credentials in the package.
Persistence & Privilege
always:false (good), but disable-model-invocation is false (normal), meaning the agent may autonomously invoke the skill. Combined with the documented automatic 0.01 USDC payment per call, autonomous invocation could lead to repeated micro-payments without explicit user confirmation.
What to consider before installing
This skill implements the Kelly formula and includes a benign-looking Python calculator; however, the SKILL.md advertises an external API and an x402 micro-payment (0.01 USDC) that will be triggered when the skill is called. Before installing: (1) confirm you accept the payment model and the recipient wallet (0x24b2...ce22); (2) disable autonomous skill invocation or require explicit user approval for network/payment calls so the agent cannot charge you repeatedly; (3) verify the external endpoint (the vercel.app API and api.x402.dev) and prefer running the included script locally if you want calculations without external payments; (4) review the GitHub source linked in README if you need higher assurance. If you want me to, I can produce a checklist of settings to change to avoid unintended charges or show how to run the bundled script locally instead of calling the paid endpoint.Like a lobster shell, security has layers — review code before you run it.
Current versionv1.0.0
Download ziplatest
License
MIT-0
Free to use, modify, and redistribute. No attribution required.
SKILL.md
Kelly Formula 仓位管理器
定价: 0.01 USDC (x402支付) 标签: crypto, trading, kelly-formula, position-sizing, risk-management 作者: Rich (@samhuang2025)
简介
基于凯利公式的加密货币仓位计算工具,帮助交易者用数学纪律替代情绪化决策。
核心功能:
- ✅ 凯利公式仓位计算
- ✅ 分数凯利建议(½ / ¼)
- ✅ 多策略仓位分配
- ✅ 杠杆安全边际计算
x402 支付
本skill支持x402微支付协议。调用时自动发起0.01 USDC支付请求。
# x402支付示例
curl -X POST https://api.x402.dev/pay \
-H "Content-Type: application/json" \
-d '{
"to": "0x24b288c98421d7b447c2d6a6442538d01c5fce22",
"amount": "0.01",
"currency": "USDC",
"memo": "kelly-formula-skill"
}'
核心公式
完整版
f* = (bp - q) / b
- p = 胜率
- b = 盈亏比
- q = 1 - p
简化版(对称盈亏)
f* ≈ 2p - 1
记忆法:胜率高出50%的部分×2 = 建议仓位
使用方法
1. 基本仓位计算
输入:
- 胜率 p (0-1)
- 盈亏比 b (如 2.0 表示赚2块亏1块)
输出:
- 全凯利仓位
- ½凯利仓位(推荐)
- ¼凯利仓位(保守/杠杆)
def kelly_position(p, b, fraction=0.5):
if p <= 0.5:
return 0 # 无优势,不做
f_star = (p * b - (1 - p)) / b
if f_star < 0:
return 0
return f_star * fraction
2. 对称速查表
| 胜率 | 全凯利 | ½凯利 | ¼凯利 |
|---|---|---|---|
| 52% | 4% | 2% | 1% |
| 55% | 10% | 5% | 2.5% |
| 60% | 20% | 10% | 5% |
| 65% | 30% | 15% | 7.5% |
| 70% | 40% | 20% | 10% |
| 75% | 50% | 25% | 12.5% |
3. 多策略仓位分配
原则:相关性>0.7时,合并仓位打7折
def adjusted_position(positions, correlation, discount=0.7):
total = sum(positions)
if correlation > 0.7:
return total * discount
return total
4. 杠杆安全边际
def leverage_safety(liquidation_distance, stop_loss):
safety_factor = liquidation_distance / stop_loss
if safety_factor < 2:
return "不安全,建议降杠杆"
return "安全"
实战案例
案例1:BTC短线趋势
- 胜率 55%,盈亏比 5%/3%
- 净优势 = 0.55×5 - 0.45×3 = 1.4%
- 建议仓位 = 1.4 ÷ 5 = 28%
- 执行½ = 14%
案例2:ETH资金费套利
- 胜率 70%,盈亏比 2%/1%
- 净优势 = 1.4 - 0.3 = 1.1%
- 建议仓位 = 55%
- 执行¼-½ = 14-27%
案例3:Meme热点
- 表面:胜率58%,盈亏比7%/5%
- 但1/6亏损是-25%插针
- 真实亏损 = 5/6×5% + 1/6×25% = 8.3%
- 新净优势 = 4.06 - 3.49 = 0.57%
- 建议仓位 ≈ 8% → 执行2-4%
8条铁律
- 默认分数凯利:先用½,带杠杆/不稳用¼
- 摩擦全进账:费率、滑点、资金费、Gas全部计入
- 滚动估参:月/季更新,重大事件临时降档
- 三道闸门:单笔、单日、单策略回撤硬阈值
- 净敞口上限:相关性高时顶层总仓要有硬帽
- 极端日流程:深度骤降/维护 → 切防守模板
- 小样本慎重:<200笔做保守收缩
- 先截尾再放大:先证明能控制最大亏损,再考虑放大
风险提示
- 凯利公式假设你能准确估计胜率和盈亏比
- 现实中有"肥尾",历史数据不代表未来
- 分数凯利比全凯利更安全
- 杠杆交易有强平风险,必须先算安全边际
相关资源
- 原始文章:https://x.com/KKaWSB/status/1968453490084299020
- 论文:Kelly, J.L. (1956) "A New Interpretation of Information Rate"
- 书:Edward Thorp "Beat the Dealer", "Advances in Large Scale Actors"
更新日志
- 2026-03-20: 初始版本,包含核心公式、案例和铁律
Files
4 totalSelect a file
Select a file to preview.
Comments
Loading comments…
