Repository navigation
Commit 1e5a4ce
[BUG] raise an informative error when CLA gets a singular covariance matrix
Closes #737
The critical line algorithm inverts the covariance submatrix of the free
assets on each iteration. When the covariance matrix is singular — e.g.
perfectly correlated or duplicated assets, or fewer observations than
assets — that inversion can fail, and users saw a bare
`numpy.linalg.LinAlgError: Singular matrix` raised from a private method,
with no indication of what was wrong or how to fix it.
Route the four inversion sites through a helper that translates the
LinAlgError into a ValueError explaining the likely cause and pointing at
concrete remedies.
Note that validating positive-definiteness up front (as the issue
suggests) would be a regression: a singular covariance matrix only breaks
CLA if a *submatrix* of the free assets happens to be singular. In a
randomised check over 40 rank-deficient covariance matrices, 29 solved
fine and only 4 raised LinAlgError, so an up-front check would reject
inputs that work today. Translating the error where it actually occurs
keeps those working and only improves the failure path.
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>1 parent a6638d2 commit 1e5a4ce
2 files changed
Lines changed: 80 additions & 5 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
192 | 192 | | |
193 | 193 | | |
194 | 194 | | |
| 195 | + | |
| 196 | + | |
| 197 | + | |
| 198 | + | |
| 199 | + | |
| 200 | + | |
| 201 | + | |
| 202 | + | |
| 203 | + | |
| 204 | + | |
| 205 | + | |
| 206 | + | |
| 207 | + | |
| 208 | + | |
| 209 | + | |
| 210 | + | |
| 211 | + | |
| 212 | + | |
| 213 | + | |
| 214 | + | |
| 215 | + | |
| 216 | + | |
| 217 | + | |
| 218 | + | |
| 219 | + | |
| 220 | + | |
| 221 | + | |
| 222 | + | |
| 223 | + | |
| 224 | + | |
| 225 | + | |
| 226 | + | |
| 227 | + | |
| 228 | + | |
| 229 | + | |
| 230 | + | |
| 231 | + | |
| 232 | + | |
| 233 | + | |
195 | 234 | | |
196 | 235 | | |
197 | 236 | | |
| |||
339 | 378 | | |
340 | 379 | | |
341 | 380 | | |
342 | | - | |
| 381 | + | |
343 | 382 | | |
344 | 383 | | |
345 | 384 | | |
| |||
354 | 393 | | |
355 | 394 | | |
356 | 395 | | |
357 | | - | |
| 396 | + | |
358 | 397 | | |
359 | 398 | | |
360 | 399 | | |
| |||
371 | 410 | | |
372 | 411 | | |
373 | 412 | | |
374 | | - | |
| 413 | + | |
375 | 414 | | |
376 | 415 | | |
377 | 416 | | |
| |||
383 | 422 | | |
384 | 423 | | |
385 | 424 | | |
386 | | - | |
| 425 | + | |
387 | 426 | | |
388 | 427 | | |
389 | 428 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1 | 1 | | |
2 | 2 | | |
3 | 3 | | |
4 | | - | |
| 4 | + | |
5 | 5 | | |
6 | 6 | | |
7 | 7 | | |
| |||
96 | 96 | | |
97 | 97 | | |
98 | 98 | | |
| 99 | + | |
| 100 | + | |
| 101 | + | |
| 102 | + | |
| 103 | + | |
| 104 | + | |
| 105 | + | |
| 106 | + | |
| 107 | + | |
| 108 | + | |
| 109 | + | |
| 110 | + | |
| 111 | + | |
| 112 | + | |
| 113 | + | |
| 114 | + | |
| 115 | + | |
| 116 | + | |
| 117 | + | |
| 118 | + | |
| 119 | + | |
| 120 | + | |
| 121 | + | |
| 122 | + | |
| 123 | + | |
| 124 | + | |
| 125 | + | |
| 126 | + | |
| 127 | + | |
| 128 | + | |
| 129 | + | |
| 130 | + | |
| 131 | + | |
| 132 | + | |
| 133 | + | |
| 134 | + | |
99 | 135 | | |
100 | 136 | | |
101 | 137 | | |
| |||
0 commit comments