Mirror Chart
Cryptocurrency: Bitcoin vs Altcoins
Mirror density comparing volatility distributions with risk metrics
Output
Python
import numpy as np
import matplotlib.pyplot as plt
from scipy.stats import gaussian_kde
np.random.seed(1975)
BG_COLOR = '#ffffff'
TEXT_COLOR = '#1f2937'
bitcoin = np.random.normal(3.5, 8, 800)
altcoins = np.random.normal(-2, 15, 1000)
bitcoin = bitcoin[(bitcoin > -30) & (bitcoin < 40)]
altcoins = altcoins[(altcoins > -50) & (altcoins < 50)]
fig, ax = plt.subplots(figsize=(12, 7), facecolor=BG_COLOR)
ax.set_facecolor(BG_COLOR)
x = np.linspace(-50, 50, 400)
kde_b = gaussian_kde(bitcoin)
y_b = kde_b(x)
ax.fill_between(x, y_b, alpha=0.3, color='#F5B027')
ax.plot(x, y_b, color='#F5B027', linewidth=2, label='Bitcoin (BTC)')
kde_a = gaussian_kde(altcoins)
y_a = kde_a(x) * -1
ax.fill_between(x, y_a, alpha=0.3, color='#4927F5')
ax.plot(x, y_a, color='#4927F5', linewidth=2, label='Altcoins')
ax.axhline(0, color=TEXT_COLOR, linewidth=1.5)
ax.axvline(0, color='#ef4444', linestyle=':', linewidth=1.5, alpha=0.5)
avg_btc = np.mean(bitcoin)
avg_alt = np.mean(altcoins)
std_btc = np.std(bitcoin)
std_alt = np.std(altcoins)
sharpe_btc = avg_btc / std_btc if std_btc > 0 else 0
sharpe_alt = avg_alt / std_alt if std_alt > 0 else 0
stats_text = 'Risk Metrics:\nBTC: %.1f%% avg, %.1f vol\nAlt: %.1f%% avg, %.1f vol\nSharpe: %.2f vs %.2f' % (avg_btc, std_btc, avg_alt, std_alt, sharpe_btc, sharpe_alt)
ax.text(0.02, 0.98, stats_text.replace('\n', chr(10)), transform=ax.transAxes, fontsize=10,
color=TEXT_COLOR, verticalalignment='top', fontfamily='monospace',
bbox=dict(boxstyle='round,pad=0.5', facecolor='#f8fafc', edgecolor='#e5e7eb', alpha=0.9))
win_rate_btc = (bitcoin > 0).sum() / len(bitcoin) * 100
win_rate_alt = (altcoins > 0).sum() / len(altcoins) * 100
ax.text(0.98, 0.98, 'Win Rate: BTC %.0f%% | Alt %.0f%%' % (win_rate_btc, win_rate_alt),
transform=ax.transAxes, fontsize=10, color='#6b7280', ha='right', va='top')
ax.set_xlabel('Daily Return (%)', fontsize=12, color=TEXT_COLOR, fontweight='500')
ax.set_ylabel('Density', fontsize=12, color=TEXT_COLOR, fontweight='500')
ax.set_title('Crypto Returns: Bitcoin vs Altcoins', fontsize=14,
color=TEXT_COLOR, fontweight='bold', pad=15)
ax.tick_params(colors='#374151', labelsize=10)
for spine in ax.spines.values():
spine.set_color('#e5e7eb')
ax.legend(loc='upper right', facecolor=BG_COLOR, edgecolor='#e5e7eb',
labelcolor=TEXT_COLOR, fontsize=10)
ax.set_xlim(-50, 50)
plt.tight_layout()
plt.show()
Library
Matplotlib
Category
Statistical
☕