Skip to content

Instantly share code, notes, and snippets.

@uqmessias
Created July 18, 2018 18:14
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save uqmessias/7d2da1ff3403ae7b43bb5eb8b5d6f850 to your computer and use it in GitHub Desktop.
Save uqmessias/7d2da1ff3403ae7b43bb5eb8b5d6f850 to your computer and use it in GitHub Desktop.
Calculate investiment already discounting the tax
const calculateInvestiment = (initial, months, annualInterestPercentage/*6.4 for instance*/, taxPercentage/*0 to 100*/) => {
const monthInterestMultiplier = Math.pow((annualInterestPercentage / 100) + 1, 1 / 12) - 1;
const totalInterestMultiplier = Math.pow(monthInterestMultiplier + 1, months) - 1;
const total = initial * (totalInterestMultiplier + 1);
const profit = total - initial;
const tax = profit * taxPercentage / 100;
const liquidProfit = profit - tax;
return {
initial,
total,
totalInterestPercentage: totalInterestMultiplier * 100,
tax,
taxPercentage,
profit,
liquidProfit,
monthInterestPercentage: monthInterestMultiplier * 100,
};
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment