#!/usr/bin/env python3
"""
Visualize MoE v12 vs MoERegression comparison.
"""

import matplotlib.pyplot as plt
import pandas as pd

# Create results dataframe
results = [
    ['MoE v12', 128, 0.352, 88.69, 11352.18],
    ['MoERegression', 39, 0.385, 8.73, 340.38]
]

df = pd.DataFrame(results, columns=['Architecture', 'Trades', 'WR', 'Avg PnL', 'Total PnL'])

# Create visualizations
fig, axes = plt.subplots(2, 2, figsize=(16, 12))

# 1. Win Rate
ax1 = axes[0, 0]
bars = ax1.bar(df['Architecture'], df['WR'] * 100, alpha=0.7, color=['green', 'red'])
ax1.set_title('Win Rate Comparison', fontsize=14, fontweight='bold')
ax1.set_ylabel('Win Rate (%)')
ax1.set_ylim(0, 50)
ax1.grid(True, alpha=0.3, axis='y')
for bar, wr in zip(bars, df['WR']):
    ax1.text(bar.get_x() + bar.get_width()/2., wr * 100 + 0.5,
            f'{wr:.1%}', ha='center', va='bottom', fontweight='bold', fontsize=12)

# 2. Avg PnL
ax2 = axes[0, 1]
colors = ['green' if pnl > 0 else 'red' for pnl in df['Avg PnL']]
bars = ax2.bar(df['Architecture'], df['Avg PnL'], alpha=0.7, color=colors)
ax2.axvline(x=0, color='black', linewidth=2)
ax2.set_title('Average PnL per Trade', fontsize=14, fontweight='bold')
ax2.set_ylabel('Avg PnL (RUB)')
ax2.grid(True, alpha=0.3, axis='x')
for bar, pnl in zip(bars, df['Avg PnL']):
    ax2.text(pnl + (50 if pnl > 0 else -50), bar.get_y() + bar.get_height()/2,
            f'{pnl:.2f}', ha='center' if pnl > 0 else 'right', va='center', fontweight='bold')

# 3. Total PnL
ax3 = axes[1, 0]
colors = ['green' if pnl > 0 else 'red' for pnl in df['Total PnL']]
bars = ax3.bar(df['Architecture'], df['Total PnL'], alpha=0.7, color=colors)
ax3.axvline(x=0, color='black', linewidth=2)
ax3.set_title('Total PnL', fontsize=14, fontweight='bold')
ax3.set_ylabel('Total PnL (RUB)')
ax3.grid(True, alpha=0.3, axis='x')
for bar, pnl in zip(bars, df['Total PnL']):
    ax3.text(pnl + (500 if pnl > 0 else -500), bar.get_y() + bar.get_height()/2,
            f'{pnl:,.0f}', ha='center' if pnl > 0 else 'right', va='center', fontweight='bold')

# 4. Trades vs Avg PnL
ax4 = axes[1, 1]
ax4.scatter(df['Trades'], df['Avg PnL'], s=df['Trades']*20, alpha=0.7)
for i, row in df.iterrows():
    ax4.text(row['Trades'], row['Avg PnL'], row['Architecture'], ha='center')
ax4.axhline(y=0, color='black', linewidth=2)
ax4.set_title('Trades vs Average PnL', fontsize=14, fontweight='bold')
ax4.set_xlabel('Number of Trades')
ax4.set_ylabel('Avg PnL (RUB)')
ax4.grid(True, alpha=0.3)

plt.tight_layout()
plt.savefig('/home/ai/projects/AI_Strategy/moe_comparison_viz.png', dpi=150)
print("✅ Saved: moe_comparison_viz.png")
