fintech-algorithms
Using a coding agent? Give it the skill: npx skills add IslamBaraka90/Fintech-Algorithms-Library What it does →

Factor-Model Covariance

Install and import#

bash
npm install fintech-algorithms
ts
import { calculate } from "fintech-algorithms/volatility-and-covariance/covariance-estimation/factor-model-covariance";

Signature#

calculate(data)

Change loadings, common-factor risk and specific risk independently. Supplied-parameter educational reference; no fitted performance claim.

Parameters#

NameTypeNotes
dataTopicInputSee 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(p²k²) transparent direct multiplication, 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#

data
{
  "loadings": [
    [1],
    [2]
  ],
  "factor_covariance": [
    [0.04]
  ],
  "specific_variances": [0.01, 0.02],
  "parameters": {}
}

Call#

calculate(data)

Returns#

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

{
  "topic_id": "D10-F04-A05",
  "title": "Factor-Model Covariance",
  "parameters": {},
  "matrix": [
    [0.05, 0.08],
    [0.08, 0.18]
  ],
  "latest": [
    [0.05, 0.08],
    [0.08, 0.18]
  ],
  "ready": true,
  "ready_at": 0,
  "diagnostics": {
    "common": [
      [0.04, 0.08],
      [0.08, 0.16]
    ],
    "specific_variances": [0.01, 0.02],
    "assets": 2,
    "factors": 1,
    "causal": true
  }
}

Diagrams#

Factor-Model Covariance — article hero
Factor-Model Covariance — concept map
Factor-Model Covariance — decision comparison
Factor-Model Covariance — worked example

Calculation flow#

Factor-Model Covariance — calculation-flow
flowchart TD
    N0["Validate B, PSD F and nonnegative D"]
    N1["Compute each common-risk cell BFBᵀ"]
    N2["Add specific variances only on diagonal"]
    N3["Check portfolio variance two ways"]
    N0 --> N1 --> N2 --> N3
Factor-Model 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["Factor-Model 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.

Read the article →

References#

  • Scope of evidence

The rest of the Covariance Estimation family#