Last active
August 27, 2016 05:05
-
-
Save pranid/0e38a2ddcf9a82de0f9c0c4c58643911 to your computer and use it in GitHub Desktop.
Amortization Schedule Example JavaScript
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
/** | |
* Created by praneeth on 8/27/2016. | |
*/ | |
var capital = 100000; | |
var period = 12; | |
var rate = 12; | |
var r = parseFloat(rate) / (100 * period) ; | |
// console.log(r); | |
var instalment = ((capital * r) / (1 - (1 / Math.pow((1 + r),period)))); | |
// var output_width = 70; | |
/*console.info("\nCapital\t\t\t" + capital); | |
console.info("Interest\t\t"+rate); | |
console.info("Period\t\t", period); | |
console.info("Installment\t\t", instalment);*/ | |
var total_interest = 0; | |
var total_recoverable = 0; | |
var running_bal = capital; | |
interest = parseFloat(running_bal) * r; | |
for (var i = 1; i <= period ; i++) { | |
var interest = parseFloat(running_bal) * r; | |
running_bal -= (instalment - interest); | |
console.error(i + "\t\t" + instalment.toFixed(2) + " \t\t" + interest.toFixed(2) + "\t\t" + (instalment - interest).toFixed(2) + "\t\t" + running_bal.toFixed(2)); | |
total_recoverable += instalment; | |
total_interest += interest; | |
} | |
console.info("Total \t" + total_recoverable.toFixed(2) + " \t\t" + total_interest.toFixed(2) + "\t\t" + (capital).toFixed(2)); | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment