Skip to main content
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

FlagDefaultDescription
--alertfalseSend Telegram if metrics fall below thresholds
--retrainfalseTrigger retrain.py if degraded (implies --alert)
--lookback N50Analyze last N trades. 0 = all time
--min-wr0.55Alert threshold: WR below this value triggers alert
--min-pf2.0Alert threshold: PF below this value
--max-cl7Alert threshold: consecutive losses at or above this value
--dry-retrainfalsePrint retrain command instead of running it

Metrics computed

MetricDescription
Win rateClosed winners / total closed trades
Profit factorGross profit / gross loss
Avg confidenceMean ensemble confidence on winning vs losing signals
Consecutive lossesCurrent streak
Daily P&LToday’s realized P&L in $
DrawdownPeak-to-trough from equity curve

Data sources

The script reads from two log files (whichever is available):
  1. logs/trades.csv — rich structured log from trading/logger.py (primary)
  2. 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.