Untitled
unknown
plain_text
14 days ago
1.3 kB
3
Indexable
import numpy as np import matplotlib.pyplot as plt # Parâmetros investimento_mensal = 100 # € anos = 10 taxa_anual = 0.07 # 7% ao ano taxa_mensal = taxa_anual / 12 meses = anos * 12 # Simulação do DCA valores_acumulados = [] valor_total = 0 for mes in range(1, meses + 1): valor_total *= (1 + taxa_mensal) # Juros compostos valor_total += investimento_mensal # Novo investimento if mes % 12 == 0: valores_acumulados.append(valor_total) # Plotar o gráfico plt.figure(figsize=(10, 6)) plt.plot(range(1, anos + 1), valores_acumulados, marker='o', linestyle='-', color='#2ecc71') plt.title('Crescimento do Investimento com DCA (100€/mês por 10 anos)', fontsize=14) plt.xlabel('Anos', fontsize=12) plt.ylabel('Valor Acumulado (€)', fontsize=12) plt.grid(True, linestyle='--', alpha=0.7) plt.xticks(range(1, anos + 1)) plt.tight_layout() # Adicionar valores finais total_investido = investimento_mensal * meses valor_final = round(valores_acumulados[-1], 2) lucro = round(valor_final - total_investido, 2) plt.annotate(f'Total Investido: {total_investido}€\nValor Final: {valor_final}€\nLucro: {lucro}€', xy=(anos, valor_final), xytext=(6, 15000), arrowprops=dict(facecolor='black', shrink=0.05), fontsize=10) plt.show()
Editor is loading...
Leave a Comment