Implementation:24mlight A Share investment Agent BacktestConfig
| Knowledge Sources | |
|---|---|
| Domains | Finance, Backtesting |
| Last Updated | 2026-10-10 14:00 GMT |
Overview
Concrete frozen dataclass for backtesting configuration including ticker, date range, initial capital/position, decision interval, and plotting options, provided by the A_Share_investment_Agent repository.
Description
The BacktestConfig dataclass is a frozen (immutable) configuration object for the Backtester class. It encapsulates all parameters needed for a backtest run. The _parse_args() function at L526-596 provides CLI argument parsing and config.json merging.
Usage
Import when you need to:
- Configure a backtest run programmatically or via CLI
Code Reference
Source Location
- Repository: A_Share_investment_Agent
- File: src/backtester.py
- Lines: L38-50
Signature
@dataclass(frozen=True)
class BacktestConfig:
ticker: str
start_date: str
end_date: str
initial_mode: str = "cash" # cash | shares
initial_capital: float = 100000.0
initial_position: int = 0
force_run: bool = False
num_of_news: int = 5
decision_interval: int = 1 # run workflow every N business days
plot: bool = False
save_plot_path: str | None = None
Import
from src.backtester import BacktestConfig
I/O Contract
Fields
| Name | Type | Default | Description |
|---|---|---|---|
| ticker | str | required | 6-digit stock code |
| start_date | str | required | Start date (YYYY-MM-DD) |
| end_date | str | required | End date (YYYY-MM-DD) |
| initial_mode | str | "cash" | "cash" or "shares" |
| initial_capital | float | 100000.0 | Initial cash (cash mode) |
| initial_position | int | 0 | Initial shares (shares mode) |
| force_run | bool | False | Append _forceN to log dir |
| num_of_news | int | 5 | News articles per workflow call |
| decision_interval | int | 1 | Run workflow every N business days |
| plot | bool | False | Show plot window |
| save_plot_path | None | None | Custom plot save path |
Usage Examples
Programmatic Construction
from src.backtester import BacktestConfig
config = BacktestConfig(
ticker="002074",
start_date="2025-10-01",
end_date="2025-11-15",
initial_capital=50000.0,
decision_interval=3, # Run workflow every 3 business days
)
CLI Parsing
from src.backtester import _parse_args
config = _parse_args()
# Parses: --ticker, --start-date, --end-date, --initial-capital,
# --initial-position, --num-of-news, --decision-interval,
# --plot, --save-plot
# Merges with config.json "backtest" section