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.17 to 0.0.18

69

dist/financial.cjs.development.js

@@ -582,2 +582,70 @@ 'use strict';

/**
* Returns the NPV (Net Present Value) of a cash flow series.
*
* @param rate - The discount rate
* @param values - The values of the time series of cash flows. The (fixed) time
* interval between cash flow "events" must be the same as that for
* which `rate` is given (i.e., if `rate` is per year, then precisely
* a year is understood to elapse between each cash flow event). By
* convention, investments or "deposits" are negative, income or
* "withdrawals" are positive; `values` must begin with the initial
* investment, thus `values[0]` will typically be negative.
* @returns The NPV of the input cash flow series `values` at the discount `rate`.
*
* ## Warnings
*
* `npv considers a series of cashflows starting in the present (t = 0).
* NPV can also be defined with a series of future cashflows, paid at the
* end, rather than the start, of each period. If future cashflows are used,
* the first cashflow `values[0]` must be zeroed and added to the net
* present value of the future cashflows. This is demonstrated in the
* examples.
*
* ## Notes
*
* Returns the result of:
*
* ```
* \\sum_{t=0}^{M-1}{\\frac{values_t}{(1+rate)^{t}}}
* ```
*
* ## Examples
*
* Consider a potential project with an initial investment of $40 000 and
* projected cashflows of $5 000, $8 000, $12 000 and $30 000 at the end of
* each period discounted at a rate of 8% per period. To find the project's
* net present value:
*
* ```javascript
* import {npv} from 'financial'
*
* const rate = 0.08
* const cashflows = [-40_000, 5000, 8000, 12000, 30000]
* npv(rate, cashflows) // 3065.2226681795255
* ```
*
* It may be preferable to split the projected cashflow into an initial
* investment and expected future cashflows. In this case, the value of
* the initial cashflow is zero and the initial investment is later added
* to the future cashflows net present value:
*
* ```javascript
* const initialCashflow = cashflows[0]
* cashflows[0] = 0
*
* npv(rate, cashflows) + initialCashflow // 3065.2226681795255
* ```
*
* ## References
*
* L. J. Gitman, "Principles of Managerial Finance, Brief,"
* 3rd ed., Addison-Wesley, 2003, pg. 346.
*/
function npv(rate, values) {
return values.reduce(function (acc, curr, i) {
return acc + curr / Math.pow(1 + rate, i);
}, 0);
}
/**
* This function is here to simply have a different name for the 'fv'

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

exports.nper = nper;
exports.npv = npv;
exports.pmt = pmt;

@@ -661,0 +730,0 @@ exports.ppmt = ppmt;

2

dist/financial.cjs.production.min.js

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

"use strict";var e;function t(e,t,r,n,o){if(void 0===o&&(o=exports.PaymentDueTime.End),0===e)return-(n+r*t);var i=Math.pow(1+e,t);return-n*i-r*(1+e*(o===exports.PaymentDueTime.Begin?1:0))/e*(i-1)}function r(e,t,r,n,o){void 0===n&&(n=0),void 0===o&&(o=exports.PaymentDueTime.End);var i=0===e,a=Math.pow(1+e,t),u=o===exports.PaymentDueTime.Begin?1:0,p=i?1:e;return-(n+r*a)/(i?t:(1+p*u)*(a-1)/p)}function n(e,t,n,i,a,u){if(void 0===a&&(a=0),void 0===u&&(u=exports.PaymentDueTime.End),t<1)return Number.NaN;if(u===exports.PaymentDueTime.Begin&&1===t)return 0;var p=o(e,t,r(e,n,i,a,u),i,u)*e;return u===exports.PaymentDueTime.Begin&&t>1&&(p/=1+e),p}function o(e,r,n,o,i){return t(e,r-1,n,o,i)}function i(e,t,r,n,o,i){var a=i===exports.PaymentDueTime.Begin?1:0,u=Math.pow(e+1,t),p=Math.pow(e+1,t-1);return(o+u*n+r*(u-1)*(e*a+1)/e)/(t*p*n-r*(u-1)*(e*a+1)/Math.pow(e,2)+t*r*p*(e*a+1)/e+r*(u-1)*a/e)}function a(e,t,r){for(var n=r+1,o=e[0],i=1;i<e.length;i++)o+=e[i]/Math.pow(n,(t[i]-t[0])/365);return o}function u(e,t,r){for(var n=r+1,o=0,i=1;i<e.length;i++){var a=(t[i]-t[0])/365;o-=a*e[i]/Math.pow(n,a+1)}return o}Object.defineProperty(exports,"__esModule",{value:!0}),(e=exports.PaymentDueTime||(exports.PaymentDueTime={})).Begin="begin",e.End="end",exports.fv=t,exports.ipmt=n,exports.irr=function(e,t,r,n){void 0===t&&(t=.1),void 0===r&&(r=1e-6),void 0===n&&(n=100);for(var o=[],i=!1,p=!1,m=0;m<e.length;m++)o[m]=0===m?0:o[m-1]+365,e[m]>0&&(i=!0),e[m]<0&&(p=!0);if(!i||!p)return Number.NaN;var v,s,d,x=t,f=0,h=!0;do{v=x-(d=a(e,o,x))/u(e,o,x),s=Math.abs(v-x),x=v,h=s>r&&Math.abs(d)>r}while(h&&++f<n);return h?Number.NaN:x},exports.nper=function(e,t,r,n,o){if(void 0===n&&(n=0),void 0===o&&(o=exports.PaymentDueTime.End),0===e)return-(n+r)/t;var i=t*(1+e*(o===exports.PaymentDueTime.Begin?1:0))/e;return Math.log((-n+i)/(r+i))/Math.log(1+e)},exports.pmt=r,exports.ppmt=function(e,t,o,i,a,u){return void 0===a&&(a=0),void 0===u&&(u=exports.PaymentDueTime.End),r(e,o,i,a,u)-n(e,t,o,i,a,u)},exports.pv=function(e,t,r,n,o){void 0===n&&(n=0),void 0===o&&(o=exports.PaymentDueTime.End);var i=o===exports.PaymentDueTime.Begin?1:0,a=0===e,u=Math.pow(1+e,t);return-(n+r*(a?t:(1+e*i)*(u-1)/e))/u},exports.rate=function(e,t,r,n,o,a,u,p){void 0===o&&(o=exports.PaymentDueTime.End),void 0===a&&(a=.1),void 0===u&&(u=1e-6),void 0===p&&(p=100);for(var m=a,v=0,s=!1;v<p&&!s;){var d=m-i(m,e,t,r,n,o);s=Math.abs(d-m)<u,v++,m=d}return s?m:Number.NaN};
"use strict";var e;function t(e,t,r,n,o){if(void 0===o&&(o=exports.PaymentDueTime.End),0===e)return-(n+r*t);var i=Math.pow(1+e,t);return-n*i-r*(1+e*(o===exports.PaymentDueTime.Begin?1:0))/e*(i-1)}function r(e,t,r,n,o){void 0===n&&(n=0),void 0===o&&(o=exports.PaymentDueTime.End);var i=0===e,u=Math.pow(1+e,t),a=o===exports.PaymentDueTime.Begin?1:0,p=i?1:e;return-(n+r*u)/(i?t:(1+p*a)*(u-1)/p)}function n(e,t,n,i,u,a){if(void 0===u&&(u=0),void 0===a&&(a=exports.PaymentDueTime.End),t<1)return Number.NaN;if(a===exports.PaymentDueTime.Begin&&1===t)return 0;var p=o(e,t,r(e,n,i,u,a),i,a)*e;return a===exports.PaymentDueTime.Begin&&t>1&&(p/=1+e),p}function o(e,r,n,o,i){return t(e,r-1,n,o,i)}function i(e,t,r,n,o,i){var u=i===exports.PaymentDueTime.Begin?1:0,a=Math.pow(e+1,t),p=Math.pow(e+1,t-1);return(o+a*n+r*(a-1)*(e*u+1)/e)/(t*p*n-r*(a-1)*(e*u+1)/Math.pow(e,2)+t*r*p*(e*u+1)/e+r*(a-1)*u/e)}function u(e,t,r){for(var n=r+1,o=e[0],i=1;i<e.length;i++)o+=e[i]/Math.pow(n,(t[i]-t[0])/365);return o}function a(e,t,r){for(var n=r+1,o=0,i=1;i<e.length;i++){var u=(t[i]-t[0])/365;o-=u*e[i]/Math.pow(n,u+1)}return o}Object.defineProperty(exports,"__esModule",{value:!0}),(e=exports.PaymentDueTime||(exports.PaymentDueTime={})).Begin="begin",e.End="end",exports.fv=t,exports.ipmt=n,exports.irr=function(e,t,r,n){void 0===t&&(t=.1),void 0===r&&(r=1e-6),void 0===n&&(n=100);for(var o=[],i=!1,p=!1,m=0;m<e.length;m++)o[m]=0===m?0:o[m-1]+365,e[m]>0&&(i=!0),e[m]<0&&(p=!0);if(!i||!p)return Number.NaN;var v,s,d,x=t,f=0,h=!0;do{v=x-(d=u(e,o,x))/a(e,o,x),s=Math.abs(v-x),x=v,h=s>r&&Math.abs(d)>r}while(h&&++f<n);return h?Number.NaN:x},exports.nper=function(e,t,r,n,o){if(void 0===n&&(n=0),void 0===o&&(o=exports.PaymentDueTime.End),0===e)return-(n+r)/t;var i=t*(1+e*(o===exports.PaymentDueTime.Begin?1:0))/e;return Math.log((-n+i)/(r+i))/Math.log(1+e)},exports.npv=function(e,t){return t.reduce((function(t,r,n){return t+r/Math.pow(1+e,n)}),0)},exports.pmt=r,exports.ppmt=function(e,t,o,i,u,a){return void 0===u&&(u=0),void 0===a&&(a=exports.PaymentDueTime.End),r(e,o,i,u,a)-n(e,t,o,i,u,a)},exports.pv=function(e,t,r,n,o){void 0===n&&(n=0),void 0===o&&(o=exports.PaymentDueTime.End);var i=o===exports.PaymentDueTime.Begin?1:0,u=0===e,a=Math.pow(1+e,t);return-(n+r*(u?t:(1+e*i)*(a-1)/e))/a},exports.rate=function(e,t,r,n,o,u,a,p){void 0===o&&(o=exports.PaymentDueTime.End),void 0===u&&(u=.1),void 0===a&&(a=1e-6),void 0===p&&(p=100);for(var m=u,v=0,s=!1;v<p&&!s;){var d=m-i(m,e,t,r,n,o);s=Math.abs(d-m)<a,v++,m=d}return s?m:Number.NaN};
//# sourceMappingURL=financial.cjs.production.min.js.map

@@ -368,1 +368,64 @@ /**

export declare function irr(values: number[], guess?: number, tol?: number, maxIter?: number): number;
/**
* Returns the NPV (Net Present Value) of a cash flow series.
*
* @param rate - The discount rate
* @param values - The values of the time series of cash flows. The (fixed) time
* interval between cash flow "events" must be the same as that for
* which `rate` is given (i.e., if `rate` is per year, then precisely
* a year is understood to elapse between each cash flow event). By
* convention, investments or "deposits" are negative, income or
* "withdrawals" are positive; `values` must begin with the initial
* investment, thus `values[0]` will typically be negative.
* @returns The NPV of the input cash flow series `values` at the discount `rate`.
*
* ## Warnings
*
* `npv considers a series of cashflows starting in the present (t = 0).
* NPV can also be defined with a series of future cashflows, paid at the
* end, rather than the start, of each period. If future cashflows are used,
* the first cashflow `values[0]` must be zeroed and added to the net
* present value of the future cashflows. This is demonstrated in the
* examples.
*
* ## Notes
*
* Returns the result of:
*
* ```
* \\sum_{t=0}^{M-1}{\\frac{values_t}{(1+rate)^{t}}}
* ```
*
* ## Examples
*
* Consider a potential project with an initial investment of $40 000 and
* projected cashflows of $5 000, $8 000, $12 000 and $30 000 at the end of
* each period discounted at a rate of 8% per period. To find the project's
* net present value:
*
* ```javascript
* import {npv} from 'financial'
*
* const rate = 0.08
* const cashflows = [-40_000, 5000, 8000, 12000, 30000]
* npv(rate, cashflows) // 3065.2226681795255
* ```
*
* It may be preferable to split the projected cashflow into an initial
* investment and expected future cashflows. In this case, the value of
* the initial cashflow is zero and the initial investment is later added
* to the future cashflows net present value:
*
* ```javascript
* const initialCashflow = cashflows[0]
* cashflows[0] = 0
*
* npv(rate, cashflows) + initialCashflow // 3065.2226681795255
* ```
*
* ## References
*
* L. J. Gitman, "Principles of Managerial Finance, Brief,"
* 3rd ed., Addison-Wesley, 2003, pg. 346.
*/
export declare function npv(rate: number, values: number[]): number;

@@ -579,2 +579,70 @@ /**

/**
* Returns the NPV (Net Present Value) of a cash flow series.
*
* @param rate - The discount rate
* @param values - The values of the time series of cash flows. The (fixed) time
* interval between cash flow "events" must be the same as that for
* which `rate` is given (i.e., if `rate` is per year, then precisely
* a year is understood to elapse between each cash flow event). By
* convention, investments or "deposits" are negative, income or
* "withdrawals" are positive; `values` must begin with the initial
* investment, thus `values[0]` will typically be negative.
* @returns The NPV of the input cash flow series `values` at the discount `rate`.
*
* ## Warnings
*
* `npv considers a series of cashflows starting in the present (t = 0).
* NPV can also be defined with a series of future cashflows, paid at the
* end, rather than the start, of each period. If future cashflows are used,
* the first cashflow `values[0]` must be zeroed and added to the net
* present value of the future cashflows. This is demonstrated in the
* examples.
*
* ## Notes
*
* Returns the result of:
*
* ```
* \\sum_{t=0}^{M-1}{\\frac{values_t}{(1+rate)^{t}}}
* ```
*
* ## Examples
*
* Consider a potential project with an initial investment of $40 000 and
* projected cashflows of $5 000, $8 000, $12 000 and $30 000 at the end of
* each period discounted at a rate of 8% per period. To find the project's
* net present value:
*
* ```javascript
* import {npv} from 'financial'
*
* const rate = 0.08
* const cashflows = [-40_000, 5000, 8000, 12000, 30000]
* npv(rate, cashflows) // 3065.2226681795255
* ```
*
* It may be preferable to split the projected cashflow into an initial
* investment and expected future cashflows. In this case, the value of
* the initial cashflow is zero and the initial investment is later added
* to the future cashflows net present value:
*
* ```javascript
* const initialCashflow = cashflows[0]
* cashflows[0] = 0
*
* npv(rate, cashflows) + initialCashflow // 3065.2226681795255
* ```
*
* ## References
*
* L. J. Gitman, "Principles of Managerial Finance, Brief,"
* 3rd ed., Addison-Wesley, 2003, pg. 346.
*/
function npv(rate, values) {
return values.reduce(function (acc, curr, i) {
return acc + curr / Math.pow(1 + rate, i);
}, 0);
}
/**
* This function is here to simply have a different name for the 'fv'

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

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

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

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

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

@@ -92,3 +92,3 @@ # Financial

- [X] `irr`
- [ ] `npv`
- [X] `npv`
- [ ] `mirr`

@@ -95,0 +95,0 @@

@@ -506,2 +506,71 @@ /**

/**
* Returns the NPV (Net Present Value) of a cash flow series.
*
* @param rate - The discount rate
* @param values - The values of the time series of cash flows. The (fixed) time
* interval between cash flow "events" must be the same as that for
* which `rate` is given (i.e., if `rate` is per year, then precisely
* a year is understood to elapse between each cash flow event). By
* convention, investments or "deposits" are negative, income or
* "withdrawals" are positive; `values` must begin with the initial
* investment, thus `values[0]` will typically be negative.
* @returns The NPV of the input cash flow series `values` at the discount `rate`.
*
* ## Warnings
*
* `npv considers a series of cashflows starting in the present (t = 0).
* NPV can also be defined with a series of future cashflows, paid at the
* end, rather than the start, of each period. If future cashflows are used,
* the first cashflow `values[0]` must be zeroed and added to the net
* present value of the future cashflows. This is demonstrated in the
* examples.
*
* ## Notes
*
* Returns the result of:
*
* ```
* \\sum_{t=0}^{M-1}{\\frac{values_t}{(1+rate)^{t}}}
* ```
*
* ## Examples
*
* Consider a potential project with an initial investment of $40 000 and
* projected cashflows of $5 000, $8 000, $12 000 and $30 000 at the end of
* each period discounted at a rate of 8% per period. To find the project's
* net present value:
*
* ```javascript
* import {npv} from 'financial'
*
* const rate = 0.08
* const cashflows = [-40_000, 5000, 8000, 12000, 30000]
* npv(rate, cashflows) // 3065.2226681795255
* ```
*
* It may be preferable to split the projected cashflow into an initial
* investment and expected future cashflows. In this case, the value of
* the initial cashflow is zero and the initial investment is later added
* to the future cashflows net present value:
*
* ```javascript
* const initialCashflow = cashflows[0]
* cashflows[0] = 0
*
* npv(rate, cashflows) + initialCashflow // 3065.2226681795255
* ```
*
* ## References
*
* L. J. Gitman, "Principles of Managerial Finance, Brief,"
* 3rd ed., Addison-Wesley, 2003, pg. 346.
*/
export function npv (rate: number, values: number[]) : number {
return values.reduce(
(acc, curr, i) => acc + (curr / (1 + rate) ** i),
0
)
}
/**
* This function is here to simply have a different name for the 'fv'

@@ -508,0 +577,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