'use client'; import React, { useState, useMemo } from 'react'; interface KellyBetSizingProps { trueProb: number; // 系統計算的真實勝率 (0.0 - 1.0) decimalOdds: number; // 莊家賠率 } export default function KellyBetSizing({ trueProb, decimalOdds }: KellyBetSizingProps) { const [bankroll, setBankroll] = useState(10000); const [kellyFraction, setKellyFraction] = useState(0.25); // 預設 1/4 凱利 // 核心計算邏輯 (套用凱利公式) const suggestedStake = useMemo(() => { const b = decimalOdds - 1.0; const p = trueProb; const q = 1.0 - p; if (b <= 0) return 0; const fullKellyPct = ((b * p) - q) / b; if (fullKellyPct <= 0) return 0; return Math.round(bankroll * fullKellyPct * kellyFraction); }, [bankroll, kellyFraction, decimalOdds, trueProb]); // 動態樣式判斷 const isHighRisk = kellyFraction > 0.5; const highlightColor = isHighRisk ? 'text-quant-red' : 'text-quant-orange'; return (

注碼風險控管

量化注碼建議

建議絕對金額

$ {suggestedStake.toLocaleString()}

{/* 控制區:總資金 */}
setBankroll(Number(e.target.value))} className="w-full h-2 bg-stone-200 rounded-lg appearance-none cursor-pointer accent-quant-orange" />
{/* 控制區:風險偏好 (分數凱利) */}
setKellyFraction(Number(e.target.value))} className="w-full h-2 bg-stone-200 rounded-lg appearance-none cursor-pointer accent-stone-700" />
保守 0.1x 一般 0.25x 高風險 1.0x
); }