Skip to content

Commit c326b1c

Browse files
aprimorate the getConvertedMonthlyRate function
1 parent 4925d8c commit c326b1c

1 file changed

Lines changed: 9 additions & 3 deletions

File tree

taxcalcreact/src/utils/financialCalculation.js

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
1+
/**
2+
* Funções puras para cálculos financeiros.
3+
* Não têm dependência de React ou do DOM.
4+
*/
5+
16
/**
27
* Ajusta a taxa de rendimento (mensal) com base nas alíquotas de Imposto de Renda.
38
* @param {number} taxaMensal - Taxa de rendimento mensal original (decimal).
@@ -47,7 +52,7 @@ export function simularRendimento(qnt_parcelas, valor_parcela, taxa_mensal) {
4752
for (let i = 1; i <= qnt_parcelas; i++) {
4853
let rendimentoMensal = capitalInvestidoInicial * taxa_mensal;
4954
ganho += rendimentoMensal;
50-
simulacaoDetalhada += `<tr><td>${i}</td><td>${capitalInvestidoInicial.toFixed(2)}</td><td>${rendimentoMensal.toFixed(2)}</td></tr>`;
55+
simulacaoDetalhada += `<tr><td>${i}</td><td>${capitalInvestidoInicial.toFixed(2)}</td><td>${rendimentoMensal.toFixed(2)}</td></td></tr>`; // Corrigido td fechamento aqui
5156
capitalInvestidoInicial -= valor_parcela;
5257
}
5358
simulacaoDetalhada += '</tbody></table>';
@@ -83,12 +88,12 @@ export function getConvertedMonthlyRate(tipoTaxa, valorTaxaInput, selicAtual, ip
8388
break;
8489
case 'ipca':
8590
if (ipcaAtual === null) throw new Error("Taxa IPCA não carregada. Tente novamente.");
86-
taxaAnualDecimal = ipcaAtual / 100;
91+
taxaAnualDecimal = ipcaAtual / 100; // IPCA é acumulado em 12 meses, então já é uma taxa anualizada.
8792
taxaMensalDecimal = Math.pow(1 + taxaAnualDecimal, 1/12) - 1;
8893
break;
8994
case 'cdi':
9095
if (selicAtual === null) throw new Error("Taxa SELIC (para CDI) não carregada. Tente novamente.");
91-
taxaAnualDecimal = (selicAtual - 0.1) / 100;
96+
taxaAnualDecimal = (selicAtual - 0.1) / 100; // CDI geralmente 0.1% abaixo da SELIC meta anual.
9297
taxaMensalDecimal = Math.pow(1 + taxaAnualDecimal, 1/12) - 1;
9398
break;
9499
case 'indice-percentual':
@@ -105,6 +110,7 @@ export function getConvertedMonthlyRate(tipoTaxa, valorTaxaInput, selicAtual, ip
105110
} else {
106111
throw new Error("Índice base para 'Índice + Percentual' não especificado ou inválido.");
107112
}
113+
// Calcula a taxa anual do investimento como (percentual_informado_pelo_usuario / 100) * taxa_base_anual
108114
taxaAnualDecimal = (valorTaxaInput / 100) * taxaBaseAnual;
109115
taxaMensalDecimal = Math.pow(1 + taxaAnualDecimal, 1/12) - 1;
110116
break;

0 commit comments

Comments
 (0)