feat: VaR/PnL schedulers + snapshots DB + page sur bouton

Backend:
- Tables var_snapshots + pnl_snapshots dans SQLite (contexte macro + prix tickers)
- var_service.py : save_var_snapshot, save_pnl_snapshot + fonctions get_*
- var_scheduler.py : threads APScheduler pour VaR (défaut 6h) et PnL (défaut 1h)
- router var.py : /run-now (POST compute+save), /latest, /snapshots, /pnl/run-now,
  /pnl/latest, /scheduler/status, /scheduler/config
- main.py : démarrage des deux schedulers au startup

Frontend:
- VaRAnalysis.tsx : plus d'auto-fetch ; charge le dernier snapshot DB au mount ;
  bouton "Calculer" → POST /run-now ; erreur backend = message clair ; historique
  de snapshots sélectionnables
- Config.tsx : section "Schedulers VaR & PnL" dans l'onglet cycle avec toggle
  enable/disable, intervalle, et boutons "Snapshot maintenant"

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
OpenSquared
2026-06-20 06:21:20 +02:00
parent d64d1029bf
commit b4f3089c58
7 changed files with 1014 additions and 394 deletions

View File

@@ -398,6 +398,51 @@ def init_db():
except Exception:
pass
c.execute("""CREATE TABLE IF NOT EXISTS var_snapshots (
id INTEGER PRIMARY KEY AUTOINCREMENT,
computed_at TEXT NOT NULL,
confidence REAL NOT NULL DEFAULT 0.95,
horizon_days INTEGER NOT NULL DEFAULT 1,
lookback_days INTEGER NOT NULL DEFAULT 252,
default_iv REAL NOT NULL DEFAULT 0.20,
hist_var_1d_pct REAL,
hist_cvar_pct REAL,
hist_var_1d_eur REAL,
param_var_1d_pct REAL,
param_cvar_pct REAL,
mc_var_1d_pct REAL,
mc_cvar_pct REAL,
n_positions INTEGER,
total_notional_eur REAL,
data_source TEXT,
breach_rate_pct REAL,
kupiec_ok INTEGER,
macro_regime TEXT,
ticker_prices TEXT,
full_result TEXT
)""")
try:
c.execute("CREATE INDEX IF NOT EXISTS idx_var_snap_ts ON var_snapshots(computed_at DESC)")
except Exception:
pass
c.execute("""CREATE TABLE IF NOT EXISTS pnl_snapshots (
id INTEGER PRIMARY KEY AUTOINCREMENT,
snapped_at TEXT NOT NULL,
n_open INTEGER,
n_closed INTEGER,
total_capital_eur REAL,
total_pnl_pct REAL,
total_pnl_eur REAL,
ticker_prices TEXT,
macro_regime TEXT,
trades_snapshot TEXT
)""")
try:
c.execute("CREATE INDEX IF NOT EXISTS idx_pnl_snap_ts ON pnl_snapshots(snapped_at DESC)")
except Exception:
pass
try:
c.execute("CREATE INDEX IF NOT EXISTS idx_kb_category ON knowledge_base(category, status)")
c.execute("CREATE INDEX IF NOT EXISTS idx_rs_version ON reasoning_state(version DESC)")