# Realized Covariance

`D10-F02-A02` · Volatility and Covariance → Realized Measures · archetype `record-transform` · difficulty 2/5 · verification **verified**

Full page: https://docs.thefintechbuilder.com/volatility-and-covariance/realized-measures/realized-covariance/
Agent skill: `npx skills add IslamBaraka90/Fintech-Algorithms-Library` — https://docs.thefintechbuilder.com/guides/agent-skill/

## Install and import

```bash
npm install fintech-algorithms
```

```ts
import { calculate } from "fintech-algorithms/volatility-and-covariance/realized-measures/realized-covariance";
```

## Signature

```ts
calculate(data)
```

Pair exact intervals, then inspect positive and negative products. Supplied-parameter educational reference; no fitted performance claim.

## Parameters

| Name | Type | Required | Notes |
| --- | --- | --- | --- |
| `data` | `TopicInput` | yes | 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(nw)`, space `Full diagnostic trace retained for teaching; see implementation for observation/window/matrix dimensions`.

## Worked example

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

`data`:

```json
{
  "returns_x": [0.01, -0.02, 0.03, -0.01],
  "returns_y": [0.02, 0.01, -0.01, -0.02],
  "timestamps_x": [
    "2026-01-01T09:00:00Z",
    "2026-01-01T09:05:00Z",
    "2026-01-01T09:10:00Z",
    "2026-01-01T09:15:00Z"
  ],
  "timestamps_y": [
    "2026-01-01T09:00:00Z",
    "2026-01-01T09:05:00Z",
    "2026-01-01T09:10:00Z",
    "2026-01-01T09:15:00Z"
  ],
  "parameters": {
    "window": 4,
    "annualization_factor": 1
  }
}
```

### Call

```ts
calculate(data)
```

### Returns

object with 8 fields: topic_id, title, parameters, series, latest, ready, ready_at, diagnostics

```json
{
  "topic_id": "D10-F02-A02",
  "title": "Realized Covariance",
  "parameters": {
    "window": 4,
    "annualization_factor": 1
  },
  "series": [
    null,
    null,
    null,
    {
      "covariance": -0.00009999999999999996,
      "contributions": [0.0002, -0.0002, -0.0003, 0.0002],
      "window_start": 0,
      "window_end": 3
    }
  ],
  "latest": {
    "covariance": -0.00009999999999999996,
    "contributions": [0.0002, -0.0002, -0.0003, 0.0002],
    "window_start": 0,
    "window_end": 3
  },
  "ready": true,
  "ready_at": 3,
  "diagnostics": {
    "causal": true,
    "input_count": 4,
    "annualization_factor": 1
  }
}
```

## Verification and provenance

Tier: **verified** (via F).

The worked example below is the figure published in this algorithm's article, replayed and asserted by the test suite on every build. The arithmetic cannot drift without the build failing.

Both tiers guarantee the signature. Full explanation: https://docs.thefintechbuilder.com/guides/verification/

Generated from the docs.json payload shipped inside fintech-algorithms@0.13.1.
The signature and parameter list are checked against the compiled implementation at build time,
so a description that contradicts the code fails the build rather than reaching this file.

## Links

- Article (how it works, step by step): https://thefintechbuilder.com/volatility-and-covariance/realized-measures/realized-covariance/
- Implementation source: https://github.com/IslamBaraka90/Fintech-Algorithms-Library/blob/main/src/volatility-and-covariance/realized-measures/realized-covariance/impl.ts
- Package on npm: https://www.npmjs.com/package/fintech-algorithms
- Domain index for agents: https://docs.thefintechbuilder.com/volatility-and-covariance/llms.txt
