mirror of
https://github.com/ZhuLinsen/daily_stock_analysis
synced 2026-09-20 10:53:33 +08:00
feat(backtest): add backtest engine with evaluation pipeline and WebUI (#269)
Add a complete backtest/evaluation system that measures the accuracy of
AI-generated stock analysis recommendations against actual market outcomes.
Backend:
- Backtest engine (src/core/backtest_engine.py) with direction inference,
stop-loss/take-profit simulation, and outcome classification (win/loss/neutral)
- Repository layer (src/repositories/backtest_repo.py) with SQLite persistence
for backtest_results and backtest_summaries tables
- Service layer (src/services/backtest_service.py) orchestrating evaluation runs
with configurable window days, neutral band, and min-age filters
- REST API endpoints: POST /run, GET /results, GET /performance, GET /performance/{code}
- Pydantic schemas for request/response validation
Frontend (apps/dsa-web):
- New Backtest page with performance dashboard sidebar showing direction
accuracy, win rate, simulated returns, SL/TP trigger rates, and W/L/N counts
- Paginated results table with outcome badges, direction indicators, and
color-coded return percentages
- Stock code filter and one-click "Run Backtest" trigger
- Full TypeScript types and API client matching backend schemas
Direction mapping fix:
- "Wait/observe" (观望) advice now maps to direction_expected="down" instead
of "flat", correctly reflecting that "wait" means "stay out due to downside
risk" rather than predicting a flat market
Tests:
- 21 unit tests covering engine logic, service orchestration, and summary
aggregation (all passing)
Docs:
- Updated README, full-guide, and translations with backtest feature docs
This commit is contained in:
3
.gitignore
vendored
3
.gitignore
vendored
@@ -6,7 +6,8 @@
|
||||
.env.*.local
|
||||
|
||||
# 测试文件(可能包含敏感配置)
|
||||
test_*.py
|
||||
# 仅忽略仓库根目录下的临时 test_*.py 脚本;tests/ 目录下的单元测试需要纳入版本控制。
|
||||
/test_*.py
|
||||
!test_env.py
|
||||
|
||||
# Python
|
||||
|
||||
Reference in New Issue
Block a user