Skip to content

Instantly share code, notes, and snippets.

Avatar

Ismael Ghalimi ghalimi

View GitHub Profile
View IRR.js
// Copyright (c) 2012 Sutoiku, Inc. (MIT License)
// Some algorithms have been ported from Apache OpenOffice:
/**************************************************************
*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
@ghalimi
ghalimi / XIRR.js
Created Jan 30, 2013
XIRR Function
View XIRR.js
// Copyright (c) 2012 Sutoiku, Inc. (MIT License)
// Some algorithms have been ported from Apache OpenOffice:
/**************************************************************
*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
@ghalimi
ghalimi / CUMIPMT.js
Last active Jul 15, 2022
CUMIPMT Function
View CUMIPMT.js
// Copyright (c) 2012 Sutoiku, Inc. (MIT License)
// Some algorithms have been ported from Apache OpenOffice:
/**************************************************************
*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
@ghalimi
ghalimi / DEC2HEX.js
Last active Mar 22, 2022
DEC2HEX Function
View DEC2HEX.js
// Copyright (c) 2012 Sutoiku, Inc. (MIT License)
function DEC2HEX(number, places) {
// Return error if number is not a number
if (isNaN(number)) return '#VALUE!';
// Return error if number is not decimal, is lower than -549755813888, or is greater than 549755813887
if (!/^-?[0-9]{1,12}$/.test(number) || number < -549755813888 || number > 549755813887) return '#NUM!';
// Ignore places and return a 10-character hexadecimal number if number is negative
@ghalimi
ghalimi / NPER.js
Created Jan 23, 2013
NPER Function
View NPER.js
// 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 / CUMPRINC.js
Last active Jan 28, 2022
CUMPRINC Function
View CUMPRINC.js
// Copyright (c) 2012 Sutoiku, Inc. (MIT License)
// Some algorithms have been ported from Apache OpenOffice:
/**************************************************************
*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
@ghalimi
ghalimi / YEARFRAC.js
Last active Jan 2, 2022
YEARFRAC Function
View YEARFRAC.js
// Copyright (c) 2012 Sutoiku, Inc. (MIT License)
function YEARFRAC(start_date, end_date, basis) {
// Credits: David A. Wheeler [http://www.dwheeler.com/]
// Initialize parameters
var basis = (typeof basis === 'undefined') ? 0 : basis;
var sdate = moment(new Date(start_date));
var edate = moment(new Date(end_date));
@ghalimi
ghalimi / FV.js
Created Jan 21, 2013
FV Function
View FV.js
// Copyright (c) 2012 Sutoiku, Inc. (MIT License)
// Some algorithms have been ported from Apache OpenOffice:
/**************************************************************
*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
@ghalimi
ghalimi / PV.js
Created Jan 25, 2013
PV Function
View PV.js
// 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 / HEX2DEC.js
Last active May 18, 2021
HEX2DEC Function
View HEX2DEC.js
// Copyright (c) 2012 Sutoiku, Inc. (MIT License)
function HEX2DEC(number) {
// Return error if number is not hexadecimal or contains more than ten characters (10 digits)
if (!/^[0-9A-Fa-f]{1,10}$/.test(number)) return '#NUM!';
// Convert hexadecimal number to decimal
var decimal = parseInt(number, 16);
// Return decimal number