Skip to content

Commit

Permalink
Update principal
Browse files Browse the repository at this point in the history
  • Loading branch information
ebradyjobory committed Dec 21, 2014
1 parent c87e1d3 commit 1038ba2
Showing 1 changed file with 5 additions and 5 deletions.
10 changes: 5 additions & 5 deletions finance.js
Original file line number Diff line number Diff line change
Expand Up @@ -85,22 +85,22 @@ Finance.prototype.ROI = function(cf0, earnings) {
};

// Amortization
Finance.prototype.AM = function (principle, rate, period, yearOrMonth) {
Finance.prototype.AM = function (principal, rate, period, yearOrMonth) {
var ratePerPeriod = rate / 12 / 100;
// for inputs in years
if (!yearOrMonth) {
var numerator = ratePerPeriod * Math.pow((1 + ratePerPeriod), period * 12);
var denominator = Math.pow((1 + ratePerPeriod), period * 12) - 1;

var am = principle * (numerator / denominator);
var am = principal * (numerator / denominator);
return Math.round(am * 100) / 100;

// for inputs in months
} else if (yearOrMonth === 1) {
var numerator = ratePerPeriod * Math.pow((1 + ratePerPeriod), period);
var denominator = Math.pow((1 + ratePerPeriod), period) - 1;

var am = principle * (numerator / denominator);
var am = principal * (numerator / denominator);
return Math.round(am * 100) / 100;
} else {
console.log('not defined');
Expand Down Expand Up @@ -135,9 +135,9 @@ Finance.prototype.DF = function(rate, numOfPeriods) {
};

// Compound Interest (CI)
Finance.prototype.CI = function(rate, numOfCompoundings, principle, numOfPeriods) {
Finance.prototype.CI = function(rate, numOfCompoundings, principal, numOfPeriods) {

var CI = principle * Math.pow((1 + ((rate/100)/ numOfCompoundings)), numOfCompoundings * numOfPeriods);
var CI = principal * Math.pow((1 + ((rate/100)/ numOfCompoundings)), numOfCompoundings * numOfPeriods);

return Math.round(CI * 100) / 100;
};
Expand Down

0 comments on commit 1038ba2

Please sign in to comment.