Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

financial

Package Overview
Dependencies
Maintainers
1
Versions
22
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

financial - npm Package Compare versions

Comparing version 0.0.14 to 0.0.15

90

dist/financial.cjs.development.js

@@ -254,3 +254,2 @@ 'use strict';

* ```
*
*/

@@ -267,24 +266,2 @@

// when = _convert_when(when)
// rate, per, nper, pv, fv, when = np.broadcast_arrays(rate, per, nper,
// pv, fv, when)
// total_pmt = pmt(rate, nper, pv, fv, when)
// ipmt_array = np.array(_rbl(rate, per, total_pmt, pv, when) * rate)
// # Payments start at the first period, so payments before that
// # don't make any sense.
// ipmt_array[per < 1] = _value_like(ipmt_array, np.nan)
// # If payments occur at the beginning of a period and this is the
// # first period, then no interest has accrued.
// per1_and_begin = (when == 1) & (per == 1)
// ipmt_array[per1_and_begin] = _value_like(ipmt_array, 0)
// # If paying at the beginning we need to discount by one period.
// per_gt_1_and_begin = (when == 1) & (per > 1)
// ipmt_array[per_gt_1_and_begin] = (
// ipmt_array[per_gt_1_and_begin] / (1 + rate[per_gt_1_and_begin])
// )
// if np.ndim(ipmt_array) == 0:
// # Follow the ufunc convention of returning scalars for scalar
// # and 0d array inputs.
// return ipmt_array.item(0)
// return ipmt_array
// Payments start at the first period, so payments before that

@@ -337,2 +314,68 @@ // don't make any sense.

/**
* Calculates the present value of an annuity investment based on constant-amount
* periodic payments and a constant interest rate.
*
* @param rate - Rate of interest (per period)
* @param nper - Number of compounding periods
* @param pmt - Payment
* @param fv - Future value
* @param when - When payments are due
*
* @returns the present value of a payment or investment
*
* ## Examples
*
* What is the present value (e.g., the initial investment)
* of an investment that needs to total $15692.93
* after 10 years of saving $100 every month? Assume the
* interest rate is 5% (annually) compounded monthly.
*
* ```javascript
* import { pv } from 'financial'
*
* pv(0.05/12, 10*12, -100, 15692.93) // -100.00067131625819
* ```
*
* By convention, the negative sign represents cash flow out
* (i.e., money not available today). Thus, to end up with
* $15,692.93 in 10 years saving $100 a month at 5% annual
* interest, one's initial deposit should also be $100.
*
* ## Notes
*
* The present value is computed by solving the equation:
*
* ```
* fv + pv * (1 + rate) ** nper + pmt * (1 + rate * when) / rate * ((1 + rate) ** nper - 1) = 0
* ```
*
* or, when `rate = 0`:
*
* ```
* fv + pv + pmt * nper = 0
* ```
*
* for `pv`, which is then returned.
*
* ## References
*
* [Wheeler, D. A., E. Rathke, and R. Weir (Eds.) (2009, May)](http://www.oasis-open.org/committees/documents.php?wg_abbrev=office-formulaOpenDocument-formula-20090508.odt).
*/
function pv(rate, nper, pmt, fv, when) {
if (fv === void 0) {
fv = 0;
}
if (when === void 0) {
when = exports.PaymentDueTime.End;
}
var whenMult = when === exports.PaymentDueTime.Begin ? 1 : 0;
var isRateZero = rate === 0;
var temp = Math.pow(1 + rate, nper);
var fact = isRateZero ? nper : (1 + rate * whenMult) * (temp - 1) / rate;
return -(fv + pmt * fact) / temp;
}
/**
* This function is here to simply have a different name for the 'fv'

@@ -355,2 +398,3 @@ * function to not interfere with the 'fv' keyword argument within the 'ipmt'

exports.ppmt = ppmt;
exports.pv = pv;
//# sourceMappingURL=financial.cjs.development.js.map

@@ -1,2 +0,2 @@

"use strict";var e;function t(e,t,n,r,i){if(void 0===i&&(i=exports.PaymentDueTime.End),0===e)return-(r+n*t);var o=Math.pow(1+e,t);return-r*o-n*(1+e*(i===exports.PaymentDueTime.Begin?1:0))/e*(o-1)}function n(e,t,n,r,i){void 0===r&&(r=0),void 0===i&&(i=exports.PaymentDueTime.End);var o=0===e,u=Math.pow(1+e,t),m=i===exports.PaymentDueTime.Begin?1:0,p=o?1:e;return-(r+n*u)/(o?t:(1+p*m)*(u-1)/p)}function r(e,t,r,o,u,m){if(void 0===u&&(u=0),void 0===m&&(m=exports.PaymentDueTime.End),t<1)return Number.NaN;if(m===exports.PaymentDueTime.Begin&&1===t)return 0;var p=i(e,t,n(e,r,o,u,m),o,m)*e;return m===exports.PaymentDueTime.Begin&&t>1&&(p/=1+e),p}function i(e,n,r,i,o){return t(e,n-1,r,i,o)}Object.defineProperty(exports,"__esModule",{value:!0}),(e=exports.PaymentDueTime||(exports.PaymentDueTime={})).Begin="begin",e.End="end",exports.fv=t,exports.ipmt=r,exports.nper=function(e,t,n,r,i){if(void 0===r&&(r=0),void 0===i&&(i=exports.PaymentDueTime.End),0===e)return-(r+n)/t;var o=t*(1+e*(i===exports.PaymentDueTime.Begin?1:0))/e;return Math.log((-r+o)/(n+o))/Math.log(1+e)},exports.pmt=n,exports.ppmt=function(e,t,i,o,u,m){return void 0===u&&(u=0),void 0===m&&(m=exports.PaymentDueTime.End),n(e,i,o,u,m)-r(e,t,i,o,u,m)};
"use strict";var e;function t(e,t,n,r,i){if(void 0===i&&(i=exports.PaymentDueTime.End),0===e)return-(r+n*t);var o=Math.pow(1+e,t);return-r*o-n*(1+e*(i===exports.PaymentDueTime.Begin?1:0))/e*(o-1)}function n(e,t,n,r,i){void 0===r&&(r=0),void 0===i&&(i=exports.PaymentDueTime.End);var o=0===e,u=Math.pow(1+e,t),m=i===exports.PaymentDueTime.Begin?1:0,p=o?1:e;return-(r+n*u)/(o?t:(1+p*m)*(u-1)/p)}function r(e,t,r,o,u,m){if(void 0===u&&(u=0),void 0===m&&(m=exports.PaymentDueTime.End),t<1)return Number.NaN;if(m===exports.PaymentDueTime.Begin&&1===t)return 0;var p=i(e,t,n(e,r,o,u,m),o,m)*e;return m===exports.PaymentDueTime.Begin&&t>1&&(p/=1+e),p}function i(e,n,r,i,o){return t(e,n-1,r,i,o)}Object.defineProperty(exports,"__esModule",{value:!0}),(e=exports.PaymentDueTime||(exports.PaymentDueTime={})).Begin="begin",e.End="end",exports.fv=t,exports.ipmt=r,exports.nper=function(e,t,n,r,i){if(void 0===r&&(r=0),void 0===i&&(i=exports.PaymentDueTime.End),0===e)return-(r+n)/t;var o=t*(1+e*(i===exports.PaymentDueTime.Begin?1:0))/e;return Math.log((-r+o)/(n+o))/Math.log(1+e)},exports.pmt=n,exports.ppmt=function(e,t,i,o,u,m){return void 0===u&&(u=0),void 0===m&&(m=exports.PaymentDueTime.End),n(e,i,o,u,m)-r(e,t,i,o,u,m)},exports.pv=function(e,t,n,r,i){void 0===r&&(r=0),void 0===i&&(i=exports.PaymentDueTime.End);var o=i===exports.PaymentDueTime.Begin?1:0,u=0===e,m=Math.pow(1+e,t);return-(r+n*(u?t:(1+e*o)*(m-1)/e))/m};
//# sourceMappingURL=financial.cjs.production.min.js.map

@@ -197,3 +197,2 @@ /**

* ```
*
*/

@@ -214,1 +213,52 @@ export declare function ipmt(rate: number, per: number, nper: number, pv: number, fv?: number, when?: PaymentDueTime): number;

export declare function ppmt(rate: number, per: number, nper: number, pv: number, fv?: number, when?: PaymentDueTime): number;
/**
* Calculates the present value of an annuity investment based on constant-amount
* periodic payments and a constant interest rate.
*
* @param rate - Rate of interest (per period)
* @param nper - Number of compounding periods
* @param pmt - Payment
* @param fv - Future value
* @param when - When payments are due
*
* @returns the present value of a payment or investment
*
* ## Examples
*
* What is the present value (e.g., the initial investment)
* of an investment that needs to total $15692.93
* after 10 years of saving $100 every month? Assume the
* interest rate is 5% (annually) compounded monthly.
*
* ```javascript
* import { pv } from 'financial'
*
* pv(0.05/12, 10*12, -100, 15692.93) // -100.00067131625819
* ```
*
* By convention, the negative sign represents cash flow out
* (i.e., money not available today). Thus, to end up with
* $15,692.93 in 10 years saving $100 a month at 5% annual
* interest, one's initial deposit should also be $100.
*
* ## Notes
*
* The present value is computed by solving the equation:
*
* ```
* fv + pv * (1 + rate) ** nper + pmt * (1 + rate * when) / rate * ((1 + rate) ** nper - 1) = 0
* ```
*
* or, when `rate = 0`:
*
* ```
* fv + pv + pmt * nper = 0
* ```
*
* for `pv`, which is then returned.
*
* ## References
*
* [Wheeler, D. A., E. Rathke, and R. Weir (Eds.) (2009, May)](http://www.oasis-open.org/committees/documents.php?wg_abbrev=office-formulaOpenDocument-formula-20090508.odt).
*/
export declare function pv(rate: number, nper: number, pmt: number, fv?: number, when?: PaymentDueTime): number;

@@ -251,3 +251,2 @@ /**

* ```
*
*/

@@ -264,24 +263,2 @@

// when = _convert_when(when)
// rate, per, nper, pv, fv, when = np.broadcast_arrays(rate, per, nper,
// pv, fv, when)
// total_pmt = pmt(rate, nper, pv, fv, when)
// ipmt_array = np.array(_rbl(rate, per, total_pmt, pv, when) * rate)
// # Payments start at the first period, so payments before that
// # don't make any sense.
// ipmt_array[per < 1] = _value_like(ipmt_array, np.nan)
// # If payments occur at the beginning of a period and this is the
// # first period, then no interest has accrued.
// per1_and_begin = (when == 1) & (per == 1)
// ipmt_array[per1_and_begin] = _value_like(ipmt_array, 0)
// # If paying at the beginning we need to discount by one period.
// per_gt_1_and_begin = (when == 1) & (per > 1)
// ipmt_array[per_gt_1_and_begin] = (
// ipmt_array[per_gt_1_and_begin] / (1 + rate[per_gt_1_and_begin])
// )
// if np.ndim(ipmt_array) == 0:
// # Follow the ufunc convention of returning scalars for scalar
// # and 0d array inputs.
// return ipmt_array.item(0)
// return ipmt_array
// Payments start at the first period, so payments before that

@@ -334,2 +311,68 @@ // don't make any sense.

/**
* Calculates the present value of an annuity investment based on constant-amount
* periodic payments and a constant interest rate.
*
* @param rate - Rate of interest (per period)
* @param nper - Number of compounding periods
* @param pmt - Payment
* @param fv - Future value
* @param when - When payments are due
*
* @returns the present value of a payment or investment
*
* ## Examples
*
* What is the present value (e.g., the initial investment)
* of an investment that needs to total $15692.93
* after 10 years of saving $100 every month? Assume the
* interest rate is 5% (annually) compounded monthly.
*
* ```javascript
* import { pv } from 'financial'
*
* pv(0.05/12, 10*12, -100, 15692.93) // -100.00067131625819
* ```
*
* By convention, the negative sign represents cash flow out
* (i.e., money not available today). Thus, to end up with
* $15,692.93 in 10 years saving $100 a month at 5% annual
* interest, one's initial deposit should also be $100.
*
* ## Notes
*
* The present value is computed by solving the equation:
*
* ```
* fv + pv * (1 + rate) ** nper + pmt * (1 + rate * when) / rate * ((1 + rate) ** nper - 1) = 0
* ```
*
* or, when `rate = 0`:
*
* ```
* fv + pv + pmt * nper = 0
* ```
*
* for `pv`, which is then returned.
*
* ## References
*
* [Wheeler, D. A., E. Rathke, and R. Weir (Eds.) (2009, May)](http://www.oasis-open.org/committees/documents.php?wg_abbrev=office-formulaOpenDocument-formula-20090508.odt).
*/
function pv(rate, nper, pmt, fv, when) {
if (fv === void 0) {
fv = 0;
}
if (when === void 0) {
when = PaymentDueTime.End;
}
var whenMult = when === PaymentDueTime.Begin ? 1 : 0;
var isRateZero = rate === 0;
var temp = Math.pow(1 + rate, nper);
var fact = isRateZero ? nper : (1 + rate * whenMult) * (temp - 1) / rate;
return -(fv + pmt * fact) / temp;
}
/**
* This function is here to simply have a different name for the 'fv'

@@ -347,3 +390,3 @@ * function to not interfere with the 'fv' keyword argument within the 'ipmt'

export { PaymentDueTime, fv, ipmt, nper, pmt, ppmt };
export { PaymentDueTime, fv, ipmt, nper, pmt, ppmt, pv };
//# sourceMappingURL=financial.esm.js.map

@@ -5,3 +5,3 @@ {

"author": "Luciano Mammino <no@spam.com> (https://loige.co)",
"version": "0.0.14",
"version": "0.0.15",
"repository": {

@@ -8,0 +8,0 @@ "type": "git",

@@ -6,3 +6,3 @@ # Financial

[![codecov](https://codecov.io/gh/lmammino/financial/branch/master/graph/badge.svg)](https://codecov.io/gh/lmammino/financial)
[![Documentation](https://api.netlify.com/api/v1/badges/eca2653e-dcaa-41db-865c-ab635687e69d/deploy-status)](https://financejs.netlify.app/)
[![Documentation](https://api.netlify.com/api/v1/badges/eca2653e-dcaa-41db-865c-ab635687e69d/deploy-status)](https://financialjs.netlify.app/)

@@ -90,3 +90,3 @@ A Zero-Dependency TypeScript / JavaScript financial utility library inspired by [numpy-financial](https://github.com/numpy/numpy-financial/) that can be used on both Node.js and the browser.

- [X] `ppmt`
- [ ] `pv`
- [X] `pv`
- [ ] `rate`

@@ -93,0 +93,0 @@ - [ ] `irr`

@@ -230,31 +230,4 @@ /**

* ```
*
*/
export function ipmt (rate: number, per: number, nper: number, pv: number, fv = 0, when = PaymentDueTime.End) : number {
// when = _convert_when(when)
// rate, per, nper, pv, fv, when = np.broadcast_arrays(rate, per, nper,
// pv, fv, when)
// total_pmt = pmt(rate, nper, pv, fv, when)
// ipmt_array = np.array(_rbl(rate, per, total_pmt, pv, when) * rate)
// # Payments start at the first period, so payments before that
// # don't make any sense.
// ipmt_array[per < 1] = _value_like(ipmt_array, np.nan)
// # If payments occur at the beginning of a period and this is the
// # first period, then no interest has accrued.
// per1_and_begin = (when == 1) & (per == 1)
// ipmt_array[per1_and_begin] = _value_like(ipmt_array, 0)
// # If paying at the beginning we need to discount by one period.
// per_gt_1_and_begin = (when == 1) & (per > 1)
// ipmt_array[per_gt_1_and_begin] = (
// ipmt_array[per_gt_1_and_begin] / (1 + rate[per_gt_1_and_begin])
// )
// if np.ndim(ipmt_array) == 0:
// # Follow the ufunc convention of returning scalars for scalar
// # and 0d array inputs.
// return ipmt_array.item(0)
// return ipmt_array
// Payments start at the first period, so payments before that

@@ -301,2 +274,62 @@ // don't make any sense.

/**
* Calculates the present value of an annuity investment based on constant-amount
* periodic payments and a constant interest rate.
*
* @param rate - Rate of interest (per period)
* @param nper - Number of compounding periods
* @param pmt - Payment
* @param fv - Future value
* @param when - When payments are due
*
* @returns the present value of a payment or investment
*
* ## Examples
*
* What is the present value (e.g., the initial investment)
* of an investment that needs to total $15692.93
* after 10 years of saving $100 every month? Assume the
* interest rate is 5% (annually) compounded monthly.
*
* ```javascript
* import { pv } from 'financial'
*
* pv(0.05/12, 10*12, -100, 15692.93) // -100.00067131625819
* ```
*
* By convention, the negative sign represents cash flow out
* (i.e., money not available today). Thus, to end up with
* $15,692.93 in 10 years saving $100 a month at 5% annual
* interest, one's initial deposit should also be $100.
*
* ## Notes
*
* The present value is computed by solving the equation:
*
* ```
* fv + pv * (1 + rate) ** nper + pmt * (1 + rate * when) / rate * ((1 + rate) ** nper - 1) = 0
* ```
*
* or, when `rate = 0`:
*
* ```
* fv + pv + pmt * nper = 0
* ```
*
* for `pv`, which is then returned.
*
* ## References
*
* [Wheeler, D. A., E. Rathke, and R. Weir (Eds.) (2009, May)](http://www.oasis-open.org/committees/documents.php?wg_abbrev=office-formulaOpenDocument-formula-20090508.odt).
*/
export function pv (rate: number, nper: number, pmt: number, fv = 0, when = PaymentDueTime.End): number {
const whenMult = when === PaymentDueTime.Begin ? 1 : 0
const isRateZero = rate === 0
const temp = (1 + rate) ** nper
const fact = isRateZero
? nper
: (1 + rate * whenMult) * (temp - 1) / rate
return -(fv + pmt * fact) / temp
}
/**
* This function is here to simply have a different name for the 'fv'

@@ -303,0 +336,0 @@ * function to not interfere with the 'fv' keyword argument within the 'ipmt'

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc