formulab 0.12.0 → 0.13.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +21 -0
- package/dist/machining/effectiveDiameter.d.ts +12 -3
- package/dist/machining/effectiveDiameter.d.ts.map +1 -1
- package/dist/machining/effectiveDiameter.js +35 -7
- package/dist/machining/effectiveDiameter.js.map +1 -1
- package/dist/machining/types.d.ts +3 -1
- package/dist/machining/types.d.ts.map +1 -1
- package/dist/quality/controlChart.d.ts +6 -1
- package/dist/quality/controlChart.d.ts.map +1 -1
- package/dist/quality/controlChart.js +78 -1
- package/dist/quality/controlChart.js.map +1 -1
- package/dist/quality/lineBalancing.js +5 -4
- package/dist/quality/lineBalancing.js.map +1 -1
- package/dist/quality/types.d.ts +1 -1
- package/dist/quality/types.d.ts.map +1 -1
- package/dist/utility/assignment.d.ts +3 -2
- package/dist/utility/assignment.d.ts.map +1 -1
- package/dist/utility/assignment.js +5 -3
- package/dist/utility/assignment.js.map +1 -1
- package/dist/utility/bilinearInterpolation.d.ts +9 -1
- package/dist/utility/bilinearInterpolation.d.ts.map +1 -1
- package/dist/utility/bilinearInterpolation.js +20 -6
- package/dist/utility/bilinearInterpolation.js.map +1 -1
- package/dist/utility/correlation.d.ts +8 -1
- package/dist/utility/correlation.d.ts.map +1 -1
- package/dist/utility/correlation.js +13 -2
- package/dist/utility/correlation.js.map +1 -1
- package/dist/utility/depreciation.d.ts +9 -1
- package/dist/utility/depreciation.d.ts.map +1 -1
- package/dist/utility/depreciation.js +18 -5
- package/dist/utility/depreciation.js.map +1 -1
- package/dist/utility/histogram.d.ts +8 -1
- package/dist/utility/histogram.d.ts.map +1 -1
- package/dist/utility/histogram.js +29 -9
- package/dist/utility/histogram.js.map +1 -1
- package/dist/utility/lcc.d.ts +9 -1
- package/dist/utility/lcc.d.ts.map +1 -1
- package/dist/utility/lcc.js +17 -4
- package/dist/utility/lcc.js.map +1 -1
- package/dist/utility/linearInterpolation.d.ts +9 -1
- package/dist/utility/linearInterpolation.d.ts.map +1 -1
- package/dist/utility/linearInterpolation.js +17 -2
- package/dist/utility/linearInterpolation.js.map +1 -1
- package/dist/utility/movingAverage.d.ts +9 -1
- package/dist/utility/movingAverage.d.ts.map +1 -1
- package/dist/utility/movingAverage.js +18 -3
- package/dist/utility/movingAverage.js.map +1 -1
- package/dist/utility/normalize.d.ts +8 -1
- package/dist/utility/normalize.d.ts.map +1 -1
- package/dist/utility/normalize.js +11 -3
- package/dist/utility/normalize.js.map +1 -1
- package/dist/utility/npv.d.ts +9 -1
- package/dist/utility/npv.d.ts.map +1 -1
- package/dist/utility/npv.js +17 -4
- package/dist/utility/npv.js.map +1 -1
- package/dist/utility/percentile.d.ts +8 -1
- package/dist/utility/percentile.d.ts.map +1 -1
- package/dist/utility/percentile.js +13 -4
- package/dist/utility/percentile.js.map +1 -1
- package/dist/utility/regression.d.ts +9 -1
- package/dist/utility/regression.d.ts.map +1 -1
- package/dist/utility/regression.js +20 -4
- package/dist/utility/regression.js.map +1 -1
- package/dist/utility/roi.d.ts +8 -1
- package/dist/utility/roi.d.ts.map +1 -1
- package/dist/utility/roi.js +16 -2
- package/dist/utility/roi.js.map +1 -1
- package/dist/utility/statistics.d.ts +8 -1
- package/dist/utility/statistics.d.ts.map +1 -1
- package/dist/utility/statistics.js +10 -2
- package/dist/utility/statistics.js.map +1 -1
- package/dist/utility/types.d.ts +1 -0
- package/dist/utility/types.d.ts.map +1 -1
- package/dist/utility/unit.d.ts +4 -2
- package/dist/utility/unit.d.ts.map +1 -1
- package/dist/utility/unit.js +12 -5
- package/dist/utility/unit.js.map +1 -1
- package/dist/utility/weightedScore.d.ts +10 -1
- package/dist/utility/weightedScore.d.ts.map +1 -1
- package/dist/utility/weightedScore.js +30 -12
- package/dist/utility/weightedScore.js.map +1 -1
- package/package.json +1 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"correlation.d.ts","sourceRoot":"","sources":["../../src/utility/correlation.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,gBAAgB,EAAE,iBAAiB,EAAE,MAAM,YAAY,CAAC;AAEtE,wBAAgB,WAAW,CAAC,KAAK,EAAE,gBAAgB,GAAG,iBAAiB,
|
|
1
|
+
{"version":3,"file":"correlation.d.ts","sourceRoot":"","sources":["../../src/utility/correlation.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,gBAAgB,EAAE,iBAAiB,EAAE,MAAM,YAAY,CAAC;AAEtE;;;;;;GAMG;AACH,wBAAgB,WAAW,CAAC,KAAK,EAAE,gBAAgB,GAAG,iBAAiB,CAmCtE"}
|
|
@@ -1,8 +1,19 @@
|
|
|
1
1
|
import { roundTo } from '../utils.js';
|
|
2
|
+
/**
|
|
3
|
+
* Pearson correlation coefficient between two equal-length samples.
|
|
4
|
+
*
|
|
5
|
+
* @param input - Paired samples x and y
|
|
6
|
+
* @returns Correlation coefficient r, r-squared, and sample size n
|
|
7
|
+
* @throws RangeError if x and y lengths differ or contain fewer than 2 points
|
|
8
|
+
*/
|
|
2
9
|
export function correlation(input) {
|
|
3
10
|
const { x, y } = input;
|
|
4
|
-
if (!x || !y || x.length !== y.length
|
|
5
|
-
|
|
11
|
+
if (!x || !y || x.length !== y.length) {
|
|
12
|
+
throw new RangeError(`x and y must have the same length, got ${x?.length ?? 0} and ${y?.length ?? 0}`);
|
|
13
|
+
}
|
|
14
|
+
if (x.length < 2) {
|
|
15
|
+
throw new RangeError(`x and y must contain at least 2 points, got ${x.length}`);
|
|
16
|
+
}
|
|
6
17
|
const n = x.length;
|
|
7
18
|
const meanX = x.reduce((a, v) => a + v, 0) / n;
|
|
8
19
|
const meanY = y.reduce((a, v) => a + v, 0) / n;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"correlation.js","sourceRoot":"","sources":["../../src/utility/correlation.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,aAAa,CAAC;AAGtC,MAAM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AAC,CAAC;IACd,IAAI,KAAK,GAAG,CAAC,CAAC;IAEd,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,CAAC,EAAE,CAAC,EAAE,EAAE,CAAC;QAC3B,MAAM,EAAE,GAAG,CAAC,CAAC,CAAC,CAAC,GAAG,KAAK,CAAC;QACxB,MAAM,EAAE,GAAG,CAAC,CAAC,CAAC,CAAC,GAAG,KAAK,CAAC;QACxB,KAAK,IAAI,EAAE,GAAG,EAAE,CAAC;QACjB,KAAK,IAAI,EAAE,GAAG,EAAE,CAAC;QACjB,KAAK,IAAI,EAAE,GAAG,EAAE,CAAC;IACnB,CAAC;IAED,MAAM,KAAK,GAAG,IAAI,CAAC,IAAI,CAAC,KAAK,GAAG,KAAK,CAAC,CAAC;IACvC,IAAI,KAAK,KAAK,CAAC;QAAE,OAAO,EAAE,CAAC,EAAE,CAAC,EAAE,EAAE,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC;IAE3C,MAAM,CAAC,GAAG,KAAK,GAAG,KAAK,CAAC;IAExB,OAAO;QACL,CAAC,EAAE,OAAO,CAAC,CAAC,EAAE,CAAC,CAAC;QAChB,EAAE,EAAE,OAAO,CAAC,CAAC,GAAG,CAAC,EAAE,CAAC,CAAC;QACrB,CAAC;KACF,CAAC;AACJ,CAAC"}
|
|
@@ -1,3 +1,11 @@
|
|
|
1
1
|
import type { DepreciationInput, DepreciationResult } from './types.js';
|
|
2
|
-
|
|
2
|
+
/**
|
|
3
|
+
* Depreciation schedule by straight-line or declining-balance method.
|
|
4
|
+
*
|
|
5
|
+
* @param input - Asset cost, salvage value, useful life, and method
|
|
6
|
+
* @returns Annual depreciation, year-by-year schedule, and total depreciation
|
|
7
|
+
* @throws RangeError if assetCost <= 0, salvageValue < 0, usefulLife <= 0,
|
|
8
|
+
* salvageValue >= assetCost, or method is unknown
|
|
9
|
+
*/
|
|
10
|
+
export declare function depreciation(input: DepreciationInput): DepreciationResult;
|
|
3
11
|
//# sourceMappingURL=depreciation.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"depreciation.d.ts","sourceRoot":"","sources":["../../src/utility/depreciation.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,iBAAiB,EAAE,kBAAkB,EAAyB,MAAM,YAAY,CAAC;AAE/F,wBAAgB,YAAY,CAAC,KAAK,EAAE,iBAAiB,GAAG,kBAAkB,
|
|
1
|
+
{"version":3,"file":"depreciation.d.ts","sourceRoot":"","sources":["../../src/utility/depreciation.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,iBAAiB,EAAE,kBAAkB,EAAyB,MAAM,YAAY,CAAC;AAE/F;;;;;;;GAOG;AACH,wBAAgB,YAAY,CAAC,KAAK,EAAE,iBAAiB,GAAG,kBAAkB,CAgBzE"}
|
|
@@ -1,17 +1,30 @@
|
|
|
1
1
|
import { roundTo } from '../utils.js';
|
|
2
|
+
/**
|
|
3
|
+
* Depreciation schedule by straight-line or declining-balance method.
|
|
4
|
+
*
|
|
5
|
+
* @param input - Asset cost, salvage value, useful life, and method
|
|
6
|
+
* @returns Annual depreciation, year-by-year schedule, and total depreciation
|
|
7
|
+
* @throws RangeError if assetCost <= 0, salvageValue < 0, usefulLife <= 0,
|
|
8
|
+
* salvageValue >= assetCost, or method is unknown
|
|
9
|
+
*/
|
|
2
10
|
export function depreciation(input) {
|
|
3
11
|
const { assetCost, salvageValue, usefulLife, method } = input;
|
|
4
|
-
if (assetCost <= 0
|
|
5
|
-
|
|
6
|
-
if (salvageValue
|
|
7
|
-
|
|
12
|
+
if (assetCost <= 0)
|
|
13
|
+
throw new RangeError(`assetCost must be > 0, got ${assetCost}`);
|
|
14
|
+
if (salvageValue < 0)
|
|
15
|
+
throw new RangeError(`salvageValue must be >= 0, got ${salvageValue}`);
|
|
16
|
+
if (usefulLife <= 0)
|
|
17
|
+
throw new RangeError(`usefulLife must be > 0, got ${usefulLife}`);
|
|
18
|
+
if (salvageValue >= assetCost) {
|
|
19
|
+
throw new RangeError(`salvageValue must be less than assetCost, got salvageValue=${salvageValue}, assetCost=${assetCost}`);
|
|
20
|
+
}
|
|
8
21
|
if (method === 'straight-line') {
|
|
9
22
|
return straightLine(assetCost, salvageValue, usefulLife);
|
|
10
23
|
}
|
|
11
24
|
if (method === 'declining-balance') {
|
|
12
25
|
return decliningBalance(assetCost, salvageValue, usefulLife);
|
|
13
26
|
}
|
|
14
|
-
|
|
27
|
+
throw new RangeError(`method must be 'straight-line' or 'declining-balance', got ${String(method)}`);
|
|
15
28
|
}
|
|
16
29
|
function straightLine(cost, salvage, life) {
|
|
17
30
|
const annual = (cost - salvage) / life;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"depreciation.js","sourceRoot":"","sources":["../../src/utility/depreciation.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,aAAa,CAAC;AAGtC,MAAM,UAAU,YAAY,CAAC,KAAwB;IACnD,MAAM,EAAE,SAAS,EAAE,YAAY,EAAE,UAAU,EAAE,MAAM,EAAE,GAAG,KAAK,CAAC;IAC9D,IAAI,SAAS,IAAI,CAAC,IAAI,YAAY,GAAG,CAAC,IAAI,UAAU,IAAI,CAAC;QAAE,
|
|
1
|
+
{"version":3,"file":"depreciation.js","sourceRoot":"","sources":["../../src/utility/depreciation.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,aAAa,CAAC;AAGtC;;;;;;;GAOG;AACH,MAAM,UAAU,YAAY,CAAC,KAAwB;IACnD,MAAM,EAAE,SAAS,EAAE,YAAY,EAAE,UAAU,EAAE,MAAM,EAAE,GAAG,KAAK,CAAC;IAC9D,IAAI,SAAS,IAAI,CAAC;QAAE,MAAM,IAAI,UAAU,CAAC,8BAA8B,SAAS,EAAE,CAAC,CAAC;IACpF,IAAI,YAAY,GAAG,CAAC;QAAE,MAAM,IAAI,UAAU,CAAC,kCAAkC,YAAY,EAAE,CAAC,CAAC;IAC7F,IAAI,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C,CAAC;AACJ,CAAC;AAED,SAAS,gBAAgB,CAAC,IAAY,EAAE,OAAe,EAAE,IAAY;IACnE,MAAM,IAAI,GAAG,CAAC,GAAG,CAAC,OAAO,GAAG,IAAI,CAAC,IAAI,CAAC,CAAC,GAAG,IAAI,CAAC,CAAC;IAChD,MAAM,QAAQ,GAA4B,EAAE,CAAC;IAC7C,IAAI,SAAS,GAAG,IAAI,CAAC;IACrB,IAAI,WAAW,GAAG,CAAC,CAAC;IAEpB,KAAK,IAAI,IAAI,GAAG,CAAC,EAAE,IAAI,IAAI,IAAI,EAAE,IAAI,EAAE,EAAE,CAAC;QACxC,MAAM,GAAG,GAAG,IAAI,KAAK,IAAI;YACvB,CAAC,CAAC,SAAS,GAAG,OAAO,CAAC,oCAAoC;YAC1D,CAAC,CAAC,SAAS,GAAG,IAAI,CAAC;QACrB,WAAW,IAAI,GAAG,CAAC;QACnB,SAAS,IAAI,GAAG,CAAC;QAEjB,QAAQ,CAAC,IAAI,CAAC;YACZ,IAAI;YACJ,YAAY,EAAE,OAAO,CAAC,GAAG,EAAE,CAAC,CAAC;YAC7B,uBAAuB,EAAE,OAAO,CAAC,WAAW,EAAE,CAAC,CAAC;YAChD,SAAS,EAAE,OAAO,CAAC,SAAS,EAAE,CAAC,CAAC;SACjC,CAAC,CAAC;IACL,CAAC;IAED,OAAO;QACL,kBAAkB,EAAE,OAAO,CAAC,QAAQ,CAAC,CAAC,CAAC,CAAC,YAAY,EAAE,CAAC,CAAC;QACxD,QAAQ;QACR,iBAAiB,EAAE,OAAO,CAAC,IAAI,GAAG,OAAO,EAAE,CAAC,CAAC;KAC9C,CAAC;AACJ,CAAC"}
|
|
@@ -1,3 +1,10 @@
|
|
|
1
1
|
import type { HistogramInput, HistogramResult } from './types.js';
|
|
2
|
-
|
|
2
|
+
/**
|
|
3
|
+
* Histogram binning with optional explicit bin count (Sturges' rule by default) and range.
|
|
4
|
+
*
|
|
5
|
+
* @param input - Data values, optional bin count, optional [min, max] range
|
|
6
|
+
* @returns Bins with counts/frequencies, bin width, and total count
|
|
7
|
+
* @throws RangeError if data is empty or bins < 1
|
|
8
|
+
*/
|
|
9
|
+
export declare function histogram(input: HistogramInput): HistogramResult;
|
|
3
10
|
//# sourceMappingURL=histogram.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"histogram.d.ts","sourceRoot":"","sources":["../../src/utility/histogram.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,cAAc,EAAE,eAAe,EAAgB,MAAM,YAAY,CAAC;AAEhF,wBAAgB,SAAS,CAAC,KAAK,EAAE,cAAc,GAAG,eAAe,
|
|
1
|
+
{"version":3,"file":"histogram.d.ts","sourceRoot":"","sources":["../../src/utility/histogram.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,cAAc,EAAE,eAAe,EAAgB,MAAM,YAAY,CAAC;AAEhF;;;;;;GAMG;AACH,wBAAgB,SAAS,CAAC,KAAK,EAAE,cAAc,GAAG,eAAe,CAwDhE"}
|
|
@@ -1,18 +1,36 @@
|
|
|
1
1
|
import { roundTo } from '../utils.js';
|
|
2
|
+
/**
|
|
3
|
+
* Histogram binning with optional explicit bin count (Sturges' rule by default) and range.
|
|
4
|
+
*
|
|
5
|
+
* @param input - Data values, optional bin count, optional [min, max] range
|
|
6
|
+
* @returns Bins with counts/frequencies, bin width, and total count
|
|
7
|
+
* @throws RangeError if data is empty or bins < 1
|
|
8
|
+
*/
|
|
2
9
|
export function histogram(input) {
|
|
3
10
|
const { data } = input;
|
|
4
|
-
if (!data || data.length === 0)
|
|
5
|
-
|
|
11
|
+
if (!data || data.length === 0) {
|
|
12
|
+
throw new RangeError('data must contain at least one value');
|
|
13
|
+
}
|
|
6
14
|
const n = data.length;
|
|
7
15
|
// Sturges' rule for default bin count
|
|
8
16
|
const numBins = input.bins ?? Math.max(1, Math.ceil(Math.log2(n) + 1));
|
|
9
|
-
if (numBins < 1)
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
17
|
+
if (numBins < 1) {
|
|
18
|
+
throw new RangeError(`bins must be >= 1, got ${numBins}`);
|
|
19
|
+
}
|
|
20
|
+
// Use explicit range when provided and valid; fall back to data-derived min/max
|
|
21
|
+
let min;
|
|
22
|
+
let max;
|
|
23
|
+
if (input.range && input.range[1] > input.range[0]) {
|
|
24
|
+
min = input.range[0];
|
|
25
|
+
max = input.range[1];
|
|
26
|
+
}
|
|
27
|
+
else {
|
|
28
|
+
min = Math.min(...data);
|
|
29
|
+
max = Math.max(...data);
|
|
30
|
+
}
|
|
13
31
|
// Handle case where all values are identical
|
|
14
|
-
const
|
|
15
|
-
const binWidth =
|
|
32
|
+
const span = max - min;
|
|
33
|
+
const binWidth = span === 0 ? 1 : span / numBins;
|
|
16
34
|
const bins = [];
|
|
17
35
|
for (let i = 0; i < numBins; i++) {
|
|
18
36
|
const lower = min + i * binWidth;
|
|
@@ -25,7 +43,9 @@ export function histogram(input) {
|
|
|
25
43
|
});
|
|
26
44
|
}
|
|
27
45
|
for (const value of data) {
|
|
28
|
-
let idx =
|
|
46
|
+
let idx = span === 0 ? 0 : Math.floor((value - min) / binWidth);
|
|
47
|
+
if (idx < 0)
|
|
48
|
+
idx = 0; // clamp values below min into first bin
|
|
29
49
|
if (idx >= numBins)
|
|
30
50
|
idx = numBins - 1; // include max in last bin
|
|
31
51
|
bins[idx].count++;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"histogram.js","sourceRoot":"","sources":["../../src/utility/histogram.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,aAAa,CAAC;AAGtC,MAAM,UAAU,SAAS,CAAC,KAAqB;IAC7C,MAAM,EAAE,IAAI,EAAE,GAAG,KAAK,CAAC;IACvB,IAAI,CAAC,IAAI,IAAI,IAAI,CAAC,MAAM,KAAK,CAAC;
|
|
1
|
+
{"version":3,"file":"histogram.js","sourceRoot":"","sources":["../../src/utility/histogram.ts"],"names":[],"mappings":"AAAA,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E,CAAC;KACd,CAAC;AACJ,CAAC"}
|
package/dist/utility/lcc.d.ts
CHANGED
|
@@ -1,3 +1,11 @@
|
|
|
1
1
|
import type { LccInput, LccResult } from './types.js';
|
|
2
|
-
|
|
2
|
+
/**
|
|
3
|
+
* Calculate life cycle cost (LCC) with present-value discounting
|
|
4
|
+
*
|
|
5
|
+
* @param input - LCC input parameters
|
|
6
|
+
* @returns LCC result with total cost, present values, and annual equivalent cost
|
|
7
|
+
* @throws RangeError if initialCost is negative, lifespan is not positive,
|
|
8
|
+
* or discountRate is outside [0, 1)
|
|
9
|
+
*/
|
|
10
|
+
export declare function lcc(input: LccInput): LccResult;
|
|
3
11
|
//# sourceMappingURL=lcc.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"lcc.d.ts","sourceRoot":"","sources":["../../src/utility/lcc.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,QAAQ,EAAE,SAAS,EAAE,MAAM,YAAY,CAAC;AAEtD,wBAAgB,GAAG,CAAC,KAAK,EAAE,QAAQ,GAAG,SAAS,
|
|
1
|
+
{"version":3,"file":"lcc.d.ts","sourceRoot":"","sources":["../../src/utility/lcc.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,QAAQ,EAAE,SAAS,EAAE,MAAM,YAAY,CAAC;AAEtD;;;;;;;GAOG;AACH,wBAAgB,GAAG,CAAC,KAAK,EAAE,QAAQ,GAAG,SAAS,CAiC9C"}
|
package/dist/utility/lcc.js
CHANGED
|
@@ -1,10 +1,23 @@
|
|
|
1
1
|
import { roundTo } from '../utils.js';
|
|
2
|
+
/**
|
|
3
|
+
* Calculate life cycle cost (LCC) with present-value discounting
|
|
4
|
+
*
|
|
5
|
+
* @param input - LCC input parameters
|
|
6
|
+
* @returns LCC result with total cost, present values, and annual equivalent cost
|
|
7
|
+
* @throws RangeError if initialCost is negative, lifespan is not positive,
|
|
8
|
+
* or discountRate is outside [0, 1)
|
|
9
|
+
*/
|
|
2
10
|
export function lcc(input) {
|
|
3
11
|
const { initialCost, annualOperatingCost, annualMaintenanceCost, disposalCost, lifespan, discountRate } = input;
|
|
4
|
-
if (initialCost < 0
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
12
|
+
if (initialCost < 0) {
|
|
13
|
+
throw new RangeError(`initialCost must be >= 0, got ${initialCost}`);
|
|
14
|
+
}
|
|
15
|
+
if (lifespan <= 0) {
|
|
16
|
+
throw new RangeError(`lifespan must be > 0, got ${lifespan}`);
|
|
17
|
+
}
|
|
18
|
+
if (discountRate < 0 || discountRate >= 1) {
|
|
19
|
+
throw new RangeError(`discountRate must be in [0, 1), got ${discountRate}`);
|
|
20
|
+
}
|
|
8
21
|
// Present value of annuity factor: (1 - (1+r)^-n) / r
|
|
9
22
|
const pvFactor = discountRate === 0
|
|
10
23
|
? lifespan
|
package/dist/utility/lcc.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"lcc.js","sourceRoot":"","sources":["../../src/utility/lcc.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,aAAa,CAAC;AAGtC,MAAM,UAAU,GAAG,CAAC,KAAe;IACjC,MAAM,EAAE,WAAW,EAAE,mBAAmB,EAAE,qBAAqB,EAAE,YAAY,EAAE,QAAQ,EAAE,YAAY,EAAE,GAAG,KAAK,CAAC;IAChH,IAAI,WAAW,GAAG,CAAC,IAAI,QAAQ,IAAI,CAAC;
|
|
1
|
+
{"version":3,"file":"lcc.js","sourceRoot":"","sources":["../../src/utility/lcc.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,aAAa,CAAC;AAGtC;;;;;;;GAOG;AACH,MAAM,UAAU,GAAG,CAAC,KAAe;IACjC,MAAM,EAAE,WAAW,EAAE,mBAAmB,EAAE,qBAAqB,EAAE,YAAY,EAAE,QAAQ,EAAE,YAAY,EAAE,GAAG,KAAK,CAAC;IAChH,IAAI,WAAW,GAAG,CAA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BAAoB,EAAE,CAAC,CAAC;KACvD,CAAC;AACJ,CAAC"}
|
|
@@ -1,3 +1,11 @@
|
|
|
1
1
|
import type { LinearInterpolationInput, LinearInterpolationResult } from './types.js';
|
|
2
|
-
|
|
2
|
+
/**
|
|
3
|
+
* Linear interpolation (and extrapolation) over a tabulated x/y series
|
|
4
|
+
*
|
|
5
|
+
* @param input - x/y table and target x value
|
|
6
|
+
* @returns Interpolated value with bracketing indices and extrapolation flag
|
|
7
|
+
* @throws RangeError if x or y is missing, x and y lengths differ,
|
|
8
|
+
* or fewer than 2 points are provided
|
|
9
|
+
*/
|
|
10
|
+
export declare function linearInterpolation(input: LinearInterpolationInput): LinearInterpolationResult;
|
|
3
11
|
//# sourceMappingURL=linearInterpolation.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"linearInterpolation.d.ts","sourceRoot":"","sources":["../../src/utility/linearInterpolation.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,wBAAwB,EAAE,yBAAyB,EAAE,MAAM,YAAY,CAAC;AAEtF,wBAAgB,mBAAmB,CAAC,KAAK,EAAE,wBAAwB,GAAG,yBAAyB,
|
|
1
|
+
{"version":3,"file":"linearInterpolation.d.ts","sourceRoot":"","sources":["../../src/utility/linearInterpolation.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,wBAAwB,EAAE,yBAAyB,EAAE,MAAM,YAAY,CAAC;AAEtF;;;;;;;GAOG;AACH,wBAAgB,mBAAmB,CAAC,KAAK,EAAE,wBAAwB,GAAG,yBAAyB,CAiD9F"}
|
|
@@ -1,8 +1,23 @@
|
|
|
1
1
|
import { roundTo } from '../utils.js';
|
|
2
|
+
/**
|
|
3
|
+
* Linear interpolation (and extrapolation) over a tabulated x/y series
|
|
4
|
+
*
|
|
5
|
+
* @param input - x/y table and target x value
|
|
6
|
+
* @returns Interpolated value with bracketing indices and extrapolation flag
|
|
7
|
+
* @throws RangeError if x or y is missing, x and y lengths differ,
|
|
8
|
+
* or fewer than 2 points are provided
|
|
9
|
+
*/
|
|
2
10
|
export function linearInterpolation(input) {
|
|
3
11
|
const { x, y, target } = input;
|
|
4
|
-
if (!x || !y
|
|
5
|
-
|
|
12
|
+
if (!x || !y) {
|
|
13
|
+
throw new RangeError('x and y arrays are required');
|
|
14
|
+
}
|
|
15
|
+
if (x.length !== y.length) {
|
|
16
|
+
throw new RangeError(`x and y must have the same length, got x.length=${x.length}, y.length=${y.length}`);
|
|
17
|
+
}
|
|
18
|
+
if (x.length < 2) {
|
|
19
|
+
throw new RangeError(`x must contain at least 2 points, got ${x.length}`);
|
|
20
|
+
}
|
|
6
21
|
// Find bracketing interval
|
|
7
22
|
let lowerIndex = 0;
|
|
8
23
|
let upperIndex = x.length - 1;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"linearInterpolation.js","sourceRoot":"","sources":["../../src/utility/linearInterpolation.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,aAAa,CAAC;AAGtC,MAAM,UAAU,mBAAmB,CAAC,KAA+B;IACjE,MAAM,EAAE,CAAC,EAAE,CAAC,EAAE,MAAM,EAAE,GAAG,KAAK,CAAC;IAC/B,IAAI,CAAC,CAAC,IAAI,CAAC,CAAC,IAAI,CAAC,CAAC,MAAM,KAAK,CAAC,CAAC,MAAM,IAAI,CAAC,CAAC,MAAM,GAAG,CAAC;
|
|
1
|
+
{"version":3,"file":"linearInterpolation.js","sourceRoot":"","sources":["../../src/utility/linearInterpolation.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,aAAa,CAAC;AAGtC;;;;;;;GAOG;AACH,MAAM,UAAU,mBAAmB,CAAC,KAA+B;IACjE,MAAM,EAAE,CAAC,EAAE,CAAC,EAAE,MAAM,EAAE,GAAG,KAAK,CAAC;IAC/B,IAAI,CAAC,CAAC,IAAI,CAAC,CAAC,EAAE,CAAC;QACb,MAAM,IAAI,UAAU,CAAC,6BAA6B,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,CAAC,CAAC;gBACf,UAAU,GAAG,CAAC,GAAG,CAAC,CAAC;gBACnB,MAAM;YACR,CAAC;QACH,CAAC;IACH,CAAC;IAED,MAAM,EAAE,GAAG,CAAC,CAAC,UAAU,CAAC,CAAC;IACzB,MAAM,EAAE,GAAG,CAAC,CAAC,UAAU,CAAC,CAAC;IACzB,MAAM,EAAE,GAAG,CAAC,CAAC,UAAU,CAAC,CAAC;IACzB,MAAM,EAAE,GAAG,CAAC,CAAC,UAAU,CAAC,CAAC;IAEzB,MAAM,CAAC,GAAG,EAAE,KAAK,EAAE,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,MAAM,GAAG,EAAE,CAAC,GAAG,CAAC,EAAE,GAAG,EAAE,CAAC,CAAC;IACpD,MAAM,KAAK,GAAG,EAAE,GAAG,CAAC,GAAG,CAAC,EAAE,GAAG,EAAE,CAAC,CAAC;IAEjC,OAAO;QACL,KAAK,EAAE,OAAO,CAAC,KAAK,EAAE,CAAC,CAAC;QACxB,UAAU;QACV,UAAU;QACV,eAAe;KAChB,CAAC;AACJ,CAAC"}
|
|
@@ -1,3 +1,11 @@
|
|
|
1
1
|
import type { MovingAverageInput, MovingAverageResult } from './types.js';
|
|
2
|
-
|
|
2
|
+
/**
|
|
3
|
+
* Calculate moving average (simple or exponential) over a data series
|
|
4
|
+
*
|
|
5
|
+
* @param input - Data series, window size, and method ('sma' | 'ema')
|
|
6
|
+
* @returns Moving average values
|
|
7
|
+
* @throws RangeError if data is empty, window is less than 1,
|
|
8
|
+
* window exceeds data length, or method is not 'sma' or 'ema'
|
|
9
|
+
*/
|
|
10
|
+
export declare function movingAverage(input: MovingAverageInput): MovingAverageResult;
|
|
3
11
|
//# sourceMappingURL=movingAverage.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"movingAverage.d.ts","sourceRoot":"","sources":["../../src/utility/movingAverage.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,kBAAkB,EAAE,mBAAmB,EAAE,MAAM,YAAY,CAAC;AAE1E,wBAAgB,aAAa,CAAC,KAAK,EAAE,kBAAkB,GAAG,mBAAmB,
|
|
1
|
+
{"version":3,"file":"movingAverage.d.ts","sourceRoot":"","sources":["../../src/utility/movingAverage.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,kBAAkB,EAAE,mBAAmB,EAAE,MAAM,YAAY,CAAC;AAE1E;;;;;;;GAOG;AACH,wBAAgB,aAAa,CAAC,KAAK,EAAE,kBAAkB,GAAG,mBAAmB,CAmB5E"}
|
|
@@ -1,15 +1,30 @@
|
|
|
1
1
|
import { roundTo } from '../utils.js';
|
|
2
|
+
/**
|
|
3
|
+
* Calculate moving average (simple or exponential) over a data series
|
|
4
|
+
*
|
|
5
|
+
* @param input - Data series, window size, and method ('sma' | 'ema')
|
|
6
|
+
* @returns Moving average values
|
|
7
|
+
* @throws RangeError if data is empty, window is less than 1,
|
|
8
|
+
* window exceeds data length, or method is not 'sma' or 'ema'
|
|
9
|
+
*/
|
|
2
10
|
export function movingAverage(input) {
|
|
3
11
|
const { data, window, method } = input;
|
|
4
|
-
if (!data || data.length === 0
|
|
5
|
-
|
|
12
|
+
if (!data || data.length === 0) {
|
|
13
|
+
throw new RangeError('data must contain at least one value');
|
|
14
|
+
}
|
|
15
|
+
if (window < 1) {
|
|
16
|
+
throw new RangeError(`window must be >= 1, got ${window}`);
|
|
17
|
+
}
|
|
18
|
+
if (window > data.length) {
|
|
19
|
+
throw new RangeError(`window must be <= data length (${data.length}), got ${window}`);
|
|
20
|
+
}
|
|
6
21
|
if (method === 'sma') {
|
|
7
22
|
return { values: sma(data, window) };
|
|
8
23
|
}
|
|
9
24
|
if (method === 'ema') {
|
|
10
25
|
return { values: ema(data, window) };
|
|
11
26
|
}
|
|
12
|
-
|
|
27
|
+
throw new RangeError(`method must be 'sma' or 'ema', got ${String(method)}`);
|
|
13
28
|
}
|
|
14
29
|
function sma(data, window) {
|
|
15
30
|
const result = [];
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"movingAverage.js","sourceRoot":"","sources":["../../src/utility/movingAverage.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,aAAa,CAAC;AAGtC,MAAM,UAAU,aAAa,CAAC,KAAyB;IACrD,MAAM,EAAE,IAAI,EAAE,MAAM,EAAE,MAAM,EAAE,GAAG,KAAK,CAAC;IACvC,IAAI,CAAC,IAAI,IAAI,IAAI,CAAC,MAAM,KAAK,CAAC,IAAI,MAAM,GAAG,CAAC,IAAI,MAAM,GAAG,IAAI,CAAC,MAAM;
|
|
1
|
+
{"version":3,"file":"movingAverage.js","sourceRoot":"","sources":["../../src/utility/movingAverage.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,aAAa,CAAC;AAGtC;;;;;;;GAOG;AACH,MAAM,UAAU,aAAa,CAAC,KAAyB;IACrD,MAAM,EAAE,IAAI,EAAE,MAAM,EAAE,MAAM,EAAE,GAAG,KAAK,CAAC;IACvC,IAAI,CAAC,IAAI,IAAI,IAAI,CAAC,MAAM,KAAK,CAAC,EAAE,CAAC;QAC/B,MAAM,IAAI,UAAU,CAAC,sCAAsC,CAAC,CAAC;IAC/D,CAAC;IACD,IAAI,MAAM,GAAG,CAAC,EAAE,CAAC;QACf,MAAM,IAAI,UAAU,CAAC,4BAA4B,MAAM,EAAE,CAAC,CAAC;IAC7D,CAAC;IACD,IAAI,MAAM,GAAG,IAAI,CAAC,MAAM,EAAE,CAAC;QACzB,MAAM,IAAI,UAAU,CAAC,kCAAkC,IAAI,CAAC,MAAM,UAAU,MAAM,EAAE,CAAC,CAAC;IACxF,CAAC;IAED,IAAI,MAAM,KAAK,KAAK,EAAE,CAAC;QACrB,OAAO,EAAE,MAAM,EAAE,GAAG,CAAC,IAAI,EAAE,MAAM,CAAC,EAAE,CAAC;IACvC,CAAC;IACD,IAAI,MAAM,KAAK,KAAK,EAAE,CAAC;QACrB,OAAO,E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AAC,GAAG,IAAI,CAAC,MAAM,EAAE,CAAC,EAAE,EAAE,CAAC;QAC1C,IAAI,GAAG,IAAI,CAAC,CAAC,CAAC,GAAG,CAAC,GAAG,IAAI,GAAG,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC;QACpC,MAAM,CAAC,IAAI,CAAC,OAAO,CAAC,IAAI,EAAE,CAAC,CAAC,CAAC,CAAC;IAChC,CAAC;IACD,OAAO,MAAM,CAAC;AAChB,CAAC"}
|
|
@@ -1,3 +1,10 @@
|
|
|
1
1
|
import type { NormalizeInput, NormalizeResult } from './types.js';
|
|
2
|
-
|
|
2
|
+
/**
|
|
3
|
+
* Normalize a data series via min-max scaling or z-score standardization
|
|
4
|
+
*
|
|
5
|
+
* @param input - Data series and method ('min-max' | 'z-score')
|
|
6
|
+
* @returns Normalized values with min/max/mean/stdDev metadata
|
|
7
|
+
* @throws RangeError if data is empty or method is not 'min-max' or 'z-score'
|
|
8
|
+
*/
|
|
9
|
+
export declare function normalize(input: NormalizeInput): NormalizeResult;
|
|
3
10
|
//# sourceMappingURL=normalize.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"normalize.d.ts","sourceRoot":"","sources":["../../src/utility/normalize.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,cAAc,EAAE,eAAe,EAAE,MAAM,YAAY,CAAC;AAElE,wBAAgB,SAAS,CAAC,KAAK,EAAE,cAAc,GAAG,eAAe,
|
|
1
|
+
{"version":3,"file":"normalize.d.ts","sourceRoot":"","sources":["../../src/utility/normalize.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,cAAc,EAAE,eAAe,EAAE,MAAM,YAAY,CAAC;AAElE;;;;;;GAMG;AACH,wBAAgB,SAAS,CAAC,KAAK,EAAE,cAAc,GAAG,eAAe,CAmChE"}
|
|
@@ -1,8 +1,16 @@
|
|
|
1
1
|
import { roundTo } from '../utils.js';
|
|
2
|
+
/**
|
|
3
|
+
* Normalize a data series via min-max scaling or z-score standardization
|
|
4
|
+
*
|
|
5
|
+
* @param input - Data series and method ('min-max' | 'z-score')
|
|
6
|
+
* @returns Normalized values with min/max/mean/stdDev metadata
|
|
7
|
+
* @throws RangeError if data is empty or method is not 'min-max' or 'z-score'
|
|
8
|
+
*/
|
|
2
9
|
export function normalize(input) {
|
|
3
10
|
const { data, method } = input;
|
|
4
|
-
if (!data || data.length === 0)
|
|
5
|
-
|
|
11
|
+
if (!data || data.length === 0) {
|
|
12
|
+
throw new RangeError('data must contain at least one value');
|
|
13
|
+
}
|
|
6
14
|
const n = data.length;
|
|
7
15
|
const min = Math.min(...data);
|
|
8
16
|
const max = Math.max(...data);
|
|
@@ -22,7 +30,7 @@ export function normalize(input) {
|
|
|
22
30
|
: data.map((v) => roundTo((v - mean) / stdDev, 6));
|
|
23
31
|
}
|
|
24
32
|
else {
|
|
25
|
-
|
|
33
|
+
throw new RangeError(`method must be 'min-max' or 'z-score', got ${String(method)}`);
|
|
26
34
|
}
|
|
27
35
|
return {
|
|
28
36
|
values,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"normalize.js","sourceRoot":"","sources":["../../src/utility/normalize.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,aAAa,CAAC;AAGtC,MAAM,UAAU,SAAS,CAAC,KAAqB;IAC7C,MAAM,EAAE,IAAI,EAAE,MAAM,EAAE,GAAG,KAAK,CAAC;IAC/B,IAAI,CAAC,IAAI,IAAI,IAAI,CAAC,MAAM,KAAK,CAAC;
|
|
1
|
+
{"version":3,"file":"normalize.js","sourceRoot":"","sources":["../../src/utility/normalize.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,aAAa,CAAC;AAGtC;;;;;;GAMG;AACH,MAAM,UAAU,SAAS,CAAC,KAAqB;IAC7C,MAAM,EAAE,IAAI,EAAE,MAAM,EAAE,GAAG,KAAK,CAAC;IAC/B,IAAI,CAAC,IAAI,IAAI,IA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AC;YACnB,CAAC,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,OAAO,CAAC,CAAC,CAAC,GAAG,IAAI,CAAC,GAAG,MAAM,EAAE,CAAC,CAAC,CAAC,CAAC;IACvD,CAAC;SAAM,CAAC;QACN,MAAM,IAAI,UAAU,CAAC,8CAA8C,MAAM,CAAC,MAAM,CAAC,EAAE,CAAC,CAAC;IACvF,CAAC;IAED,OAAO;QACL,MAAM;QACN,GAAG,EAAE,OAAO,CAAC,GAAG,EAAE,CAAC,CAAC;QACpB,GAAG,EAAE,OAAO,CAAC,GAAG,EAAE,CAAC,CAAC;QACpB,IAAI,EAAE,OAAO,CAAC,IAAI,EAAE,CAAC,CAAC;QACtB,MAAM,EAAE,OAAO,CAAC,MAAM,EAAE,CAAC,CAAC;KAC3B,CAAC;AACJ,CAAC"}
|
package/dist/utility/npv.d.ts
CHANGED
|
@@ -1,3 +1,11 @@
|
|
|
1
1
|
import type { NpvInput, NpvResult } from './types.js';
|
|
2
|
-
|
|
2
|
+
/**
|
|
3
|
+
* Calculate net present value (NPV), IRR, and profitability index
|
|
4
|
+
*
|
|
5
|
+
* @param input - Initial investment, cash flow series, and discount rate
|
|
6
|
+
* @returns NPV result (irr is null when the IRR iteration does not converge)
|
|
7
|
+
* @throws RangeError if initialInvestment is negative, cashFlows is empty,
|
|
8
|
+
* or discountRate is outside [0, 1)
|
|
9
|
+
*/
|
|
10
|
+
export declare function npv(input: NpvInput): NpvResult;
|
|
3
11
|
//# sourceMappingURL=npv.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"npv.d.ts","sourceRoot":"","sources":["../../src/utility/npv.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,QAAQ,EAAE,SAAS,EAAE,MAAM,YAAY,CAAC;AAEtD,wBAAgB,GAAG,CAAC,KAAK,EAAE,QAAQ,GAAG,SAAS,
|
|
1
|
+
{"version":3,"file":"npv.d.ts","sourceRoot":"","sources":["../../src/utility/npv.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,QAAQ,EAAE,SAAS,EAAE,MAAM,YAAY,CAAC;AAEtD;;;;;;;GAOG;AACH,wBAAgB,GAAG,CAAC,KAAK,EAAE,QAAQ,GAAG,SAAS,CA4B9C"}
|
package/dist/utility/npv.js
CHANGED
|
@@ -1,10 +1,23 @@
|
|
|
1
1
|
import { roundTo } from '../utils.js';
|
|
2
|
+
/**
|
|
3
|
+
* Calculate net present value (NPV), IRR, and profitability index
|
|
4
|
+
*
|
|
5
|
+
* @param input - Initial investment, cash flow series, and discount rate
|
|
6
|
+
* @returns NPV result (irr is null when the IRR iteration does not converge)
|
|
7
|
+
* @throws RangeError if initialInvestment is negative, cashFlows is empty,
|
|
8
|
+
* or discountRate is outside [0, 1)
|
|
9
|
+
*/
|
|
2
10
|
export function npv(input) {
|
|
3
11
|
const { initialInvestment, cashFlows, discountRate } = input;
|
|
4
|
-
if (initialInvestment < 0
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
12
|
+
if (initialInvestment < 0) {
|
|
13
|
+
throw new RangeError(`initialInvestment must be >= 0, got ${initialInvestment}`);
|
|
14
|
+
}
|
|
15
|
+
if (!cashFlows || cashFlows.length === 0) {
|
|
16
|
+
throw new RangeError('cashFlows must contain at least one value');
|
|
17
|
+
}
|
|
18
|
+
if (discountRate < 0 || discountRate >= 1) {
|
|
19
|
+
throw new RangeError(`discountRate must be in [0, 1), got ${discountRate}`);
|
|
20
|
+
}
|
|
8
21
|
const pvCashFlows = cashFlows.reduce((acc, cf, i) => {
|
|
9
22
|
return acc + cf / (1 + discountRate) ** (i + 1);
|
|
10
23
|
}, 0);
|
package/dist/utility/npv.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"npv.js","sourceRoot":"","sources":["../../src/utility/npv.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,aAAa,CAAC;AAGtC,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AS;YAAE,OAAO,IAAI,CAAC;QAC9C,IAAI,UAAU,KAAK,CAAC;YAAE,OAAO,IAAI,CAAC;QAElC,IAAI,GAAG,IAAI,GAAG,MAAM,GAAG,UAAU,CAAC;QAElC,IAAI,IAAI,IAAI,CAAC,CAAC;YAAE,OAAO,IAAI,CAAC,CAAC,WAAW;IAC1C,CAAC;IAED,OAAO,IAAI,CAAC,CAAC,mBAAmB;AAClC,CAAC"}
|
|
@@ -1,3 +1,10 @@
|
|
|
1
1
|
import type { PercentileInput, PercentileResult } from './types.js';
|
|
2
|
-
|
|
2
|
+
/**
|
|
3
|
+
* Calculate a percentile of a data series (linear interpolation between ranks)
|
|
4
|
+
*
|
|
5
|
+
* @param input - Data series and percentile (0-100)
|
|
6
|
+
* @returns Percentile result
|
|
7
|
+
* @throws RangeError if data is empty or percentile is outside [0, 100]
|
|
8
|
+
*/
|
|
9
|
+
export declare function percentile(input: PercentileInput): PercentileResult;
|
|
3
10
|
//# sourceMappingURL=percentile.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"percentile.d.ts","sourceRoot":"","sources":["../../src/utility/percentile.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,eAAe,EAAE,gBAAgB,EAAE,MAAM,YAAY,CAAC;AAEpE,wBAAgB,UAAU,CAAC,KAAK,EAAE,eAAe,GAAG,gBAAgB,
|
|
1
|
+
{"version":3,"file":"percentile.d.ts","sourceRoot":"","sources":["../../src/utility/percentile.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,eAAe,EAAE,gBAAgB,EAAE,MAAM,YAAY,CAAC;AAEpE;;;;;;GAMG;AACH,wBAAgB,UAAU,CAAC,KAAK,EAAE,eAAe,GAAG,gBAAgB,CA0BnE"}
|
|
@@ -1,10 +1,19 @@
|
|
|
1
1
|
import { roundTo } from '../utils.js';
|
|
2
|
+
/**
|
|
3
|
+
* Calculate a percentile of a data series (linear interpolation between ranks)
|
|
4
|
+
*
|
|
5
|
+
* @param input - Data series and percentile (0-100)
|
|
6
|
+
* @returns Percentile result
|
|
7
|
+
* @throws RangeError if data is empty or percentile is outside [0, 100]
|
|
8
|
+
*/
|
|
2
9
|
export function percentile(input) {
|
|
3
10
|
const { data, percentile: p } = input;
|
|
4
|
-
if (!data || data.length === 0)
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
11
|
+
if (!data || data.length === 0) {
|
|
12
|
+
throw new RangeError('data must contain at least one value');
|
|
13
|
+
}
|
|
14
|
+
if (p < 0 || p > 100) {
|
|
15
|
+
throw new RangeError(`percentile must be in [0, 100], got ${p}`);
|
|
16
|
+
}
|
|
8
17
|
const sorted = [...data].sort((a, b) => a - b);
|
|
9
18
|
const n = sorted.length;
|
|
10
19
|
if (p === 0)
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"percentile.js","sourceRoot":"","sources":["../../src/utility/percentile.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,aAAa,CAAC;AAGtC,MAAM,UAAU,UAAU,CAAC,KAAsB;IAC/C,MAAM,EAAE,IAAI,EAAE,UAAU,EAAE,CAAC,EAAE,GAAG,KAAK,CAAC;IACtC,IAAI,CAAC,IAAI,IAAI,IAAI,CAAC,MAAM,KAAK,CAAC;
|
|
1
|
+
{"version":3,"file":"percentile.js","sourceRoot":"","sources":["../../src/utility/percentile.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,aAAa,CAAC;AAGtC;;;;;;GAMG;AACH,MAAM,UAAU,UAAU,CAAC,KAAsB;IAC/C,MAAM,EAAE,IAAI,EAAE,UAAU,EAAE,CAAC,EAAE,GAAG,KAAK,CAAC;IACtC,IAAI,CAAC,IAAI,IAAI,IAAI,CAAC,MAAM,KAAK,CAAC,EAAE,CAAC;QAC/B,MAAM,IAAI,UAAU,CAAC,sCAAsC,CAAC,CAAC;IAC/D,CAAC;IACD,IAAI,CAAC,GAAG,CAAC,IAAI,CA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Regression input with x and y data arrays
|
|
6
|
+
* @returns Slope, intercept, R² and equation string
|
|
7
|
+
* @throws RangeError if x or y is missing, if x and y lengths differ,
|
|
8
|
+
* if fewer than 2 data points are provided, or if all x values are identical
|
|
9
|
+
*/
|
|
10
|
+
export declare function regression(input: RegressionInput): RegressionResult;
|
|
3
11
|
//# sourceMappingURL=regression.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"regression.d.ts","sourceRoot":"","sources":["../../src/utility/regression.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,eAAe,EAAE,gBAAgB,EAAE,MAAM,YAAY,CAAC;AAEpE,wBAAgB,UAAU,CAAC,KAAK,EAAE,eAAe,GAAG,gBAAgB,
|
|
1
|
+
{"version":3,"file":"regression.d.ts","sourceRoot":"","sources":["../../src/utility/regression.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,eAAe,EAAE,gBAAgB,EAAE,MAAM,YAAY,CAAC;AAEpE;;;;;;;GAOG;AACH,wBAAgB,UAAU,CAAC,KAAK,EAAE,eAAe,GAAG,gBAAgB,CAqDnE"}
|
|
@@ -1,8 +1,23 @@
|
|
|
1
1
|
import { roundTo } from '../utils.js';
|
|
2
|
+
/**
|
|
3
|
+
* Simple linear regression (least squares)
|
|
4
|
+
*
|
|
5
|
+
* @param input - Regression input with x and y data arrays
|
|
6
|
+
* @returns Slope, intercept, R² and equation string
|
|
7
|
+
* @throws RangeError if x or y is missing, if x and y lengths differ,
|
|
8
|
+
* if fewer than 2 data points are provided, or if all x values are identical
|
|
9
|
+
*/
|
|
2
10
|
export function regression(input) {
|
|
3
11
|
const { x, y } = input;
|
|
4
|
-
if (!x || !y
|
|
5
|
-
|
|
12
|
+
if (!x || !y) {
|
|
13
|
+
throw new RangeError('x and y data arrays are required');
|
|
14
|
+
}
|
|
15
|
+
if (x.length !== y.length) {
|
|
16
|
+
throw new RangeError(`x and y must have the same length, got ${x.length} and ${y.length}`);
|
|
17
|
+
}
|
|
18
|
+
if (x.length < 2) {
|
|
19
|
+
throw new RangeError(`at least 2 data points are required, got ${x.length}`);
|
|
20
|
+
}
|
|
6
21
|
const n = x.length;
|
|
7
22
|
const meanX = x.reduce((a, v) => a + v, 0) / n;
|
|
8
23
|
const meanY = y.reduce((a, v) => a + v, 0) / n;
|
|
@@ -16,8 +31,9 @@ export function regression(input) {
|
|
|
16
31
|
sumX2 += dx * dx;
|
|
17
32
|
sumY2 += dy * dy;
|
|
18
33
|
}
|
|
19
|
-
if (sumX2 === 0)
|
|
20
|
-
|
|
34
|
+
if (sumX2 === 0) {
|
|
35
|
+
throw new RangeError('x values must not all be identical (zero variance in x)');
|
|
36
|
+
}
|
|
21
37
|
const slope = sumXY / sumX2;
|
|
22
38
|
const intercept = meanY - slope * meanX;
|
|
23
39
|
const ssTot = sumY2;
|