Code coverage report for financial/futureValue.js

Statements: 100% (12 / 12)      Branches: 100% (6 / 6)      Functions: 100% (3 / 3)      Lines: 100% (11 / 11)     

All files » financial/ » futureValue.js
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 271             1 14   2   12 12 6   12 4   12       1      
define(['./compoundInterest'], function (compoundInterest) {
 
    /**
     * Calculate future value of an investment.
     * http://en.wikipedia.org/wiki/Annuity_%28finance_theory%29
     * @version 0.2.0 (2012/03/20)
     */
    function futureValue(rate, nPeriods, payment, presentValue, isDue){
        if (rate === 0) {
            //isDue makes no difference since rate is zero..
            return payment * nPeriods;
        } else {
            var s = payment * ((Math.pow(1 + rate, nPeriods) - 1) / rate);
            if (isDue) {
                s *= (1 + rate);
            }
            if (presentValue) {
                s += presentValue * Math.pow(1 + rate, nPeriods);
            }
            return s;
        }
    }
 
    return futureValue;
 
});