""" Compare performance of 15 core models across tournaments Fetches last 7 rounds of data and creates comparison report """ import pandas as pd from numerapi import NumerAPI, SignalsAPI, CryptoAPI from datetime import datetime import json # 15 Core Models CORE_MODELS = { 'main': [ {'name': 'Main - Full Blend', 'id': '633f467a-6756-4816-a22b-ee66a1017cf8'}, {'name': 'Main - Lightweight', 'id': '5476ea55-7320-47ed-876f-4f63373f73d4'}, {'name': 'Main - 3T Full', 'id': '278bf264-c658-4ea8-a2de-6672aecc285a'}, {'name': 'Main - High Variance', 'id': 'bc632a2b-da46-400b-ae58-ff774caa5b3f'}, {'name': 'Main - Ultimate Combo', 'id': 'ae6bd3de-d5db-4b54-9690-7216f10fc4c0'}, ], 'signals': [ {'name': 'Signals - Blend Tester', 'id': 'f82be170-5b93-4b9d-92e9-2defec6cdd13'}, {'name': 'Signals - Historical Validation', 'id': '36c3c35a-8313-4b48-a447-6c5b056ddf81'}, {'name': 'Signals - 3T Blend', 'id': 'ca23b82d-e36c-45ee-9acb-6446db424408'}, {'name': 'Signals - High Variance', 'id': 'e09317f5-92ab-4bec-83a9-f717d6e7f891'}, {'name': 'Signals - Ultimate Combo', 'id': 'c832a144-0005-4e3a-9c6d-2c7aa6b95206'}, ], 'crypto': [ {'name': 'Crypto - Multi-Activation', 'id': 'bbbba758-c759-4e81-aa5b-bdb095709a36'}, {'name': 'Crypto - V2', 'id': 'f72a5c79-d1c0-4576-b9d0-fee4f9a4918f'}, {'name': 'Crypto - 3T Multi', 'id': '421d6dfd-0990-4ca1-9aa8-7cfe66178934'}, {'name': 'Crypto - 3T Multi V2', 'id': 'bc632a2b-da46-400b-ae58-ff774caa5b3f'}, {'name': 'Crypto - Ultimate Combo', 'id': 'ae6bd3de-d5db-4b54-9690-7216f10fc4c0'}, ] } def fetch_model_performance(api, model_id, model_name, tournament, last_n_rounds=7): """Fetch performance for a single model""" try: print(f" Fetching {model_name}...") rounds = api.round_model_performances(model_id) if not rounds: return [] # Get last N rounds with scores recent_rounds = [r for r in rounds if r.get('corr') is not None][:last_n_rounds] results = [] for r in recent_rounds: results.append({ 'model': model_name, 'tournament': tournament, 'round': r.get('roundNumber'), 'corr': r.get('corr'), 'corrPercentile': r.get('corrPercentile'), 'mmc': r.get('mmc'), 'tc': r.get('tc'), 'tcPercentile': r.get('tcPercentile'), }) return results except Exception as e: print(f" ERROR: {e}") return [] def main(): print("=" * 80) print("COMPARING 15 CORE MODELS - LAST 7 ROUNDS") print("=" * 80) print() all_results = [] # MAIN Tournament print("\n[MAIN TOURNAMENT]") napi = NumerAPI() for model in CORE_MODELS['main']: results = fetch_model_performance(napi, model['id'], model['name'], 'main') all_results.extend(results) # SIGNALS Tournament print("\n[SIGNALS TOURNAMENT]") sapi = SignalsAPI() for model in CORE_MODELS['signals']: results = fetch_model_performance(sapi, model['id'], model['name'], 'signals') all_results.extend(results) # CRYPTO Tournament print("\n[CRYPTO TOURNAMENT]") capi = CryptoAPI() for model in CORE_MODELS['crypto']: results = fetch_model_performance(capi, model['id'], model['name'], 'crypto') all_results.extend(results) # Create DataFrame df = pd.DataFrame(all_results) if df.empty: print("\nNo data retrieved!") return # Save raw data timestamp = datetime.now().strftime('%Y%m%d_%H%M%S') csv_file = f"logs/core_models_comparison_{timestamp}.csv" df.to_csv(csv_file, index=False) print(f"\n\nRaw data saved to: {csv_file}") # Analysis print("\n" + "=" * 80) print("ANALYSIS - LAST 7 ROUNDS") print("=" * 80) # Summary by tournament for tournament in ['main', 'signals', 'crypto']: print(f"\n{tournament.upper()} TOURNAMENT:") print("-" * 80) t_df = df[df['tournament'] == tournament].copy() if t_df.empty: print(" No data available") continue # Calculate averages per model summary = t_df.groupby('model').agg({ 'corr': ['mean', 'std', 'min', 'max', 'count'], 'mmc': 'mean', 'tc': 'mean', 'corrPercentile': 'mean' }).round(4) print(summary.to_string()) # Overall rankings print("\n" + "=" * 80) print("OVERALL RANKINGS (by average correlation)") print("=" * 80) rankings = df.groupby('model').agg({ 'corr': 'mean', 'mmc': 'mean', 'tc': 'mean', 'corrPercentile': 'mean' }).sort_values('corr', ascending=False).round(4) print(rankings.to_string()) # Top performers print("\n" + "=" * 80) print("TOP 5 PERFORMERS (by average correlation)") print("=" * 80) for i, (model, row) in enumerate(rankings.head(5).iterrows(), 1): print(f"\n{i}. {model}") print(f" Avg Corr: {row['corr']:.4f}") print(f" Avg MMC: {row['mmc']:.4f}") print(f" Avg TC: {row['tc']:.4f}") print(f" Percentile: {row['corrPercentile']:.1f}") # Bottom performers print("\n" + "=" * 80) print("BOTTOM 5 PERFORMERS (by average correlation)") print("=" * 80) for i, (model, row) in enumerate(rankings.tail(5).iterrows(), 1): print(f"\n{i}. {model}") print(f" Avg Corr: {row['corr']:.4f}") print(f" Avg MMC: {row['mmc']:.4f}") print(f" Avg TC: {row['tc']:.4f}") print(f" Percentile: {row['corrPercentile']:.1f}") # Round-by-round comparison print("\n" + "=" * 80) print("ROUND-BY-ROUND CORRELATION") print("=" * 80) pivot = df.pivot_table( index='model', columns='round', values='corr', aggfunc='first' ).round(4) print(pivot.to_string()) # Save summary summary_file = f"logs/core_models_summary_{timestamp}.txt" with open(summary_file, 'w') as f: f.write("=" * 80 + "\n") f.write("CORE MODELS PERFORMANCE COMPARISON\n") f.write("=" * 80 + "\n\n") f.write(f"Generated: {datetime.now().strftime('%Y-%m-%d %H:%M:%S')}\n") f.write(f"Models analyzed: 15 core models\n") f.write(f"Rounds analyzed: Last 7 rounds with scores\n\n") f.write("\nOVERALL RANKINGS:\n") f.write("-" * 80 + "\n") f.write(rankings.to_string()) f.write("\n\nROUND-BY-ROUND:\n") f.write("-" * 80 + "\n") f.write(pivot.to_string()) print(f"\n\nSummary saved to: {summary_file}") print(f"Data saved to: {csv_file}") print("\n" + "=" * 80) print("COMPARISON COMPLETE") print("=" * 80) if __name__ == '__main__': main()