2. How to run a backtest

2.1. Entry point and configuration method

Run the backtest using qt.run(op, mode=1, …). The configuration can be set in advance via qt.configure(…). The kwargs passed to run will be merged with the current configuration (parameters passed to run take precedence).

2.2. Complete list of backtest runtime parameters (list and briefly explain)

The following are the main parameters related to mode=1 backtesting; please refer to the current qteasy 2.0 API for specifics.

Parameter name

Type/optional values

Meaning

asset_pool

str or list

Backtest universe (stock tickers, etc.).

asset_type

str

Asset type (e.g., ‘E’ for equities).

invest_start

str

Backtest start date.

invest_end

str

Backtest end date.

invest_cash_amounts

list/float

Invest funds initially or in installments.

invest_cash_dates

list

Investment dates corresponding to invest_cash_amounts (if in batches).

trade_batch_size

float

Minimum quantity unit per trade (minimum 0.01; for example, for A-shares you can set it to 100 to represent one lot).

cost_rate_buy

float

Buy cost rate (commissions, etc.).

cost_rate_sell

float

Sell cost rate.

cost_min

float

Minimum cost per transaction.

allow_sell_short

bool

Whether short selling is allowed.

trade_log

bool

Whether to record the trade log.

visual

bool

Whether to output visualization charts.

Other possible parameters: slippage, trading unit, stamp duty, etc. Please refer to the documentation for qt.configure() or run.

2.3. Minimum runnable example

import qteasy as qt

# 假设已配置数据源与 Operator
op = qt.Operator(strategies='dma', signal_type='PT', run_freq='d')
qt.configure(asset_pool='000001.SZ', invest_start='2020-01-01', invest_end='2023-12-31')
result = qt.run(op, mode=1)

2.4. Common use cases

  • Cost settings: use cost_rate_buy, cost_rate_sell, and cost_min to simulate commissions and stamp duty.

  • Trading unit: trade_batch_size controls the minimum trading unit (minimum is 0.01; for example, for A-shares it can be set to 100 shares).

  • Whether short selling is allowed: allow_sell_short=False means long-only.