Skip to content

Instantly share code, notes, and snippets.

@goshki
Created May 12, 2010 15:20
Show Gist options
  • Save goshki/398707 to your computer and use it in GitHub Desktop.
Save goshki/398707 to your computer and use it in GitHub Desktop.
/**
* Calculates a compound interest (procent składany) for a given period of time
* with given annual interest rate, number of capitalizations and saving period.
*
* @param amount
* initial investment
*
* @param interestRate
* nominal annual interest rate (in decimal, so if interest rate is 5%,
* we give 0.05)
*
* @param capitalizations
* number of capitalizations per year
*
* @param period
* saving period (in years, as decimal if shorter period needed)
*
* @return calculated compound interest
*/
function compoundInterest( amount, interestRate, capitalizations, period ) {
return amount * Math.pow( ( 1 + ( interestRate / capitalizations ) ),
capitalizations * period );
}
alert( compoundInterest( 10000.0, 0.04, 365, 0.4 ) );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment