ANOVA Boxplot
Hedge Fund Strategy Returns ANOVA
Comparing monthly returns across different hedge fund strategies.
Output
Python
import matplotlib.pyplot as plt
import numpy as np
import scipy.stats as stats
np.random.seed(456)
# Monthly returns (%)
long_short = np.random.normal(0.8, 2.5, 60)
global_macro = np.random.normal(0.6, 3.2, 60)
event_driven = np.random.normal(1.1, 2.8, 60)
quant = np.random.normal(0.9, 1.8, 60)
multi_strat = np.random.normal(0.7, 2.0, 60)
F_stat, p_value = stats.f_oneway(long_short, global_macro, event_driven, quant, multi_strat)
fig, ax = plt.subplots(figsize=(13, 7), facecolor='#0d1117')
ax.set_facecolor('#0d1117')
colors = ['#27D3F5', '#F5B027', '#F5276C', '#6CF527', '#4927F5']
data = [long_short, global_macro, event_driven, quant, multi_strat]
bp = ax.boxplot(data, positions=[1, 2, 3, 4, 5], widths=0.55, patch_artist=True,
medianprops={'color': 'white', 'linewidth': 2},
whiskerprops={'color': '#555555', 'linewidth': 1.5},
capprops={'color': '#555555', 'linewidth': 1.5},
flierprops={'marker': 'o', 'markerfacecolor': '#444444', 'markersize': 4})
for patch, color in zip(bp['boxes'], colors):
patch.set_facecolor(color)
patch.set_alpha(0.65)
patch.set_edgecolor('white')
patch.set_linewidth(1.5)
# Zero line
ax.axhline(y=0, color='#ef4444', linestyle='-', alpha=0.5, linewidth=1)
labels = ['Long/Short', 'Global Macro', 'Event Driven', 'Quant', 'Multi-Strat']
# Sharpe ratio annotations
sharpe = [0.32, 0.19, 0.39, 0.50, 0.35]
for i, (sr, color) in enumerate(zip(sharpe, colors)):
ax.text(i+1, -9, f'Sharpe: {sr:.2f}', ha='center', fontsize=8, color=color, fontweight='bold')
# Stats header
stats_text = f"ANOVA: F={F_stat:.2f}, p={p_value:.4f} | Best Risk-Adj: Quant (Sharpe=0.50)"
bbox = dict(boxstyle="round,pad=0.3", facecolor='#1a1a2e', edgecolor='#6CF527', lw=2)
ax.text(0.5, 1.02, stats_text, transform=ax.transAxes, fontsize=9, color='white',
ha='center', va='bottom', fontfamily='monospace', bbox=bbox)
ax.set_xticks([1, 2, 3, 4, 5])
ax.set_xticklabels(labels, fontsize=10, color='white')
ax.set_ylabel('Monthly Return (%)', fontsize=12, color='white', fontweight='500')
ax.set_title('Hedge Fund Strategy Performance\n5-Year Monthly Returns Comparison',
fontsize=14, color='white', fontweight='bold', pad=25)
ax.tick_params(colors='#888888')
for spine in ax.spines.values():
spine.set_color('#333333')
ax.yaxis.grid(True, color='#1a1a2e', linewidth=0.5)
ax.set_axisbelow(True)
ax.set_ylim(-12, 10)
plt.tight_layout()
plt.show()
Library
Matplotlib
Category
Statistical
More ANOVA Boxplot examples
☕