Overview
Themonitor.py module provides logging setup and progress monitoring functions for the genetic algorithm evolution loop. It handles dual logging (file + console), periodic progress reports, and generation summaries with leaderboards.
Functions
setup_logging() → logging.Logger
Configure dual logging with file and console handlers.Configured logger instance named “evolution”
- Creates
STATE_DIR/evolution.logfor full debug logs - Outputs INFO+ messages to console with timestamps
- Automatically creates state directory if missing
- Prevents duplicate handlers on re-initialization
- File:
2023-12-31 10:30:45 [INFO] message - Console:
[10:30:45] message
log_tick_progress()
Log periodic progress during a generation’s trading period.Logger instance from setup_logging()
Current generation number
Number of ticks elapsed in this generation
List of all bots in this generation
Optional market data feed for unrealized ROI calculation
- Elapsed time in hours
- Active bots (with at least one trade)
- Total open positions across all bots
- Total trades and settled positions
- Best and median ROI (both estimated and realized)
log_generation_summary()
Log a complete generation summary with leaderboard after trading completes.Logger instance from setup_logging()
Generation number being summarized
List of all bots in this generation
Fitness scores (ROI percentages) for each bot
- Top 20 bots ranked by fitness (ROI)
- Bot ID, ROI%, total trades, settled trades, win rate, signal type
- Distribution of signal types across population
- Category preferences of top 10 performers
compute_generation_stats(bots: list[GeneticBot]) → dict
Compute summary statistics for a completed generation.List of all bots in the generation
Dictionary containing:
best_roi: Highest fitness (ROI%) in generationmedian_roi: Median fitness across all botsworst_roi: Lowest fitness in generationmean_roi: Average fitness across all botsmean_trades: Average number of trades per botmax_trades: Maximum trades by any single botmean_win_rate: Average win rate percentagetotal_settled: Total settled positions across all botsactive_bots: Number of bots that made at least one trade
Usage Example
Complete monitoring setup for an evolution loop:Configuration
Uses these constants fromgenetic.config:
STATE_DIR: Directory for log file storageTICK_INTERVAL_SECONDS: Used to calculate elapsed hours