squeeze-kernel 3.1.1__tar.gz → 3.2.0__tar.gz
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.
Potentially problematic release.
This version of squeeze-kernel might be problematic. Click here for more details.
- {squeeze_kernel-3.1.1 → squeeze_kernel-3.2.0}/PKG-INFO +19 -14
- {squeeze_kernel-3.1.1 → squeeze_kernel-3.2.0}/README.md +18 -13
- {squeeze_kernel-3.1.1 → squeeze_kernel-3.2.0}/pyproject.toml +1 -1
- {squeeze_kernel-3.1.1 → squeeze_kernel-3.2.0}/pyproject.toml.orig +1 -1
- {squeeze_kernel-3.1.1 → squeeze_kernel-3.2.0}/src/squeeze_kernel/__init__.py +1 -1
- {squeeze_kernel-3.1.1 → squeeze_kernel-3.2.0}/src/squeeze_kernel/core.py +2 -0
- {squeeze_kernel-3.1.1 → squeeze_kernel-3.2.0}/src/squeeze_kernel/estimator.py +37 -0
- {squeeze_kernel-3.1.1 → squeeze_kernel-3.2.0}/src/squeeze_kernel/batch.py +0 -0
- {squeeze_kernel-3.1.1 → squeeze_kernel-3.2.0}/src/squeeze_kernel/kernels.py +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: squeeze-kernel
|
|
3
|
-
Version: 3.
|
|
3
|
+
Version: 3.2.0
|
|
4
4
|
Summary: Streaming, PSD-by-construction covariance estimator with Fisher-kernel weighting and adaptive shrinkage
|
|
5
5
|
Keywords: covariance,correlation,ewma,kernel,risk,streaming
|
|
6
6
|
Author: Robert Kende
|
|
@@ -48,20 +48,21 @@ for r_t in returns: # NaN marks missing assets
|
|
|
48
48
|
cov = sk.covariance()
|
|
49
49
|
```
|
|
50
50
|
|
|
51
|
-
Reference: *
|
|
51
|
+
Reference: Kende (2026), *The Squeeze Kernel Covariance Estimator* — [SSRN abstract 6455918](https://ssrn.com/abstract=6455918). The 3.x estimator is described in the paper's September 2026 revision, *The Squeeze Kernel Covariance Estimator: A Diagonal-Congruence Flow in Per-Asset Trading Time*.
|
|
52
52
|
|
|
53
53
|
## Why
|
|
54
54
|
|
|
55
55
|
Markets do not keep calendar time. Following Mandelbrot, the estimator treats a panel as a collection of partially coupled markets, **each advancing on its own activity-driven clock** — and reads those clocks from the panel's own correlation structure, so a hot cluster (say precious metals and FX) advances its correlation state while an idle one (agriculture) does not, without anyone identifying a cluster. On those clocks it runs a single recursion that:
|
|
56
56
|
|
|
57
|
-
- **is PSD at every step, structurally** — the correlation state evolves by a diagonal-congruence flow (a congruence plus a rank-one term); no eigenvalue clipping, no nearest-PSD repair, and no factorisation anywhere in the state update. (The adaptive
|
|
58
|
-
- **learns in market time and forgets in calendar time** — observations enter with a saturating, self-studentising weight (no day counts more than one unit of trading time); memory decays at fixed per-day rates on a geometric ladder of three timescales `(lam⁴, lam, lam^¼)`. Pairs accrue covariance at the geometric mean of their two clock increments, which is the most positive semi-definiteness allows and exactly the Cauchy–Schwarz bound on how far two assets' clocks can overlap;
|
|
59
|
-
- **
|
|
60
|
-
- **
|
|
57
|
+
- **is PSD at every step, structurally** — the correlation state evolves by a diagonal-congruence flow (a congruence plus a rank-one term); no eigenvalue clipping, no nearest-PSD repair, and no factorisation anywhere in the state update. (The adaptive mixture is the one exception: it reads the gradient of the blend's own log score, which costs one Cholesky factorisation of the blend and a positive-definiteness check of each timescale's block per day. Switch it off on `SqueezeKernelEstimator` and the estimator is pure `O(Kn²)`.)
|
|
58
|
+
- **learns in market time and forgets in calendar time** — observations enter with a saturating, self-studentising weight (no day counts more than one unit of trading time); memory decays at fixed per-day rates on a geometric ladder of three timescales `(lam⁴, lam, lam^¼)`. Pairs accrue covariance at the geometric mean of their two clock increments, which is the most positive semi-definiteness allows and exactly the Cauchy–Schwarz bound on how far two assets' clocks can overlap. In closed form, each timescale's correlation is that of an exponentially weighted Gram matrix of the clock-weighted returns `√w·z`: day `s` enters the pair `(i, j)` with weight `√(w_i,s·w_j,s)` (market time) and is discounted by `lam_k^(t−s)` (calendar time). That makes it the natural-gradient step of the Gaussian log score, taken as a chord in calendar time on clock-weighted data; the geodesic along the same gradient would be an unbounded time change;
|
|
59
|
+
- **uses each day's magnitude once** — the day's Mahalanobis norm under the estimator's own forecast, `m = r'Σ⁻¹r`, sets the clock and is then removed from the observation: the innovation carries the weight `ω = n/m`, the posterior mean of the inverse trading-time increment under a scale-free prior (Tyler's weight; the Student-t score-driven weight is the same posterior mean under an inverse-gamma prior). A day's direction moves the state; its size only says how much trading time it carried. One dot product from the factorisation the mixture already performs, no constant;
|
|
60
|
+
- **regularises itself** — each timescale's shrinkage intensity is computed from two online statistics, the concentration `n/ν` (dimension per unit trading time) and the de-noised fraction of correlation dispersion the target explains; the target is the Hadamard square of the running correlation, which is exactly the correlation matrix of the *squared* returns (cluster-respecting, PSD by the Schur product theorem, and sign-blind by construction — the signs are carried by the unshrunk term). The intensity rule is the *prior* of a learned split: each timescale's shrunk correlation is a pool of its raw correlation, its equicorrelation level and its Hadamard square, whose weights are pulled toward the rule's `(1−α, α(1−α), α²)` by a fixed share and corrected online by the blend gradient;
|
|
61
|
+
- **adapts its memory to regime breaks, in both stages** — the timescale mix moves by an exponentiated-gradient step on the *blend's* own log score (not on any single timescale's, which would select rather than blend): each weight follows the Fisher–Rao inner product of its timescale with the day's natural gradient, at a temperature calibrated so that uninformative evidence leaves the mix within a factor e of its prior; the marginal variance is tracked on its own three-rung ladder, two octaves below the correlation ladder, and pooled panel-wide by the same rule on saturated evidence, so one spike day cannot hand a stale rung weeks of weight. Nothing in either mixture is fitted: the ladders are derived from `lam`, the evidence memory is the fastest rung's, and the temperature is the null's;
|
|
61
62
|
- **ingests missing values natively** — listings, delistings, halts enter as `NaN`;
|
|
62
|
-
- **is
|
|
63
|
+
- **is cheap, with no solver** — `O(Kn²)` state work plus `K + 1` Cholesky factorisations a day, no iterative optimisation anywhere; a thirty-year daily pass at n = 300 takes about two minutes single-threaded (the mixture's factorisation also certifies the spectral floor of the scored blend inactive on almost every day, and supplies the observation weight for one dot product). CM-IEWMA as released by its authors takes 11–41 times as long on the same panels, most of it a daily convex programme that is infeasible on up to 19% of days at n = 300; DCC and DCC-NL are cheaper still.
|
|
63
64
|
|
|
64
|
-
**Evidence.** On thirty years of S&P 500 constituents against
|
|
65
|
+
**Evidence.** On thirty years of S&P 500 constituents against a ten-method field, every baseline fitted on a tuning block (EWMA, DCC, DCC-NL, Ledoit–Wolf, OAS, nonlinear shrinkage, RMT filtering, Gerber, IEWMA, CM-IEWMA), it leads at every universe size from 50 to 300 and is the **sole member of the 90% model confidence set at every size**. Frozen on data to 2021, it leads the best baseline on 2022–2026 by 1.7, 3.7, 11.1 and 19.2 NLL per day at n = 50, 100, 200 and 300. On twenty-four pre-registered universes of small and mid caps sealed before any scoring (two draws of twelve) it is first on every one against a field fitted to each universe, by 13 to 18 NLL per day at n = 300; the second draw was sealed for the observation weight, which improved the estimator on eleven of the twelve, by 0.6 to 1.8 NLL per day at n ≥ 200. Carried **zero-shot** to a diversified panel of 121 futures across eight asset classes it beats the five baselines that run there, *calibrated on that panel's own history*, by 11.3 to 121 NLL per day out-of-time (the weight costs 0.5 per day on that block, its one trade-off); on the public FF49 industry panel of Johansson et al. it has the lowest regret on their own metric. The ranking holds under the Student-t and density-power scores.
|
|
65
66
|
|
|
66
67
|
## See the difference
|
|
67
68
|
|
|
@@ -74,7 +75,7 @@ A passive strategy any allocator would recognize: long-only minimum-variance ove
|
|
|
74
75
|
|
|
75
76
|
| Method | CAGR | Vol | Sharpe | MaxDD | Calmar | Vol-target RMSE |
|
|
76
77
|
|---|---|---|---|---|---|---|
|
|
77
|
-
| **Squeeze Kernel (default)** | **12.
|
|
78
|
+
| **Squeeze Kernel (default)** | **12.5%** | **13.6%** | **0.92** | **-34.5%** | **0.36** | **7.05%** |
|
|
78
79
|
| Ledoit-Wolf (252d) | 11.7% | 14.6% | 0.80 | -38.7% | 0.30 | 7.51% |
|
|
79
80
|
|
|
80
81
|
Reproduce from the repo alone (the 300-stock panel ships as a parquet; survivorship and provenance are documented in the script):
|
|
@@ -88,7 +89,7 @@ python examples/vol_targeted_portfolio.py # ~2 minutes
|
|
|
88
89
|
|
|
89
90
|
```bash
|
|
90
91
|
pip install squeeze-kernel # NumPy only
|
|
91
|
-
pip install "squeeze-kernel[full]" # + SciPy (faster
|
|
92
|
+
pip install "squeeze-kernel[full]" # + SciPy (faster Cholesky factorisations for the mixture)
|
|
92
93
|
```
|
|
93
94
|
|
|
94
95
|
## Quickstart
|
|
@@ -111,6 +112,8 @@ cov_path, corr_path, weights = estimate_squeeze_cov(returns, with_weights=True)
|
|
|
111
112
|
|
|
112
113
|
Missing values: pass `NaN` (or `mask=` on `update`). Newly listed, delisted or halted assets need no imputation and no complete-case subsetting.
|
|
113
114
|
|
|
115
|
+
Units: pass returns in decimal units (`0.01` = 1%). The numerical floors are absolute (`ε = 1e-8` in squared-return units), so percent-unit returns give a different path. A panel whose first day carries many exact-zero returns starts with a transient that the slow timescale remembers; start a day later.
|
|
116
|
+
|
|
114
117
|
## What derives from `lam`
|
|
115
118
|
|
|
116
119
|
| quantity | value |
|
|
@@ -119,15 +122,17 @@ Missing values: pass `NaN` (or `mask=` on `update`). Newly listed, delisted or h
|
|
|
119
122
|
| kernel scale | state: `κ_t = ⅓ · EWMA(activity)` at the anchor rate |
|
|
120
123
|
| shrinkage intensity | per timescale, `α = min(1,c) · g̃²/(g̃² + (1−g̃)²·max(0, 1/c − 1))` from the online concentration `c = n/ν` and target-fit `g̃` |
|
|
121
124
|
| timescale weights | prior ∝ √h, moved by exponentiated gradient on the blend log score at the null temperature, fast-rung memory |
|
|
125
|
+
| shrinkage split | per timescale, a learned pool of the raw correlation, its equicorrelation level and its Hadamard square; prior `(1−α, α(1−α), α²)`, moved by the blend gradient |
|
|
126
|
+
| observation weight | state: `ω_t = n_t/m_t`, the day's observed count over its Mahalanobis distance under yesterday's forecast, from the mixture's own factorisation |
|
|
122
127
|
| volatility memory | ladder `(h/16, h/4, h)`, pooled panel-wide by the same rule on tanh-saturated evidence, uniform prior |
|
|
123
|
-
| structural constants | K=3, b=4, θ=½, κ-scale ⅓, Schur power 2 — each bracketed by ablation in the paper |
|
|
124
|
-
| fitted constants |
|
|
128
|
+
| structural constants | K=3, b=4, θ=½, κ-scale ⅓, Schur power 2, intensity exponent 2 — each bracketed by ablation in the paper |
|
|
129
|
+
| fitted constants | `lam` itself (0.996, chosen on data to 2021); nothing else is fitted |
|
|
125
130
|
|
|
126
|
-
`from squeeze_kernel import CONSTANTS` exposes the structural constants for research. The published v1 estimator (all its knobs) remains available as `SqueezeKernelEstimator` / `SqueezeKernel.v1(...)`; every 2.0
|
|
131
|
+
`from squeeze_kernel import CONSTANTS` exposes the structural constants for research. The published v1 estimator (all its knobs) remains available as `SqueezeKernelEstimator` / `SqueezeKernel.v1(...)`; every mechanism since 2.0 is also an estimator-level switch for ablation. See [MIGRATION.md](MIGRATION.md).
|
|
127
132
|
|
|
128
133
|
## How it works
|
|
129
134
|
|
|
130
|
-
One daily update: variance on a three-rung ladder per asset, pooled by panel-wide self-adapting weights → standardised surprise → per-asset clock increments from the Schur-square-weighted neighbourhood mean of squared surprises → diagonal-congruence update of each timescale's correlation state on those clocks → per-timescale shrinkage as a learned pool of the raw correlation, its equicorrelation level and its Hadamard square, with the self-tuning intensity rule as the prior and the blend gradient as the correction → blend across timescales, moved by the gradient of the blend's own log score → covariance. The paper gives the derivations, guarantees (PSD, conditioning floor, exact reductions to the published special cases), and the full evaluation.
|
|
135
|
+
One daily update: variance on a three-rung ladder per asset, pooled by panel-wide self-adapting weights → standardised surprise → per-asset clock increments from the Schur-square-weighted neighbourhood mean of squared surprises → diagonal-congruence update of each timescale's correlation state on those clocks, the day's outer product scaled by `n/m` → per-timescale shrinkage as a learned pool of the raw correlation, its equicorrelation level and its Hadamard square, with the self-tuning intensity rule as the prior and the blend gradient as the correction → blend across timescales, moved by the gradient of the blend's own log score → covariance. The paper gives the derivations (the natural-gradient and Gram-matrix forms of the flow, the Fisher–Rao form of the mixture), the guarantees (PSD, conditioning floor, exact reductions to the published special cases), and the full evaluation.
|
|
131
136
|
|
|
132
137
|
## Development
|
|
133
138
|
|
|
@@ -17,20 +17,21 @@ for r_t in returns: # NaN marks missing assets
|
|
|
17
17
|
cov = sk.covariance()
|
|
18
18
|
```
|
|
19
19
|
|
|
20
|
-
Reference: *
|
|
20
|
+
Reference: Kende (2026), *The Squeeze Kernel Covariance Estimator* — [SSRN abstract 6455918](https://ssrn.com/abstract=6455918). The 3.x estimator is described in the paper's September 2026 revision, *The Squeeze Kernel Covariance Estimator: A Diagonal-Congruence Flow in Per-Asset Trading Time*.
|
|
21
21
|
|
|
22
22
|
## Why
|
|
23
23
|
|
|
24
24
|
Markets do not keep calendar time. Following Mandelbrot, the estimator treats a panel as a collection of partially coupled markets, **each advancing on its own activity-driven clock** — and reads those clocks from the panel's own correlation structure, so a hot cluster (say precious metals and FX) advances its correlation state while an idle one (agriculture) does not, without anyone identifying a cluster. On those clocks it runs a single recursion that:
|
|
25
25
|
|
|
26
|
-
- **is PSD at every step, structurally** — the correlation state evolves by a diagonal-congruence flow (a congruence plus a rank-one term); no eigenvalue clipping, no nearest-PSD repair, and no factorisation anywhere in the state update. (The adaptive
|
|
27
|
-
- **learns in market time and forgets in calendar time** — observations enter with a saturating, self-studentising weight (no day counts more than one unit of trading time); memory decays at fixed per-day rates on a geometric ladder of three timescales `(lam⁴, lam, lam^¼)`. Pairs accrue covariance at the geometric mean of their two clock increments, which is the most positive semi-definiteness allows and exactly the Cauchy–Schwarz bound on how far two assets' clocks can overlap;
|
|
28
|
-
- **
|
|
29
|
-
- **
|
|
26
|
+
- **is PSD at every step, structurally** — the correlation state evolves by a diagonal-congruence flow (a congruence plus a rank-one term); no eigenvalue clipping, no nearest-PSD repair, and no factorisation anywhere in the state update. (The adaptive mixture is the one exception: it reads the gradient of the blend's own log score, which costs one Cholesky factorisation of the blend and a positive-definiteness check of each timescale's block per day. Switch it off on `SqueezeKernelEstimator` and the estimator is pure `O(Kn²)`.)
|
|
27
|
+
- **learns in market time and forgets in calendar time** — observations enter with a saturating, self-studentising weight (no day counts more than one unit of trading time); memory decays at fixed per-day rates on a geometric ladder of three timescales `(lam⁴, lam, lam^¼)`. Pairs accrue covariance at the geometric mean of their two clock increments, which is the most positive semi-definiteness allows and exactly the Cauchy–Schwarz bound on how far two assets' clocks can overlap. In closed form, each timescale's correlation is that of an exponentially weighted Gram matrix of the clock-weighted returns `√w·z`: day `s` enters the pair `(i, j)` with weight `√(w_i,s·w_j,s)` (market time) and is discounted by `lam_k^(t−s)` (calendar time). That makes it the natural-gradient step of the Gaussian log score, taken as a chord in calendar time on clock-weighted data; the geodesic along the same gradient would be an unbounded time change;
|
|
28
|
+
- **uses each day's magnitude once** — the day's Mahalanobis norm under the estimator's own forecast, `m = r'Σ⁻¹r`, sets the clock and is then removed from the observation: the innovation carries the weight `ω = n/m`, the posterior mean of the inverse trading-time increment under a scale-free prior (Tyler's weight; the Student-t score-driven weight is the same posterior mean under an inverse-gamma prior). A day's direction moves the state; its size only says how much trading time it carried. One dot product from the factorisation the mixture already performs, no constant;
|
|
29
|
+
- **regularises itself** — each timescale's shrinkage intensity is computed from two online statistics, the concentration `n/ν` (dimension per unit trading time) and the de-noised fraction of correlation dispersion the target explains; the target is the Hadamard square of the running correlation, which is exactly the correlation matrix of the *squared* returns (cluster-respecting, PSD by the Schur product theorem, and sign-blind by construction — the signs are carried by the unshrunk term). The intensity rule is the *prior* of a learned split: each timescale's shrunk correlation is a pool of its raw correlation, its equicorrelation level and its Hadamard square, whose weights are pulled toward the rule's `(1−α, α(1−α), α²)` by a fixed share and corrected online by the blend gradient;
|
|
30
|
+
- **adapts its memory to regime breaks, in both stages** — the timescale mix moves by an exponentiated-gradient step on the *blend's* own log score (not on any single timescale's, which would select rather than blend): each weight follows the Fisher–Rao inner product of its timescale with the day's natural gradient, at a temperature calibrated so that uninformative evidence leaves the mix within a factor e of its prior; the marginal variance is tracked on its own three-rung ladder, two octaves below the correlation ladder, and pooled panel-wide by the same rule on saturated evidence, so one spike day cannot hand a stale rung weeks of weight. Nothing in either mixture is fitted: the ladders are derived from `lam`, the evidence memory is the fastest rung's, and the temperature is the null's;
|
|
30
31
|
- **ingests missing values natively** — listings, delistings, halts enter as `NaN`;
|
|
31
|
-
- **is
|
|
32
|
+
- **is cheap, with no solver** — `O(Kn²)` state work plus `K + 1` Cholesky factorisations a day, no iterative optimisation anywhere; a thirty-year daily pass at n = 300 takes about two minutes single-threaded (the mixture's factorisation also certifies the spectral floor of the scored blend inactive on almost every day, and supplies the observation weight for one dot product). CM-IEWMA as released by its authors takes 11–41 times as long on the same panels, most of it a daily convex programme that is infeasible on up to 19% of days at n = 300; DCC and DCC-NL are cheaper still.
|
|
32
33
|
|
|
33
|
-
**Evidence.** On thirty years of S&P 500 constituents against
|
|
34
|
+
**Evidence.** On thirty years of S&P 500 constituents against a ten-method field, every baseline fitted on a tuning block (EWMA, DCC, DCC-NL, Ledoit–Wolf, OAS, nonlinear shrinkage, RMT filtering, Gerber, IEWMA, CM-IEWMA), it leads at every universe size from 50 to 300 and is the **sole member of the 90% model confidence set at every size**. Frozen on data to 2021, it leads the best baseline on 2022–2026 by 1.7, 3.7, 11.1 and 19.2 NLL per day at n = 50, 100, 200 and 300. On twenty-four pre-registered universes of small and mid caps sealed before any scoring (two draws of twelve) it is first on every one against a field fitted to each universe, by 13 to 18 NLL per day at n = 300; the second draw was sealed for the observation weight, which improved the estimator on eleven of the twelve, by 0.6 to 1.8 NLL per day at n ≥ 200. Carried **zero-shot** to a diversified panel of 121 futures across eight asset classes it beats the five baselines that run there, *calibrated on that panel's own history*, by 11.3 to 121 NLL per day out-of-time (the weight costs 0.5 per day on that block, its one trade-off); on the public FF49 industry panel of Johansson et al. it has the lowest regret on their own metric. The ranking holds under the Student-t and density-power scores.
|
|
34
35
|
|
|
35
36
|
## See the difference
|
|
36
37
|
|
|
@@ -43,7 +44,7 @@ A passive strategy any allocator would recognize: long-only minimum-variance ove
|
|
|
43
44
|
|
|
44
45
|
| Method | CAGR | Vol | Sharpe | MaxDD | Calmar | Vol-target RMSE |
|
|
45
46
|
|---|---|---|---|---|---|---|
|
|
46
|
-
| **Squeeze Kernel (default)** | **12.
|
|
47
|
+
| **Squeeze Kernel (default)** | **12.5%** | **13.6%** | **0.92** | **-34.5%** | **0.36** | **7.05%** |
|
|
47
48
|
| Ledoit-Wolf (252d) | 11.7% | 14.6% | 0.80 | -38.7% | 0.30 | 7.51% |
|
|
48
49
|
|
|
49
50
|
Reproduce from the repo alone (the 300-stock panel ships as a parquet; survivorship and provenance are documented in the script):
|
|
@@ -57,7 +58,7 @@ python examples/vol_targeted_portfolio.py # ~2 minutes
|
|
|
57
58
|
|
|
58
59
|
```bash
|
|
59
60
|
pip install squeeze-kernel # NumPy only
|
|
60
|
-
pip install "squeeze-kernel[full]" # + SciPy (faster
|
|
61
|
+
pip install "squeeze-kernel[full]" # + SciPy (faster Cholesky factorisations for the mixture)
|
|
61
62
|
```
|
|
62
63
|
|
|
63
64
|
## Quickstart
|
|
@@ -80,6 +81,8 @@ cov_path, corr_path, weights = estimate_squeeze_cov(returns, with_weights=True)
|
|
|
80
81
|
|
|
81
82
|
Missing values: pass `NaN` (or `mask=` on `update`). Newly listed, delisted or halted assets need no imputation and no complete-case subsetting.
|
|
82
83
|
|
|
84
|
+
Units: pass returns in decimal units (`0.01` = 1%). The numerical floors are absolute (`ε = 1e-8` in squared-return units), so percent-unit returns give a different path. A panel whose first day carries many exact-zero returns starts with a transient that the slow timescale remembers; start a day later.
|
|
85
|
+
|
|
83
86
|
## What derives from `lam`
|
|
84
87
|
|
|
85
88
|
| quantity | value |
|
|
@@ -88,15 +91,17 @@ Missing values: pass `NaN` (or `mask=` on `update`). Newly listed, delisted or h
|
|
|
88
91
|
| kernel scale | state: `κ_t = ⅓ · EWMA(activity)` at the anchor rate |
|
|
89
92
|
| shrinkage intensity | per timescale, `α = min(1,c) · g̃²/(g̃² + (1−g̃)²·max(0, 1/c − 1))` from the online concentration `c = n/ν` and target-fit `g̃` |
|
|
90
93
|
| timescale weights | prior ∝ √h, moved by exponentiated gradient on the blend log score at the null temperature, fast-rung memory |
|
|
94
|
+
| shrinkage split | per timescale, a learned pool of the raw correlation, its equicorrelation level and its Hadamard square; prior `(1−α, α(1−α), α²)`, moved by the blend gradient |
|
|
95
|
+
| observation weight | state: `ω_t = n_t/m_t`, the day's observed count over its Mahalanobis distance under yesterday's forecast, from the mixture's own factorisation |
|
|
91
96
|
| volatility memory | ladder `(h/16, h/4, h)`, pooled panel-wide by the same rule on tanh-saturated evidence, uniform prior |
|
|
92
|
-
| structural constants | K=3, b=4, θ=½, κ-scale ⅓, Schur power 2 — each bracketed by ablation in the paper |
|
|
93
|
-
| fitted constants |
|
|
97
|
+
| structural constants | K=3, b=4, θ=½, κ-scale ⅓, Schur power 2, intensity exponent 2 — each bracketed by ablation in the paper |
|
|
98
|
+
| fitted constants | `lam` itself (0.996, chosen on data to 2021); nothing else is fitted |
|
|
94
99
|
|
|
95
|
-
`from squeeze_kernel import CONSTANTS` exposes the structural constants for research. The published v1 estimator (all its knobs) remains available as `SqueezeKernelEstimator` / `SqueezeKernel.v1(...)`; every 2.0
|
|
100
|
+
`from squeeze_kernel import CONSTANTS` exposes the structural constants for research. The published v1 estimator (all its knobs) remains available as `SqueezeKernelEstimator` / `SqueezeKernel.v1(...)`; every mechanism since 2.0 is also an estimator-level switch for ablation. See [MIGRATION.md](MIGRATION.md).
|
|
96
101
|
|
|
97
102
|
## How it works
|
|
98
103
|
|
|
99
|
-
One daily update: variance on a three-rung ladder per asset, pooled by panel-wide self-adapting weights → standardised surprise → per-asset clock increments from the Schur-square-weighted neighbourhood mean of squared surprises → diagonal-congruence update of each timescale's correlation state on those clocks → per-timescale shrinkage as a learned pool of the raw correlation, its equicorrelation level and its Hadamard square, with the self-tuning intensity rule as the prior and the blend gradient as the correction → blend across timescales, moved by the gradient of the blend's own log score → covariance. The paper gives the derivations, guarantees (PSD, conditioning floor, exact reductions to the published special cases), and the full evaluation.
|
|
104
|
+
One daily update: variance on a three-rung ladder per asset, pooled by panel-wide self-adapting weights → standardised surprise → per-asset clock increments from the Schur-square-weighted neighbourhood mean of squared surprises → diagonal-congruence update of each timescale's correlation state on those clocks, the day's outer product scaled by `n/m` → per-timescale shrinkage as a learned pool of the raw correlation, its equicorrelation level and its Hadamard square, with the self-tuning intensity rule as the prior and the blend gradient as the correction → blend across timescales, moved by the gradient of the blend's own log score → covariance. The paper gives the derivations (the natural-gradient and Gram-matrix forms of the flow, the Fisher–Rao form of the mixture), the guarantees (PSD, conditioning floor, exact reductions to the published special cases), and the full evaluation.
|
|
100
105
|
|
|
101
106
|
## Development
|
|
102
107
|
|
|
@@ -4,7 +4,7 @@ build-backend = "uv_build"
|
|
|
4
4
|
|
|
5
5
|
[project]
|
|
6
6
|
name = "squeeze-kernel"
|
|
7
|
-
version = "3.
|
|
7
|
+
version = "3.2.0"
|
|
8
8
|
description = "Streaming, PSD-by-construction covariance estimator with Fisher-kernel weighting and adaptive shrinkage"
|
|
9
9
|
readme = "README.md"
|
|
10
10
|
license = "MIT"
|
|
@@ -4,7 +4,7 @@ build-backend = "uv_build"
|
|
|
4
4
|
|
|
5
5
|
[project]
|
|
6
6
|
name = "squeeze-kernel"
|
|
7
|
-
version = "3.
|
|
7
|
+
version = "3.2.0"
|
|
8
8
|
description = "Streaming, PSD-by-construction covariance estimator with Fisher-kernel weighting and adaptive shrinkage"
|
|
9
9
|
readme = "README.md"
|
|
10
10
|
license = "MIT"
|
|
@@ -121,6 +121,7 @@ class SqueezeKernel:
|
|
|
121
121
|
vol_ladder=True,
|
|
122
122
|
weights="eg_blend",
|
|
123
123
|
split_learn=True,
|
|
124
|
+
obs_weight="tyler",
|
|
124
125
|
epsilon=c.epsilon,
|
|
125
126
|
)
|
|
126
127
|
|
|
@@ -177,6 +178,7 @@ class SqueezeKernel:
|
|
|
177
178
|
"rung_nu": nu,
|
|
178
179
|
"detector_tilt": 0.0 if det is None else det.tilt,
|
|
179
180
|
"split": det.v.copy() if isinstance(det, _BlendGradient) and det.split else None,
|
|
181
|
+
"omega_t": est._last_omega,
|
|
180
182
|
}
|
|
181
183
|
|
|
182
184
|
# ── v1 escape hatch ──────────────────────────────────────────────────
|
|
@@ -193,10 +193,17 @@ class _BlendGradient:
|
|
|
193
193
|
self.prev_vol: np.ndarray | None = None
|
|
194
194
|
self.prev_v: np.ndarray | None = None
|
|
195
195
|
self._gc: np.ndarray | None = None
|
|
196
|
+
# The day's Mahalanobis distance under the forecast, m = r' Sigma^-1 r
|
|
197
|
+
# on the observed subvector, and that subvector's size: read by the
|
|
198
|
+
# 3.2 observation weight; NaN on a day the gradient abstains.
|
|
199
|
+
self.m_last = float("nan")
|
|
200
|
+
self.n_last = 0
|
|
196
201
|
|
|
197
202
|
def score(self, r_t: np.ndarray, finite: np.ndarray) -> np.ndarray | None:
|
|
198
203
|
"""Gradient of the previous blend's log score at ``r_t`` (observed
|
|
199
204
|
subvector), one entry per rung; ``None`` on a degenerate day."""
|
|
205
|
+
self.m_last = float("nan")
|
|
206
|
+
self.n_last = 0
|
|
200
207
|
if self.prev_sig is None or self.prev_w is None:
|
|
201
208
|
return None
|
|
202
209
|
idx = np.flatnonzero(finite)
|
|
@@ -261,6 +268,8 @@ class _BlendGradient:
|
|
|
261
268
|
except (np.linalg.LinAlgError, ValueError):
|
|
262
269
|
return None
|
|
263
270
|
u, sinv = sol
|
|
271
|
+
self.m_last = float(r_t[idx] @ u)
|
|
272
|
+
self.n_last = int(idx.size)
|
|
264
273
|
g = np.empty(K)
|
|
265
274
|
self._gc = None
|
|
266
275
|
if self.split and self.prev_comps is not None:
|
|
@@ -442,6 +451,7 @@ class SqueezeKernelEstimator:
|
|
|
442
451
|
vol_ladder: bool = False,
|
|
443
452
|
weights: str = "cusum",
|
|
444
453
|
split_learn: bool = False,
|
|
454
|
+
obs_weight: str | None = None,
|
|
445
455
|
):
|
|
446
456
|
self.n_assets = n_assets
|
|
447
457
|
if weights not in ("cusum", "eg_blend"):
|
|
@@ -450,6 +460,21 @@ class SqueezeKernelEstimator:
|
|
|
450
460
|
if split_learn and weights != "eg_blend":
|
|
451
461
|
raise ValueError("split_learn requires weights='eg_blend'.")
|
|
452
462
|
self.split_learn = bool(split_learn)
|
|
463
|
+
# 3.2: the joint observation weight. "tyler" scales each day's
|
|
464
|
+
# correlation innovation by omega = n/m, m = r' Sigma^-1 r the
|
|
465
|
+
# day's Mahalanobis distance under the estimator's own forecast of
|
|
466
|
+
# the day before (n the observed count): the posterior mean of the
|
|
467
|
+
# inverse common trading-time increment under the scale-invariant
|
|
468
|
+
# prior, Tyler's shape weight, the nu -> 0 limit of the Student-t
|
|
469
|
+
# score weight. The day's norm then enters the state once, through
|
|
470
|
+
# the clock, and its direction through the outer product. None
|
|
471
|
+
# keeps the 3.1 path bit-for-bit.
|
|
472
|
+
if obs_weight not in (None, "tyler"):
|
|
473
|
+
raise ValueError("obs_weight must be None or 'tyler'.")
|
|
474
|
+
if obs_weight is not None and (weights != "eg_blend" or clock != "asset"):
|
|
475
|
+
raise ValueError("obs_weight='tyler' requires weights='eg_blend' and clock='asset'.")
|
|
476
|
+
self.obs_weight = obs_weight
|
|
477
|
+
self._last_omega = 1.0
|
|
453
478
|
self.vol_ladder = bool(vol_ladder)
|
|
454
479
|
self.lambda_vol = lambda_vol
|
|
455
480
|
self.lambda_corr = lambda_corr
|
|
@@ -748,6 +773,16 @@ class SqueezeKernelEstimator:
|
|
|
748
773
|
finite,
|
|
749
774
|
self._kap_lam * kap_a + (1.0 - self._kap_lam) * a_act,
|
|
750
775
|
kap_a)
|
|
776
|
+
# 3.2 observation weight: sqrt(omega) on the innovation, omega =
|
|
777
|
+
# n/m from the gradient's own solve of the forecast at r_t; one
|
|
778
|
+
# on a day the gradient abstained.
|
|
779
|
+
sq_omega = 1.0
|
|
780
|
+
if w_vec is not None and self.obs_weight == "tyler":
|
|
781
|
+
assert isinstance(detector, _BlendGradient)
|
|
782
|
+
m_day = detector.m_last
|
|
783
|
+
if np.isfinite(m_day) and m_day > 1e-12:
|
|
784
|
+
sq_omega = float(np.sqrt(detector.n_last / m_day))
|
|
785
|
+
self._last_omega = sq_omega * sq_omega
|
|
751
786
|
s_eff = 0.0
|
|
752
787
|
for k in range(corr_lam.size):
|
|
753
788
|
S_list[k] = corr_lam[k] * S_list[k] + w_t
|
|
@@ -759,6 +794,8 @@ class SqueezeKernelEstimator:
|
|
|
759
794
|
eta_v = w_vec / S_a[k]
|
|
760
795
|
o = np.sqrt(1.0 - eta_v)
|
|
761
796
|
u = np.sqrt(eta_v) * z_t
|
|
797
|
+
if sq_omega != 1.0:
|
|
798
|
+
u = u * sq_omega
|
|
762
799
|
np.multiply.outer(o, o, out=self._scratch_had)
|
|
763
800
|
Q_list[k] *= self._scratch_had
|
|
764
801
|
np.multiply.outer(u, u, out=self._scratch_had)
|
|
File without changes
|
|
File without changes
|