scripts/performance_monitor.py reads the live trade logs, computes win rate, profit factor, drawdown, and confidence stats, and sends a Telegram alert if metrics fall below thresholds. Run it on a cron or on-demand.
User lane: use this script for monitoring and alerts only. Developer/operator lane may use --retrain to trigger retraining workflows.
Usage
# One-shot report (no alert)
python scripts/performance_monitor.py
# Report + Telegram alert if metrics are degraded
python scripts/performance_monitor.py --alert
# Alert + trigger retrain if degraded
python scripts/performance_monitor.py --retrain
# Last 30 trades only
python scripts/performance_monitor.py --lookback 30
# All-time stats
python scripts/performance_monitor.py --lookback 0
# Custom degradation thresholds
python scripts/performance_monitor.py --alert --min-wr 0.55 --min-pf 2.0 --max-cl 7
Cron setup
Run every 4 hours on the trading VM:
0 */4 * * * cd /path/to/NOVOSKY && .venv/bin/python scripts/performance_monitor.py --alert --lookback 50 >> logs/monitor.log 2>&1
CLI flags
| Flag | Default | Description |
|---|
--alert | false | Send Telegram if metrics fall below thresholds |
--retrain | false | Trigger retrain.py if degraded (implies --alert) |
--lookback N | 50 | Analyze last N trades. 0 = all time |
--min-wr | 0.55 | Alert threshold: WR below this value triggers alert |
--min-pf | 2.0 | Alert threshold: PF below this value |
--max-cl | 7 | Alert threshold: consecutive losses at or above this value |
--dry-retrain | false | Print retrain command instead of running it |
Metrics computed
| Metric | Description |
|---|
| Win rate | Closed winners / total closed trades |
| Profit factor | Gross profit / gross loss |
| Avg confidence | Mean ensemble confidence on winning vs losing signals |
| Consecutive losses | Current streak |
| Daily P&L | Today’s realized P&L in $ |
| Drawdown | Peak-to-trough from equity curve |
Data sources
The script reads from two log files (whichever is available):
logs/trades.csv — rich structured log from trading/logger.py (primary)
trade_log.csv — simple append-mode fallback from trading/bot.py
Sample output
NOVOSKY Performance Monitor
============================
Trades analyzed : 47 (last 50, 3 open)
Source : logs/trades.csv
Win rate : 82.9% [OK]
Profit factor : 4.31 [OK]
Avg hold : 6.4 bars
Consec losses : 0 [OK]
Daily P&L : +$14.32
Confidence (W) : 0.73
Confidence (L) : 0.63
Status: HEALTHY
Degradation alert
If any threshold is breached, the script sends a Telegram message and optionally triggers retraining:
[NOVOSKY ALERT] Performance degradation detected
WR: 48.2% (threshold: 55%)
PF: 1.71 (threshold: 2.0)
Consecutive losses: 8 (threshold: 7)
Action: running retrain...
The retrain is triggered via python scripts/retrain.py --refresh.