Backtest#
In Swordfish’s plugin module, the swordfish.plugins.backtest module is defined for creating backtesting engines. Its core structure includes:
Configuration Classes (BacktestBasicConfig)
The base configuration class BacktestBasicConfig serves as the parent class for all backtest configurations, defining commonly used parameters such as time range, asset type, capital, and transaction fees. Different asset types have corresponding subclasses that extend this base class with asset-specific parameters:
StockConfig: Parameters specific to stock backtests, such as commission, tax, and stock dividends.
MarginConfig: Margin-related backtest parameters, such as line_of_credit and margin_trading_interest_rate.
OptionConfig: Option-specific parameters, such as security_reference and maintenance_margin.
FuturesConfig: Futures-specific parameters, such as futures_type and enable_algo_order.
BondConfig: For bond backtests, only security_reference is required.
CryptoConfig: For cryptocurrency backtests, security_reference and funding_rate are required.
Strategy Template (StrategyTemplate)
The base strategy template defines callback functions such as initialize, on_snapshot, and on_bar.
Account Interface (Account)
Provides access to various backtest result data, including daily positions, account net value, performance statistics, and trade details.
Backtester (Backtester)
The core engine that executes strategy backtests, responsible for loading data, driving strategy execution, and producing backtest results.
Swordfish’s backtesting features include:
A unified class inheritance model: users only need to inherit from the strategy template and implement the callback methods.
Multi-asset support: stocks, futures, options, margin accounts, bonds (CFETS, XSHG), and cryptocurrencies.
Support for account segmentation and multiple account configurations.
Simulation of market factors such as trade matching, delays, transaction fees, and stamp duty.
Indicator subscription and computation, allowing user-defined functions to be used during backtests.
Comprehensive backtest results, including positions, equity curves, trade details, and performance summaries.
This document provides a detailed introduction to the backtesting-related classes and their methods.
The asset type. |
|
A timer event that triggers at a specified time or frequency. |
|