# ROI-Berechnung
years = ['Jahr 0', 'Jahr 1', 'Jahr 2', 'Jahr 3']
investment = [-205000, -50000, -50000, -50000]
savings = [0, 384300, 534300, 534300]
net = [inv + sav for inv, sav in zip(investment, savings)]
cumulative = [sum(net[:i+1]) for i in range(len(net))]
fig, (ax1, ax2) = plt.subplots(1, 2, figsize=(16, 6))
# Subplot 1: Jährliche Cashflows
x = range(len(years))
width = 0.35
bars1 = ax1.bar([i - width/2 for i in x], investment, width, label='Investition', color='red', alpha=0.7)
bars2 = ax1.bar([i + width/2 for i in x], savings, width, label='Einsparungen', color='green', alpha=0.7)
ax1.set_xlabel('Jahr', fontsize=12)
ax1.set_ylabel('Betrag (€)', fontsize=12)
ax1.set_title('Jährliche Cashflows', fontsize=14, fontweight='bold')
ax1.set_xticks(x)
ax1.set_xticklabels(years)
ax1.legend()
ax1.axhline(y=0, color='black', linewidth=0.8)
ax1.grid(axis='y', alpha=0.3)
# Werte auf Balken
for bars in [bars1, bars2]:
for bar in bars:
height = bar.get_height()
ax1.text(bar.get_x() + bar.get_width()/2., height,
f'{int(height/1000)}k €',
ha='center', va='bottom' if height > 0 else 'top',
fontsize=9)
# Subplot 2: Kumulierter ROI
colors_cum = ['red' if c < 0 else 'green' for c in cumulative]
bars3 = ax2.bar(x, cumulative, color=colors_cum, alpha=0.7)
ax2.plot(x, cumulative, color='darkblue', marker='o', linewidth=2, markersize=10)
ax2.set_xlabel('Jahr', fontsize=12)
ax2.set_ylabel('Kumulierter Cashflow (€)', fontsize=12)
ax2.set_title('Kumulierter ROI (Break-Even nach ~8 Monaten)', fontsize=14, fontweight='bold')
ax2.set_xticks(x)
ax2.set_xticklabels(years)
ax2.axhline(y=0, color='black', linewidth=1.5, linestyle='--')
ax2.grid(axis='y', alpha=0.3)
# Werte auf Balken
for bar, val in zip(bars3, cumulative):
ax2.text(bar.get_x() + bar.get_width()/2., val,
f'{int(val/1000)}k €',
ha='center', va='bottom' if val > 0 else 'top',
fontsize=10, fontweight='bold')
plt.tight_layout()
plt.show()