Last active
March 16, 2022 13:50
-
-
Save diefferson/29d4771e564cdcb46aef691dd95700ef to your computer and use it in GitHub Desktop.
FinanceUtils
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import 'dart:math'; | |
class FinanceUtils { | |
FinanceUtils._(); | |
///Calcula o pagamento periódico de um investimento anual, | |
///com base em pagamentos periódicos e constantes | |
///e em uma taxa de juros constante. | |
static double calcPmt({ | |
required double amount, | |
required double fee, | |
required int period, | |
}) { | |
final fv = amount * pow((1 + (fee / 100)), period); | |
final pmt = (fv * (fee / 100)) / (pow((1 + (fee / 100)), period) - 1); | |
return pmt; | |
} | |
///Calculo de juros compostos simples | |
static double compoundInterest({ | |
required double amount, | |
required double fee, | |
required int period, | |
}) { | |
return amount * pow((1 + (fee / 100)), period); | |
} | |
///Calculo de valor final de um financiamento com possibilidade de carencia | |
static double totalFinancingValue({ | |
required double amount, | |
required double fee, | |
required int period, | |
int lack = 0, | |
}) { | |
final valueWithLack = compoundInterest( | |
amount: amount, | |
fee: fee, | |
period: lack, | |
); | |
return calcPmt(amount: valueWithLack, period: period, fee: fee) * period; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment