Overview
TheBacktestConfig struct defines all configuration parameters for running a backtest, including initial capital, latency simulation, fee structure, risk management rules, execution realism, and output settings.
Source: nano-backtest/src/config.rs
BacktestConfig
Fields
| Field | Type | Description |
|---|---|---|
initial_capital | f64 | Starting capital in dollars |
latency | LatencyConfig | Latency simulation parameters |
fees | FeeConfig | Trading fee structure |
risk | RiskConfig | Risk management settings |
execution | ExecutionConfig | Execution simulation parameters |
output | OutputConfig | Logging and recording settings |
Constructors
default
Creates a balanced configuration suitable for most backtests.
- Initial capital: $1,000,000
- Latency: 100μs order, 50μs market data
- CME standard fees
- Conservative risk limits
aggressive_hft
Configuration optimized for high-frequency trading strategies.
- Ultra-low latency: 50μs order, 10μs market data
- Tight risk limits (max position: 50 contracts)
- 4% max drawdown
- High jitter variance (5μs)
conservative
Configuration for strategy validation with pessimistic assumptions.
- Higher latency: 200μs order, 50μs market data
- Increased fees (20% buffer)
- Stricter risk limits (3% max drawdown)
- More conservative fill probability (70% decay)
- Partial fills more likely (40%)
LatencyConfig
Defines latency simulation parameters.Fields
| Field | Type | Default | Description |
|---|---|---|---|
order_latency_ns | u64 | 100,000 | Order submission latency (nanoseconds) |
market_data_latency_ns | u64 | 50,000 | Market data reception latency (ns) |
ack_latency_ns | u64 | 100,000 | Order acknowledgment latency (ns) |
jitter_ns | u64 | 10,000 | Latency jitter standard deviation (ns) |
use_random_jitter | bool | true | Enable random jitter simulation |
FeeConfig
Defines trading fee structure (typically for CME futures).Fields
| Field | Type | Default | Description |
|---|---|---|---|
maker_fee | f64 | 0.10 | Maker rebate/fee per contract |
taker_fee | f64 | 0.52 | Taker fee per contract |
exchange_fee | f64 | 0.42 | Exchange fee per contract |
clearing_fee | f64 | 0.02 | Clearing fee per contract |
Methods
calculate_fee
Calculates total fee for a trade.
quantity: Number of contractsis_maker: Whether the trade provides liquidity (maker) or removes it (taker)
RiskConfig
Defines risk management rules and limits.Fields
| Field | Type | Default | Description |
|---|---|---|---|
max_position | i64 | 100 | Maximum net position (contracts) |
max_order_size | u32 | 20 | Maximum single order size |
max_drawdown_pct | f64 | 0.05 | Maximum drawdown (5%) before stop |
max_daily_loss | f64 | 100,000.0 | Maximum daily loss before stop ($) |
max_open_orders | usize | 20 | Maximum concurrent open orders |
enable_kill_switch | bool | true | Enable automatic kill switch |
ExecutionConfig
Defines execution simulation realism parameters.Fields
| Field | Type | Default | Description |
|---|---|---|---|
track_queue_position | bool | true | Track order queue position |
fill_probability_decay | f64 | 0.9 | Fill probability decay with queue depth |
partial_fill_probability | f64 | 0.2 | Probability of partial fills (20%) |
min_partial_fill | u32 | 1 | Minimum partial fill size |
simulate_adverse_selection | bool | true | Simulate adverse selection |
adverse_selection_prob | f64 | 0.1 | Probability of adverse fill (10%) |
fill_probability_decay: Lower values make fills less likely for orders behind in queuesimulate_adverse_selection: When enabled, limit orders at BBO have higher chance of filling when price moves against them
OutputConfig
Defines logging and data recording settings.Fields
| Field | Type | Default | Description |
|---|---|---|---|
verbosity | u8 | 1 | Log level (0-3) |
record_tick_pnl | bool | false | Record P&L at every tick |
record_fills | bool | true | Record all fill events |
record_orders | bool | true | Record order history |
snapshot_interval | usize | 10,000 | Snapshot state every N events |
Complete Example
See Also
- BacktestEngine - Using the engine
- LatencyConfig - Latency simulation details
- RiskConfig - Risk management details