sizing

Compare original and translation side by side

🇺🇸

Original

English
🇨🇳

Translation

Chinese

Sizing - Complete API Reference

仓位计算 - 完整API参考

Calculate optimal position sizes using Kelly criterion, fractional Kelly, and portfolio-level allocation.

使用Kelly准则、部分凯利法和投资组合层面的分配来计算最优仓位大小。

Chat Commands

聊天命令

Kelly Calculator

Kelly计算器

/kelly 0.45 0.55 10000              Market price, your prob, bankroll
/kelly "Trump 2028" 0.55 --bank 10k Calculate for specific market
/kelly --half 0.45 0.55 10000       Half Kelly (safer)
/kelly --quarter 0.45 0.55 10000    Quarter Kelly (conservative)
/kelly 0.45 0.55 10000              Market price, your prob, bankroll
/kelly "Trump 2028" 0.55 --bank 10k Calculate for specific market
/kelly --half 0.45 0.55 10000       Half Kelly (safer)
/kelly --quarter 0.45 0.55 10000    Quarter Kelly (conservative)

Position Sizing

仓位大小计算

/size 10000 --risk 2%               Size for 2% risk per trade
/size 10000 --max-position 25%      Max 25% in single position
/size portfolio --rebalance         Rebalance to target weights
/size 10000 --risk 2%               Size for 2% risk per trade
/size 10000 --max-position 25%      Max 25% in single position
/size portfolio --rebalance         Rebalance to target weights

Edge Calculation

优势计算

/edge 0.45 0.55                     Calculate edge (prob - price)
/edge "Trump 2028" --estimate 0.55  Edge vs market price

/edge 0.45 0.55                     Calculate edge (prob - price)
/edge "Trump 2028" --estimate 0.55  Edge vs market price

TypeScript API Reference

TypeScript API参考

Create Sizing Calculator

创建仓位计算器

typescript
import { createSizingCalculator } from 'clodds/sizing';

const sizing = createSizingCalculator({
  // Bankroll
  bankroll: 10000,

  // Kelly fraction (1 = full, 0.5 = half)
  kellyFraction: 0.5,

  // Limits
  maxPositionPercent: 25,
  maxTotalExposure: 80,
});
typescript
import { createSizingCalculator } from 'clodds/sizing';

const sizing = createSizingCalculator({
  // Bankroll
  bankroll: 10000,

  // Kelly fraction (1 = full, 0.5 = half)
  kellyFraction: 0.5,

  // Limits
  maxPositionPercent: 25,
  maxTotalExposure: 80,
});

Basic Kelly

基础凯利计算

typescript
// Binary outcome (YES/NO market)
const size = sizing.kelly({
  marketPrice: 0.45,        // Current price
  estimatedProb: 0.55,      // Your probability estimate
  bankroll: 10000,
});

console.log(`Optimal bet: $${size.optimalSize}`);
console.log(`Edge: ${size.edge}%`);
console.log(`Kelly %: ${size.kellyPercent}%`);
console.log(`Expected value: $${size.expectedValue}`);
typescript
// Binary outcome (YES/NO market)
const size = sizing.kelly({
  marketPrice: 0.45,        // Current price
  estimatedProb: 0.55,      // Your probability estimate
  bankroll: 10000,
});

console.log(`Optimal bet: $${size.optimalSize}`);
console.log(`Edge: ${size.edge}%`);
console.log(`Kelly %: ${size.kellyPercent}%`);
console.log(`Expected value: $${size.expectedValue}`);

Fractional Kelly

部分凯利计算

typescript
// Half Kelly (recommended for most traders)
const halfKelly = sizing.kelly({
  marketPrice: 0.45,
  estimatedProb: 0.55,
  bankroll: 10000,
  fraction: 0.5,  // Half Kelly
});

// Quarter Kelly (very conservative)
const quarterKelly = sizing.kelly({
  marketPrice: 0.45,
  estimatedProb: 0.55,
  bankroll: 10000,
  fraction: 0.25,
});

console.log(`Full Kelly: $${sizing.kelly({...}).optimalSize}`);
console.log(`Half Kelly: $${halfKelly.optimalSize}`);
console.log(`Quarter Kelly: $${quarterKelly.optimalSize}`);
typescript
// Half Kelly (recommended for most traders)
const halfKelly = sizing.kelly({
  marketPrice: 0.45,
  estimatedProb: 0.55,
  bankroll: 10000,
  fraction: 0.5,  // Half Kelly
});

// Quarter Kelly (very conservative)
const quarterKelly = sizing.kelly({
  marketPrice: 0.45,
  estimatedProb: 0.55,
  bankroll: 10000,
  fraction: 0.25,
});

console.log(`Full Kelly: $${sizing.kelly({...}).optimalSize}`);
console.log(`Half Kelly: $${halfKelly.optimalSize}`);
console.log(`Quarter Kelly: $${quarterKelly.optimalSize}`);

Multi-Outcome Kelly

多结果凯利计算

typescript
// For markets with 3+ outcomes
const multiKelly = sizing.kellyMultiOutcome({
  outcomes: [
    { name: 'Trump', price: 0.35, estimatedProb: 0.40 },
    { name: 'DeSantis', price: 0.25, estimatedProb: 0.20 },
    { name: 'Haley', price: 0.15, estimatedProb: 0.15 },
    { name: 'Other', price: 0.25, estimatedProb: 0.25 },
  ],
  bankroll: 10000,
  fraction: 0.5,
});

for (const alloc of multiKelly.allocations) {
  console.log(`${alloc.name}: $${alloc.size} (${alloc.percent}%)`);
}
typescript
// For markets with 3+ outcomes
const multiKelly = sizing.kellyMultiOutcome({
  outcomes: [
    { name: 'Trump', price: 0.35, estimatedProb: 0.40 },
    { name: 'DeSantis', price: 0.25, estimatedProb: 0.20 },
    { name: 'Haley', price: 0.15, estimatedProb: 0.15 },
    { name: 'Other', price: 0.25, estimatedProb: 0.25 },
  ],
  bankroll: 10000,
  fraction: 0.5,
});

for (const alloc of multiKelly.allocations) {
  console.log(`${alloc.name}: $${alloc.size} (${alloc.percent}%)`);
}

Portfolio-Level Kelly

投资组合层面凯利计算

typescript
// Optimal allocation across multiple markets
const portfolio = sizing.kellyPortfolio({
  positions: [
    { market: 'Trump 2028', price: 0.45, prob: 0.55 },
    { market: 'Fed Rate Cut', price: 0.60, prob: 0.70 },
    { market: 'BTC > 100k', price: 0.30, prob: 0.40 },
  ],
  bankroll: 10000,
  correlations: correlationMatrix,  // Optional
  fraction: 0.5,
});

console.log('Optimal Portfolio:');
for (const pos of portfolio.positions) {
  console.log(`  ${pos.market}: $${pos.size}`);
}
console.log(`Total exposure: ${portfolio.totalExposure}%`);
typescript
// Optimal allocation across multiple markets
const portfolio = sizing.kellyPortfolio({
  positions: [
    { market: 'Trump 2028', price: 0.45, prob: 0.55 },
    { market: 'Fed Rate Cut', price: 0.60, prob: 0.70 },
    { market: 'BTC > 100k', price: 0.30, prob: 0.40 },
  ],
  bankroll: 10000,
  correlations: correlationMatrix,  // Optional
  fraction: 0.5,
});

console.log('Optimal Portfolio:');
for (const pos of portfolio.positions) {
  console.log(`  ${pos.market}: $${pos.size}`);
}
console.log(`Total exposure: ${portfolio.totalExposure}%`);

Confidence-Adjusted Sizing

置信度调整仓位计算

typescript
// Reduce size when less confident
const size = sizing.kellyWithConfidence({
  marketPrice: 0.45,
  estimatedProb: 0.55,
  confidence: 0.7,  // 70% confident in estimate
  bankroll: 10000,
});

// Size is reduced proportionally to confidence
console.log(`Confidence-adjusted size: $${size.optimalSize}`);
typescript
// Reduce size when less confident
const size = sizing.kellyWithConfidence({
  marketPrice: 0.45,
  estimatedProb: 0.55,
  confidence: 0.7,  // 70% confident in estimate
  bankroll: 10000,
});

// Size is reduced proportionally to confidence
console.log(`Confidence-adjusted size: $${size.optimalSize}`);

Edge Calculation

优势计算

typescript
// Calculate edge
const edge = sizing.calculateEdge({
  marketPrice: 0.45,
  estimatedProb: 0.55,
});

console.log(`Edge: ${edge.edgePercent}%`);
console.log(`EV per dollar: $${edge.evPerDollar}`);
console.log(`Implied odds: ${edge.impliedOdds}`);
console.log(`True odds: ${edge.trueOdds}`);
typescript
// Calculate edge
const edge = sizing.calculateEdge({
  marketPrice: 0.45,
  estimatedProb: 0.55,
});

console.log(`Edge: ${edge.edgePercent}%`);
console.log(`EV per dollar: $${edge.evPerDollar}`);
console.log(`Implied odds: ${edge.impliedOdds}`);
console.log(`True odds: ${edge.trueOdds}`);

Risk-Based Sizing

基于风险的仓位计算

typescript
// Size based on risk per trade
const size = sizing.riskBased({
  bankroll: 10000,
  riskPercent: 2,     // Risk 2% per trade
  stopLossPercent: 10, // 10% stop loss
});

console.log(`Position size: $${size.positionSize}`);
console.log(`Max loss: $${size.maxLoss}`);

typescript
// Size based on risk per trade
const size = sizing.riskBased({
  bankroll: 10000,
  riskPercent: 2,     // Risk 2% per trade
  stopLossPercent: 10, // 10% stop loss
});

console.log(`Position size: $${size.positionSize}`);
console.log(`Max loss: $${size.maxLoss}`);

Kelly Fractions

Kelly比例

FractionRisk LevelUse Case
Full (1.0)AggressiveMathematical optimum, high variance
Half (0.5)ModerateMost traders, good balance
Quarter (0.25)ConservativeNew traders, uncertain edges
Tenth (0.1)Very SafeLearning, small edges

比例风险等级使用场景
Full (1.0)激进型数学最优解,高波动性
Half (0.5)稳健型适合大多数交易者,平衡风险与收益
Quarter (0.25)保守型新手交易者,胜率不确定时
Tenth (0.1)极低风险学习阶段,优势较小时

Edge Requirements

优势要求

EdgeRecommendation
< 2%Don't trade
2-5%Small size (quarter Kelly)
5-10%Normal size (half Kelly)
10%+Larger size, verify edge

优势建议
< 2%不要交易
2-5%小仓位(四分之一凯利法)
5-10%正常仓位(半凯利法)
10%+加大仓位,验证优势

Formulas

公式

Kelly Formula

Kelly公式

f* = (p * b - q) / b

Where:
f* = fraction of bankroll to bet
p = probability of winning
q = probability of losing (1 - p)
b = odds received (1/price - 1)
f* = (p * b - q) / b

Where:
f* = fraction of bankroll to bet
p = probability of winning
q = probability of losing (1 - p)
b = odds received (1/price - 1)

Edge Formula

优势公式

Edge = Estimated Prob - Market Price
EV = Edge * Bet Size

Edge = Estimated Prob - Market Price
EV = Edge * Bet Size

Best Practices

最佳实践

  1. Use fractional Kelly — Full Kelly has too much variance
  2. Be conservative on edge — Overconfidence kills accounts
  3. Account for correlation — Don't over-expose to same theme
  4. Set max position — Never more than 25% in one market
  5. Reassess regularly — Edge changes as prices move
  1. 使用部分凯利法 — 全凯利法波动性过高
  2. 对优势保持保守 — 过度自信会导致账户亏损
  3. 考虑相关性 — 不要过度暴露于同一主题的资产
  4. 设置最大仓位限制 — 单个市场仓位占比绝不超过25%
  5. 定期重新评估 — 随着价格变动,优势会发生变化