Last active
June 7, 2018 09:55
-
-
Save paulswail/016c6049dac3d8bd1f094f0fe0aeb63d to your computer and use it in GitHub Desktop.
Calculate investment's compound growth
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
// Calculates the compound growth of an investment over number of periods. | |
// Assumes fixed regular contributions and average growth rate. | |
function compoundGrowth(startingBalance = 0, periodContribution = 100, periodGrowthRate=0, nPeriods = 1, currencyLabel = '£') { | |
const totalContribution = startingBalance + periodContribution * nPeriods; | |
const finalBalance = [...Array(nPeriods)].reduce((runningBalance) => { | |
return runningBalance + (runningBalance * periodGrowthRate) + periodContribution; | |
}, startingBalance); | |
const absoluteGrowth = finalBalance - totalContribution; | |
const relativeGrowth = absoluteGrowth / totalContribution; | |
console.log(`${currencyLabel}${finalBalance.toFixed(2)} will be returned after ${nPeriods} periods with ${currencyLabel}${periodContribution.toFixed(2)} contributed each period and an average period growth rate of ${periodGrowthRate * 100}% and initial lump sum of ${currencyLabel}${startingBalance}. | |
Absolute Growth: ${currencyLabel}${absoluteGrowth.toFixed(2)} | |
Relative Growth: ${(relativeGrowth * 100).toFixed(2)}%`); | |
return finalBalance; | |
} | |
compoundGrowth(0, 100, 0.005, 12); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment