UNPKG

crit-maxfest

Version:

Criticide Application Library

2 lines (1 loc) 6.76 kB
!function(t,r){"object"==typeof exports&&"undefined"!=typeof module?r(exports,require("ramda")):"function"==typeof define&&define.amd?define(["exports","ramda"],r):r(t["crit-maxfest"]={},t.ramda)}(this,function(t,r){"use strict";var e="crit-maxfest",n="1.0.48",o="AGPL-3.0";var a,u=(function(t,r){var e=function(){};function n(t,r,e){for(var n=0,o=0,a=0;a<t.length;a++)n+=t[a]/Math.pow(1+e,r[a]);for(a=0;a<t.length;a++)o+=-t[a]*r[a]*Math.pow(1+e,-1-r[a]);return n/o}e.prototype.PV=function(t,r,e){e=void 0!==e?e:1;var n;t/=100;return n=r/Math.pow(1+t,e),Math.round(100*n)/100},e.prototype.FV=function(t,r,e){var n;t/=100;return n=r*Math.pow(1+t,e),Math.round(100*n)/100},e.prototype.NPV=function(t){t/=100;for(var r=arguments[1],e=2;e<arguments.length;e++)r+=arguments[e]/Math.pow(1+t,e-1);return Math.round(100*r)/100},e.prototype.IRR=function(t){var r,e,n=arguments,o=1;if(Array.prototype.slice.call(n).forEach(function(t){t>0&&(r=!0),t<0&&(e=!0)}),!r||!e)throw new Error("IRR requires at least one positive value and one negative value");return Math.round(100*function(t){for(var r=1;t(r)>0;)r+=1;for(;t(r)<0;)r-=.01;return r+.01}(function(t){if(++o>1e3)throw new Error("IRR can't find a result");for(var r=1+t/100,e=n[0],a=1;a<n.length;a++)e+=n[a]/Math.pow(r,a);return e}))/100},e.prototype.PP=function(t,r){if(0===t)return Math.abs(arguments[1])/arguments[2];var e=arguments[1],n=1;for(i=2;i<arguments.length;i++){if((e+=arguments[i])>0)return n+=(e-arguments[i])/arguments[i];n++}},e.prototype.ROI=function(t,r){var e=(r-Math.abs(t))/Math.abs(t)*100;return Math.round(100*e)/100},e.prototype.AM=function(t,r,e,n,o){var a,u,i,p=r/12/100;return n?1===n?(a=f(e),u=Math.pow(1+p,e)-1):console.log("not defined"):(a=f(12*e),u=Math.pow(1+p,12*e)-1),i=t*(a/u),Math.round(100*i)/100;function f(t){return o&&(t-=1),p*Math.pow(1+p,t)}},e.prototype.PI=function(t,r){for(var e,n=0,o=2;o<arguments.length;o++){var a;a=1/Math.pow(1+t/100,o-1),n+=arguments[o]*a}return e=n/Math.abs(arguments[1]),Math.round(100*e)/100},e.prototype.DF=function(t,r){for(var e,n=[],o=1;o<r;o++)e=1/Math.pow(1+t/100,o-1),roundedDiscountFactor=Math.ceil(1e3*e)/1e3,n.push(roundedDiscountFactor);return n},e.prototype.CI=function(t,r,e,n){var o=e*Math.pow(1+t/100/r,r*n);return Math.round(100*o)/100},e.prototype.CAGR=function(t,r,e){var n=Math.pow(r/t,1/e)-1;return Math.round(1e4*n)/100},e.prototype.LR=function(t,r,e){return(t+r)/e},e.prototype.R72=function(t){return 72/t},e.prototype.WACC=function(t,r,e,n,o){E=t,D=r,V=t+r,Re=e,Rd=n,T=o;var a=E/V*Re/100+D/V*Rd/100*(1-T/100);return Math.round(1e3*a)/10},e.prototype.PMT=function(t,r,e){return-e*t/(1-Math.pow(1+t,-r))},e.prototype.IAR=function(t,r){return 100*((1+t)/(1+r)-1)},e.prototype.XIRR=function(t,r,e){if(t.length!=r.length)throw new Error("Number of cash flows and dates should match");var o,a;if(Array.prototype.slice.call(t).forEach(function(t){t>0&&(o=!0),t<0&&(a=!0)}),!o||!a)throw new Error("XIRR requires at least one positive value and one negative value");e=e||0;var u,i,p,f=100,h=[];h.push(0);for(var c=1;c<r.length;c++)h.push((i=r[0],p=r[c],Math.abs(p.getTime()-i.getTime())/31536e6));do{e=(u=e)-n(t,h,u),f--}while(u.toFixed(5)!=e.toFixed(5)&&f>0);var s=u.toFixed(5)!=e.toFixed(5)?null:100*e;return Math.round(100*s)/100},t.exports&&(t.exports=e,t.exports.Finance=e)}(a={exports:{}},a.exports),a.exports),p=(u.Finance,Math.random);function f(t,r){return t<r?-1:t>r?1:t>=r?0:NaN}var h,c;1===(h=f).length&&(c=h,h=function(t,r){return f(c(t),r)});var s=function(t){if(Array.isArray(t)){for(var r=0,e=Array(t.length);r<t.length;r++)e[r]=t[r];return e}return Array.from(t)},v=new u,d=function(t,e,n){var o=new u,a=Array(n).fill(e/n),i=1===Math.sign(t)?-1*t:t,p=r.prepend(i,a);try{o.IRR.apply(o,s(p))}catch(t){var f;(f=console).log.apply(f,[t.message].concat(s(p),[e]))}return o.IRR.apply(o,s(p))},M=function(t,r){var e,n,o,a,u,i,f=l(t);return(e=f.mean,n=f.stdDev,u=NaN,i={mean:function(t){return arguments.length?(o=t||0,u=NaN,i):o},stdev:function(t){return arguments.length?(a=null==t?1:t,u=NaN,i):a},sample:function(){var t,r,e=0,n=0;if(u==u)return e=u,u=NaN,e;do{t=(e=2*p()-1)*e+(n=2*p()-1)*n}while(0===t||t>1);return r=Math.sqrt(-2*Math.log(t)/t),u=o+n*r*a,o+e*r*a},pdf:function(t){var r=Math.exp(Math.pow(t-o,2)/(-2*Math.pow(a,2)));return 1/(a*Math.sqrt(2*Math.PI))*r},cdf:function(t){var r,e=(t-o)/a,n=Math.abs(e);if(n>37)r=0;else{var u=Math.exp(-n*n/2);n<7.07106781186547?(r=u*((((((.0352624965998911*n+.700383064443688)*n+6.37396220353165)*n+33.912866078383)*n+112.079291497871)*n+221.213596169931)*n+220.206867912376),r/=((((((.0883883476483184*n+1.75566716318264)*n+16.064177579207)*n+86.7807322029461)*n+296.564248779674)*n+637.333633378831)*n+793.826512519948)*n+440.413735824752):r=u/(n+1/(n+2/(n+3/(n+4/(n+.65)))))/2.506628274631}return e>0?1-r:r},icdf:function(t){if(t<=0||t>=1)return NaN;var r=2*t-1,e=8*(Math.PI-3)/(3*Math.PI*(4-Math.PI)),n=2/(Math.PI*e)+Math.log(1-Math.pow(r,2))/2,u=Math.log(1-r*r)/e,i=(r>0?1:-1)*Math.sqrt(Math.sqrt(n*n-u)-n);return o+a*Math.SQRT2*i}},i.mean(e).stdev(n)).icdf(r)},l=function(t){var e=!(arguments.length>1&&void 0!==arguments[1])||arguments[1],n=2===t.length&&e?r.prepend((Math.max.apply(Math,s(t))-Math.min.apply(Math,s(t)))/2,t):t,o=r.reduce(function(t,r){var e=t.sum+r,n=t.count+1,o=r*r,a=e/n,u=t.sqSum+o;return{mean:a,stDev:Math.sqrt(u/n-a*a),count:n,sum:e,sqSum:u}},{mean:0,stDev:0,sum:0,count:0,sqSum:0},n);return Object.freeze({mean:o.mean,count:o.count,stdDev:o.stDev})},g=function(t,r){var e=t>1?t/100:t,n=e*(r>1?r/100:r);return Object.freeze({target:e,upperBoundary:e+n,lowerBoundary:e-n})},y=function(t){return function(r){return r>=t.lowerBoundary&&r<=t.upperBoundary}},m=function(t){return function(r){return(t.target-r)/t.target}},w=function(t,r,e){for(var n,o,a,u,i,p,f=y(g(e,.01)),h=m(g(e,.01)),c=0,s=(n=t,a=(o=e)<1?100*o:o,v.PV(a,n)),M=!0;M;){var l=d(s,t,r)/100;f(l)?(c=s,M=!1):(u=s,i=h(l),void 0,p=u*Math.abs(i),s=Math.sign(i)<0?u+p:u-p)}return c},R=function(t,r,e,n){for(var o,a,u,i,p,f,h,c=y(g(e,.02)),s=m(g(e,.02)),M=(o=t,u=r/12,i=(a=e)<1?100*a:a,v.FV(i,o,u)),l=0,w=M+M*n,R=!0,x=w,I=0;R;)if(c(I=d(t,w,r)/100))l=w,R=!1;else{var b=(p=x,f=s(I),void 0,h=p*Math.abs(f),Math.sign(f)<0?p-h:p+h);x=b,w=b+b*n}return l},x=Object.freeze({invested:0,margin:.33,period:48,revenue:0,revProb:.5,target:.25});t.version=function(){return e+" - Version "+n+" - License "+o},t.solveForInvestment=function(t){var e=r.mergeDeepLeft(t,x),n=M(e.revenue,e.revProb),o=w(n,e.period,e.target);return{revenue:n,period:e.period,return:e.target,investment:o}},t.solveForRevenue=function(t){var e=r.mergeDeepLeft(t,x);return{revenue:R(e.invested,e.period,e.target,e.margin),period:e.period,return:e.target,investment:e.invested}},Object.defineProperty(t,"__esModule",{value:!0})});