/**
 * Agent-specific trading types — @vauban-org/agent-sdk v0.7.1 (sprint-526 Bloc 5b)
 *
 * Pure types + one pure helper. No I/O, no side effects.
 *
 * Types mirror the `trade_detail` DB schema (sprint-526:quick-1) so the SDK
 * surface stays in sync with persistence without a direct DB dependency.
 *
 * @public
 */
/**
 * Compute a Kelly criterion sizing fraction with a bootstrap fallback.
 *
 * V5 anti-pattern #2 (piège 2): never apply full Kelly before sufficient
 * historical data. When `historicalTradeCount < bootstrap_trade_threshold`,
 * returns a conservative fixed fraction instead of the Kelly estimate.
 *
 * Variance is floored at `1e-9` to guard against divide-by-zero.
 * Fraction is clamped to `[0, kelly_cap]` — never negative, never unbounded.
 *
 * @param historicalTradeCount - Completed trades available for calibration.
 * @param expectedReturn       - Expected return per trade (e.g. mean PnL).
 * @param variance             - Variance of returns (must be ≥ 0).
 * @param config               - Cap + bootstrap parameters.
 * @returns Sizing fraction and the mode used for traceability.
 *
 * @public
 */
export function computeKellyFraction(historicalTradeCount, expectedReturn, variance, config) {
    if (historicalTradeCount < config.bootstrap_trade_threshold) {
        return { fraction: config.kelly_bootstrap_fraction, mode: "bootstrap" };
    }
    const kelly = expectedReturn / Math.max(variance, 1e-9);
    return {
        fraction: Math.min(Math.max(kelly, 0), config.kelly_cap),
        mode: "kelly",
    };
}
//# sourceMappingURL=trading.js.map