orderflow-metrics 0.24.0 → 0.25.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 +12 -0
- package/dist/index.d.ts +1 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1 -0
- package/dist/index.js.map +1 -1
- package/dist/robustvol.d.ts +39 -0
- package/dist/robustvol.d.ts.map +1 -0
- package/dist/robustvol.js +79 -0
- package/dist/robustvol.js.map +1 -0
- package/package.json +2 -2
- package/src/index.ts +1 -0
- package/src/robustvol.ts +79 -0
package/CHANGELOG.md
CHANGED
|
@@ -4,6 +4,18 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/).
|
|
|
4
4
|
This project follows [Semantic Versioning](https://semver.org/); pre-1.0 the
|
|
5
5
|
public API may still change between minor versions.
|
|
6
6
|
|
|
7
|
+
## [0.25.0] - 2026-08-26
|
|
8
|
+
|
|
9
|
+
### Added
|
|
10
|
+
- Jump-robust realized variance (`robustvol`) — `minRV` and `medRV`, integrated
|
|
11
|
+
variance estimators built from the minimum / median of neighbouring absolute
|
|
12
|
+
returns (Andersen, Dobrev & Schaumburg, 2012). Like bipower variation they
|
|
13
|
+
strip discrete jumps out of realized variance, but more robustly — MedRV also
|
|
14
|
+
shrugs off isolated zero returns and outliers. Plus `realizedQuarticity`
|
|
15
|
+
((n/3)·Σrᵢ⁴, Barndorff-Nielsen & Shephard 2002), the integrated-quarticity
|
|
16
|
+
estimate that sets the standard error of realized variance and standardises
|
|
17
|
+
jump tests. Test suite included. (Python: 0.13.0.)
|
|
18
|
+
|
|
7
19
|
## [0.24.0] - 2026-08-25
|
|
8
20
|
|
|
9
21
|
### Changed
|
package/dist/index.d.ts
CHANGED
|
@@ -31,6 +31,7 @@ export type { HurstOptions } from "./hurst.ts";
|
|
|
31
31
|
export { hurstExponent } from "./hurst.ts";
|
|
32
32
|
export { realizedSkewness, realizedKurtosis } from "./moments.ts";
|
|
33
33
|
export { bipowerVariation, jumpVariation, relativeJumpVariation, } from "./jumps.ts";
|
|
34
|
+
export { minRV, medRV, realizedQuarticity } from "./robustvol.ts";
|
|
34
35
|
export type { Semivariance } from "./semivar.ts";
|
|
35
36
|
export { realizedSemivariance, downsideVarianceRatio, signedJumpVariation, } from "./semivar.ts";
|
|
36
37
|
export { shannonEntropy, normalizedEntropy, signEntropy, } from "./entropy.ts";
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,YAAY,EAAE,OAAO,EAAE,KAAK,EAAE,IAAI,EAAE,MAAM,YAAY,CAAC;AACvD,OAAO,EAAE,GAAG,EAAE,SAAS,EAAE,eAAe,EAAE,MAAM,UAAU,CAAC;AAC3D,OAAO,EAAE,cAAc,EAAE,cAAc,EAAE,MAAM,gBAAgB,CAAC;AAChE,YAAY,EAAE,YAAY,EAAE,MAAM,WAAW,CAAC;AAC9C,OAAO,EACL,IAAI,EACJ,cAAc,EACd,cAAc,EACd,iBAAiB,GAClB,MAAM,WAAW,CAAC;AACnB,YAAY,EAAE,eAAe,EAAE,MAAM,gBAAgB,CAAC;AACtD,OAAO,EACL,eAAe,EACf,mBAAmB,EACnB,cAAc,EACd,WAAW,EACX,UAAU,EACV,UAAU,GACX,MAAM,gBAAgB,CAAC;AACxB,OAAO,EAAE,GAAG,EAAE,WAAW,EAAE,iBAAiB,EAAE,MAAM,gBAAgB,CAAC;AACrE,YAAY,EAAE,IAAI,EAAE,UAAU,EAAE,MAAM,eAAe,CAAC;AACtD,OAAO,EAAE,QAAQ,EAAE,QAAQ,EAAE,MAAM,eAAe,CAAC;AACnD,YAAY,EAAE,YAAY,EAAE,MAAM,gBAAgB,CAAC;AACnD,OAAO,EAAE,iBAAiB,EAAE,MAAM,gBAAgB,CAAC;AACnD,OAAO,EACL,gBAAgB,EAChB,kBAAkB,EAClB,oBAAoB,GACrB,MAAM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,aAAa,EAAE,MAAM,YAAY,CAAC;AAC3C,OAAO,EAAE,gBAAgB,EAAE,gBAAgB,EAAE,MAAM,cAAc,CAAC;AAClE,OAAO,EACL,gBAAgB,EAChB,aAAa,EACb,qBAAqB,GACtB,MAAM,YAAY,CAAC;AACpB,OAAO,EAAE,KAAK,EAAE,KAAK,EAAE,kBAAkB,EAAE,MAAM,gBAAgB,CAAC;AAClE,YAAY,EAAE,YAAY,EAAE,MAAM,cAAc,CAAC;AACjD,OAAO,EACL,oBAAoB,EACpB,qBAAqB,EACrB,mBAAmB,GACpB,MAAM,cAAc,CAAC;AACtB,OAAO,EACL,cAAc,EACd,iBAAiB,EACjB,WAAW,GACZ,MAAM,cAAc,CAAC;AACtB,OAAO,EACL,OAAO,EACP,IAAI,EACJ,YAAY,EACZ,aAAa,GACd,MAAM,aAAa,CAAC;AACrB,OAAO,EACL,kBAAkB,EAClB,mBAAmB,EACnB,YAAY,GACb,MAAM,iBAAiB,CAAC"}
|
package/dist/index.js
CHANGED
|
@@ -18,6 +18,7 @@ export { parkinsonVolatility, garmanKlassVolatility, rogersSatchellVolatility, y
|
|
|
18
18
|
export { hurstExponent } from "./hurst.js";
|
|
19
19
|
export { realizedSkewness, realizedKurtosis } from "./moments.js";
|
|
20
20
|
export { bipowerVariation, jumpVariation, relativeJumpVariation, } from "./jumps.js";
|
|
21
|
+
export { minRV, medRV, realizedQuarticity } from "./robustvol.js";
|
|
21
22
|
export { realizedSemivariance, downsideVarianceRatio, signedJumpVariation, } from "./semivar.js";
|
|
22
23
|
export { shannonEntropy, normalizedEntropy, signEntropy, } from "./entropy.js";
|
|
23
24
|
export { Welford, Ewma, EwmaVariance, RollingWindow, } from "./online.js";
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,GAAG,EAAE,SAAS,EAAE,eAAe,EAAE,MAAM,UAAU,C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AAO,EAAE,uBAAuB,EAAE,kBAAkB,EAAE,MAAM,gBAAgB,CAAC;AAE7E,OAAO,EAAE,aAAa,EAAE,WAAW,EAAE,MAAM,gBAAgB,CAAC;AAE5D,OAAO,EACL,mBAAmB,EACnB,qBAAqB,EACrB,wBAAwB,EACxB,mBAAmB,GACpB,MAAM,eAAe,CAAC;AAEvB,OAAO,EAAE,aAAa,EAAE,MAAM,YAAY,CAAC;AAC3C,OAAO,EAAE,gBAAgB,EAAE,gBAAgB,EAAE,MAAM,cAAc,CAAC;AAClE,OAAO,EACL,gBAAgB,EAChB,aAAa,EACb,qBAAqB,GACtB,MAAM,YAAY,CAAC;AACpB,OAAO,EAAE,KAAK,EAAE,KAAK,EAAE,kBAAkB,EAAE,MAAM,gBAAgB,CAAC;AAElE,OAAO,EACL,oBAAoB,EACpB,qBAAqB,EACrB,mBAAmB,GACpB,MAAM,cAAc,CAAC;AACtB,OAAO,EACL,cAAc,EACd,iBAAiB,EACjB,WAAW,GACZ,MAAM,cAAc,CAAC;AACtB,OAAO,EACL,OAAO,EACP,IAAI,EACJ,YAAY,EACZ,aAAa,GACd,MAAM,aAAa,CAAC;AACrB,OAAO,EACL,kBAAkB,EAClB,mBAAmB,EACnB,YAAY,GACb,MAAM,iBAAiB,CAAC"}
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Jump-robust realized variance and realized quarticity.
|
|
3
|
+
*
|
|
4
|
+
* Plain realized variance (RV = Σ rᵢ²) is inflated by discrete jumps. Like
|
|
5
|
+
* bipower variation, MinRV and MedRV estimate only the *continuous* part of
|
|
6
|
+
* variance, but using the minimum / median of neighbouring absolute returns —
|
|
7
|
+
* which is even more robust to jumps (and, for MedRV, to occasional zero
|
|
8
|
+
* returns and isolated outliers) than the product form of bipower variation.
|
|
9
|
+
* Andersen, Dobrev & Schaumburg (2012).
|
|
10
|
+
*
|
|
11
|
+
* MinRV = (π/(π−2)) · (n/(n−1)) · Σ min(|rᵢ₋₁|, |rᵢ|)²
|
|
12
|
+
* MedRV = (π/(6−4√3+π)) · (n/(n−2)) · Σ med(|rᵢ₋₁|, |rᵢ|, |rᵢ₊₁|)²
|
|
13
|
+
*
|
|
14
|
+
* Realized quarticity (RQ = (n/3) · Σ rᵢ⁴) estimates the integrated quarticity
|
|
15
|
+
* ∫σ⁴ — the quantity that sets the standard error of realized variance and
|
|
16
|
+
* appears in the denominator of jump tests. Barndorff-Nielsen & Shephard (2002).
|
|
17
|
+
*
|
|
18
|
+
* Each function takes a return series and returns a non-negative number.
|
|
19
|
+
*/
|
|
20
|
+
/**
|
|
21
|
+
* MinRV — jump-robust integrated variance from the squared minimum of adjacent
|
|
22
|
+
* absolute returns. A single jump inflates one return but is paired with a
|
|
23
|
+
* smaller neighbour, so `min` discards it. Returns 0 for fewer than two returns.
|
|
24
|
+
*/
|
|
25
|
+
export declare function minRV(returns: readonly number[]): number;
|
|
26
|
+
/**
|
|
27
|
+
* MedRV — jump-robust integrated variance from the squared median of three
|
|
28
|
+
* consecutive absolute returns. The median ignores a lone jump *and* a lone
|
|
29
|
+
* near-zero return, making it the most robust of the three continuous-variance
|
|
30
|
+
* estimators here. Returns 0 for fewer than three returns.
|
|
31
|
+
*/
|
|
32
|
+
export declare function medRV(returns: readonly number[]): number;
|
|
33
|
+
/**
|
|
34
|
+
* Realized quarticity: (n/3) · Σ rᵢ⁴, an estimate of the integrated quarticity
|
|
35
|
+
* ∫σ⁴ used to form the standard error of realized variance and to standardise
|
|
36
|
+
* jump tests. Returns 0 for an empty series.
|
|
37
|
+
*/
|
|
38
|
+
export declare function realizedQuarticity(returns: readonly number[]): number;
|
|
39
|
+
//# sourceMappingURL=robustvol.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"robustvol.d.ts","sourceRoot":"","sources":["../src/robustvol.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;GAkBG;AAOH;;;;GAIG;AACH,wBAAgB,KAAK,CAAC,OAAO,EAAE,SAAS,MAAM,EAAE,GAAG,MAAM,CAWxD;AAED;;;;;GAKG;AACH,wBAAgB,KAAK,CAAC,OAAO,EAAE,SAAS,MAAM,EAAE,GAAG,MAAM,CAaxD;AAED;;;;GAIG;AACH,wBAAgB,kBAAkB,CAAC,OAAO,EAAE,SAAS,MAAM,EAAE,GAAG,MAAM,CASrE"}
|
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Jump-robust realized variance and realized quarticity.
|
|
3
|
+
*
|
|
4
|
+
* Plain realized variance (RV = Σ rᵢ²) is inflated by discrete jumps. Like
|
|
5
|
+
* bipower variation, MinRV and MedRV estimate only the *continuous* part of
|
|
6
|
+
* variance, but using the minimum / median of neighbouring absolute returns —
|
|
7
|
+
* which is even more robust to jumps (and, for MedRV, to occasional zero
|
|
8
|
+
* returns and isolated outliers) than the product form of bipower variation.
|
|
9
|
+
* Andersen, Dobrev & Schaumburg (2012).
|
|
10
|
+
*
|
|
11
|
+
* MinRV = (π/(π−2)) · (n/(n−1)) · Σ min(|rᵢ₋₁|, |rᵢ|)²
|
|
12
|
+
* MedRV = (π/(6−4√3+π)) · (n/(n−2)) · Σ med(|rᵢ₋₁|, |rᵢ|, |rᵢ₊₁|)²
|
|
13
|
+
*
|
|
14
|
+
* Realized quarticity (RQ = (n/3) · Σ rᵢ⁴) estimates the integrated quarticity
|
|
15
|
+
* ∫σ⁴ — the quantity that sets the standard error of realized variance and
|
|
16
|
+
* appears in the denominator of jump tests. Barndorff-Nielsen & Shephard (2002).
|
|
17
|
+
*
|
|
18
|
+
* Each function takes a return series and returns a non-negative number.
|
|
19
|
+
*/
|
|
20
|
+
// π / (π − 2): the MinRV scaling constant (from E[min(|Z₁|,|Z₂|)²], Z ~ N(0,1)).
|
|
21
|
+
const MIN_RV_SCALE = Math.PI / (Math.PI - 2);
|
|
22
|
+
// π / (6 − 4√3 + π): the MedRV scaling constant (from E[med(|Z₁|,|Z₂|,|Z₃|)²]).
|
|
23
|
+
const MED_RV_SCALE = Math.PI / (6 - 4 * Math.sqrt(3) + Math.PI);
|
|
24
|
+
/**
|
|
25
|
+
* MinRV — jump-robust integrated variance from the squared minimum of adjacent
|
|
26
|
+
* absolute returns. A single jump inflates one return but is paired with a
|
|
27
|
+
* smaller neighbour, so `min` discards it. Returns 0 for fewer than two returns.
|
|
28
|
+
*/
|
|
29
|
+
export function minRV(returns) {
|
|
30
|
+
const n = returns.length;
|
|
31
|
+
if (n < 2)
|
|
32
|
+
return 0;
|
|
33
|
+
let s = 0;
|
|
34
|
+
for (let i = 1; i < n; i++) {
|
|
35
|
+
const a = Math.abs(returns[i - 1]);
|
|
36
|
+
const b = Math.abs(returns[i]);
|
|
37
|
+
const m = a < b ? a : b;
|
|
38
|
+
s += m * m;
|
|
39
|
+
}
|
|
40
|
+
return MIN_RV_SCALE * (n / (n - 1)) * s;
|
|
41
|
+
}
|
|
42
|
+
/**
|
|
43
|
+
* MedRV — jump-robust integrated variance from the squared median of three
|
|
44
|
+
* consecutive absolute returns. The median ignores a lone jump *and* a lone
|
|
45
|
+
* near-zero return, making it the most robust of the three continuous-variance
|
|
46
|
+
* estimators here. Returns 0 for fewer than three returns.
|
|
47
|
+
*/
|
|
48
|
+
export function medRV(returns) {
|
|
49
|
+
const n = returns.length;
|
|
50
|
+
if (n < 3)
|
|
51
|
+
return 0;
|
|
52
|
+
let s = 0;
|
|
53
|
+
for (let i = 1; i < n - 1; i++) {
|
|
54
|
+
const a = Math.abs(returns[i - 1]);
|
|
55
|
+
const b = Math.abs(returns[i]);
|
|
56
|
+
const c = Math.abs(returns[i + 1]);
|
|
57
|
+
// median of a, b, c without allocating an array
|
|
58
|
+
const med = Math.max(Math.min(a, b), Math.min(Math.max(a, b), c));
|
|
59
|
+
s += med * med;
|
|
60
|
+
}
|
|
61
|
+
return MED_RV_SCALE * (n / (n - 2)) * s;
|
|
62
|
+
}
|
|
63
|
+
/**
|
|
64
|
+
* Realized quarticity: (n/3) · Σ rᵢ⁴, an estimate of the integrated quarticity
|
|
65
|
+
* ∫σ⁴ used to form the standard error of realized variance and to standardise
|
|
66
|
+
* jump tests. Returns 0 for an empty series.
|
|
67
|
+
*/
|
|
68
|
+
export function realizedQuarticity(returns) {
|
|
69
|
+
const n = returns.length;
|
|
70
|
+
if (n < 1)
|
|
71
|
+
return 0;
|
|
72
|
+
let s = 0;
|
|
73
|
+
for (const r of returns) {
|
|
74
|
+
const r2 = r * r;
|
|
75
|
+
s += r2 * r2;
|
|
76
|
+
}
|
|
77
|
+
return (n / 3) * s;
|
|
78
|
+
}
|
|
79
|
+
//# sourceMappingURL=robustvol.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"robustvol.js","sourceRoot":"","sources":["../src/robustvol.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;GAkBG;AAEH,iFAAiF;AACjF,MAAM,YAAY,GAAG,IAAI,CAAC,EAAE,GAAG,CAAC,IAAI,CAAC,EAAE,GAAG,CAAC,CAAC,CAAC;AAC7C,gFAAgF;AAChF,MAAM,YAAY,GAAG,IAAI,CAAC,EAAE,GAAG,CAAC,CAAC,GAAG,CAAC,GAAG,IAAI,CAAC,IAAI,CAAC,CAAC,CAAC,GAAG,IAAI,CAAC,EAAE,CAAC,CAAC;AAEhE;;;;GAIG;AACH,MAAM,UAAU,KAAK,CAAC,OAA0B;IAC9C,MAAM,CAAC,GAAG,OAAO,CAAC,MAAM,CAAC;IACzB,IAAI,CAAC,GAAG,CAAC;QAAE,OAAO,CAAC,CAAC;IACpB,IAAI,CAAC,GAAG,CAAC,CAAC;IACV,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,CAAC,EAAE,CAAC,EAAE,EAAE,CAAC;QAC3B,MAAM,CAAC,GAAG,IAAI,CAAC,GAAG,CAAC,OAAO,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC;QACnC,MAAM,CAAC,GAAG,IAAI,CAAC,GAAG,CAAC,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C;AAC1C,CAAC;AAED;;;;GAIG;AACH,MAAM,UAAU,kBAAkB,CAAC,OAA0B;IAC3D,MAAM,CAAC,GAAG,OAAO,CAAC,MAAM,CAAC;IACzB,IAAI,CAAC,GAAG,CAAC;QAAE,OAAO,CAAC,CAAC;IACpB,IAAI,CAAC,GAAG,CAAC,CAAC;IACV,KAAK,MAAM,CAAC,IAAI,OAAO,EAAE,CAAC;QACxB,MAAM,EAAE,GAAG,CAAC,GAAG,CAAC,CAAC;QACjB,CAAC,IAAI,EAAE,GAAG,EAAE,CAAC;IACf,CAAC;IACD,OAAO,CAAC,CAAC,GAAG,CAAC,CAAC,GAAG,CAAC,CAAC;AACrB,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "orderflow-metrics",
|
|
3
|
-
"version": "0.
|
|
4
|
-
"description": "Microstructure metrics in dependency-free TypeScript — OFI, VPIN, information-driven bars, market impact (square-root & Almgren-Chriss), markouts, implementation shortfall, high-low spread estimators (Corwin-Schultz, Abdi-Ranaldo), range-based volatility (Parkinson, Garman-Klass, Rogers-Satchell, Yang-Zhang), Hurst exponent, realized skewness & kurtosis, bipower variation & jump detection, realized semivariance & signed jump variation, order-flow entropy, online/streaming estimators (Welford, EWMA, rolling window), realized covariance/correlation/beta, Kyle's lambda, trade-sign classification, Amihud illiquidity.",
|
|
3
|
+
"version": "0.25.0",
|
|
4
|
+
"description": "Microstructure metrics in dependency-free TypeScript — OFI, VPIN, information-driven bars, market impact (square-root & Almgren-Chriss), markouts, implementation shortfall, high-low spread estimators (Corwin-Schultz, Abdi-Ranaldo), range-based volatility (Parkinson, Garman-Klass, Rogers-Satchell, Yang-Zhang), Hurst exponent, realized skewness & kurtosis, bipower variation & jump detection, jump-robust variance (MinRV, MedRV) & realized quarticity, realized semivariance & signed jump variation, order-flow entropy, online/streaming estimators (Welford, EWMA, rolling window), realized covariance/correlation/beta, Kyle's lambda, trade-sign classification, Amihud illiquidity.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./dist/index.js",
|
|
7
7
|
"module": "./dist/index.js",
|
package/src/index.ts
CHANGED
package/src/robustvol.ts
ADDED
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Jump-robust realized variance and realized quarticity.
|
|
3
|
+
*
|
|
4
|
+
* Plain realized variance (RV = Σ rᵢ²) is inflated by discrete jumps. Like
|
|
5
|
+
* bipower variation, MinRV and MedRV estimate only the *continuous* part of
|
|
6
|
+
* variance, but using the minimum / median of neighbouring absolute returns —
|
|
7
|
+
* which is even more robust to jumps (and, for MedRV, to occasional zero
|
|
8
|
+
* returns and isolated outliers) than the product form of bipower variation.
|
|
9
|
+
* Andersen, Dobrev & Schaumburg (2012).
|
|
10
|
+
*
|
|
11
|
+
* MinRV = (π/(π−2)) · (n/(n−1)) · Σ min(|rᵢ₋₁|, |rᵢ|)²
|
|
12
|
+
* MedRV = (π/(6−4√3+π)) · (n/(n−2)) · Σ med(|rᵢ₋₁|, |rᵢ|, |rᵢ₊₁|)²
|
|
13
|
+
*
|
|
14
|
+
* Realized quarticity (RQ = (n/3) · Σ rᵢ⁴) estimates the integrated quarticity
|
|
15
|
+
* ∫σ⁴ — the quantity that sets the standard error of realized variance and
|
|
16
|
+
* appears in the denominator of jump tests. Barndorff-Nielsen & Shephard (2002).
|
|
17
|
+
*
|
|
18
|
+
* Each function takes a return series and returns a non-negative number.
|
|
19
|
+
*/
|
|
20
|
+
|
|
21
|
+
// π / (π − 2): the MinRV scaling constant (from E[min(|Z₁|,|Z₂|)²], Z ~ N(0,1)).
|
|
22
|
+
const MIN_RV_SCALE = Math.PI / (Math.PI - 2);
|
|
23
|
+
// π / (6 − 4√3 + π): the MedRV scaling constant (from E[med(|Z₁|,|Z₂|,|Z₃|)²]).
|
|
24
|
+
const MED_RV_SCALE = Math.PI / (6 - 4 * Math.sqrt(3) + Math.PI);
|
|
25
|
+
|
|
26
|
+
/**
|
|
27
|
+
* MinRV — jump-robust integrated variance from the squared minimum of adjacent
|
|
28
|
+
* absolute returns. A single jump inflates one return but is paired with a
|
|
29
|
+
* smaller neighbour, so `min` discards it. Returns 0 for fewer than two returns.
|
|
30
|
+
*/
|
|
31
|
+
export function minRV(returns: readonly number[]): number {
|
|
32
|
+
const n = returns.length;
|
|
33
|
+
if (n < 2) return 0;
|
|
34
|
+
let s = 0;
|
|
35
|
+
for (let i = 1; i < n; i++) {
|
|
36
|
+
const a = Math.abs(returns[i - 1]);
|
|
37
|
+
const b = Math.abs(returns[i]);
|
|
38
|
+
const m = a < b ? a : b;
|
|
39
|
+
s += m * m;
|
|
40
|
+
}
|
|
41
|
+
return MIN_RV_SCALE * (n / (n - 1)) * s;
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
/**
|
|
45
|
+
* MedRV — jump-robust integrated variance from the squared median of three
|
|
46
|
+
* consecutive absolute returns. The median ignores a lone jump *and* a lone
|
|
47
|
+
* near-zero return, making it the most robust of the three continuous-variance
|
|
48
|
+
* estimators here. Returns 0 for fewer than three returns.
|
|
49
|
+
*/
|
|
50
|
+
export function medRV(returns: readonly number[]): number {
|
|
51
|
+
const n = returns.length;
|
|
52
|
+
if (n < 3) return 0;
|
|
53
|
+
let s = 0;
|
|
54
|
+
for (let i = 1; i < n - 1; i++) {
|
|
55
|
+
const a = Math.abs(returns[i - 1]);
|
|
56
|
+
const b = Math.abs(returns[i]);
|
|
57
|
+
const c = Math.abs(returns[i + 1]);
|
|
58
|
+
// median of a, b, c without allocating an array
|
|
59
|
+
const med = Math.max(Math.min(a, b), Math.min(Math.max(a, b), c));
|
|
60
|
+
s += med * med;
|
|
61
|
+
}
|
|
62
|
+
return MED_RV_SCALE * (n / (n - 2)) * s;
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
/**
|
|
66
|
+
* Realized quarticity: (n/3) · Σ rᵢ⁴, an estimate of the integrated quarticity
|
|
67
|
+
* ∫σ⁴ used to form the standard error of realized variance and to standardise
|
|
68
|
+
* jump tests. Returns 0 for an empty series.
|
|
69
|
+
*/
|
|
70
|
+
export function realizedQuarticity(returns: readonly number[]): number {
|
|
71
|
+
const n = returns.length;
|
|
72
|
+
if (n < 1) return 0;
|
|
73
|
+
let s = 0;
|
|
74
|
+
for (const r of returns) {
|
|
75
|
+
const r2 = r * r;
|
|
76
|
+
s += r2 * r2;
|
|
77
|
+
}
|
|
78
|
+
return (n / 3) * s;
|
|
79
|
+
}
|