307 lines
8.7 KiB
Python
307 lines
8.7 KiB
Python
#!/usr/bin/env python3
|
||||
|
|
"""
|
|||
|
|
📊 Analyze Historical JSON Performance Data
|
|||
|
|
Detaillierte Analyse der 166 historischen Trades
|
|||
|
|
"""
|
|||
|
|
|
|||
|
|
import json
|
|||
|
|
from collections import defaultdict
|
|||
|
|
from datetime import datetime
|
|||
|
|
|
|||
|
|
# Load JSON data
|
|||
|
|
with open('trade_performance_v16_XAUUSD_202511.json', 'r') as f:
|
|||
|
|
data = json.load(f)
|
|||
|
|
|
|||
|
|
# Handle both list and dict formats
|
|||
|
|
if isinstance(data, list):
|
|||
|
|
trades = data
|
|||
|
|
elif isinstance(data, dict):
|
|||
|
|
trades = data.get('closed_trades', data.get('trades', []))
|
|||
|
|
else:
|
|||
|
|
trades = []
|
|||
|
|
|
|||
|
|
print("=" * 80)
|
|||
|
|
print("📊 DETAILLIERTE PERFORMANCE ANALYSE")
|
|||
|
|
print("=" * 80)
|
|||
|
|
print(f"\nTotal Closed Trades: {len(trades)}")
|
|||
|
|
|
|||
|
|
# ==========================================
|
|||
|
|
# CONFIDENCE ANALYSIS
|
|||
|
|
# ==========================================
|
|||
|
|
|
|||
|
|
print("\n" + "=" * 80)
|
|||
|
|
print("🎯 PERFORMANCE BY CONFIDENCE LEVEL")
|
|||
|
|
print("=" * 80)
|
|||
|
|
|
|||
|
|
confidence_bins = {
|
|||
|
|
'60-70': [],
|
|||
|
|
'70-75': [],
|
|||
|
|
'75-80': [],
|
|||
|
|
'80-85': [],
|
|||
|
|
'85+': []
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
for trade in trades:
|
|||
|
|
conf = trade.get('confidence', 0)
|
|||
|
|
profit = trade.get('profit', 0)
|
|||
|
|
|
|||
|
|
if conf < 70:
|
|||
|
|
confidence_bins['60-70'].append(profit)
|
|||
|
|
elif conf < 75:
|
|||
|
|
confidence_bins['70-75'].append(profit)
|
|||
|
|
elif conf < 80:
|
|||
|
|
confidence_bins['75-80'].append(profit)
|
|||
|
|
elif conf < 85:
|
|||
|
|
confidence_bins['80-85'].append(profit)
|
|||
|
|
else:
|
|||
|
|
confidence_bins['85+'].append(profit)
|
|||
|
|
|
|||
|
|
print("\nRange | Trades | Wins | Win% | Total Profit | Avg Profit | Recommendation")
|
|||
|
|
print("-" * 80)
|
|||
|
|
|
|||
|
|
for conf_range, profits in confidence_bins.items():
|
|||
|
|
if not profits:
|
|||
|
|
continue
|
|||
|
|
|
|||
|
|
total = len(profits)
|
|||
|
|
wins = sum(1 for p in profits if p > 0)
|
|||
|
|
win_rate = (wins / total * 100) if total > 0 else 0
|
|||
|
|
total_profit = sum(profits)
|
|||
|
|
avg_profit = total_profit / total if total > 0 else 0
|
|||
|
|
|
|||
|
|
# Recommendation
|
|||
|
|
if win_rate >= 40 and avg_profit > 5:
|
|||
|
|
rec = "✅ EXCELLENT"
|
|||
|
|
elif win_rate >= 35 and avg_profit > 2:
|
|||
|
|
rec = "✅ Good"
|
|||
|
|
elif win_rate >= 30:
|
|||
|
|
rec = "⚠️ Marginal"
|
|||
|
|
else:
|
|||
|
|
rec = "❌ Avoid"
|
|||
|
|
|
|||
|
|
print(f"{conf_range:8} | {total:6} | {wins:4} | {win_rate:4.1f} | ${total_profit:11.2f} | ${avg_profit:9.2f} | {rec}")
|
|||
|
|
|
|||
|
|
# ==========================================
|
|||
|
|
# SESSION + CONFIDENCE COMBINED
|
|||
|
|
# ==========================================
|
|||
|
|
|
|||
|
|
print("\n" + "=" * 80)
|
|||
|
|
print("📍 SESSION × CONFIDENCE MATRIX")
|
|||
|
|
print("=" * 80)
|
|||
|
|
|
|||
|
|
session_conf = defaultdict(lambda: defaultdict(list))
|
|||
|
|
|
|||
|
|
for trade in trades:
|
|||
|
|
session = trade.get('session', 'unknown')
|
|||
|
|
conf = trade.get('confidence', 0)
|
|||
|
|
profit = trade.get('profit', 0)
|
|||
|
|
|
|||
|
|
if conf >= 75:
|
|||
|
|
conf_level = 'High (75+)'
|
|||
|
|
elif conf >= 70:
|
|||
|
|
conf_level = 'Med (70-75)'
|
|||
|
|
else:
|
|||
|
|
conf_level = 'Low (<70)'
|
|||
|
|
|
|||
|
|
session_conf[session][conf_level].append(profit)
|
|||
|
|
|
|||
|
|
for session in ['ny', 'asian', 'london', 'overlap']:
|
|||
|
|
if session not in session_conf:
|
|||
|
|
continue
|
|||
|
|
|
|||
|
|
print(f"\n{session.upper()} Session:")
|
|||
|
|
print(" Confidence | Trades | Wins | Win% | Total Profit | Avg | Verdict")
|
|||
|
|
print(" " + "-" * 70)
|
|||
|
|
|
|||
|
|
for conf_level in ['High (75+)', 'Med (70-75)', 'Low (<70)']:
|
|||
|
|
profits = session_conf[session].get(conf_level, [])
|
|||
|
|
if not profits:
|
|||
|
|
continue
|
|||
|
|
|
|||
|
|
total = len(profits)
|
|||
|
|
wins = sum(1 for p in profits if p > 0)
|
|||
|
|
win_rate = (wins / total * 100) if total > 0 else 0
|
|||
|
|
total_profit = sum(profits)
|
|||
|
|
avg_profit = total_profit / total if total > 0 else 0
|
|||
|
|
|
|||
|
|
# Verdict
|
|||
|
|
if win_rate >= 40 and total_profit > 100:
|
|||
|
|
verdict = "✅ BEST"
|
|||
|
|
elif win_rate >= 35 and total_profit > 0:
|
|||
|
|
verdict = "✅ Good"
|
|||
|
|
elif total_profit > 0:
|
|||
|
|
verdict = "⚠️ OK"
|
|||
|
|
else:
|
|||
|
|
verdict = "❌ Bad"
|
|||
|
|
|
|||
|
|
print(f" {conf_level:11} | {total:6} | {wins:4} | {win_rate:4.1f} | ${total_profit:11.2f} | ${avg_profit:4.1f} | {verdict}")
|
|||
|
|
|
|||
|
|
# ==========================================
|
|||
|
|
# TIME-BASED ANALYSIS
|
|||
|
|
# ==========================================
|
|||
|
|
|
|||
|
|
print("\n" + "=" * 80)
|
|||
|
|
print("⏰ PERFORMANCE BY HOUR (UTC)")
|
|||
|
|
print("=" * 80)
|
|||
|
|
|
|||
|
|
hourly = defaultdict(list)
|
|||
|
|
|
|||
|
|
for trade in trades:
|
|||
|
|
entry_time = trade.get('entry_time', '')
|
|||
|
|
if not entry_time:
|
|||
|
|
continue
|
|||
|
|
|
|||
|
|
# Parse hour
|
|||
|
|
try:
|
|||
|
|
dt = datetime.fromisoformat(entry_time.replace('Z', '+00:00'))
|
|||
|
|
hour = dt.hour
|
|||
|
|
profit = trade.get('profit', 0)
|
|||
|
|
hourly[hour].append(profit)
|
|||
|
|
except:
|
|||
|
|
continue
|
|||
|
|
|
|||
|
|
# Sort by total profit
|
|||
|
|
hourly_stats = []
|
|||
|
|
for hour, profits in hourly.items():
|
|||
|
|
total = len(profits)
|
|||
|
|
wins = sum(1 for p in profits if p > 0)
|
|||
|
|
win_rate = (wins / total * 100) if total > 0 else 0
|
|||
|
|
total_profit = sum(profits)
|
|||
|
|
avg_profit = total_profit / total if total > 0 else 0
|
|||
|
|
|
|||
|
|
hourly_stats.append({
|
|||
|
|
'hour': hour,
|
|||
|
|
'trades': total,
|
|||
|
|
'wins': wins,
|
|||
|
|
'win_rate': win_rate,
|
|||
|
|
'total_profit': total_profit,
|
|||
|
|
'avg_profit': avg_profit
|
|||
|
|
})
|
|||
|
|
|
|||
|
|
hourly_stats.sort(key=lambda x: x['total_profit'], reverse=True)
|
|||
|
|
|
|||
|
|
print("\nTop 10 Best Hours:")
|
|||
|
|
print("Hour | Trades | Wins | Win% | Total Profit | Avg Profit")
|
|||
|
|
print("-" * 60)
|
|||
|
|
|
|||
|
|
for stat in hourly_stats[:10]:
|
|||
|
|
hour = stat['hour']
|
|||
|
|
session_marker = ""
|
|||
|
|
if 13 <= hour < 21:
|
|||
|
|
session_marker = " (NY)"
|
|||
|
|
elif 7 <= hour < 15:
|
|||
|
|
session_marker = " (London/Asian)"
|
|||
|
|
|
|||
|
|
print(f"{hour:2d}{session_marker:15} | {stat['trades']:6} | {stat['wins']:4} | "
|
|||
|
|
f"{stat['win_rate']:4.1f} | ${stat['total_profit']:11.2f} | ${stat['avg_profit']:9.2f}")
|
|||
|
|
|
|||
|
|
print("\nWorst 5 Hours:")
|
|||
|
|
print("Hour | Trades | Wins | Win% | Total Profit | Avg Profit")
|
|||
|
|
print("-" * 60)
|
|||
|
|
|
|||
|
|
for stat in hourly_stats[-5:]:
|
|||
|
|
hour = stat['hour']
|
|||
|
|
session_marker = ""
|
|||
|
|
if 13 <= hour < 21:
|
|||
|
|
session_marker = " (NY)"
|
|||
|
|
elif 7 <= hour < 15:
|
|||
|
|
session_marker = " (London/Asian)"
|
|||
|
|
|
|||
|
|
print(f"{hour:2d}{session_marker:15} | {stat['trades']:6} | {stat['wins']:4} | "
|
|||
|
|
f"{stat['win_rate']:4.1f} | ${stat['total_profit']:11.2f} | ${stat['avg_profit']:9.2f}")
|
|||
|
|
|
|||
|
|
# ==========================================
|
|||
|
|
# HOLD TIME ANALYSIS
|
|||
|
|
# ==========================================
|
|||
|
|
|
|||
|
|
print("\n" + "=" * 80)
|
|||
|
|
print("⏱️ PERFORMANCE BY HOLD TIME")
|
|||
|
|
print("=" * 80)
|
|||
|
|
|
|||
|
|
hold_times = {
|
|||
|
|
'< 1h': [],
|
|||
|
|
'1-2h': [],
|
|||
|
|
'2-4h': [],
|
|||
|
|
'4-8h': [],
|
|||
|
|
'8h+': []
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
for trade in trades:
|
|||
|
|
hold_time = trade.get('hold_time', 0)
|
|||
|
|
profit = trade.get('profit', 0)
|
|||
|
|
|
|||
|
|
if hold_time < 1:
|
|||
|
|
hold_times['< 1h'].append(profit)
|
|||
|
|
elif hold_time < 2:
|
|||
|
|
hold_times['1-2h'].append(profit)
|
|||
|
|
elif hold_time < 4:
|
|||
|
|
hold_times['2-4h'].append(profit)
|
|||
|
|
elif hold_time < 8:
|
|||
|
|
hold_times['4-8h'].append(profit)
|
|||
|
|
else:
|
|||
|
|
hold_times['8h+'].append(profit)
|
|||
|
|
|
|||
|
|
print("\nRange | Trades | Wins | Win% | Total Profit | Avg Profit")
|
|||
|
|
print("-" * 60)
|
|||
|
|
|
|||
|
|
for time_range, profits in hold_times.items():
|
|||
|
|
if not profits:
|
|||
|
|
continue
|
|||
|
|
|
|||
|
|
total = len(profits)
|
|||
|
|
wins = sum(1 for p in profits if p > 0)
|
|||
|
|
win_rate = (wins / total * 100) if total > 0 else 0
|
|||
|
|
total_profit = sum(profits)
|
|||
|
|
avg_profit = total_profit / total if total > 0 else 0
|
|||
|
|
|
|||
|
|
print(f"{time_range:6} | {total:6} | {wins:4} | {win_rate:4.1f} | ${total_profit:11.2f} | ${avg_profit:9.2f}")
|
|||
|
|
|
|||
|
|
# ==========================================
|
|||
|
|
# RECOMMENDATIONS
|
|||
|
|
# ==========================================
|
|||
|
|
|
|||
|
|
print("\n" + "=" * 80)
|
|||
|
|
print("💡 KEY RECOMMENDATIONS")
|
|||
|
|
print("=" * 80)
|
|||
|
|
|
|||
|
|
# Find best session + confidence combo
|
|||
|
|
best_combos = []
|
|||
|
|
|
|||
|
|
for session in ['ny', 'asian', 'london', 'overlap']:
|
|||
|
|
for conf_level in ['High (75+)', 'Med (70-75)', 'Low (<70)']:
|
|||
|
|
profits = session_conf.get(session, {}).get(conf_level, [])
|
|||
|
|
if not profits or len(profits) < 5: # Min 5 trades for significance
|
|||
|
|
continue
|
|||
|
|
|
|||
|
|
total_profit = sum(profits)
|
|||
|
|
wins = sum(1 for p in profits if p > 0)
|
|||
|
|
win_rate = (wins / len(profits) * 100)
|
|||
|
|
|
|||
|
|
if total_profit > 0:
|
|||
|
|
best_combos.append({
|
|||
|
|
'session': session,
|
|||
|
|
'conf': conf_level,
|
|||
|
|
'trades': len(profits),
|
|||
|
|
'win_rate': win_rate,
|
|||
|
|
'profit': total_profit,
|
|||
|
|
'avg': total_profit / len(profits)
|
|||
|
|
})
|
|||
|
|
|
|||
|
|
best_combos.sort(key=lambda x: x['profit'], reverse=True)
|
|||
|
|
|
|||
|
|
print("\n✅ TOP 5 PROFITABLE COMBINATIONS:")
|
|||
|
|
for i, combo in enumerate(best_combos[:5], 1):
|
|||
|
|
print(f"\n{i}. {combo['session'].upper()} + {combo['conf']}")
|
|||
|
|
print(f" Trades: {combo['trades']}, Win Rate: {combo['win_rate']:.1f}%")
|
|||
|
|
print(f" Profit: ${combo['profit']:.2f} (Avg: ${combo['avg']:.2f})")
|
|||
|
|
|
|||
|
|
print("\n\n❌ WORST 3 COMBINATIONS TO AVOID:")
|
|||
|
|
for i, combo in enumerate(best_combos[-3:], 1):
|
|||
|
|
print(f"\n{i}. {combo['session'].upper()} + {combo['conf']}")
|
|||
|
|
print(f" Trades: {combo['trades']}, Win Rate: {combo['win_rate']:.1f}%")
|
|||
|
|
print(f" Loss: ${combo['profit']:.2f} (Avg: ${combo['avg']:.2f})")
|
|||
|
|
|
|||
|
|
print("\n" + "=" * 80)
|
|||
|
|
print("✅ Analysis Complete!")
|
|||
|
|
print("=" * 80)
|