Created
February 5, 2018 19:15
-
-
Save fipo/e911cc0b7529d3f2aa33c4ee4af0d654 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
// Compound interest for principal | |
// CIfP = P(1+r/n)^nt | |
// Future value of a series: | |
// PMT * (((1 + r/n)^nt - 1) / (r/n)) * (1+r/n) | |
// Total = [ Compound interest for principal ] + [ Future value of a series ] | |
// Total = [ P(1+r/n)^nt ] + [ PMT * (((1 + r/n)^nt - 1) / (r/n)) ] | |
// CIfP = the future value of the investment/loan, including interest | |
// P = the principal investment amount (the initial deposit) | |
// r = the annual interest rate (decimal) | |
// n = the number of times that interest is compounded per year AND additional payment frequency | |
// t = the number of years the money is invested | |
// PMT = the monthly payment | |
const P = 5000 | |
const r = 0.10 | |
const n = 12 | |
const t = 10 | |
const PMT = 1000 | |
const options = | |
`Initial Capital: ${P} | |
Interest Rate: ${r}% (decimal) | |
Years: ${t} | |
Monthly payment: ${PMT} | |
` | |
let CIfP = (P * Math.pow((1 + r/n), n*t)).toFixed(2) | |
let FVoS = (PMT * ( ( (Math.pow((1 + r/n), n*t) - 1) ) / (r/n) * (1+r/n) )).toFixed(2) | |
let Balance = (parseFloat(CIfP) + parseFloat(FVoS)).toFixed(2) | |
let RowInvestment = n * PMT * t + P | |
let Gain = (Balance - RowInvestment).toFixed(2) | |
console.log(options) | |
console.log(`Balance: ${Balance}, \nInvestment: ${RowInvestment}\nTotal Interest: ${Gain}`); | |
console.log(`Monthly: ${((Balance * 0.1)/12).toFixed(2)}`); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment