Calculate Total Investment Value With Dividends Added

Online Investment Calculator and JavaScript Algorithm.

Below are the tool and the code in JavaScript to calculate the total value of your investment after adding monthly dividends to the principal amount over a period of time (months).

Investment Value Calculator With Monthly Dividends









JavaScript Code

function calculateTotalInvestmentValue({
  initialInvestment,
  monthlyInvestment,
  dividendPercentage,
  numberOfMonths }) {

  const dividend = dividendPercentage / 100;
  let totalValue = initialInvestment;
  let totalInvestment = initialInvestment;

  for (let i = 0; i < numberOfMonths; i++) {
    totalValue += (totalValue * (dividend)) + monthlyInvestment;
    totalInvestment += monthlyInvestment;
  }

  totalValue = Math.ceil(totalValue)
  
  return {
    totalValue,
    totalInvestment,
    totalProfit: totalValue - totalInvestment
  }
};

Calling the above function with example values:

calculateTotalInvestmentValue({
  initialInvestment: 500,
  monthlyInvestment: 500,
  dividendPercentage: 1,
  numberOfMonths: 11
});

// => { totalValue: 6342, totalInvestment: 6000, totalProfit: 342 }

See also

When you purchase through links on techighness.com, I may earn an affiliate commission.