Skip to content

Instantly share code, notes, and snippets.

View ghalimi's full-sized avatar

Ismael Ghalimi ghalimi

View GitHub Profile
@ghalimi
ghalimi / RRI.js
Created January 26, 2013 17:42
RRI Function
// Copyright (c) 2012 Sutoiku, Inc. (MIT License)
function RRI(periods, present, future) {
// Return error if any of the parameters is not a number
if (isNaN(periods) || isNaN(present) || isNaN(future)) return '#VALUE!';
// Return error if periods or present is equal to 0 (zero)
if (periods === 0 || present === 0) return '#NUM!';
// Return equivalent interest rate
@ghalimi
ghalimi / RATE.js
Last active December 7, 2022 08:13
RATE Function
// Copyright (c) 2012 Sutoiku, Inc. (MIT License)
function RATE(periods, payment, present, future, type, guess) {
// Credits: rabugento
// Initialize guess
var guess = (typeof guess === 'undefined') ? 0.01 : guess;
// Initialize future
var future = (typeof future === 'undefined') ? 0 : future;
@ghalimi
ghalimi / PV.js
Created January 25, 2013 23:27
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);
@ghalimi
ghalimi / PPMT.js
Created January 25, 2013 20:03
PPMT Function
// Copyright (c) 2012 Sutoiku, Inc. (MIT License)
function PPMT(rate, period, periods, present, future, type) {
return PMT(rate, periods, present, future, type) - IPMT(rate, period, periods, present, future, type);
}
@ghalimi
ghalimi / PDURATION.js
Created January 24, 2013 15:39
PDURATION Function
// Copyright (c) 2012 Sutoiku, Inc. (MIT License)
function PDURATION(rate, present, future) {
// Return error if any of the parameters is not a number
if (isNaN(rate) || isNaN(present) || isNaN(future)) return '#VALUE!';
// Return error if rate <=0
if (rate <= 0) return '#NUM!';
// Return number of periods
@ghalimi
ghalimi / NPER.js
Created January 23, 2013 23:13
NPER Function
// Copyright (c) 2012 Sutoiku, Inc. (MIT License)
function NPER(rate, payment, present, future, type) {
// Initialize type
var type = (typeof type === 'undefined') ? 0 : type;
// Initialize future value
var future = (typeof future === 'undefined') ? 0 : future;
// Evaluate rate and periods (TODO: replace with secure expression evaluator)
@ghalimi
ghalimi / NOMINAL.js
Created January 23, 2013 22:07
NOMINAL
// Copyright (c) 2012 Sutoiku, Inc. (MIT License)
function NOMINAL(rate, periods) {
// Return error if any of the parameters is not a number
if (isNaN(rate) || isNaN(periods)) return '#VALUE!';
// Return error if rate <=0 or periods < 1
if (rate <=0 || periods < 1) return '#NUM!';
// Truncate periods if it is not an integer
@ghalimi
ghalimi / MIRR.js
Created January 22, 2013 23:29
MIRR Function
// Copyright (c) 2012 Sutoiku, Inc. (MIT License)
function MIRR(values, finance_rate, reinvest_rate) {
// Initialize number of values
var n = values.length;
// Lookup payments (negative values) and incomes (positive values)
var payments = [];
var incomes = [];
for (var i = 0; i < n; i++) {
@ghalimi
ghalimi / NPV.js
Last active March 31, 2017 23:19
NPV Function
// Copyright (c) 2012 Sutoiku, Inc. (MIT License)
function NPV() {
// Cast arguments to array
var args = [];
for (i = 0; i < arguments.length; i++) {
args = args.concat(arguments[i]);
}
// Lookup rate
@ghalimi
ghalimi / ISPMT.js
Created January 22, 2013 19:23
ISPMT Function
// Copyright (c) 2012 Sutoiku, Inc. (MIT License)
function ISPMT(rate, period, periods, value) {
// Evaluate rate and periods (TODO: replace with secure expression evaluator)
rate = eval(rate);
periods = eval(periods);
// Return interest
return value * rate * (period / periods - 1);
}