Skip to content

Instantly share code, notes, and snippets.

@eivindingebrigtsen
Created March 31, 2016 15:14
Show Gist options
  • Save eivindingebrigtsen/253e02e2e6eb4f42a21f6000e204ce77 to your computer and use it in GitHub Desktop.
Save eivindingebrigtsen/253e02e2e6eb4f42a21f6000e204ce77 to your computer and use it in GitHub Desktop.
var calculateSavingsvalue = function(years, monthlyAmount, additionalAnualSavings, balance){
var investment = monthlyAmount;
var annualRate = self.profile.expectedReturn;
var monthlyRate = (annualRate / 12 / 100) || 0;
var additionalMonthlyRate = (additionalAnualSavings / 12 / 100) || 0;
var months = years * 12;
var futureValue = balance || 0;
for ( i = 1; i <= months; i++ ) {
if(additionalMonthlyRate){
investment = investment * (1+additionalMonthlyRate);
}
futureValue = (futureValue + investment) * (1 + monthlyRate);
}
return {
balance: futureValue,
monthlyAmount: investment
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment