Skip to content

Instantly share code, notes, and snippets.

@einarlove
Last active August 29, 2015 13:58
Show Gist options
  • Save einarlove/10270117 to your computer and use it in GitHub Desktop.
Save einarlove/10270117 to your computer and use it in GitHub Desktop.
var listofSumsWithnoRate = [109012, 118837, 129547, 141222, 153950, 167824, 182949, 199437, 217411, 237005, 258364, 281649, 307032, 334703, 364868, 397751, 433598, 472675, 515274, 561713]
var listOfKLPSums = [108791, 118355, 128760, 140080, 152394, 165792, 180367, 196223, 213474, 232240, 252657, 274869, 299033, 325322, 353921, 385035, 418884, 455709, 495772, 539356]
function cal(deposit, year, yield, rate){
while(year--){
deposit = (deposit * yield) * (1 - rate)
}
return Math.round(deposit)
}
function matchCheck(list, yield, rate){
for(var i=1; i <= 20; i++){
var sum = cal(100000, i, yield, rate)
var correctSum = list[i - 1]
if(correctSum !== sum){
console.group('Year ' + i)
console.log('%c' + sum, 'color:red')
console.log('%c' + correctSum, 'color:green')
console.log('%c ≠ ' + (correctSum - sum), 'color:black')
console.groupEnd()
}
}
}
var rate = 1.09012352
console.log('Checking 20 years with no yield')
matchCheck(listofSumsWithnoRate, rate, 0)
console.log('Checking KLP for 20 years with 0.02% in yield')
matchCheck(listOfKLPSums, rate, 0.002)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment