squeeze-kernel 3.2.0__tar.gz → 4.0.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.

@@ -0,0 +1,242 @@
1
+ Metadata-Version: 2.4
2
+ Name: squeeze-kernel
3
+ Version: 4.0.0
4
+ Summary: Streaming, PSD-by-construction covariance estimator with Fisher-kernel weighting and adaptive shrinkage
5
+ Keywords: covariance,correlation,ewma,kernel,risk,streaming
6
+ Author: Robert Kende
7
+ License-Expression: MIT
8
+ Classifier: Development Status :: 4 - Beta
9
+ Classifier: Intended Audience :: Science/Research
10
+ Classifier: Topic :: Scientific/Engineering :: Mathematics
11
+ Classifier: License :: OSI Approved :: MIT License
12
+ Classifier: Programming Language :: Python :: 3
13
+ Classifier: Programming Language :: Python :: 3.10
14
+ Classifier: Programming Language :: Python :: 3.11
15
+ Classifier: Programming Language :: Python :: 3.12
16
+ Classifier: Programming Language :: Python :: 3.13
17
+ Classifier: Operating System :: OS Independent
18
+ Requires-Dist: numpy>=1.24
19
+ Requires-Dist: pytest>=7.0 ; extra == 'dev'
20
+ Requires-Dist: ruff>=0.7 ; extra == 'dev'
21
+ Requires-Dist: scipy>=1.11 ; extra == 'dev'
22
+ Requires-Dist: mypy>=1.10 ; extra == 'dev'
23
+ Requires-Dist: scipy>=1.11 ; extra == 'full'
24
+ Requires-Python: >=3.10
25
+ Project-URL: Homepage, https://github.com/r0k3/squeeze-kernel
26
+ Project-URL: Repository, https://github.com/r0k3/squeeze-kernel
27
+ Project-URL: Issues, https://github.com/r0k3/squeeze-kernel/issues
28
+ Provides-Extra: dev
29
+ Provides-Extra: full
30
+ Description-Content-Type: text/markdown
31
+
32
+ # Squeeze Kernel Covariance Estimator
33
+
34
+ [![CI](https://github.com/r0k3/squeeze-kernel/actions/workflows/ci.yml/badge.svg)](https://github.com/r0k3/squeeze-kernel/actions/workflows/ci.yml)
35
+ [![PyPI](https://img.shields.io/pypi/v/squeeze-kernel.svg)](https://pypi.org/project/squeeze-kernel/)
36
+ [![Python](https://img.shields.io/pypi/pyversions/squeeze-kernel.svg)](https://pypi.org/project/squeeze-kernel/)
37
+ [![License: MIT](https://img.shields.io/badge/license-MIT-green.svg)](LICENSE)
38
+ [![DOI](https://zenodo.org/badge/1188987927.svg)](https://doi.org/10.5281/zenodo.19170801)
39
+ [![Paper](https://img.shields.io/badge/paper-SSRN%206455918-b31b1b.svg)](https://ssrn.com/abstract=6455918)
40
+
41
+ **A streaming covariance estimator for panels of financial returns that beats every fitted baseline out of sample, costs half a millisecond to ten milliseconds a day, and has one parameter.**
42
+
43
+ ```python
44
+ from squeeze_kernel import SqueezeKernel
45
+
46
+ sk = SqueezeKernel(lam=0.996) # the entire public surface
47
+ for r_t in returns: # NaN marks missing assets
48
+ sk.update(r_t)
49
+ cov = sk.covariance() # positive semi-definite by construction, every day
50
+ ```
51
+
52
+ - **State of the art, measured.** On thirty years of S&P 500 constituents it leads ten baselines fitted to the data (CM-IEWMA, DCC, DCC-NL, nonlinear shrinkage, Ledoit–Wolf, OAS, RMT denoising, Gerber, IEWMA, EWMA) at every universe size from 50 to 300, every Diebold–Mariano *p* below 10⁻⁷, and it is the **sole member of the 90% model confidence set at every size**. With its configuration frozen on data to 2021 it stays first on 2022–2026, on **twenty-four sealed small- and mid-cap universes it had never seen**, on a 121-instrument futures panel across eight asset classes, and on the public Fama–French 49 panel on the competing authors' own metric.
53
+ - **Fast, with nothing that can fail.** One `O(Kn²)` state update, one Cholesky factorisation of the blend and `K` positive-definiteness checks a day. No rolling window, no likelihood refit, no daily solver. **0.54 ms a day at n = 50, 10.1 ms at n = 300.** The closest competitor on accuracy, CM-IEWMA as released by its authors, takes 18 to 51 times as long and spends most of it in a convex programme that is infeasible on about one scored day in five at n = 300.
54
+ - **One number, no tuning.** Everything else is derived from `lam`, fixed by a structural argument, or computed online from the estimator's own state. Listings, delistings and halts enter as `NaN`. Only dependency: NumPy.
55
+
56
+ Paper: Kende (2026), *The Squeeze Kernel Covariance Estimator*, [SSRN 6455918](https://ssrn.com/abstract=6455918). Every number on this page is taken from the tables of the paper's September 2026 revision, *A Diagonal-Congruence Flow in Per-Asset Trading Time*, which describes the 3.x estimator and carries the protocol, the proofs and the full ablation ledger.
57
+
58
+ [Benchmarks](#benchmarks) · [See the difference](#see-the-difference) · [Installation](#installation) · [Quickstart](#quickstart) · [How it works](#how-it-works) · [Citation](#citation)
59
+
60
+ ## Why
61
+
62
+ 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: a hot cluster (say precious metals and FX) advances its correlation state while an idle one (agriculture) does not, and nobody has to identify the cluster. On those clocks it runs a single recursion that **learns in market time and forgets in calendar time**, shrinks itself from two online statistics, and re-weights its three timescales by the gradient of its own log score. Nothing is fitted but `lam`.
63
+
64
+ Against the field it is scored on:
65
+
66
+ | | Squeeze Kernel | CM-IEWMA (as released) | DCC, DCC-NL | Window shrinkage (LW, OAS, NLS, RMT) |
67
+ |---|---|---|---|---|
68
+ | Clock | per-asset market clocks | calendar | calendar | calendar window |
69
+ | Daily work | `O(Kn²)` update, one Cholesky, no solver | daily convex programme | GARCH recursion | re-estimate on the window |
70
+ | Tuned in the paper | nothing: `lam = 0.996`, fixed on data to 2021 | fitted on a tuning block, re-fitted to each sealed universe | fitted on a tuning block, re-fitted to each sealed universe | fitted on a tuning block, re-fitted to each sealed universe |
71
+ | Milliseconds a day, n = 50 → 300 | **0.54 → 10.1** | 18.8 → 182.2 | 0.05 → 0.83, 0.09 → 1.83 | not timed |
72
+ | Days the solver fails, n = 300 | no solver | 1,196 of 6,439 scored | — | — |
73
+
74
+ ## Benchmarks
75
+
76
+ The score is the one-step-ahead Gaussian negative log-likelihood (NLL) of the next day's returns under each estimator's forecast, averaged per day; lower is better. Every baseline is fitted on a tuning block before it is scored. The ranking holds under the Student-t and density-power scores as well.
77
+
78
+ ### Thirty years of S&P 500 constituents, 1995–2026
79
+
80
+ Each baseline's row is its **excess NLL per day over the Squeeze Kernel**. Every Diebold–Mariano *p* is below 10⁻⁷. The Squeeze Kernel is the sole member of the 90% model confidence set at every size.
81
+
82
+ | | n = 50 | n = 100 | n = 200 | n = 300 |
83
+ |---|---:|---:|---:|---:|
84
+ | **Squeeze Kernel, average NLL** | **−371.28** | **−753.21** | **−1539.32** | **−2334.88** |
85
+ | CM-IEWMA | +1.63 | +4.58 | +12.45 | +20.70 |
86
+ | DCC | +2.04 | +5.31 | +13.49 | +25.38 |
87
+ | DCC-NL | +2.21 | +5.53 | +13.90 | +24.67 |
88
+ | RMT denoising | +6.60 | +14.72 | +32.39 | +58.94 |
89
+ | Gerber (PSD) | +7.00 | +15.61 | +38.82 | +62.98 |
90
+ | Nonlinear shrinkage | +6.29 | +16.10 | +42.84 | +73.22 |
91
+ | IEWMA | +3.98 | +16.56 | +79.79 | +224.73 |
92
+ | EWMA | +7.10 | +19.92 | +58.71 | +80.81 |
93
+ | Ledoit–Wolf | +6.75 | +20.44 | +60.42 | +98.94 |
94
+ | OAS | +8.44 | +23.96 | +66.04 | +106.56 |
95
+
96
+ ### Out of sample, configuration frozen on data to 2021
97
+
98
+ | | n = 50 | n = 100 | n = 200 | n = 300 |
99
+ |---|---:|---:|---:|---:|
100
+ | **S&P constituents, 2022–2026**: lead over the best baseline (CM-IEWMA at every size), NLL per day | 1.72 | 3.72 | 11.12 | 19.16 |
101
+ | **Twenty-four sealed small- and mid-cap universes**, six per size, 2022–2026, field fitted to each universe: universes on which it is first | 6 of 6 | 6 of 6 | 6 of 6 | 6 of 6 |
102
+ | lead over the best baseline, range | 0.1–1.2 | 2.7–4.0 | 8.6–10.9 | 13.2–17.5 |
103
+ | sole member of the 90% model confidence set | 1 of 6 | 6 of 6 | 6 of 6 | 6 of 6 |
104
+
105
+ Carried **zero-shot** to other panels, same `lam`:
106
+
107
+ | Panel | Result |
108
+ |---|---|
109
+ | **121 futures**, eight asset classes, held out from mid-2018, baselines calibrated on that panel's own history | first; leads DCC-NL by 11.3 NLL per day (*p* = 10⁻⁸), IEWMA by 14.4, DCC by 18.2, EWMA by 36.0, Ledoit–Wolf by 121.4 |
110
+ | **Fama–French 49 industries**, scored with the CM-IEWMA authors' own regret metric (lower is better) | **16.35**, against CM-IEWMA 16.96, IEWMA 18.20, EWMA 19.39 |
111
+
112
+ ### Cost
113
+
114
+ Milliseconds per forecast day, single-threaded, over the full thirty-year pass:
115
+
116
+ | | n = 50 | n = 100 | n = 200 | n = 300 |
117
+ |---|---:|---:|---:|---:|
118
+ | **Squeeze Kernel** | **0.54** | **0.91** | **2.80** | **10.1** |
119
+ | CM-IEWMA as released | 18.8 | 46.4 | 106.8 | 182.2 |
120
+ | of which the daily convex programme | 16.1 | 39.9 | 85.4 | 142.1 |
121
+ | days on which the programme fails | 0 | 50 | 294 | 1,196 |
122
+ | peak memory, GB | 2.0 | 6.4 | 22.4 | 45.3 |
123
+ | DCC | 0.05 | 0.11 | 0.28 | 0.83 |
124
+ | DCC-NL | 0.09 | 0.25 | 0.92 | 1.83 |
125
+
126
+ Two honest footnotes. The released CM-IEWMA code overstates what the method has to cost: its linear algebra alone, with the programme treated as free, would run in 60% to 121% of the Squeeze Kernel's time. The cost is the solver, and so is the fragility. And DCC and DCC-NL are cheaper than both; they are also 13 to 25 NLL per day behind at n = 200 and 300.
127
+
128
+ ## See the difference
129
+
130
+ A passive strategy any allocator would recognise: long-only minimum-variance over 300 liquid US stocks, scaled to a 15% volatility target, rebalanced monthly, 5 bps costs. Two runs on identical data; the only difference is the covariance matrix. The Squeeze Kernel arm runs `SqueezeKernel(lam=0.996)`, **nothing tuned on this panel**.
131
+
132
+ <picture>
133
+ <source media="(prefers-color-scheme: dark)" srcset="https://raw.githubusercontent.com/r0k3/squeeze-kernel/main/examples/figures/vol_targeted_portfolio_dark.png">
134
+ <img alt="Vol-targeted long-only minimum-variance portfolio on 300 US equities: Squeeze Kernel vs Ledoit-Wolf equity curves, drawdown, realized volatility, and risk/return profile" src="https://raw.githubusercontent.com/r0k3/squeeze-kernel/main/examples/figures/vol_targeted_portfolio.png">
135
+ </picture>
136
+
137
+ | Method | CAGR | Vol | Sharpe | MaxDD | Calmar | Vol-target RMSE |
138
+ |---|---|---|---|---|---|---|
139
+ | **Squeeze Kernel (default)** | **12.6%** | **13.6%** | **0.92** | **-34.3%** | **0.37** | **7.05%** |
140
+ | Ledoit-Wolf (252d) | 11.7% | 14.6% | 0.80 | -38.7% | 0.30 | 7.51% |
141
+
142
+ Reproduce from the repo alone (the 300-stock panel ships as a parquet; survivorship and provenance are documented in the script):
143
+
144
+ ```bash
145
+ pip install squeeze-kernel pandas pyarrow scikit-learn matplotlib
146
+ python examples/vol_targeted_portfolio.py # ~1 minute for the 26-year stream
147
+ ```
148
+
149
+ ## Installation
150
+
151
+ ```bash
152
+ pip install squeeze-kernel # NumPy only
153
+ pip install "squeeze-kernel[full]" # + SciPy (faster Cholesky factorisations for the mixture)
154
+ ```
155
+
156
+ ## Quickstart
157
+
158
+ ```python
159
+ import numpy as np
160
+ from squeeze_kernel import SqueezeKernel, estimate_squeeze_cov
161
+
162
+ returns = np.random.default_rng(42).normal(0.0, 0.01, size=(500, 30))
163
+
164
+ sk = SqueezeKernel() # lam=0.996 (anchor half-life ~173 days)
165
+ for r_t in returns:
166
+ w = sk.update(r_t) # returns the day's kernel weight
167
+ cov, corr = sk.covariance(), sk.correlation()
168
+ sk.state() # kernel scale, per-timescale effective sizes, mixture tilt
169
+
170
+ # batch mode: full panel in, covariance path out
171
+ cov_path, corr_path, weights = estimate_squeeze_cov(returns, with_weights=True)
172
+ ```
173
+
174
+ Missing values: pass `NaN` (or `mask=` on `update`). Newly listed, delisted or halted assets need no imputation and no complete-case subsetting.
175
+
176
+ 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.
177
+
178
+ ## How it works
179
+
180
+ ```mermaid
181
+ flowchart LR
182
+ R["return r_t<br/>(NaN = missing)"] --> V["variance ladder<br/>3 rungs per asset,<br/>pooled panel-wide"]
183
+ V --> Z["standardised<br/>surprise z_t"]
184
+ Z --> W["per-asset clocks<br/>from the correlation<br/>neighbourhood"]
185
+ W --> Q["diagonal-congruence update<br/>of 3 correlation timescales,<br/>outer product scaled by n/m"]
186
+ Q --> S["per-timescale shrinkage<br/>raw / equicorrelation /<br/>Hadamard square"]
187
+ S --> B["blend across timescales<br/>by the gradient of<br/>its own log score"]
188
+ B --> O["Σ_t"]
189
+ ```
190
+
191
+ One daily update, in words:
192
+
193
+ 1. **Volatility with self-selected memory.** Each asset's variance runs on a three-rung ladder of half-lives (`h/16, h/4, h`), pooled panel-wide by weights that move on saturated evidence, so one spike day cannot hand a stale rung weeks of weight. The day's return is standardised by it.
194
+ 2. **Per-asset clocks.** Each asset reads its activity as the neighbourhood mean of squared surprises, weighted by the Hadamard square of yesterday's correlation (under conditional Gaussianity that square *is* the correlation of squared returns, so the neighbourhood is the asset's own cluster, no labels needed). A saturating kernel maps activity to a clock increment in `[0, 1)`: an unbounded shock is squeezed into at most one unit of trading time.
195
+ 3. **Magnitude once, direction once.** The day's Mahalanobis norm under the estimator's own forecast, `m = r'Σ⁻¹r`, sets the clocks; the innovation then enters with weight `n/m`, so a day's direction moves the state and its size only says how much trading time it carried. Score-driven and robust estimators down-weight such a day as contamination; this one reads it as time.
196
+ 4. **Diagonal-congruence flow on three timescales.** Each correlation state advances by a congruence plus a rank-one term on the clocks, with decays `(lam⁴, lam, lam^¼)`. In closed form it is an exponentially weighted Gram matrix of clock-weighted returns: pairs accrue at the geometric mean of their two clock increments, which is exactly the Cauchy–Schwarz bound on how far two clocks can overlap and the most positive semi-definiteness allows. No eigenvalue clipping, no nearest-PSD repair, any missing-data pattern.
197
+ 5. **Self-tuning, label-free shrinkage.** Each timescale's shrunk correlation is a pool of its raw correlation, its equicorrelation level and its Hadamard square. The Hadamard square suppresses cross-cluster noise quadratically (0.10 → 0.01) while keeping intra-cluster blocks (0.60 → 0.36). The pool's prior weights come from a closed-form intensity rule read off two online statistics; the blend gradient corrects them.
198
+ 6. **Blend by the gradient of the blend's own score.** The timescale weights follow an exponentiated-gradient step on the blend's log score (not any single timescale's, which would select rather than blend), at a temperature calibrated so that uninformative evidence leaves the mix within a factor *e* of its prior. Nothing in either mixture is fitted.
199
+
200
+ The paper gives the derivations (natural-gradient and Gram-matrix forms of the flow, the Fisher–Rao form of the mixture), the guarantees (PSD at every step, a conditioning floor, strict positive definiteness whenever a positively weighted timescale has its intensity strictly inside (0, 1), exact reductions to the published special cases) and the full evaluation.
201
+
202
+ ### What derives from `lam`
203
+
204
+ | quantity | value |
205
+ |---|---|
206
+ | timescale ladder | decays `(lam⁴, lam, lam^¼)` — half-lives `(h/4, h, 4h)`, `h = -1/log2(lam)` |
207
+ | kernel scale | state: `κ_t = ⅓ · EWMA(activity)` at the anchor rate |
208
+ | 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̃` |
209
+ | timescale weights | prior ∝ √h, moved by exponentiated gradient on the blend log score at the null temperature, fast-rung memory |
210
+ | 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 |
211
+ | 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 |
212
+ | volatility memory | ladder `(h/16, h/4, h)`, pooled panel-wide by the same rule on tanh-saturated evidence, uniform prior |
213
+ | structural constants | K=3, b=4, θ=½, κ-scale ⅓, Schur power 2, intensity exponent 2 — each bracketed by ablation in the paper |
214
+ | fitted constants | `lam` itself (0.996, chosen on data to 2021); nothing else is fitted |
215
+
216
+
217
+ ## Development
218
+
219
+ ```bash
220
+ uv sync --extra full --extra dev
221
+ uv run python -m pytest # test suite
222
+ uv run python -m ruff check . # lint
223
+ uv run mypy # strict type check (src/squeeze_kernel)
224
+ uv build # build sdist + wheel
225
+ ```
226
+
227
+ ## Citation
228
+
229
+ ```bibtex
230
+ @article{kende2026squeeze,
231
+ title = {The Squeeze Kernel Covariance Estimator},
232
+ author = {Kende, Robert},
233
+ year = {2026},
234
+ note = {Working paper. Available at SSRN: \url{https://ssrn.com/abstract=6455918}}
235
+ }
236
+ ```
237
+
238
+ See also [`CITATION.cff`](CITATION.cff).
239
+
240
+ ## License
241
+
242
+ MIT
@@ -0,0 +1,211 @@
1
+ # Squeeze Kernel Covariance Estimator
2
+
3
+ [![CI](https://github.com/r0k3/squeeze-kernel/actions/workflows/ci.yml/badge.svg)](https://github.com/r0k3/squeeze-kernel/actions/workflows/ci.yml)
4
+ [![PyPI](https://img.shields.io/pypi/v/squeeze-kernel.svg)](https://pypi.org/project/squeeze-kernel/)
5
+ [![Python](https://img.shields.io/pypi/pyversions/squeeze-kernel.svg)](https://pypi.org/project/squeeze-kernel/)
6
+ [![License: MIT](https://img.shields.io/badge/license-MIT-green.svg)](LICENSE)
7
+ [![DOI](https://zenodo.org/badge/1188987927.svg)](https://doi.org/10.5281/zenodo.19170801)
8
+ [![Paper](https://img.shields.io/badge/paper-SSRN%206455918-b31b1b.svg)](https://ssrn.com/abstract=6455918)
9
+
10
+ **A streaming covariance estimator for panels of financial returns that beats every fitted baseline out of sample, costs half a millisecond to ten milliseconds a day, and has one parameter.**
11
+
12
+ ```python
13
+ from squeeze_kernel import SqueezeKernel
14
+
15
+ sk = SqueezeKernel(lam=0.996) # the entire public surface
16
+ for r_t in returns: # NaN marks missing assets
17
+ sk.update(r_t)
18
+ cov = sk.covariance() # positive semi-definite by construction, every day
19
+ ```
20
+
21
+ - **State of the art, measured.** On thirty years of S&P 500 constituents it leads ten baselines fitted to the data (CM-IEWMA, DCC, DCC-NL, nonlinear shrinkage, Ledoit–Wolf, OAS, RMT denoising, Gerber, IEWMA, EWMA) at every universe size from 50 to 300, every Diebold–Mariano *p* below 10⁻⁷, and it is the **sole member of the 90% model confidence set at every size**. With its configuration frozen on data to 2021 it stays first on 2022–2026, on **twenty-four sealed small- and mid-cap universes it had never seen**, on a 121-instrument futures panel across eight asset classes, and on the public Fama–French 49 panel on the competing authors' own metric.
22
+ - **Fast, with nothing that can fail.** One `O(Kn²)` state update, one Cholesky factorisation of the blend and `K` positive-definiteness checks a day. No rolling window, no likelihood refit, no daily solver. **0.54 ms a day at n = 50, 10.1 ms at n = 300.** The closest competitor on accuracy, CM-IEWMA as released by its authors, takes 18 to 51 times as long and spends most of it in a convex programme that is infeasible on about one scored day in five at n = 300.
23
+ - **One number, no tuning.** Everything else is derived from `lam`, fixed by a structural argument, or computed online from the estimator's own state. Listings, delistings and halts enter as `NaN`. Only dependency: NumPy.
24
+
25
+ Paper: Kende (2026), *The Squeeze Kernel Covariance Estimator*, [SSRN 6455918](https://ssrn.com/abstract=6455918). Every number on this page is taken from the tables of the paper's September 2026 revision, *A Diagonal-Congruence Flow in Per-Asset Trading Time*, which describes the 3.x estimator and carries the protocol, the proofs and the full ablation ledger.
26
+
27
+ [Benchmarks](#benchmarks) · [See the difference](#see-the-difference) · [Installation](#installation) · [Quickstart](#quickstart) · [How it works](#how-it-works) · [Citation](#citation)
28
+
29
+ ## Why
30
+
31
+ 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: a hot cluster (say precious metals and FX) advances its correlation state while an idle one (agriculture) does not, and nobody has to identify the cluster. On those clocks it runs a single recursion that **learns in market time and forgets in calendar time**, shrinks itself from two online statistics, and re-weights its three timescales by the gradient of its own log score. Nothing is fitted but `lam`.
32
+
33
+ Against the field it is scored on:
34
+
35
+ | | Squeeze Kernel | CM-IEWMA (as released) | DCC, DCC-NL | Window shrinkage (LW, OAS, NLS, RMT) |
36
+ |---|---|---|---|---|
37
+ | Clock | per-asset market clocks | calendar | calendar | calendar window |
38
+ | Daily work | `O(Kn²)` update, one Cholesky, no solver | daily convex programme | GARCH recursion | re-estimate on the window |
39
+ | Tuned in the paper | nothing: `lam = 0.996`, fixed on data to 2021 | fitted on a tuning block, re-fitted to each sealed universe | fitted on a tuning block, re-fitted to each sealed universe | fitted on a tuning block, re-fitted to each sealed universe |
40
+ | Milliseconds a day, n = 50 → 300 | **0.54 → 10.1** | 18.8 → 182.2 | 0.05 → 0.83, 0.09 → 1.83 | not timed |
41
+ | Days the solver fails, n = 300 | no solver | 1,196 of 6,439 scored | — | — |
42
+
43
+ ## Benchmarks
44
+
45
+ The score is the one-step-ahead Gaussian negative log-likelihood (NLL) of the next day's returns under each estimator's forecast, averaged per day; lower is better. Every baseline is fitted on a tuning block before it is scored. The ranking holds under the Student-t and density-power scores as well.
46
+
47
+ ### Thirty years of S&P 500 constituents, 1995–2026
48
+
49
+ Each baseline's row is its **excess NLL per day over the Squeeze Kernel**. Every Diebold–Mariano *p* is below 10⁻⁷. The Squeeze Kernel is the sole member of the 90% model confidence set at every size.
50
+
51
+ | | n = 50 | n = 100 | n = 200 | n = 300 |
52
+ |---|---:|---:|---:|---:|
53
+ | **Squeeze Kernel, average NLL** | **−371.28** | **−753.21** | **−1539.32** | **−2334.88** |
54
+ | CM-IEWMA | +1.63 | +4.58 | +12.45 | +20.70 |
55
+ | DCC | +2.04 | +5.31 | +13.49 | +25.38 |
56
+ | DCC-NL | +2.21 | +5.53 | +13.90 | +24.67 |
57
+ | RMT denoising | +6.60 | +14.72 | +32.39 | +58.94 |
58
+ | Gerber (PSD) | +7.00 | +15.61 | +38.82 | +62.98 |
59
+ | Nonlinear shrinkage | +6.29 | +16.10 | +42.84 | +73.22 |
60
+ | IEWMA | +3.98 | +16.56 | +79.79 | +224.73 |
61
+ | EWMA | +7.10 | +19.92 | +58.71 | +80.81 |
62
+ | Ledoit–Wolf | +6.75 | +20.44 | +60.42 | +98.94 |
63
+ | OAS | +8.44 | +23.96 | +66.04 | +106.56 |
64
+
65
+ ### Out of sample, configuration frozen on data to 2021
66
+
67
+ | | n = 50 | n = 100 | n = 200 | n = 300 |
68
+ |---|---:|---:|---:|---:|
69
+ | **S&P constituents, 2022–2026**: lead over the best baseline (CM-IEWMA at every size), NLL per day | 1.72 | 3.72 | 11.12 | 19.16 |
70
+ | **Twenty-four sealed small- and mid-cap universes**, six per size, 2022–2026, field fitted to each universe: universes on which it is first | 6 of 6 | 6 of 6 | 6 of 6 | 6 of 6 |
71
+ | lead over the best baseline, range | 0.1–1.2 | 2.7–4.0 | 8.6–10.9 | 13.2–17.5 |
72
+ | sole member of the 90% model confidence set | 1 of 6 | 6 of 6 | 6 of 6 | 6 of 6 |
73
+
74
+ Carried **zero-shot** to other panels, same `lam`:
75
+
76
+ | Panel | Result |
77
+ |---|---|
78
+ | **121 futures**, eight asset classes, held out from mid-2018, baselines calibrated on that panel's own history | first; leads DCC-NL by 11.3 NLL per day (*p* = 10⁻⁸), IEWMA by 14.4, DCC by 18.2, EWMA by 36.0, Ledoit–Wolf by 121.4 |
79
+ | **Fama–French 49 industries**, scored with the CM-IEWMA authors' own regret metric (lower is better) | **16.35**, against CM-IEWMA 16.96, IEWMA 18.20, EWMA 19.39 |
80
+
81
+ ### Cost
82
+
83
+ Milliseconds per forecast day, single-threaded, over the full thirty-year pass:
84
+
85
+ | | n = 50 | n = 100 | n = 200 | n = 300 |
86
+ |---|---:|---:|---:|---:|
87
+ | **Squeeze Kernel** | **0.54** | **0.91** | **2.80** | **10.1** |
88
+ | CM-IEWMA as released | 18.8 | 46.4 | 106.8 | 182.2 |
89
+ | of which the daily convex programme | 16.1 | 39.9 | 85.4 | 142.1 |
90
+ | days on which the programme fails | 0 | 50 | 294 | 1,196 |
91
+ | peak memory, GB | 2.0 | 6.4 | 22.4 | 45.3 |
92
+ | DCC | 0.05 | 0.11 | 0.28 | 0.83 |
93
+ | DCC-NL | 0.09 | 0.25 | 0.92 | 1.83 |
94
+
95
+ Two honest footnotes. The released CM-IEWMA code overstates what the method has to cost: its linear algebra alone, with the programme treated as free, would run in 60% to 121% of the Squeeze Kernel's time. The cost is the solver, and so is the fragility. And DCC and DCC-NL are cheaper than both; they are also 13 to 25 NLL per day behind at n = 200 and 300.
96
+
97
+ ## See the difference
98
+
99
+ A passive strategy any allocator would recognise: long-only minimum-variance over 300 liquid US stocks, scaled to a 15% volatility target, rebalanced monthly, 5 bps costs. Two runs on identical data; the only difference is the covariance matrix. The Squeeze Kernel arm runs `SqueezeKernel(lam=0.996)`, **nothing tuned on this panel**.
100
+
101
+ <picture>
102
+ <source media="(prefers-color-scheme: dark)" srcset="https://raw.githubusercontent.com/r0k3/squeeze-kernel/main/examples/figures/vol_targeted_portfolio_dark.png">
103
+ <img alt="Vol-targeted long-only minimum-variance portfolio on 300 US equities: Squeeze Kernel vs Ledoit-Wolf equity curves, drawdown, realized volatility, and risk/return profile" src="https://raw.githubusercontent.com/r0k3/squeeze-kernel/main/examples/figures/vol_targeted_portfolio.png">
104
+ </picture>
105
+
106
+ | Method | CAGR | Vol | Sharpe | MaxDD | Calmar | Vol-target RMSE |
107
+ |---|---|---|---|---|---|---|
108
+ | **Squeeze Kernel (default)** | **12.6%** | **13.6%** | **0.92** | **-34.3%** | **0.37** | **7.05%** |
109
+ | Ledoit-Wolf (252d) | 11.7% | 14.6% | 0.80 | -38.7% | 0.30 | 7.51% |
110
+
111
+ Reproduce from the repo alone (the 300-stock panel ships as a parquet; survivorship and provenance are documented in the script):
112
+
113
+ ```bash
114
+ pip install squeeze-kernel pandas pyarrow scikit-learn matplotlib
115
+ python examples/vol_targeted_portfolio.py # ~1 minute for the 26-year stream
116
+ ```
117
+
118
+ ## Installation
119
+
120
+ ```bash
121
+ pip install squeeze-kernel # NumPy only
122
+ pip install "squeeze-kernel[full]" # + SciPy (faster Cholesky factorisations for the mixture)
123
+ ```
124
+
125
+ ## Quickstart
126
+
127
+ ```python
128
+ import numpy as np
129
+ from squeeze_kernel import SqueezeKernel, estimate_squeeze_cov
130
+
131
+ returns = np.random.default_rng(42).normal(0.0, 0.01, size=(500, 30))
132
+
133
+ sk = SqueezeKernel() # lam=0.996 (anchor half-life ~173 days)
134
+ for r_t in returns:
135
+ w = sk.update(r_t) # returns the day's kernel weight
136
+ cov, corr = sk.covariance(), sk.correlation()
137
+ sk.state() # kernel scale, per-timescale effective sizes, mixture tilt
138
+
139
+ # batch mode: full panel in, covariance path out
140
+ cov_path, corr_path, weights = estimate_squeeze_cov(returns, with_weights=True)
141
+ ```
142
+
143
+ Missing values: pass `NaN` (or `mask=` on `update`). Newly listed, delisted or halted assets need no imputation and no complete-case subsetting.
144
+
145
+ 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.
146
+
147
+ ## How it works
148
+
149
+ ```mermaid
150
+ flowchart LR
151
+ R["return r_t<br/>(NaN = missing)"] --> V["variance ladder<br/>3 rungs per asset,<br/>pooled panel-wide"]
152
+ V --> Z["standardised<br/>surprise z_t"]
153
+ Z --> W["per-asset clocks<br/>from the correlation<br/>neighbourhood"]
154
+ W --> Q["diagonal-congruence update<br/>of 3 correlation timescales,<br/>outer product scaled by n/m"]
155
+ Q --> S["per-timescale shrinkage<br/>raw / equicorrelation /<br/>Hadamard square"]
156
+ S --> B["blend across timescales<br/>by the gradient of<br/>its own log score"]
157
+ B --> O["Σ_t"]
158
+ ```
159
+
160
+ One daily update, in words:
161
+
162
+ 1. **Volatility with self-selected memory.** Each asset's variance runs on a three-rung ladder of half-lives (`h/16, h/4, h`), pooled panel-wide by weights that move on saturated evidence, so one spike day cannot hand a stale rung weeks of weight. The day's return is standardised by it.
163
+ 2. **Per-asset clocks.** Each asset reads its activity as the neighbourhood mean of squared surprises, weighted by the Hadamard square of yesterday's correlation (under conditional Gaussianity that square *is* the correlation of squared returns, so the neighbourhood is the asset's own cluster, no labels needed). A saturating kernel maps activity to a clock increment in `[0, 1)`: an unbounded shock is squeezed into at most one unit of trading time.
164
+ 3. **Magnitude once, direction once.** The day's Mahalanobis norm under the estimator's own forecast, `m = r'Σ⁻¹r`, sets the clocks; the innovation then enters with weight `n/m`, so a day's direction moves the state and its size only says how much trading time it carried. Score-driven and robust estimators down-weight such a day as contamination; this one reads it as time.
165
+ 4. **Diagonal-congruence flow on three timescales.** Each correlation state advances by a congruence plus a rank-one term on the clocks, with decays `(lam⁴, lam, lam^¼)`. In closed form it is an exponentially weighted Gram matrix of clock-weighted returns: pairs accrue at the geometric mean of their two clock increments, which is exactly the Cauchy–Schwarz bound on how far two clocks can overlap and the most positive semi-definiteness allows. No eigenvalue clipping, no nearest-PSD repair, any missing-data pattern.
166
+ 5. **Self-tuning, label-free shrinkage.** Each timescale's shrunk correlation is a pool of its raw correlation, its equicorrelation level and its Hadamard square. The Hadamard square suppresses cross-cluster noise quadratically (0.10 → 0.01) while keeping intra-cluster blocks (0.60 → 0.36). The pool's prior weights come from a closed-form intensity rule read off two online statistics; the blend gradient corrects them.
167
+ 6. **Blend by the gradient of the blend's own score.** The timescale weights follow an exponentiated-gradient step on the blend's log score (not any single timescale's, which would select rather than blend), at a temperature calibrated so that uninformative evidence leaves the mix within a factor *e* of its prior. Nothing in either mixture is fitted.
168
+
169
+ The paper gives the derivations (natural-gradient and Gram-matrix forms of the flow, the Fisher–Rao form of the mixture), the guarantees (PSD at every step, a conditioning floor, strict positive definiteness whenever a positively weighted timescale has its intensity strictly inside (0, 1), exact reductions to the published special cases) and the full evaluation.
170
+
171
+ ### What derives from `lam`
172
+
173
+ | quantity | value |
174
+ |---|---|
175
+ | timescale ladder | decays `(lam⁴, lam, lam^¼)` — half-lives `(h/4, h, 4h)`, `h = -1/log2(lam)` |
176
+ | kernel scale | state: `κ_t = ⅓ · EWMA(activity)` at the anchor rate |
177
+ | 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̃` |
178
+ | timescale weights | prior ∝ √h, moved by exponentiated gradient on the blend log score at the null temperature, fast-rung memory |
179
+ | 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 |
180
+ | 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 |
181
+ | volatility memory | ladder `(h/16, h/4, h)`, pooled panel-wide by the same rule on tanh-saturated evidence, uniform prior |
182
+ | structural constants | K=3, b=4, θ=½, κ-scale ⅓, Schur power 2, intensity exponent 2 — each bracketed by ablation in the paper |
183
+ | fitted constants | `lam` itself (0.996, chosen on data to 2021); nothing else is fitted |
184
+
185
+
186
+ ## Development
187
+
188
+ ```bash
189
+ uv sync --extra full --extra dev
190
+ uv run python -m pytest # test suite
191
+ uv run python -m ruff check . # lint
192
+ uv run mypy # strict type check (src/squeeze_kernel)
193
+ uv build # build sdist + wheel
194
+ ```
195
+
196
+ ## Citation
197
+
198
+ ```bibtex
199
+ @article{kende2026squeeze,
200
+ title = {The Squeeze Kernel Covariance Estimator},
201
+ author = {Kende, Robert},
202
+ year = {2026},
203
+ note = {Working paper. Available at SSRN: \url{https://ssrn.com/abstract=6455918}}
204
+ }
205
+ ```
206
+
207
+ See also [`CITATION.cff`](CITATION.cff).
208
+
209
+ ## License
210
+
211
+ MIT
@@ -4,7 +4,7 @@ build-backend = "uv_build"
4
4
 
5
5
  [project]
6
6
  name = "squeeze-kernel"
7
- version = "3.2.0"
7
+ version = "4.0.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.2.0"
7
+ version = "4.0.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"
@@ -0,0 +1,30 @@
1
+ """
2
+ Squeeze Kernel Covariance Estimator
3
+ ====================================
4
+
5
+ Streaming, PSD-by-construction covariance estimator whose public surface
6
+ is one number: everything else derives from that decay, is a structural
7
+ constant of the method, or is state computed online -- including per-asset
8
+ market clocks read from the correlation structure itself.
9
+
10
+ Quick start::
11
+
12
+ import numpy as np
13
+ from squeeze_kernel import SqueezeKernel
14
+
15
+ returns = np.random.default_rng(42).normal(0.0, 0.01, size=(250, 30))
16
+
17
+ sk = SqueezeKernel(lam=0.996) # the entire public surface
18
+ for r_t in returns:
19
+ sk.update(r_t) # NaN marks missing assets
20
+
21
+ cov = sk.covariance()
22
+ corr = sk.correlation()
23
+ """
24
+
25
+ from squeeze_kernel.core import SqueezeKernel
26
+ from squeeze_kernel.batch import estimate_squeeze_cov
27
+
28
+ __all__ = ["SqueezeKernel", "estimate_squeeze_cov"]
29
+
30
+ __version__ = "4.0.0"