The run Command

The run command executes a strategy backtest. This chapter provides a comprehensive guide to all available options.

Basic usage

algo run --strategy <name> --symbols <symbols> [flags]

At minimum, a strategy and at least one symbol must be specified.

Date range

FlagDefaultDescription
--date-from2010-01-01Start date (YYYY-MM-DD)
--date-toTodayEnd date (YYYY-MM-DD)
--use-first NUse only the first N% of data (in-sample)
--use-last NUse only the last N% of data (out-of-sample)
algo run --strategy kbt --symbols @ES --date-from 2015-01-01 --date-to 2024-12-31

The --use-first and --use-last flags are useful for dividing data into in-sample and out-of-sample periods:

# Train on first 70%
algo run --strategy kbt --symbols @ES --use-first 70

# Test on last 30%
algo run --strategy kbt --symbols @ES --use-last 30

Bar configuration

FlagDefaultDescription
--bar-intervaldailyBar size: daily, weekly, monthly, Nm, Nh
--bar-building-modenaturalnatural or session
--max-bars-back263Maximum lookback period
--no-look-inside-barfalseDisable intra-bar order evaluation
--bouncing-ticks0Bouncing ticks percentage (0-100)

Session configuration

FlagDefaultDescription
--session-hoursSymbol defaultTrading hours (e.g., 9:30am-4:00pm)
--session-daysSymbol defaultTrading days (e.g., Mon-Fri)
--timezoneExchange timezoneIANA timezone (e.g., America/New_York)
--no-out-of-session-executionfalseDisable shadow bar processing

Cost model

Slippage

FlagDefaultDescription
--slippage-modeper-unitper-unit or per-trade
--slippage-ticks0Number of ticks of slippage

Commission

FlagDefaultDescription
--commission-modeper-unitper-unit, per-trade, or percentage
--commission-amount0Commission amount (supports currency: 2.50USD)
--commission-percentage0Commission as percentage of trade value

Capital and position sizing

FlagDefaultDescription
--initial-capital1000000Starting capital (supports formats: USD100000, 100,000 USD)
--position-size1Default contracts/shares per trade
--risk-free-rate0.04Annual risk-free rate for Sharpe calculation

Direction control

FlagDefaultDescription
--dir-long-onlyfalseAllow only long positions
--dir-short-onlyfalseAllow only short positions
--no-pyramidingtrueDisable pyramiding

Strategy inputs

Override strategy input defaults from the command line:

algo run --strategy macrossover --symbols @ES --inputs LenFast=5,LenSlow=50

Multiple inputs are comma-separated. Values must match the type of the corresponding struct field.

Data detrending

Apply logarithmic detrending to remove trend bias:

algo run --strategy kbt --symbols @ES --detrend 0 --detrend-mode simple

The --detrend argument specifies which data series indices to detrend (0-based). The mode can be simple or regression.

Parallel execution

When running multiple symbols, use --parallel to run them concurrently:

algo run --strategy kbt --symbols @ES,@NQ,@GC,@CL --parallel 8

The default is 64 workers. Use --parallel 0 for sequential execution.

Symbol specification

The --symbols flag supports flexible syntax. The / separator has higher precedence than ,: slashes divide the expression into positional legs (Data0, Data1, etc.), while commas list alternatives within each leg. The cartesian product of all legs produces the final set of runs.

SyntaxMeaningRuns
@ESSingle symbol1 run
@ES,@NQComma-separated alternatives2 runs (one per symbol)
@ES/@NQTwo legs, one symbol each1 run with 2 data series
@ES,@NQ/@GCTwo legs, first has 2 alternatives2 runs (@ES/@GC, @NQ/@GC)
<metalsPortfolio reference1 run per symbol in the file
<metals/@NQPortfolio × symbol5 runs (each metal paired with @NQ)
<metals/<softsPortfolio × portfolio40 runs (5 metals × 8 softs)
@ES,@NQ,@YM/<metals3 alternatives × 5 metals15 runs
@ES/[@GC,@HG,@PA]Bracket group (see below)1 run with 4 data series
@ES,@NQ/[<metals]Alternatives × bracket group2 runs (each primary with all metals)

Bracket grouping

Square brackets [...] group symbols into a single entity that is passed to the strategy as a whole, rather than being expanded via cartesian product. All symbols inside the brackets become consecutive data series (Data1, Data2, etc.) within a single run.

# Without brackets: 15 runs (3 × 5 cartesian product, each a 2-series run)
algo run --strategy spread --symbols @ES,@NQ,@YM/<metals

# With brackets: 3 runs (each primary symbol gets ALL metals as Data1-Data5)
algo run --strategy multisymbol --symbols @ES,@NQ,@YM/[<metals]

Portfolio references work inside brackets:

# Each soft commodity gets all metals as a group (8 runs, each with 6 data series)
algo run --strategy multisymbol --symbols <softs/[<metals]

# Each soft commodity gets all softs as a group, including itself (8 runs)
algo run --strategy multisymbol --symbols <softs/[<softs]

Brackets on the primary (Data0) position never make sense, since primary symbols are always processed one at a time. Use brackets only on non-primary legs.

Bar intervals with grouped symbols

When using bracket groups, the --bar-interval flag follows these rules:

Intervals providedBehaviour
1 (daily)All data series use the same interval
2 (daily/weekly)Data0 uses the first, all others use the second
N (matching symbol count)Each data series uses the corresponding interval
# All 6 series use daily bars
algo run --strategy ms --symbols @ES/[@GC,@HG,@PA,@PL,@SI] --bar-interval daily

# Data0 (@ES) uses daily, Data1-5 (metals) all use weekly
algo run --strategy ms --symbols @ES/[@GC,@HG,@PA,@PL,@SI] --bar-interval daily/weekly

If more than two bar intervals are provided, the count must exactly match the number of symbols in the run.