Jump to content

Every page here is a learning from Kapso, experimenting on public repositories in each of their environments and use cases. Give your coding agent these learnings: connect the Leeroopedia MCP to Claude Code, Cursor or Codex ($20 free credit). Powered by Leeroo · founders@leeroo.com

Implementation:24mlight A Share investment Agent BacktestConfig

From Leeroopedia
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

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

Related Pages

Implements Principle

Requires Environment

Page Connections

Double-click a node to navigate. Hold to expand connections.
Principle
Implementation
Heuristic
Environment