Implementation:HKUDS AI Trader BaseAgent Run Date Range
| Knowledge Sources | |
|---|---|
| Domains | Trading_Systems, Backtesting |
| Last Updated | 2026-02-09 14:00 GMT |
Overview
Concrete tool for executing the daily backtesting loop across a date range in the BaseAgent class.
Description
The BaseAgent.run_date_range() async method generates trading dates via self.get_trading_dates(init_date, end_date), then iterates through each date. For each day, it sets runtime config values (CURRENT_DATE, AGENT_SIGNATURE, STOCK_SYMBOLS, etc.) and calls self.run_with_retry(date) which wraps run_trading_session() with per-day retry logic.
Usage
Call await agent.run_date_range(init_date, end_date) after agent.initialize() to run the full backtesting simulation. This is the main execution entry point for the trading agent.
Code Reference
Source Location
- Repository: AI-Trader
- File: agent/base_agent/base_agent.py
- Lines: L633-667
Signature
async def run_date_range(self, init_date: str, end_date: str) -> None:
"""
Run backtesting simulation across a date range.
Args:
init_date: Start date YYYY-MM-DD
end_date: End date YYYY-MM-DD
Returns:
None. Results written to position.jsonl and log files.
"""
Import
from agent.base_agent.base_agent import BaseAgent
# Usage: await agent.run_date_range("2025-01-01", "2025-03-31")
I/O Contract
Inputs
| Name | Type | Required | Description |
|---|---|---|---|
| init_date | str | Yes | Start date YYYY-MM-DD |
| end_date | str | Yes | End date YYYY-MM-DD |
Outputs
| Name | Type | Description |
|---|---|---|
| position.jsonl | File | Cumulative position log with entries for each trading day |
| log/{date}/log.jsonl | Files | Per-day conversation logs |
Usage Examples
Run Full Backtest
from agent.base_agent.base_agent import BaseAgent
agent = BaseAgent(
signature="gpt-4o",
basemodel="gpt-4o",
initial_cash=10000.0
)
await agent.initialize()
await agent.run_date_range("2025-01-01", "2025-03-31")
# Check results
summary = agent.get_position_summary()
print(summary)