Skip to content

Instantly share code, notes, and snippets.

@wendylauw
Forked from ghalimi/PV.js
Created September 5, 2019 04:36
Show Gist options
  • Select an option

  • Save wendylauw/c7a0e27308631fe70007b75a717efccd to your computer and use it in GitHub Desktop.

Select an option

Save wendylauw/c7a0e27308631fe70007b75a717efccd to your computer and use it in GitHub Desktop.

Revisions

  1. @ghalimi ghalimi created this gist Jan 25, 2013.
    17 changes: 17 additions & 0 deletions PV.js
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,17 @@
    // Copyright (c) 2012 Sutoiku, Inc. (MIT License)

    function PV(rate, periods, payment, future, type) {
    // Initialize type
    var type = (typeof type === 'undefined') ? 0 : type;

    // Evaluate rate and periods (TODO: replace with secure expression evaluator)
    rate = eval(rate);
    periods = eval(periods);

    // Return present value
    if (rate === 0) {
    return - payment * periods - future;
    } else {
    return (((1 - Math.pow(1 + rate, periods)) / rate) * payment * (1 +rate * type) - future) / Math.pow(1 + rate, periods);
    }
    }