Getting started

Install fbtf and run your first minimal backtest.

Getting started

Install

npm install @thecommandcat/fbtf

fbtf is ESM-only and targets Node 20+.

Minimal usage

import {
  createHistoricalFeed,
  createPaperBroker,
  createRunner,
  defineStrategy,
} from '@thecommandcat/fbtf';
import { normalizeBars } from '@thecommandcat/fbtf/data';
import { mnq } from '@thecommandcat/fbtf/markets';
 
const bars = normalizeBars(
  [
    { startTime: '2024-03-08T14:30:00.000Z', open: 18420, high: 18425, low: 18418, close: 18420, volume: 120 },
    { startTime: '2024-03-08T14:35:00.000Z', open: 18420, high: 18440, low: 18420, close: 18435, volume: 180 },
  ],
  { defaultMarketId: mnq.id, defaultTimeframe: '5m' },
);
 
const strategy = defineStrategy({
  onBar() {
    return undefined;
  },
});
 
const runner = createRunner({
  mode: 'backtest',
  runId: 'demo-run',
  strategyId: 'demo-strategy',
  market: mnq,
  strategy,
  feed: createHistoricalFeed(bars),
  broker: createPaperBroker({ market: mnq, initialCash: 25_000 }),
});
 
await runner.start();

What this example is doing

  1. normalizeBars() turns simple input records into canonical bars with a market id and parsed timeframe.
  2. defineStrategy() gives the runner a deterministic decision function.
  3. createHistoricalFeed() replays the bars in order.
  4. createPaperBroker() handles fills, positions, and account state.
  5. createRunner() ties the strategy, market, feed, and broker together.

That is the core shape of the library. Most of the rest of the API is there to help you prepare inputs, inspect outputs, or run the same model through a config-driven experiment workflow.

What to expect from the first release

  • a small root package surface
  • explicit subpaths for data, markets, results, risk, and experiments
  • deterministic bar-driven behavior
  • futures-first practical examples

What you should not expect yet:

  • real-money execution
  • tick-level simulation
  • a huge built-in strategy framework
  • a multi-asset portfolio product

Next steps

On this page