Skip to content

Instantly share code, notes, and snippets.

@ghalimi
Created January 25, 2013 23:27
Show Gist options
  • Star 18 You must be signed in to star a gist
  • Fork 4 You must be signed in to fork a gist
  • Save ghalimi/4638848 to your computer and use it in GitHub Desktop.
Save ghalimi/4638848 to your computer and use it in GitHub Desktop.
PV Function
// 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);
}
}
@cezarsmpio
Copy link

Hi, nice script!

function PV(rate, nper, pmt)
{
    return pmt / rate * (1 - Math.pow(1 + rate, -nper));
}

This function is more simple? No?

Thanks!

@burbabull
Copy link

hey, thanks!

@SivanKarthick
Copy link

thanks cezarlz

@elisma
Copy link

elisma commented May 5, 2020

thanks

@ahmadjoya
Copy link

thanks

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment