Documentation Index
Fetch the complete documentation index at: https://mintlify.com/theonetrade/backtest-kit/llms.txt
Use this file to discover all available pages before exploring further.
addSizingSchema registers a named position sizing calculator that computes how many units to buy or sell for a given trade. Backtest Kit ships three sizing methods out of the box—fixed percentage of account balance, Kelly Criterion, and ATR-based—each with optional position constraints. Once registered, a sizing schema is invoked via PositionSize.fixedPercentage, PositionSize.kellyCriterion, or PositionSize.atrBased inside a strategy’s getSignal function to produce a cost value before returning the signal.
Function Signature
ISizingSchema is a discriminated union selected by the method field:
ISizingSchemaFixedPercentage(method: "fixed-percentage")ISizingSchemaKelly(method: "kelly-criterion")ISizingSchemaATR(method: "atr-based")
Common Parameters (all methods)
A unique identifier for this sizing configuration. Used as the routing key in
PositionSize.* calls.Selects the sizing algorithm. Must match the corresponding interface (
ISizingSchemaFixedPercentage, etc.).Optional cap expressed as a percentage of account balance (0–100). The calculated size is clamped so it never exceeds this fraction of the account.
Optional floor for the calculated position size (absolute value in quote currency).
Optional ceiling for the calculated position size (absolute value in quote currency).
Optional lifecycle callbacks:
onCalculate(quantity, params)— called after every size calculation with the result and input parameters. Useful for logging or auditing.
Optional developer note.
Method-Specific Parameters
method: "fixed-percentage"
Percentage of account balance at risk per trade (0–100). The position size is derived from the distance between entry and stop-loss so that the maximum loss equals
riskPercentage of the account.method: "kelly-criterion"
Fractional Kelly multiplier (0–1).
0.25 = quarter Kelly, which reduces variance compared to full Kelly while still achieving long-run growth. Lower values are more conservative.method: "atr-based"
Percentage of account balance at risk per trade (0–100).
Multiplier applied to the ATR value to set the stop distance. A larger multiplier gives more room for noise.
Default Sizing Behavior
If a strategy does not callPositionSize.* inside getSignal, the signal’s cost field defaults to CC_POSITION_ENTRY_COST (default: $100 per DCA entry). This flat-dollar default is suitable for backtesting without capital management, but production strategies should always compute size explicitly.