TradingView backtesting guides

Optimal f Calculator: Historical Growth and Worst-Loss Risk

Optimal f maximizes the compounded wealth of an entered trade sample, using its largest loss as the risk scale. Calculate that historical optimum, then append a larger loss to see how fragile it is. This is a research calculation, not a position recommendation.

Comma or newline separated; positive wins, negative losses, zero breakevens. Use the same currency and constant base size, net of costs. No headers, currency symbols or thousands separators. Maximum 10,000 trades.

Shows f × equity as the modeled loss if the historical worst trade repeats. This is not a suggested risk budget.

Sample-optimal f

46.7619%

The result fits only these outcomes. A future loss can exceed the historical risk scale.

Trade count
7
Largest loss magnitude L
50
Terminal wealth relative
4.7581×
Log terminal wealth
1.5599
Max closed-equity drawdown
46.76%
Geometric gain per trade
24.9617%
Growth objective across f
Growth objective across f1.5598-5.0903f: 0 to 0.99 (101 plotted points)
Trade-by-trade log equity at optimal f
Trade-by-trade log equity at optimal f1.55990Trade: 0 to 7

Both charts use natural log wealth, starting from wealth 1. The optimum is solved separately from the plotted grid. Drawdown uses every trade in the entered order and excludes open-position losses.

Same history, different fractions (illustrations only)
fLog wealthTerminal wealth
0.0000%01.0000×
23.3810%1.20933.3512×
46.7619% (optimum)1.55994.7581×
73.3810%0.9862.6805×

Append one larger loss

One hypothetical trade is appended. The revised optimum uses the new largest loss. The old-rule test keeps the original f and loss scale.

Added loss: -200. Re-fitted f: 31.3399% (original: 46.7619%). Revised terminal wealth: 1.1736×.

At the original loss scale, the revised exposure is equivalent to f = 7.8350%. Compare this with the original 46.7619%; raw f values use different loss denominators.

Old-rule shock multiplier: -0.8705. Modeled ruin: equity is exhausted or negative. Compounding stops; a negative multiplier is not a recoverable wealth result.

What the historical optimum actually measures

For outcomes t₁ through tₙ at a constant base position size, let L = |min(tᵢ)| and rᵢ = tᵢ / L. Each trade multiplies modeled equity by 1 + f × rᵢ. The largest historical loss has r = −1, so f = 1 would exhaust the account on that trade. This calculator searches 0 ≤ f < 1.

G(f) = Σ ln(1 + f × rᵢ); TWR(f) = exp(G(f))

Ralph Vince describes optimal f as the fixed fraction that maximizes geometric growth. Here every observation has equal weight. The calculation uses log wealth to avoid overflow from multiplying many growth factors. The derivative Σ rᵢ / (1 + f × rᵢ) decreases with f; 80 bisection steps locate its root. If its value at zero is nonpositive, f = 0 is the optimum. The displayed curve is illustrative and does not limit the optimizer to grid points.

Zero outcomes contribute a multiplier of 1. The model assumes sequential trades, continuous fractional sizing and reinvestment, with no cash transfers, margin calls, lot rounding or simultaneous positions. Costs must already be included. Outcomes cannot be more than 10¹² times, or less than 10⁻¹² times, the largest loss in nonzero magnitude; unsupported numerical ranges return an error. Very large or small TWR values are displayed in powers of ten.

A three-trade example that fails after one new loss

Use the constructed sample 200, 200, -100, in constant-size USD outcomes net of costs. L = 100 and the factors are (1 + 2f), (1 + 2f), (1 − f). Setting 4 / (1 + 2f) − 1 / (1 − f) = 0 gives f = 0.5. Terminal wealth is 2 × 2 × 0.5 = 2, with a 50% closed-equity drawdown on the final trade. Half that f produces 1.5 × 1.5 × 0.75 = 1.6875, not a recommendation.

Append -300. Keeping the old f and old L produces 1 − 0.5 × 3 = −0.5 on the shock: the positive-wealth model has failed. Re-fitting all four observations with L = 300 instead gives f = 0, since their sum is zero and every positive f reduces geometric wealth. The previous optimum was a property of three observations, not a bound on the fourth loss.

Optimal f, Kelly and Fixed Ratio solve different inputs

Kelly criterion maximizes expected log wealth under an assumed probability distribution. Its familiar two-outcome formula uses win probability and payoff odds. Empirical optimal f applies the same log-growth objective to the observed distribution; it retains the individual win and loss sizes rather than compressing them into a binary model. Neither approach removes estimation error.

Fixed Ratio sizing, associated with Ryan Jones, raises contract tiers when cumulative profit reaches delta-based thresholds. It does not solve this trade sample's log-wealth maximum. Its discrete contract steps and profit path need a separate simulation. Even for optimal f, reordering trades preserves terminal wealth but can change the drawdown path.

Prepare TradingView data before calculating

  1. Export the trade list from TradingView's Strategy Report. Tabs export separately; a summary of performance metrics is not the list of individual outcomes.
  2. Retain one completed outcome per trade. Reconcile entry/exit rows and partial exits instead of counting the same P&L twice. Exclude open positions and use net P&L rather than cumulative P&L, run-up or drawdown columns.
  3. If sizes vary, convert each outcome to a consistent base quantity and currency first. Do not paste compounded dollar results as if each came from the same exposure. Include spread, commissions and slippage consistently; this calculator deducts nothing.
  4. Paste only the prepared numeric outcomes here. This page does not import a TradingView CSV. Retain separate holdout trades and compare results across periods before interpreting a fitted optimum.

Backtest Deep Report parses supported TradingView trade CSVs into closed trades, including quantity and net P&L, and reports metrics such as total trades and drawdown. Check that source data first. The optimal-f search and shock test on this page are independent calculations; they are not presented as built-in Deep Report metrics. Closed-trade statistics cannot detect all intratrade margin or gap risks.

Frequently asked questions

Does changing trade order change optimal f?

No. With the same outcomes, loss normalization and fixed fraction, terminal wealth is a product of the same factors in any order. Optimal f is unchanged. The intermediate equity path and maximum drawdown can change. Rounding contracts, margin calls or other path-dependent rules would define a different model.

What if my trade list has no losses or no positive edge?

Without a negative trade, the largest-loss normalization is undefined, so this calculator gives no f. With at least one loss and a nonpositive sum of normalized outcomes, the maximum on 0 ≤ f < 1 is f = 0 and terminal wealth relative is 1. All losses therefore produce zero, rather than a forced positive position.

Is optimal f the percentage of equity to invest?

Here f is the equity fraction lost if the historical worst loss repeats at the modeled exposure. It is not the percentage invested, notional leverage or a guaranteed stop-loss limit. The model quantity is f times current equity divided by the loss per base unit, before lot rounding or margin constraints.

Can a new worst loss make the old optimal f bankrupt?

Yes. A loss m times the original largest loss has equity multiplier 1 − m × f under the old rule. At zero the modeled account is exhausted; below zero the model is insolvent and positive-wealth compounding must stop. Recalculating f afterward does not repair that loss.

Sources and method references

Sources checked October 18, 2026. The worked examples are constructed and calculated from the formulas above.

This calculator is for educational research and is not investment advice. It does not estimate the probability of future ruin, recommend a trading fraction or place orders.

Review the trade record behind the fraction

Check supported CSV inputs and report metrics in Backtest Deep Report. If you need to express a research sizing rule in Pine Script, use Pine Script AI Coding Agent to draft editable code, then verify quantities, costs and fills in TradingView.

Explore Backtest Deep Report

Review Pine Script AI Coding Agent