qntjs-lib 1.1.5 → 2.0.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/dist/bundle/index.d.ts +17 -18
- package/dist/bundle/index.js +47 -47
- package/dist/perf/dd.d.ts +4 -4
- package/dist/perf/distribution.d.ts +6 -6
- package/dist/perf/index.d.ts +4 -4
- package/dist/perf/returns.d.ts +1 -1
- package/dist/untyped/index.d.ts +16 -16
- package/package.json +1 -1
package/dist/bundle/index.d.ts
CHANGED
|
@@ -1613,7 +1613,7 @@ declare function cagr(returns: ArrayLike<number>, freq?: number): number;
|
|
|
1613
1613
|
* @param tzOffsetMinutes Optional timezone offset in minutes (default 0, UTC)
|
|
1614
1614
|
* @returns Object { days: number[], dailyReturns: Float32Array }
|
|
1615
1615
|
*/
|
|
1616
|
-
declare function
|
|
1616
|
+
declare function dailyreturns(tsMs: ArrayLike<number>, returnsArr: ArrayLike<number>, tzOffsetMinutes?: number): {
|
|
1617
1617
|
days: number[];
|
|
1618
1618
|
dailyReturns: Float32Array<ArrayBuffer>;
|
|
1619
1619
|
};
|
|
@@ -1672,7 +1672,7 @@ declare function dduration(equity: ArrayLike<number>): DrawdownDurationResult;
|
|
|
1672
1672
|
* @param freq Periods per year (default 252)
|
|
1673
1673
|
* @returns Recovery factor or NaN
|
|
1674
1674
|
*/
|
|
1675
|
-
declare function
|
|
1675
|
+
declare function recoveryfactor(equity: ArrayLike<number>, freq?: number): number;
|
|
1676
1676
|
/**
|
|
1677
1677
|
* Calmar ratio: CAGR over a lookback period divided by the max drawdown magnitude over the same period.
|
|
1678
1678
|
* If `lookbackPeriodYears` is null uses the entire series. Returns NaN on invalid inputs or zero drawdown.
|
|
@@ -1681,14 +1681,14 @@ declare function recoveryFactor(equity: ArrayLike<number>, freq?: number): numbe
|
|
|
1681
1681
|
* @param freq Periods per year (default 252)
|
|
1682
1682
|
* @returns Calmar ratio or NaN
|
|
1683
1683
|
*/
|
|
1684
|
-
declare function
|
|
1684
|
+
declare function calmar(equity: ArrayLike<number>, lookbackPeriodYears?: number | null, freq?: number): number;
|
|
1685
1685
|
/**
|
|
1686
1686
|
* Ulcer Index: measures depth and duration of drawdowns (root-mean-square of depths).
|
|
1687
1687
|
* Returns NaN for empty input.
|
|
1688
1688
|
* @param equity Array-like equity or price series
|
|
1689
1689
|
* @returns Ulcer Index (>=0) or NaN
|
|
1690
1690
|
*/
|
|
1691
|
-
declare function
|
|
1691
|
+
declare function ulcer(equity: ArrayLike<number>): number;
|
|
1692
1692
|
/**
|
|
1693
1693
|
* Rolling Ulcer Index computed over a trailing window.
|
|
1694
1694
|
* Returns NaN for windows with insufficient valid samples (< minPeriod) or invalid window.
|
|
@@ -1697,7 +1697,7 @@ declare function ulcerIndex(equity: ArrayLike<number>): number;
|
|
|
1697
1697
|
* @param minPeriod Minimum number of valid points required in window
|
|
1698
1698
|
* @returns Float64Array of rolling ulcer index values
|
|
1699
1699
|
*/
|
|
1700
|
-
declare function
|
|
1700
|
+
declare function rollulcer(equity: ArrayLike<number>, window: number, minPeriod?: number): Float64Array;
|
|
1701
1701
|
|
|
1702
1702
|
/**
|
|
1703
1703
|
* Compute the (annualized) Sharpe ratio for a returns series.
|
|
@@ -1780,7 +1780,7 @@ declare function valueAtRisk(returns: ArrayLike<number>, alpha?: number, method?
|
|
|
1780
1780
|
* @param method 'historical' | 'parametric' (default 'historical')
|
|
1781
1781
|
* @returns Expected shortfall (left-tail) or NaN
|
|
1782
1782
|
*/
|
|
1783
|
-
declare function
|
|
1783
|
+
declare function expshortfall(returns: ArrayLike<number>, alpha?: number, method?: 'historical' | 'parametric'): number;
|
|
1784
1784
|
/**
|
|
1785
1785
|
* Tail ratio: mean of upper tail divided by absolute mean of lower tail.
|
|
1786
1786
|
* Returns NaN for empty inputs, invalid alpha, or when either tail has no observations or lower mean is zero.
|
|
@@ -1788,7 +1788,7 @@ declare function expectedShortfall(returns: ArrayLike<number>, alpha?: number, m
|
|
|
1788
1788
|
* @param alpha Tail probability (default 0.05)
|
|
1789
1789
|
* @returns Tail ratio or NaN
|
|
1790
1790
|
*/
|
|
1791
|
-
declare function
|
|
1791
|
+
declare function tail(returns: ArrayLike<number>, alpha?: number): number;
|
|
1792
1792
|
/**
|
|
1793
1793
|
* Omega ratio: sum of gains above `requiredReturn` divided by sum of losses below it.
|
|
1794
1794
|
* Returns NaN for empty inputs or when there is no variation (all gains or all losses zero).
|
|
@@ -1796,36 +1796,35 @@ declare function tailRatio(returns: ArrayLike<number>, alpha?: number): number;
|
|
|
1796
1796
|
* @param requiredReturn Threshold for gains/losses (default 0)
|
|
1797
1797
|
* @returns Omega ratio number, Infinity if no losses, or NaN when no variation
|
|
1798
1798
|
*/
|
|
1799
|
-
declare function
|
|
1799
|
+
declare function omega(returns: ArrayLike<number>, requiredReturn?: number): number;
|
|
1800
1800
|
|
|
1801
1801
|
type index_d_DrawdownDurationResult = DrawdownDurationResult;
|
|
1802
1802
|
type index_d_MaxDrawdownInfo = MaxDrawdownInfo;
|
|
1803
1803
|
declare const index_d_cagr: typeof cagr;
|
|
1804
|
-
declare const
|
|
1804
|
+
declare const index_d_calmar: typeof calmar;
|
|
1805
1805
|
declare const index_d_cumreturns: typeof cumreturns;
|
|
1806
|
-
declare const
|
|
1806
|
+
declare const index_d_dailyreturns: typeof dailyreturns;
|
|
1807
1807
|
declare const index_d_dd: typeof dd;
|
|
1808
1808
|
declare const index_d_dduration: typeof dduration;
|
|
1809
|
-
declare const
|
|
1809
|
+
declare const index_d_expshortfall: typeof expshortfall;
|
|
1810
1810
|
declare const index_d_logreturns: typeof logreturns;
|
|
1811
1811
|
declare const index_d_maxdd: typeof maxdd;
|
|
1812
1812
|
declare const index_d_maxddDetails: typeof maxddDetails;
|
|
1813
|
-
declare const
|
|
1814
|
-
declare const
|
|
1813
|
+
declare const index_d_omega: typeof omega;
|
|
1814
|
+
declare const index_d_recoveryfactor: typeof recoveryfactor;
|
|
1815
1815
|
declare const index_d_returns: typeof returns;
|
|
1816
|
-
declare const index_d_rollUlcerIndex: typeof rollUlcerIndex;
|
|
1817
1816
|
declare const index_d_rollmaxdd: typeof rollmaxdd;
|
|
1818
1817
|
declare const index_d_rollsharpe: typeof rollsharpe;
|
|
1819
1818
|
declare const index_d_rollsortino: typeof rollsortino;
|
|
1819
|
+
declare const index_d_rollulcer: typeof rollulcer;
|
|
1820
1820
|
declare const index_d_rollvol: typeof rollvol;
|
|
1821
1821
|
declare const index_d_sharpe: typeof sharpe;
|
|
1822
1822
|
declare const index_d_sortino: typeof sortino;
|
|
1823
|
-
declare const
|
|
1824
|
-
declare const
|
|
1825
|
-
declare const index_d_valueAtRisk: typeof valueAtRisk;
|
|
1823
|
+
declare const index_d_tail: typeof tail;
|
|
1824
|
+
declare const index_d_ulcer: typeof ulcer;
|
|
1826
1825
|
declare const index_d_vol: typeof vol;
|
|
1827
1826
|
declare namespace index_d {
|
|
1828
|
-
export { index_d_cagr as cagr,
|
|
1827
|
+
export { index_d_cagr as cagr, index_d_calmar as calmar, index_d_cumreturns as cumreturns, index_d_dailyreturns as dailyreturns, index_d_dd as dd, index_d_dduration as dduration, index_d_expshortfall as expshortfall, index_d_logreturns as logreturns, index_d_maxdd as maxdd, index_d_maxddDetails as maxddDetails, index_d_omega as omega, index_d_recoveryfactor as recoveryfactor, index_d_returns as returns, index_d_rollmaxdd as rollmaxdd, index_d_rollsharpe as rollsharpe, index_d_rollsortino as rollsortino, index_d_rollulcer as rollulcer, index_d_rollvol as rollvol, index_d_sharpe as sharpe, index_d_sortino as sortino, index_d_tail as tail, index_d_ulcer as ulcer, valueAtRisk as var, index_d_vol as vol };
|
|
1829
1828
|
export type { index_d_DrawdownDurationResult as DrawdownDurationResult, index_d_MaxDrawdownInfo as MaxDrawdownInfo };
|
|
1830
1829
|
}
|
|
1831
1830
|
|
package/dist/bundle/index.js
CHANGED
|
@@ -10,7 +10,7 @@ function $(t, n) {
|
|
|
10
10
|
e[r] = t[r] + l[r];
|
|
11
11
|
return e;
|
|
12
12
|
}
|
|
13
|
-
function
|
|
13
|
+
function X(t, n) {
|
|
14
14
|
if (typeof n == "number") {
|
|
15
15
|
const r = t.length, i = new Float64Array(r);
|
|
16
16
|
for (let s = 0; s < r; s++)
|
|
@@ -108,7 +108,7 @@ function qt(t) {
|
|
|
108
108
|
l[o] = Math.ceil(t[o]);
|
|
109
109
|
return l;
|
|
110
110
|
}
|
|
111
|
-
function
|
|
111
|
+
function Bt(t) {
|
|
112
112
|
const n = t.length;
|
|
113
113
|
if (n === 0)
|
|
114
114
|
return new Float64Array(0);
|
|
@@ -118,7 +118,7 @@ function Rt(t) {
|
|
|
118
118
|
l[o] = t[o] - t[o - 1];
|
|
119
119
|
return l;
|
|
120
120
|
}
|
|
121
|
-
function
|
|
121
|
+
function Xt(t, n) {
|
|
122
122
|
const l = t.length, o = n;
|
|
123
123
|
for (let e = 0; e < l; e++)
|
|
124
124
|
t[e] = o(t[e], e);
|
|
@@ -136,7 +136,7 @@ function q(t, n, l) {
|
|
|
136
136
|
e[s] = l(t[s], r[s]) ? 1 : 0;
|
|
137
137
|
return e;
|
|
138
138
|
}
|
|
139
|
-
function
|
|
139
|
+
function Rt(t, n) {
|
|
140
140
|
return q(t, n, (o, e) => o < e);
|
|
141
141
|
}
|
|
142
142
|
function zt(t, n) {
|
|
@@ -858,14 +858,14 @@ const Io = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineProperty({
|
|
|
858
858
|
cummin: Mn,
|
|
859
859
|
cumprod: Zt,
|
|
860
860
|
cumsum: hn,
|
|
861
|
-
diff:
|
|
861
|
+
diff: Bt,
|
|
862
862
|
div: jt,
|
|
863
863
|
dot: xn,
|
|
864
864
|
eq: Ht,
|
|
865
865
|
floor: Ut,
|
|
866
866
|
gt: Kt,
|
|
867
867
|
gte: Yt,
|
|
868
|
-
lt:
|
|
868
|
+
lt: Rt,
|
|
869
869
|
lte: zt,
|
|
870
870
|
max: vn,
|
|
871
871
|
min: gn,
|
|
@@ -889,7 +889,7 @@ const Io = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineProperty({
|
|
|
889
889
|
round: Tt,
|
|
890
890
|
scale: Pt,
|
|
891
891
|
sign: Ct,
|
|
892
|
-
sub:
|
|
892
|
+
sub: X,
|
|
893
893
|
sum: ot
|
|
894
894
|
}, Symbol.toStringTag, { value: "Module" }));
|
|
895
895
|
function Sn(t, n, l, o) {
|
|
@@ -1158,11 +1158,11 @@ function qn(t, n) {
|
|
|
1158
1158
|
i[a] = 2 * s[a] - f[a];
|
|
1159
1159
|
return J(i, r, !1);
|
|
1160
1160
|
}
|
|
1161
|
-
function
|
|
1161
|
+
function Bn(t, n, l = 2, o = 30, e = !0) {
|
|
1162
1162
|
if (n <= 0)
|
|
1163
1163
|
throw new Error("Period must be positive");
|
|
1164
1164
|
const r = t.length, i = new Float64Array(r);
|
|
1165
|
-
return r < n ? (i.fill(NaN), i) : (e && !V() && !k(t) && (e = !1), e ?
|
|
1165
|
+
return r < n ? (i.fill(NaN), i) : (e && !V() && !k(t) && (e = !1), e ? Xn(t, n, l, o) : rt(t, n, l, o));
|
|
1166
1166
|
}
|
|
1167
1167
|
function rt(t, n, l, o) {
|
|
1168
1168
|
const e = t.length, r = new Float64Array(e);
|
|
@@ -1183,7 +1183,7 @@ function rt(t, n, l, o) {
|
|
|
1183
1183
|
}
|
|
1184
1184
|
return r;
|
|
1185
1185
|
}
|
|
1186
|
-
function
|
|
1186
|
+
function Xn(t, n, l, o) {
|
|
1187
1187
|
const e = t.length, r = new Float64Array(e);
|
|
1188
1188
|
r.fill(NaN);
|
|
1189
1189
|
let i = !1;
|
|
@@ -1208,7 +1208,7 @@ function Bn(t, n, l, o) {
|
|
|
1208
1208
|
}
|
|
1209
1209
|
return r;
|
|
1210
1210
|
}
|
|
1211
|
-
function
|
|
1211
|
+
function Rn(t, n, l, o) {
|
|
1212
1212
|
for (let i = 0; i < n; i++)
|
|
1213
1213
|
o[i] = NaN;
|
|
1214
1214
|
if (n === 1) {
|
|
@@ -1246,7 +1246,7 @@ function lt(t, n, l = !0) {
|
|
|
1246
1246
|
if (n <= 0)
|
|
1247
1247
|
throw new Error("Period must be positive");
|
|
1248
1248
|
const o = t.length, e = new Float64Array(o);
|
|
1249
|
-
return o < n ? (e.fill(NaN), e) : (l && !V() && !k(t) && (l = !1), l ? zn(t, n, o, e) :
|
|
1249
|
+
return o < n ? (e.fill(NaN), e) : (l && !V() && !k(t) && (l = !1), l ? zn(t, n, o, e) : Rn(t, n, o, e));
|
|
1250
1250
|
}
|
|
1251
1251
|
function Kn(t, n, l) {
|
|
1252
1252
|
if (n <= 0)
|
|
@@ -1338,7 +1338,7 @@ function Ft(t, n = { ddof: 1, skipna: !0 }) {
|
|
|
1338
1338
|
const a = s - l;
|
|
1339
1339
|
return a <= 0 ? NaN : (i - s * f * f) / a;
|
|
1340
1340
|
}
|
|
1341
|
-
function
|
|
1341
|
+
function R(t, n = { ddof: 1, skipna: !0 }) {
|
|
1342
1342
|
const l = Ft(t, n);
|
|
1343
1343
|
return Math.sqrt(l);
|
|
1344
1344
|
}
|
|
@@ -1445,7 +1445,7 @@ function xt(t, n, l, o = { ddof: 1 }) {
|
|
|
1445
1445
|
}
|
|
1446
1446
|
return i;
|
|
1447
1447
|
}
|
|
1448
|
-
function
|
|
1448
|
+
function B(t, n, l = { skipna: !0, ddof: 1 }) {
|
|
1449
1449
|
const o = dt(t, n, l), e = new Float64Array(o.length);
|
|
1450
1450
|
for (let r = 0; r < o.length; r++)
|
|
1451
1451
|
e[r] = Math.sqrt(o[r]);
|
|
@@ -1848,7 +1848,7 @@ function ee(t, n = !0) {
|
|
|
1848
1848
|
if (l === 0)
|
|
1849
1849
|
return o;
|
|
1850
1850
|
!V() && n && (k(t) || (n = !1));
|
|
1851
|
-
const e = C(t, { skipna: n }), r =
|
|
1851
|
+
const e = C(t, { skipna: n }), r = R(t, { ddof: 1, skipna: n });
|
|
1852
1852
|
if (r === 0 || r !== r)
|
|
1853
1853
|
return o.fill(NaN), o;
|
|
1854
1854
|
for (let i = 0; i < l; i++)
|
|
@@ -1932,7 +1932,7 @@ function le(t, n, l, o) {
|
|
|
1932
1932
|
for (let h = 0; h < r; h++)
|
|
1933
1933
|
s[h] = h < t.length ? t[h] : NaN, f[h] = h < n.length ? n[h] : NaN;
|
|
1934
1934
|
}
|
|
1935
|
-
const a = xt(s, f, l), c =
|
|
1935
|
+
const a = xt(s, f, l), c = B(s, l, { skipna: i }), u = B(f, l, { skipna: i }), N = new Float64Array(r);
|
|
1936
1936
|
for (let h = 0; h < r; h++) {
|
|
1937
1937
|
const m = c[h] * u[h];
|
|
1938
1938
|
m > 1e-12 ? N[h] = a[h] / m : N[h] = NaN;
|
|
@@ -2122,12 +2122,12 @@ const ko = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineProperty({
|
|
|
2122
2122
|
rollmedian: pn,
|
|
2123
2123
|
rollquantile: ne,
|
|
2124
2124
|
rollskew: ae,
|
|
2125
|
-
rollstdev:
|
|
2125
|
+
rollstdev: B,
|
|
2126
2126
|
rollvar: dt,
|
|
2127
2127
|
sample: Ne,
|
|
2128
2128
|
shuffle: ue,
|
|
2129
2129
|
skew: se,
|
|
2130
|
-
stdev:
|
|
2130
|
+
stdev: R,
|
|
2131
2131
|
var: Ft,
|
|
2132
2132
|
winsorize: ie,
|
|
2133
2133
|
zscore: ee
|
|
@@ -2512,17 +2512,17 @@ function Ie(t, n, l = 1) {
|
|
|
2512
2512
|
function ke(t, n = 0, l = 252) {
|
|
2513
2513
|
if (t.length === 0)
|
|
2514
2514
|
return NaN;
|
|
2515
|
-
const e = n / l, r =
|
|
2515
|
+
const e = n / l, r = X(t, e), i = C(r);
|
|
2516
2516
|
if (i !== i)
|
|
2517
2517
|
return NaN;
|
|
2518
|
-
const s =
|
|
2518
|
+
const s = R(r, { ddof: 1, skipna: !0 });
|
|
2519
2519
|
return s === 0 || s !== s ? NaN : i * Math.sqrt(l) / s;
|
|
2520
2520
|
}
|
|
2521
2521
|
function Ve(t, n = 0, l = 252, o = 1) {
|
|
2522
2522
|
const e = t.length;
|
|
2523
2523
|
if (e === 0)
|
|
2524
2524
|
return NaN;
|
|
2525
|
-
const r = n / l, i =
|
|
2525
|
+
const r = n / l, i = X(t, r), s = C(i);
|
|
2526
2526
|
if (s !== s)
|
|
2527
2527
|
return NaN;
|
|
2528
2528
|
let f = 0, a = 0;
|
|
@@ -2539,7 +2539,7 @@ function Se(t, n, l = 0, o = 252, e = 1) {
|
|
|
2539
2539
|
const r = t.length, i = new Float64Array(r);
|
|
2540
2540
|
if (r === 0)
|
|
2541
2541
|
return i;
|
|
2542
|
-
const s = l / o, f =
|
|
2542
|
+
const s = l / o, f = X(t, s), a = _(f), c = ct(f, n), u = B(f, n, { skipna: !0, ddof: 0 }), N = Z(a, n);
|
|
2543
2543
|
for (let h = 0; h < r; h++) {
|
|
2544
2544
|
const m = N[h];
|
|
2545
2545
|
if (m !== m || m < e) {
|
|
@@ -2563,12 +2563,12 @@ function Le(t, n, l = 0, o = 252, e = 1) {
|
|
|
2563
2563
|
const r = t.length, i = new Float64Array(r);
|
|
2564
2564
|
if (r === 0)
|
|
2565
2565
|
return i;
|
|
2566
|
-
const s = l / o, f =
|
|
2566
|
+
const s = l / o, f = X(t, s), a = new Float64Array(r);
|
|
2567
2567
|
for (let m = 0; m < r; m++) {
|
|
2568
2568
|
const w = f[m];
|
|
2569
2569
|
a[m] = w === w && w < 0 ? w : NaN;
|
|
2570
2570
|
}
|
|
2571
|
-
const c = _(a), u = ct(f, n), N =
|
|
2571
|
+
const c = _(a), u = ct(f, n), N = B(a, n, { skipna: !0, ddof: 0 }), h = Z(c, n);
|
|
2572
2572
|
for (let m = 0; m < r; m++) {
|
|
2573
2573
|
const w = h[m], g = u[m];
|
|
2574
2574
|
if (w !== w || g !== g || w < 2) {
|
|
@@ -2587,14 +2587,14 @@ function Le(t, n, l = 0, o = 252, e = 1) {
|
|
|
2587
2587
|
function _e(t, n = 252) {
|
|
2588
2588
|
if (t.length === 0)
|
|
2589
2589
|
return NaN;
|
|
2590
|
-
const o =
|
|
2590
|
+
const o = R(t, { ddof: 1, skipna: !0 });
|
|
2591
2591
|
return o !== o || o === 0 ? NaN : o * Math.sqrt(n);
|
|
2592
2592
|
}
|
|
2593
2593
|
function je(t, n, l = 252, o = 1) {
|
|
2594
2594
|
const e = t.length, r = new Float64Array(e);
|
|
2595
2595
|
if (e === 0)
|
|
2596
2596
|
return r;
|
|
2597
|
-
const i =
|
|
2597
|
+
const i = B(t, n, { skipna: !0, ddof: 0 }), s = Z(_(t), n);
|
|
2598
2598
|
for (let f = 0; f < e; f++) {
|
|
2599
2599
|
const a = s[f];
|
|
2600
2600
|
if (a !== a || a < o) {
|
|
@@ -2631,7 +2631,7 @@ function De(t, n = 0.05, l = "historical") {
|
|
|
2631
2631
|
const s = Y(t);
|
|
2632
2632
|
return s.length === 0 ? NaN : O(s, n);
|
|
2633
2633
|
}
|
|
2634
|
-
const e = C(t), r =
|
|
2634
|
+
const e = C(t), r = R(t);
|
|
2635
2635
|
if (e !== e || r !== r || r === 0)
|
|
2636
2636
|
return NaN;
|
|
2637
2637
|
const i = kt(n);
|
|
@@ -2654,7 +2654,7 @@ function Oe(t, n = 0.05, l = "historical") {
|
|
|
2654
2654
|
}
|
|
2655
2655
|
return c / u;
|
|
2656
2656
|
}
|
|
2657
|
-
const e = C(t), r =
|
|
2657
|
+
const e = C(t), r = R(t);
|
|
2658
2658
|
if (e !== e || r !== r || r === 0)
|
|
2659
2659
|
return NaN;
|
|
2660
2660
|
const i = kt(n);
|
|
@@ -2693,28 +2693,28 @@ function Te(t, n = 0) {
|
|
|
2693
2693
|
const Vo = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineProperty({
|
|
2694
2694
|
__proto__: null,
|
|
2695
2695
|
cagr: ve,
|
|
2696
|
-
|
|
2696
|
+
calmar: xe,
|
|
2697
2697
|
cumreturns: ge,
|
|
2698
|
-
|
|
2698
|
+
dailyreturns: Ae,
|
|
2699
2699
|
dd: ye,
|
|
2700
2700
|
dduration: Fe,
|
|
2701
|
-
|
|
2701
|
+
expshortfall: Oe,
|
|
2702
2702
|
logreturns: we,
|
|
2703
2703
|
maxdd: ut,
|
|
2704
2704
|
maxddDetails: be,
|
|
2705
|
-
|
|
2706
|
-
|
|
2705
|
+
omega: Te,
|
|
2706
|
+
recoveryfactor: de,
|
|
2707
2707
|
returns: me,
|
|
2708
|
-
rollUlcerIndex: Ie,
|
|
2709
2708
|
rollmaxdd: Me,
|
|
2710
2709
|
rollsharpe: Se,
|
|
2711
2710
|
rollsortino: Le,
|
|
2711
|
+
rollulcer: Ie,
|
|
2712
2712
|
rollvol: je,
|
|
2713
2713
|
sharpe: ke,
|
|
2714
2714
|
sortino: Ve,
|
|
2715
|
-
|
|
2716
|
-
|
|
2717
|
-
|
|
2715
|
+
tail: Ce,
|
|
2716
|
+
ulcer: Ee,
|
|
2717
|
+
var: De,
|
|
2718
2718
|
vol: _e
|
|
2719
2719
|
}, Symbol.toStringTag, { value: "Module" }));
|
|
2720
2720
|
function Ue(t, n, l = 5, o = 34, e = !0) {
|
|
@@ -2743,7 +2743,7 @@ function Ue(t, n, l = 5, o = 34, e = !0) {
|
|
|
2743
2743
|
return i;
|
|
2744
2744
|
}
|
|
2745
2745
|
const f = mt(t, n), a = L(f, l), c = L(f, o);
|
|
2746
|
-
return
|
|
2746
|
+
return X(a, c);
|
|
2747
2747
|
}
|
|
2748
2748
|
function qe(t, n, l) {
|
|
2749
2749
|
if (n <= 0 || l <= 0)
|
|
@@ -2767,7 +2767,7 @@ function qe(t, n, l) {
|
|
|
2767
2767
|
}
|
|
2768
2768
|
return e;
|
|
2769
2769
|
}
|
|
2770
|
-
function
|
|
2770
|
+
function Be(t, n) {
|
|
2771
2771
|
if (n <= 0)
|
|
2772
2772
|
throw new Error("Period must be positive");
|
|
2773
2773
|
const l = t.length, o = new Float64Array(l);
|
|
@@ -2795,7 +2795,7 @@ function Re(t, n) {
|
|
|
2795
2795
|
}
|
|
2796
2796
|
return o;
|
|
2797
2797
|
}
|
|
2798
|
-
function
|
|
2798
|
+
function Xe(t, n, l, o) {
|
|
2799
2799
|
if (n <= 0 || l <= 0 || o <= 0)
|
|
2800
2800
|
throw new Error("Periods must be positive");
|
|
2801
2801
|
const e = t.length, r = new Float64Array(e), i = new Float64Array(e), s = new Float64Array(e);
|
|
@@ -2820,7 +2820,7 @@ function Be(t, n, l, o) {
|
|
|
2820
2820
|
}
|
|
2821
2821
|
return [r, i, s];
|
|
2822
2822
|
}
|
|
2823
|
-
function
|
|
2823
|
+
function Re(t, n) {
|
|
2824
2824
|
if (n <= 0)
|
|
2825
2825
|
throw new Error("Period must be positive");
|
|
2826
2826
|
const l = t.length, o = new Float64Array(l).fill(NaN, 0, Math.min(l, n));
|
|
@@ -3312,7 +3312,7 @@ function tt(t, n, l, o) {
|
|
|
3312
3312
|
}
|
|
3313
3313
|
function io(t, n, l, o) {
|
|
3314
3314
|
const e = tt(t, n, l, o);
|
|
3315
|
-
return
|
|
3315
|
+
return Xt(e, (r, i) => r / l[i] * 100), e;
|
|
3316
3316
|
}
|
|
3317
3317
|
function so(t, n, l, o, e) {
|
|
3318
3318
|
if (o <= 0)
|
|
@@ -3412,7 +3412,7 @@ function _t(t, n, l) {
|
|
|
3412
3412
|
const o = t.length, e = L(t, n, !0), r = new Float64Array(o), i = new Float64Array(o);
|
|
3413
3413
|
if (i.fill(NaN, 0, Math.min(o, n)), r.fill(NaN, 0, Math.min(o, n)), o < n)
|
|
3414
3414
|
return [e.fill(NaN), r.fill(NaN), i.fill(NaN)];
|
|
3415
|
-
const s = !(V() === !1 && !k(t)), f =
|
|
3415
|
+
const s = !(V() === !1 && !k(t)), f = B(t, n, { skipna: s, ddof: 0 });
|
|
3416
3416
|
for (let a = n - 1; a < o; a++) {
|
|
3417
3417
|
const c = e[a], u = f[a];
|
|
3418
3418
|
if (c !== c || u !== u) {
|
|
@@ -3704,7 +3704,7 @@ const So = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineProperty({
|
|
|
3704
3704
|
bbw: No,
|
|
3705
3705
|
cci: pe,
|
|
3706
3706
|
change: Ke,
|
|
3707
|
-
cmo:
|
|
3707
|
+
cmo: Be,
|
|
3708
3708
|
cross: ft,
|
|
3709
3709
|
crossover: en,
|
|
3710
3710
|
crossunder: on,
|
|
@@ -3717,12 +3717,12 @@ const So = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineProperty({
|
|
|
3717
3717
|
falling: nn,
|
|
3718
3718
|
hma: qn,
|
|
3719
3719
|
ichimoku: uo,
|
|
3720
|
-
kama:
|
|
3720
|
+
kama: Bn,
|
|
3721
3721
|
keltner: mo,
|
|
3722
3722
|
kst: Ze,
|
|
3723
|
-
macd:
|
|
3723
|
+
macd: Xe,
|
|
3724
3724
|
mfi: yo,
|
|
3725
|
-
mom:
|
|
3725
|
+
mom: Re,
|
|
3726
3726
|
natr: io,
|
|
3727
3727
|
obv: bo,
|
|
3728
3728
|
pnvi: Mo,
|
package/dist/perf/dd.d.ts
CHANGED
|
@@ -52,7 +52,7 @@ export declare function dduration(equity: ArrayLike<number>): DrawdownDurationRe
|
|
|
52
52
|
* @param freq Periods per year (default 252)
|
|
53
53
|
* @returns Recovery factor or NaN
|
|
54
54
|
*/
|
|
55
|
-
export declare function
|
|
55
|
+
export declare function recoveryfactor(equity: ArrayLike<number>, freq?: number): number;
|
|
56
56
|
/**
|
|
57
57
|
* Calmar ratio: CAGR over a lookback period divided by the max drawdown magnitude over the same period.
|
|
58
58
|
* If `lookbackPeriodYears` is null uses the entire series. Returns NaN on invalid inputs or zero drawdown.
|
|
@@ -61,14 +61,14 @@ export declare function recoveryFactor(equity: ArrayLike<number>, freq?: number)
|
|
|
61
61
|
* @param freq Periods per year (default 252)
|
|
62
62
|
* @returns Calmar ratio or NaN
|
|
63
63
|
*/
|
|
64
|
-
export declare function
|
|
64
|
+
export declare function calmar(equity: ArrayLike<number>, lookbackPeriodYears?: number | null, freq?: number): number;
|
|
65
65
|
/**
|
|
66
66
|
* Ulcer Index: measures depth and duration of drawdowns (root-mean-square of depths).
|
|
67
67
|
* Returns NaN for empty input.
|
|
68
68
|
* @param equity Array-like equity or price series
|
|
69
69
|
* @returns Ulcer Index (>=0) or NaN
|
|
70
70
|
*/
|
|
71
|
-
export declare function
|
|
71
|
+
export declare function ulcer(equity: ArrayLike<number>): number;
|
|
72
72
|
/**
|
|
73
73
|
* Rolling Ulcer Index computed over a trailing window.
|
|
74
74
|
* Returns NaN for windows with insufficient valid samples (< minPeriod) or invalid window.
|
|
@@ -77,4 +77,4 @@ export declare function ulcerIndex(equity: ArrayLike<number>): number;
|
|
|
77
77
|
* @param minPeriod Minimum number of valid points required in window
|
|
78
78
|
* @returns Float64Array of rolling ulcer index values
|
|
79
79
|
*/
|
|
80
|
-
export declare function
|
|
80
|
+
export declare function rollulcer(equity: ArrayLike<number>, window: number, minPeriod?: number): Float64Array;
|
|
@@ -17,7 +17,7 @@ export declare function valueAtRisk(returns: ArrayLike<number>, alpha?: number,
|
|
|
17
17
|
* @param method 'historical' | 'parametric' (default 'historical')
|
|
18
18
|
* @returns Expected shortfall (left-tail) or NaN
|
|
19
19
|
*/
|
|
20
|
-
export declare function
|
|
20
|
+
export declare function expshortfall(returns: ArrayLike<number>, alpha?: number, method?: 'historical' | 'parametric'): number;
|
|
21
21
|
/**
|
|
22
22
|
* Tail ratio: mean of upper tail divided by absolute mean of lower tail.
|
|
23
23
|
* Returns NaN for empty inputs, invalid alpha, or when either tail has no observations or lower mean is zero.
|
|
@@ -25,7 +25,7 @@ export declare function expectedShortfall(returns: ArrayLike<number>, alpha?: nu
|
|
|
25
25
|
* @param alpha Tail probability (default 0.05)
|
|
26
26
|
* @returns Tail ratio or NaN
|
|
27
27
|
*/
|
|
28
|
-
export declare function
|
|
28
|
+
export declare function tail(returns: ArrayLike<number>, alpha?: number): number;
|
|
29
29
|
/**
|
|
30
30
|
* Omega ratio: sum of gains above `requiredReturn` divided by sum of losses below it.
|
|
31
31
|
* Returns NaN for empty inputs or when there is no variation (all gains or all losses zero).
|
|
@@ -33,11 +33,11 @@ export declare function tailRatio(returns: ArrayLike<number>, alpha?: number): n
|
|
|
33
33
|
* @param requiredReturn Threshold for gains/losses (default 0)
|
|
34
34
|
* @returns Omega ratio number, Infinity if no losses, or NaN when no variation
|
|
35
35
|
*/
|
|
36
|
-
export declare function
|
|
36
|
+
export declare function omega(returns: ArrayLike<number>, requiredReturn?: number): number;
|
|
37
37
|
declare const _default: {
|
|
38
38
|
valueAtRisk: typeof valueAtRisk;
|
|
39
|
-
expectedShortfall: typeof
|
|
40
|
-
tailRatio: typeof
|
|
41
|
-
omegaRatio: typeof
|
|
39
|
+
expectedShortfall: typeof expshortfall;
|
|
40
|
+
tailRatio: typeof tail;
|
|
41
|
+
omegaRatio: typeof omega;
|
|
42
42
|
};
|
|
43
43
|
export default _default;
|
package/dist/perf/index.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
export { cagr, cumreturns, logreturns, returns,
|
|
2
|
-
export { dd, dduration, maxdd, maxddDetails,
|
|
3
|
-
export type { DrawdownDurationResult, MaxDrawdownInfo } from './dd.js';
|
|
1
|
+
export { cagr, cumreturns, logreturns, returns, dailyreturns } from './returns.js';
|
|
2
|
+
export { dd, dduration, maxdd, maxddDetails, recoveryfactor, calmar, rollmaxdd, ulcer, rollulcer } from './dd.js';
|
|
4
3
|
export { sharpe, sortino, rollsharpe, rollsortino, vol, rollvol } from './volatility.js';
|
|
5
|
-
export { valueAtRisk,
|
|
4
|
+
export { valueAtRisk as var, expshortfall, omega, tail } from './distribution.js';
|
|
5
|
+
export type { DrawdownDurationResult, MaxDrawdownInfo } from './dd.js';
|
package/dist/perf/returns.d.ts
CHANGED
|
@@ -41,7 +41,7 @@ export declare function cagr(returns: ArrayLike<number>, freq?: number): number;
|
|
|
41
41
|
* @param tzOffsetMinutes Optional timezone offset in minutes (default 0, UTC)
|
|
42
42
|
* @returns Object { days: number[], dailyReturns: Float32Array }
|
|
43
43
|
*/
|
|
44
|
-
export declare function
|
|
44
|
+
export declare function dailyreturns(tsMs: ArrayLike<number>, returnsArr: ArrayLike<number>, tzOffsetMinutes?: number): {
|
|
45
45
|
days: number[];
|
|
46
46
|
dailyReturns: Float32Array<ArrayBuffer>;
|
|
47
47
|
};
|
package/dist/untyped/index.d.ts
CHANGED
|
@@ -1221,7 +1221,7 @@ declare namespace perf {
|
|
|
1221
1221
|
* @param freq Periods per year (default 252)
|
|
1222
1222
|
* @returns Calmar ratio or NaN
|
|
1223
1223
|
*/
|
|
1224
|
-
export function
|
|
1224
|
+
export function calmar(equity: ArrayLike<number>, lookbackPeriodYears?: number | null, freq?: number): number;
|
|
1225
1225
|
/**
|
|
1226
1226
|
* Compute cumulative compound returns from a returns series, skipping NaNs.
|
|
1227
1227
|
* Cumulative return at i is prod_{j<=i, r_j finite} (1+r_j) - 1; NaN inputs leave an output NaN at that position.
|
|
@@ -1241,7 +1241,7 @@ declare namespace perf {
|
|
|
1241
1241
|
* @param tzOffsetMinutes Optional timezone offset in minutes (default 0, UTC)
|
|
1242
1242
|
* @returns Object { days: number[], dailyReturns: Float32Array }
|
|
1243
1243
|
*/
|
|
1244
|
-
export function
|
|
1244
|
+
export function dailyreturns(tsMs: ArrayLike<number>, returnsArr: ArrayLike<number>, tzOffsetMinutes?: number): {
|
|
1245
1245
|
days: number[];
|
|
1246
1246
|
dailyReturns: number[];
|
|
1247
1247
|
};
|
|
@@ -1268,7 +1268,7 @@ declare namespace perf {
|
|
|
1268
1268
|
* @param method 'historical' | 'parametric' (default 'historical')
|
|
1269
1269
|
* @returns Expected shortfall (left-tail) or NaN
|
|
1270
1270
|
*/
|
|
1271
|
-
export function
|
|
1271
|
+
export function expshortfall(returns: ArrayLike<number>, alpha?: number, method?: 'historical' | 'parametric'): number;
|
|
1272
1272
|
/**
|
|
1273
1273
|
* Compute log returns from a level series.
|
|
1274
1274
|
* For each i>0: logreturns[i] = log(source[i]/source[i-1]) when both values are finite and previous>0.
|
|
@@ -1298,7 +1298,7 @@ declare namespace perf {
|
|
|
1298
1298
|
* @param requiredReturn Threshold for gains/losses (default 0)
|
|
1299
1299
|
* @returns Omega ratio number, Infinity if no losses, or NaN when no variation
|
|
1300
1300
|
*/
|
|
1301
|
-
export function
|
|
1301
|
+
export function omega(returns: ArrayLike<number>, requiredReturn?: number): number;
|
|
1302
1302
|
/**
|
|
1303
1303
|
* Recovery factor: ratio of annualized return (CAGR) to maximum drawdown magnitude.
|
|
1304
1304
|
* Returns NaN if insufficient data, invalid start value, or zero/NaN max drawdown.
|
|
@@ -1306,7 +1306,7 @@ declare namespace perf {
|
|
|
1306
1306
|
* @param freq Periods per year (default 252)
|
|
1307
1307
|
* @returns Recovery factor or NaN
|
|
1308
1308
|
*/
|
|
1309
|
-
export function
|
|
1309
|
+
export function recoveryfactor(equity: ArrayLike<number>, freq?: number): number;
|
|
1310
1310
|
/**
|
|
1311
1311
|
* Compute simple period returns from a level series.
|
|
1312
1312
|
* For each i>0: returns[i] = source[i]/source[i-1] - 1 when both values are finite and previous != 0.
|
|
@@ -1315,15 +1315,6 @@ declare namespace perf {
|
|
|
1315
1315
|
* @returns Float32Array of simple returns (same length as `source`)
|
|
1316
1316
|
*/
|
|
1317
1317
|
export function returns(source: ArrayLike<number>): number[];
|
|
1318
|
-
/**
|
|
1319
|
-
* Rolling Ulcer Index computed over a trailing window.
|
|
1320
|
-
* Returns NaN for windows with insufficient valid samples (< minPeriod) or invalid window.
|
|
1321
|
-
* @param equity Array-like equity or price series
|
|
1322
|
-
* @param window Rolling window length (positive integer)
|
|
1323
|
-
* @param minPeriod Minimum number of valid points required in window
|
|
1324
|
-
* @returns Float64Array of rolling ulcer index values
|
|
1325
|
-
*/
|
|
1326
|
-
export function rollUlcerIndex(equity: ArrayLike<number>, window: number, minPeriod?: number): number[];
|
|
1327
1318
|
/**
|
|
1328
1319
|
* Rolling maximum drawdown over a trailing window.
|
|
1329
1320
|
* For each index i computes the max drawdown observed within the trailing window.
|
|
@@ -1354,6 +1345,15 @@ declare namespace perf {
|
|
|
1354
1345
|
* @returns Float64Array of rolling Sortino ratios
|
|
1355
1346
|
*/
|
|
1356
1347
|
export function rollsortino(returns: ArrayLike<number>, window: number, requiredReturn?: number, freq?: number, minPeriod?: number): number[];
|
|
1348
|
+
/**
|
|
1349
|
+
* Rolling Ulcer Index computed over a trailing window.
|
|
1350
|
+
* Returns NaN for windows with insufficient valid samples (< minPeriod) or invalid window.
|
|
1351
|
+
* @param equity Array-like equity or price series
|
|
1352
|
+
* @param window Rolling window length (positive integer)
|
|
1353
|
+
* @param minPeriod Minimum number of valid points required in window
|
|
1354
|
+
* @returns Float64Array of rolling ulcer index values
|
|
1355
|
+
*/
|
|
1356
|
+
export function rollulcer(equity: ArrayLike<number>, window: number, minPeriod?: number): number[];
|
|
1357
1357
|
/**
|
|
1358
1358
|
* Rolling annualized volatility (sample stddev) over a trailing window.
|
|
1359
1359
|
* Outputs NaN for windows with insufficient valid samples or zero/NaN sigma.
|
|
@@ -1392,14 +1392,14 @@ declare namespace perf {
|
|
|
1392
1392
|
* @param alpha Tail probability (default 0.05)
|
|
1393
1393
|
* @returns Tail ratio or NaN
|
|
1394
1394
|
*/
|
|
1395
|
-
export function
|
|
1395
|
+
export function tail(returns: ArrayLike<number>, alpha?: number): number;
|
|
1396
1396
|
/**
|
|
1397
1397
|
* Ulcer Index: measures depth and duration of drawdowns (root-mean-square of depths).
|
|
1398
1398
|
* Returns NaN for empty input.
|
|
1399
1399
|
* @param equity Array-like equity or price series
|
|
1400
1400
|
* @returns Ulcer Index (>=0) or NaN
|
|
1401
1401
|
*/
|
|
1402
|
-
export function
|
|
1402
|
+
export function ulcer(equity: ArrayLike<number>): number;
|
|
1403
1403
|
/**
|
|
1404
1404
|
* Value-at-Risk (VaR) estimator.
|
|
1405
1405
|
* Supports `historical` (empirical quantile) and `parametric` (normal) methods.
|