-
Notifications
You must be signed in to change notification settings - Fork 0
/
VF_Variavel_Ant.py
96 lines (66 loc) · 3.45 KB
/
VF_Variavel_Ant.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
# Projeção de Valor Futuro - Parcelas Antecipadas - Aportes Variáveis por Período
import numpy as np
import pandas as pd
import seaborn as sns
import matplotlib.pyplot as plt
# Input das variáveis do cálculo
capital_inicial = int(input("Digite o valor inicial: "))
prazo_anos = int(input("Digite o prazo total da projeção em anos: "))
num_periodos = int(input("Digite o número de períodos de aportes diferentes: "))
# Input dos aportes por período
aportes_por_periodo = []
for i in range(num_periodos):
aporte = int(input(f"Digite o valor do aporte mensal para o período {i+1}: "))
duracao_anos = int(input(f"Digite a duração do período {i+1} em anos: "))
duracao_meses = duracao_anos * 12 # Convertendo anos para meses
aportes_por_periodo.append((aporte, duracao_meses))
taxa_juros = float(input("Digite a taxa de juros ao mês: "))
prazo_meses = prazo_anos * 12 # Convertendo prazo total de anos para meses
taxa_juros = taxa_juros / 100
# Cálculo do Valor Futuro com Aportes
def valor_futuro_antecipado(capital_inicial, taxa_juros, aportes_por_periodo):
patrimonio_mensal = []
valor_futuro_total = capital_inicial
mes_atual = 0
for aporte, duracao in aportes_por_periodo:
for _ in range(duracao):
valor_futuro_total = (valor_futuro_total + aporte) * (1 + taxa_juros) # Parcelas antecipadas
patrimonio_mensal.append(valor_futuro_total)
mes_atual += 1
# Caso os períodos de aporte sejam menores que o prazo total
while mes_atual < prazo_meses:
valor_futuro_total = valor_futuro_total * (1 + taxa_juros)
patrimonio_mensal.append(valor_futuro_total)
mes_atual += 1
return valor_futuro_total, patrimonio_mensal
# Cálculo do Valor Futuro sem Aportes
def valor_futuro_sem_aporte(capital_inicial, taxa_juros, prazo_meses):
patrimonio_mensal_sem_aportes = []
valor_futuro_sem_aporte = capital_inicial
for mes in range(1, prazo_meses + 1):
valor_futuro_sem_aporte = valor_futuro_sem_aporte * (1 + taxa_juros)
patrimonio_mensal_sem_aportes.append(valor_futuro_sem_aporte)
return valor_futuro_sem_aporte, patrimonio_mensal_sem_aportes
# Chamada das Funções
valor_futuro_final, patrimonio_mensal = valor_futuro_antecipado(capital_inicial, taxa_juros, aportes_por_periodo)
print(f"Valor Futuro com Aporte Antecipado: R$ {valor_futuro_final:.2f}")
valor_futuro_sem_aporte_final, patrimonio_mensal_sem_aporte_final = valor_futuro_sem_aporte(capital_inicial, taxa_juros, prazo_meses)
print(f'Valor Futuro sem Aporte: R$ {valor_futuro_sem_aporte_final:.2f}')
# Criando o DataFrame para plotagem
df = pd.DataFrame({
'Mês': np.arange(1, prazo_meses + 1),
'Patrimônio com Aporte': patrimonio_mensal,
'Patrimônio sem Aporte': patrimonio_mensal_sem_aporte_final
})
# Plotagem do Gráfico
sns.set_theme(style="whitegrid")
plt.figure(figsize=(12, 6))
sns.lineplot(x='Mês', y='Patrimônio com Aporte', data=df, marker='o', color='b', label='Com Aporte')
sns.lineplot(x='Mês', y='Patrimônio sem Aporte', data=df, marker='o', color='r', label='Sem Aporte')
plt.title('Projeção de Crescimento do Patrimônio (Parcelas Antecipadas)', fontsize=16)
plt.xlabel('Tempo (Meses)', fontsize=14)
plt.ylabel('Patrimônio (R$)', fontsize=14)
plt.legend(title='Tipo de Investimento', fontsize=12)
plt.tight_layout()
# Mostrar o gráfico
plt.show()