mirror of
https://github.com/Xe138/AI-Trader.git
synced 2026-04-01 17:17:24 -04:00
docs: document duplicate prevention and cross-job continuity
Added documentation for: - Duplicate simulation prevention in JobManager.create_job() - Cross-job portfolio continuity in position tracking - Updated CLAUDE.md with Duplicate Simulation Prevention section - Updated docs/developer/architecture.md with Position Tracking Across Jobs section
This commit is contained in:
28
CLAUDE.md
28
CLAUDE.md
@@ -202,6 +202,34 @@ bash main.sh
|
||||
- Search results: News filtered by publication date
|
||||
- All tools enforce temporal boundaries via `TODAY_DATE` from `runtime_env.json`
|
||||
|
||||
### Duplicate Simulation Prevention
|
||||
|
||||
**Automatic Skip Logic:**
|
||||
- `JobManager.create_job()` checks database for already-completed model-day pairs
|
||||
- Skips completed simulations automatically
|
||||
- Returns warnings list with skipped pairs
|
||||
- Raises `ValueError` if all requested simulations are already completed
|
||||
|
||||
**Example:**
|
||||
```python
|
||||
result = job_manager.create_job(
|
||||
config_path="config.json",
|
||||
date_range=["2025-10-15", "2025-10-16"],
|
||||
models=["model-a"],
|
||||
model_day_filter=[("model-a", "2025-10-15")] # Already completed
|
||||
)
|
||||
|
||||
# result = {
|
||||
# "job_id": "new-job-uuid",
|
||||
# "warnings": ["Skipped model-a/2025-10-15 - already completed"]
|
||||
# }
|
||||
```
|
||||
|
||||
**Cross-Job Portfolio Continuity:**
|
||||
- `get_current_position_from_db()` queries across ALL jobs for a given model
|
||||
- Enables portfolio continuity even when new jobs are created with overlapping dates
|
||||
- Starting position = most recent trading_day.ending_cash + holdings where date < current_date
|
||||
|
||||
## Configuration File Format
|
||||
|
||||
```json
|
||||
|
||||
@@ -66,3 +66,28 @@ See README.md for architecture diagram.
|
||||
- Search results filtered by publication date
|
||||
|
||||
See [CLAUDE.md](../../CLAUDE.md) for implementation details.
|
||||
|
||||
---
|
||||
|
||||
## Position Tracking Across Jobs
|
||||
|
||||
**Design:** Portfolio state is tracked per-model across all jobs, not per-job.
|
||||
|
||||
**Query Logic:**
|
||||
```python
|
||||
# Get starting position for current trading day
|
||||
SELECT id, ending_cash FROM trading_days
|
||||
WHERE model = ? AND date < ? # No job_id filter
|
||||
ORDER BY date DESC
|
||||
LIMIT 1
|
||||
```
|
||||
|
||||
**Benefits:**
|
||||
- Portfolio continuity when creating new jobs with overlapping dates
|
||||
- Prevents accidental portfolio resets
|
||||
- Enables flexible job scheduling (resume, rerun, backfill)
|
||||
|
||||
**Example:**
|
||||
- Job 1: Runs 2025-10-13 to 2025-10-15 for model-a
|
||||
- Job 2: Runs 2025-10-16 to 2025-10-20 for model-a
|
||||
- Job 2 starts with Job 1's ending position from 2025-10-15
|
||||
|
||||
Reference in New Issue
Block a user