EWMA Covariance
Install and import#
npm install fintech-algorithmsimport { calculate } from "fintech-algorithms/volatility-and-covariance/covariance-estimation/ewma-covariance";Signature#
calculate(data)Watch the same new vector compete with the existing matrix. 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": [
[0.01, 0.02],
[-0.02, 0.01]
],
"parameters": {
"decay": 0.5
}
}Call#
calculate(data)Returns#
object with 8 fields: topic_id, title, parameters, matrix, latest, ready, ready_at, diagnostics
{
"topic_id": "D10-F04-A02",
"title": "EWMA Covariance",
"parameters": {
"decay": 0.5
},
"matrix": [
[0.00022500000000000002, -0.00005],
[-0.00005, 0.00015000000000000001]
],
"latest": [
[0.00022500000000000002, -0.00005],
[-0.00005, 0.00015000000000000001]
],
"ready": true,
"ready_at": 0,
"diagnostics": {
"observations": 2,
"assets": 2,
"means": [-0.005, 0.015],
"causal": true,
"ml_covariance": [
[0.000225, 0.000075],
[0.000075, 0.000025]
],
"states": [
[
[0.00005, 0.0001],
[0.0001, 0.0002]
],
[
[0.00022500000000000002, -0.00005],
[-0.00005, 0.00015000000000000001]
]
],
"mean_convention": "supplied zero-mean residuals",
"weight_mass": 0.75,
"seed_weight": 0.25
}
}Diagrams#
Calculation flow#
EWMA Covariance — calculation-flow
flowchart TD
N0["Declare zero-mean residuals and seed"]
N1["Compute current outer product"]
N2["Blend λ old + (1−λ) new"]
N3["Report remaining seed weight"]
N0 --> N1 --> N2 --> N3
EWMA Covariance — 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["EWMA Covariance 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