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

Graphical-Lasso Covariance

Install and import#

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

Signature#

calculate(data)

Vary penalty independently from sample count and inspect precision edges. 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(np²) empirical covariance plus bounded iterative block optimization; iteration-dependent, 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
{
  "returns": [
    [1, 1.3660254037844386],
    [1, -0.3660254037844386],
    [-1, 0.3660254037844386]
  ],
  "parameters": {
    "alpha": 0.1
  }
}

Call#

calculate(data)

Returns#

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

{
  "topic_id": "D10-F04-A06",
  "title": "Graphical-Lasso Covariance",
  "parameters": {
    "alpha": 0.1
  },
  "matrix": [
    [1, 0.4],
    [0.4, 1]
  ],
  "latest": [
    [1, 0.4],
    [0.4, 1]
  ],
  "ready": true,
  "ready_at": 0,
  "diagnostics": {
    "observations": 4,
    "assets": 2,
    "means": [0, 0],
    "causal": true,
    "ml_covariance": [
      [1, 0.5],
      [0.5, 1]
    ],
    "graphical_lasso": {
      "iterations": 1,
      "converged": true,
      "alpha": 0.1,
      "precision": [
        [1.1904761904761905, -0.4761904761904762],
        [-0.4761904761904762, 1.1904761904761905]
      ],
      "kkt_residual": 5.551115123125783e-17,
      "dual_gap": -9.71445146547012e-17,
      "history": [
        {
          "iteration": 1,
          "kkt_residual": 5.551115123125783e-17,
          "dual_gap": -9.71445146547012e-17,
          "objective": 1.8256466128552222
        }
      ]
    }
  }
}

Diagrams#

Graphical-Lasso Covariance — article hero
Graphical-Lasso Covariance — concept map
Graphical-Lasso Covariance — decision comparison
Graphical-Lasso Covariance — worked example

Calculation flow#

Graphical-Lasso Covariance — calculation-flow
flowchart TD
    N0["Center observations into ML C"]
    N1["Solve block lasso with fixed diagonal"]
    N2["Check SPD, KKT residual and dual gap"]
    N3["Invert to precision; interpret conditional edges"]
    N0 --> N1 --> N2 --> N3
Graphical-Lasso 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["Graphical-Lasso 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#