feat: time-aware trade maturity classification

- Add _trade_maturity() helper: classifies trades by % of horizon elapsed
  (trop_tot <10%, debut 10-35%, mature 35-75%, fin_horizon >75%)
- Fix horizon_days fallback chain in log_trade_entries (default 30→90)
- journal.py: enrich each MTM trade with maturity dict + horizon_days
- reasoning.py: portfolio report segments trades by maturity; GPT-4o
  draws lessons only from matures (≥35% elapsed), never from trop_tot
- auto_cycle.py: 90d window, maturity-aware prompt with timing rules
- JournalDeBord.tsx: maturity badge with emoji, label, progress bar
  and day counter (Xj / Yj Z%) replacing plain days_held column

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
OpenSquared
2026-06-16 23:49:33 +02:00
parent 4bbcd7a3a6
commit 9075762dd5
5 changed files with 223 additions and 57 deletions

View File

@@ -1,7 +1,7 @@
from fastapi import APIRouter
from typing import Any, Dict, List
import math
from services.database import get_macro_regime_history, get_geo_alert_history, get_trade_entry_prices, reset_journal_history, _fetch_live_prices
from services.database import get_macro_regime_history, get_geo_alert_history, get_trade_entry_prices, reset_journal_history, _fetch_live_prices, _trade_maturity
def _sanitize(obj: Any) -> Any:
@@ -66,12 +66,16 @@ def trade_mtm(days: int = 30):
except Exception:
pass
horizon = e.get("horizon_days") or 90
maturity = _trade_maturity(days_held or 0, horizon)
result.append({
**e,
"current_price": current_price,
"pnl_pct": pnl_pct,
"days_held": days_held,
"direction": "bearish" if _is_bearish(e.get("strategy", "")) else "bullish",
"maturity": maturity,
})
return _sanitize({"trades": result, "days": days, "tickers_fetched": len(current_prices)})