4. Transaction process records

4.1. Enable trading log

Set trade_log=True in qt.run(…, trade_log=True) to record each trade during backtesting. Related settings (such as the log save path) depend on qt.configure() or the runtime environment.

4.2. Log content description

The trade log typically includes the following fields (list them and briefly explain them); the actual output shall prevail:

Field

Meaning

Time/Date

Execution time or date.

Underlying

Stock/contract code.

Direction

Buy/Sell.

Price

Execution price.

Quantity

Executed quantity.

Amount

Executed amount.

Fee

Commissions, stamp duty, etc.

Note

Other notes (if any).

4.3. View and save

  • View: After the backtest ends, you can read trade_log via the result object or the API (e.g., as a DataFrame or a file path).

  • Save: If the framework writes logs to a file, the path is determined by the config item trade_log_file_path (supports relative/absolute/home-directory paths; can be hot-modified via qt.configure()). See the API documentation for details.

  • Log rotation (rotate): When trade_log_keep_days is a positive integer, qteasy performs one cleanup of the current trade_log_file_path directory based on that retention period after the process starts and the qteasy module is successfully imported: it deletes trade_log_*.csv, trade_summary_*.csv, and value_curve_*.csv older than the retention period (the timestamp in the filename or the file mtime is used to determine age). It will not automatically clean up again before writing new CSVs at the end of each backtest; if a long-running single session generates many files, you can call qt.rotate_trade_logs() to clean up manually. The default trade_log_keep_days is 3; set it to None or less than or equal to 0 to disable automatic deletion. Rotation only affects old files on disk and does not change backtest results or any external API.

4.4. Relationship with result

  • trade_log corresponds to the backtest’s loop_result and oper_count: each record corresponds to one actual operation, and oper_count can be aggregated statistics.

  • Used to verify consistency between the backtest process and performance metrics.