File size: 7,114 Bytes
5bfc765 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 | """
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()
|