Backtest Config Files
Algo Trading Stack uses YAML config files to control simulation parameters and assets.
These configs describe portfolio setup, fees, and detailed contract specs for each instrument.
File structure
A config YAML has two layers:
- Global settings — apply to the whole backtest.
- Assets list — each symbol has its own entry with overrides.
Example (10-yr multi-market):
data_source: Yahoo_Finance
initial_cash: 1000000
commission_per_contract: 2.5 # USD per contract (both sides, can be per side if desired)
fee_per_trade: 1.0 # USD per trade (flat, optional)
assets:
- symbol: 6B=F # British Pound Futures
type: futures
file: yahoo_finance/data/Futures/British_Pound/1Day_timeframe/british_pound_10yr.csv
contract_size: 62500
tick_size: 0.0001
tick_value: 6.25
initial_margin: 2420
maintenance_margin: 2200
slippage_pct: 0.0007
commission_per_contract: 2.0
fee_per_trade: 1.5
currency: USD
exchange: CME
- symbol: CL=F # Crude Oil Futures
type: futures
file: yahoo_finance/data/Futures/Crude_Oil/1Day_timeframe/crude_oil_10yr.csv
contract_size: 1000
tick_size: 0.01
tick_value: 10.0
initial_margin: 5060
maintenance_margin: 4600
slippage_pct: 0.0005
commission_per_contract: 2.0
fee_per_trade: 1.5
currency: USD
exchange: NYMEX
Global keys
Key | Type | Meaning |
---|---|---|
data_source | string | Records where the asset price data came from. |
initial_cash | float | Starting portfolio equity in USD (or chosen base currency). |
commission_per_contract | float | Default commission charged per contract (can be overridden per asset). |
fee_per_trade | float | Flat per-trade fee (order-level). |
include_slippage | bool | Whether to apply slippage logic globally. |
slippage_ticks | int | Slippage in ticks (preferred over percent). |
slippage_pct | float | Slippage as fraction of price (fallback if no ticks specified). |
live_price_mode | string | How live bars are exposed: "open_only" (default) or "random_in_hilo" . |
random_seed | int | RNG seed for deterministic backtests (used in "random_in_hilo" mode). |
skip_synthetic_open_bars | bool | If true (default), skip bars with missing OPEN when emitting live data. |
Global values serve as defaults; assets can override commissions, fees, and slippage.
(These are applied in _apply_global_defaults
.)
Asset entries
Each element in assets:
specifies one tradable instrument.
Key | Type | Meaning |
---|---|---|
symbol | string | Identifier (e.g. "CL=F" for Crude Oil futures). |
type | string | Currently "futures" (others can be added). |
file | string | Path to historical data CSV (Yahoo or TradeStation supported). |
contract_size | int | Units per contract (e.g. 1,000 barrels for CL). |
tick_size | float | Minimum price increment. |
tick_value | float | P&L value per tick per contract. |
initial_margin | float | Exchange initial margin requirement per contract. |
maintenance_margin | float | Maintenance margin (falls back to initial_margin if not given). |
commission_per_contract | float | Override per-contract commission. |
fee_per_trade | float | Override per-trade fee. |
slippage_ticks | int | Override ticks of slippage. |
slippage_pct | float | Override percent slippage. |
currency | string | Trading currency (default "USD" ). |
exchange | string | Exchange code (e.g. CME, NYMEX, COMEX). |
Data loading
- Yahoo Finance CSVs and TradeStation CSVs are auto-detected and normalized.
- Missing dates across assets produce synthetic bars:
- O/H/L left as
NaN
(to mark gaps). - Close forward-filled to keep equity continuous.
- Volume zero-filled.
- O/H/L left as
Intrabar policies
The config can also include an exit resolution policy:
intrabar_tp_sl_policy: worst_case
Options
worst_case
(default) → Stop-loss assumed hit first if both touched.best_case
→ Take-profit assumed hit.sl_first
/tp_first
→ Explicit priority.
Putting it together
- Start with a base config (e.g.
backtest_config.yaml
). - Add multiple assets with their margins, contract sizes, and CSV data paths.
- Override global fees/slippage if some markets have different specs.
- Run:
python run_backtest.py --config backtest_configs/backtest_config_10_yrs.yaml
The engine will load the config, normalize data, and enforce margins, commissions, slippage, and fees exactly as described.
Summary
Config files are the backbone of reproducible backtests:
- Globals define portfolio cash, fees, and defaults.
- Assets define contract specs, margin requirements, and data.
- Policies control intrabar exit handling and slippage.
By editing YAML, you can swap asset universes, adjust fees, or change assumptions without touching code.