-
-
Save eivindingebrigtsen/253e02e2e6eb4f42a21f6000e204ce77 to your computer and use it in GitHub Desktop.
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
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