Principle:24mlight A Share investment Agent Backtesting Strategy
Appearance
| Knowledge Sources | |
|---|---|
| Domains | Finance, Quantitative_Analysis, Backtesting |
| Last Updated | 2026-10-10 14:00 GMT |
Overview
A systematic backtesting framework that iterates over business days, calling the full investment analysis workflow at each decision interval with rate limiting, trade execution, and performance reporting — designed to avoid look-ahead bias.
Description
Backtesting evaluates a trading strategy by simulating it on historical data. This framework:
- Configuration: Uses a frozen
BacktestConfigdataclass with ticker, date range, initial capital/position, decision interval, and plotting options.
- Price Data Prefetch: Fetches price data for the full backtest range plus 200 days before the start (for technical indicator warmup).
- Initial Position Setup: If configured, establishes initial stock position using the previous trading day's close price.
- Iterative Decision Loop: For each business day (using
pd.date_range(freq="B")):
- Every
decision_intervaldays, calls the full analysis workflow (run_hedge_fund) - Uses the previous trading day's close as the decision cutoff to avoid look-ahead bias
- Executes trades at the current day's open price
- Applies rate limiting (max 8 calls per 60s window, 6s minimum between calls)
- Trade Execution: Buys and sells at current price, with cash constraint checking (can't buy more than affordable, can't sell more than held).
- Performance Analysis: Computes daily returns, cumulative returns, and total return. Generates matplotlib charts saved to the backtest log directory.
Usage
Use this principle when:
- Validating investment strategies against historical market data
- Measuring portfolio performance under specific trading rules
- Testing the full agent workflow end-to-end with realistic execution constraints
Theoretical Basis
Look-ahead bias prevention:
# Decision uses data up to previous trading day
decision_end = previous_trading_day_close
lookback_start = decision_end - 30_days
# Trade executes at current day's open price
current_price = day_rows.iloc[-1]["open"]
Rate limiting:
# Window-based rate limiter (abstract)
if calls_in_window >= 8:
sleep(60 - time_in_current_window)
if time_since_last_call < 6:
sleep(6 - time_since_last_call)
Performance metrics:
Related Pages
Implemented By
- Implementation:24mlight_A_Share_investment_Agent_Backtester
- Implementation:24mlight_A_Share_investment_Agent_BacktestConfig
Uses Heuristics
Page Connections
Double-click a node to navigate. Hold to expand connections.
Principle
Implementation
Heuristic
Environment