Skip to main content

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.

The Walker singleton runs walk-forward analysis across a list of strategies over a shared historical period. Walk-forward analysis is a validation technique that avoids overfitting: instead of testing all strategies on the same data, you optimize on an in-sample window and evaluate the winner on an unseen out-of-sample window. In Backtest Kit, the Walker iterates a strategies list, backtests each one against the same frame and exchange, scores them on a configured metric, and streams progress updates after each strategy completes. Walk-forward analysis matters because a strategy can be hand-fitted to historical data (curve-fit) and show outstanding in-sample metrics that collapse on live data. By comparing multiple strategy variants and measuring performance on held-out data, you detect overfitting before deploying real capital.

addWalkerSchema

Before running Walker, register a walker schema:
import { addWalkerSchema } from 'backtest-kit';

addWalkerSchema({
  walkerName:   'rsi-param-search',
  exchangeName: 'binance',
  frameName:    '2025-q4',
  strategies:   ['rsi-14', 'rsi-21', 'rsi-7', 'rsi-28'],
  metric:       'sharpeRatio',  // default
  callbacks: {
    onStrategyStart: (strategyName, symbol) => {
      console.log(`Testing ${strategyName} on ${symbol}...`);
    },
    onStrategyComplete: (strategyName, symbol, stats, metric) => {
      console.log(`${strategyName}: metric=${metric?.toFixed(4) ?? 'N/A'}`);
    },
    onComplete: (results) => {
      console.log(`Best strategy: ${results.bestStrategy} (${results.bestMetric?.toFixed(4)})`);
    },
  },
});

IWalkerSchema Parameters

walkerName
string
required
Unique identifier for the walker configuration.
exchangeName
string
required
Exchange schema used for all strategy backtests in this walker run.
frameName
string
required
Frame schema defining the shared backtest period.
strategies
string[]
required
Ordered list of strategy names to compare. Each must be registered via addStrategySchema.
metric
WalkerMetric
default:"\"sharpeRatio\""
Optimization target. Higher values are always better.Available metrics: "sharpeRatio" | "annualizedSharpeRatio" | "winRate" | "totalPnl" | "certaintyRatio" | "avgPnl" | "expectedYearlyReturns"
callbacks
Partial<IWalkerCallbacks>
onStrategyStart, onStrategyComplete, onStrategyError, onComplete hooks.

run()

Walker.run(
  symbol: string,
  context: { walkerName: string }
): AsyncGenerator<WalkerContract>
Pull-based execution. Yields a WalkerContract after each strategy completes, giving real-time visibility into the optimization progress.
import { Walker } from 'backtest-kit';

for await (const progress of Walker.run('BTCUSDT', { walkerName: 'rsi-param-search' })) {
  console.log(
    `[${progress.strategiesTested}/${progress.totalStrategies}] ` +
    `${progress.strategyName}: ${progress.metricValue?.toFixed(4) ?? 'N/A'} ` +
    `(best so far: ${progress.bestStrategy} = ${progress.bestMetric?.toFixed(4)})`
  );
}

WalkerContract Fields

FieldDescription
walkerNameName of the running walker.
strategyNameStrategy that just finished testing.
statsFull BacktestStatisticsModel for the completed strategy.
metricValueThe configured metric value for this strategy (null if invalid).
metricWhich metric is being optimized.
bestMetricBest metric value seen so far across all strategies.
bestStrategyStrategy name that achieved bestMetric.
strategiesTestedCount of strategies completed so far.
totalStrategiesTotal number of strategies in the walker.

background()

Walker.background(
  symbol: string,
  context: { walkerName: string }
): () => void
Event-driven background execution. Returns a stop function. Subscribe to listenWalker or listenWalkerComplete to observe results.
import { Walker, listenWalkerComplete } from 'backtest-kit';

Walker.background('BTCUSDT', { walkerName: 'rsi-param-search' });

listenWalkerComplete((results) => {
  console.log(`Walker complete!`);
  console.log(`Best: ${results.bestStrategy} (${results.bestMetric?.toFixed(4)})`);
  console.log(`Tested ${results.totalStrategies} strategies`);
});

getData()

Walker.getData(
  symbol: string,
  context: { walkerName: string }
): Promise<WalkerCompleteContract>
Returns the final results object after the walker completes. Contains bestStrategy, bestMetric, bestStats, and totalStrategies.

getReport()

Walker.getReport(
  symbol: string,
  context: { walkerName: string }
): Promise<string>
Returns a Markdown report comparing all strategies by the configured metric, including a ranked table and the best strategy’s full statistics.

dump()

Walker.dump(
  symbol: string,
  context: { walkerName: string },
  path?: string
): Promise<void>
Writes the Markdown comparison report to disk. Default output path: ./dump/walker/.

stop()

Walker.stop(
  symbol: string,
  context: { walkerName: string }
): Promise<void>
Stops all strategies in the walker from generating new signals. The current active signal closes naturally before the walk terminates.
The Walker requires a registered walker schema (addWalkerSchema) before Walker.run or Walker.background can be called. The walker schema specifies the exchange, frame, and list of strategies to compare—all of which must be registered independently before the walker schema is created.

Build docs developers (and LLMs) love