Ledoit-Wolf Shrinkage
Install and import#
npm install fintech-algorithmsimport { calculate } from "fintech-algorithms/volatility-and-covariance/covariance-estimation/ledoit-wolf-shrinkage";Signature#
calculate(data)Compare estimated outer-product noise with target distance. Supplied-parameter educational reference; no fitted performance claim.
Parameters#
| Name | Type | Notes |
|---|---|---|
data | TopicInput | See data-contract/CONTRACT.md. |
Returns#
TopicResult
Structured result with readiness, values, parameters, and diagnostics.
Warm-up#
The first depends on window or model order positions are null prefix until minimum history exists.
Errors#
- When required data is missing, non-finite, malformed, or out of range — raises ContractError / Error
Complexity: time O(np²),
space Full diagnostic trace retained for teaching; see implementation for observation/window/matrix dimensions.
Worked example#
executed Captured by running this function on the input its own test provides. Real output of real code — but not asserted against a published figure.
Input#
{
"returns": [
[1, 1.3660254037844386],
[1, -0.3660254037844386],
[-1, 0.3660254037844386]
],
"parameters": {}
}Call#
calculate(data)Returns#
object with 8 fields: topic_id, title, parameters, matrix, latest, ready, ready_at, diagnostics
{
"topic_id": "D10-F04-A03",
"title": "Ledoit-Wolf Shrinkage",
"parameters": {},
"matrix": [
[1, 0],
[0, 1]
],
"latest": [
[1, 0],
[0, 1]
],
"ready": true,
"ready_at": 0,
"diagnostics": {
"observations": 4,
"assets": 2,
"means": [0, 0],
"causal": true,
"ml_covariance": [
[1, 0.5],
[0.5, 1]
],
"noise_estimate": 0.5625,
"target_distance": 0.5,
"shrinkage": 1,
"target": 1
}
}Diagrams#
Calculation flow#
Ledoit-Wolf Shrinkage — calculation-flow
flowchart TD
N0["Center data and divide by n"]
N1["Build average-variance identity target"]
N2["Estimate noise / target distance"]
N3["Clip intensity and blend matrices"]
N0 --> N1 --> N2 --> N3
Ledoit-Wolf Shrinkage — decision-boundary
flowchart TD
A["Supplied observations and parameters"] --> B{"Contract valid?"}
B -->|No| E["Reject with explicit error"]
B -->|Yes| C{"Required history available?"}
C -->|No| W["Withhold; never insert zero"]
C -->|Yes| D["Ledoit-Wolf Shrinkage calculation"]
D --> F["Inspect diagnostics and stated limits"]
How it works#
This page states the contract — how to call it correctly. The article explains the concept: why it works, and where it breaks.
References#
- Scope of evidence