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

GARCH

Install and import#

bash
npm install fintech-algorithms
ts
import { calculate } from "fintech-algorithms/volatility-and-covariance/conditional-volatility/garch";

Signature#

calculate(data)

Separate new shock information from carried variance. 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(n), 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": [-0.02, 0.01, 0],
  "parameters": {
    "omega": 0.000002,
    "initial_variance": 0.0001,
    "alpha": 0.1,
    "beta": 0.8
  }
}

Call#

calculate(data)

Returns#

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

{
  "topic_id": "D10-F03-A02",
  "title": "GARCH",
  "parameters": {
    "omega": 0.000002,
    "initial_variance": 0.0001,
    "alpha": 0.1,
    "beta": 0.8
  },
  "series": [
    {
      "index": 0,
      "variance": 0.0001,
      "initialization": true
    },
    {
      "index": 1,
      "variance": 0.00012200000000000001,
      "intercept": 0.000002,
      "shock_contribution": 0.00004,
      "threshold_contribution": 0,
      "carry": 0.00008
    },
    {
      "index": 2,
      "variance": 0.00010960000000000001,
      "intercept": 0.000002,
      "shock_contribution": 0.00001,
      "threshold_contribution": 0,
      "carry": 0.00009760000000000001
    }
  ],
  "latest": {
    "index": 2,
    "variance": 0.00010960000000000001,
    "intercept": 0.000002,
    "shock_contribution": 0.00001,
    "threshold_contribution": 0,
    "carry": 0.00009760000000000001
  },
  "ready": true,
  "ready_at": 0,
  "diagnostics": {
    "causal": true,
    "input_count": 3,
    "fitted_parameters": false,
    "model": "garch"
  }
}

Diagrams#

GARCH — article hero
GARCH — concept map
GARCH — decision comparison
GARCH — worked example

Calculation flow#

GARCH — calculation-flow
flowchart TD
    N0["Read explicit initial variance"]
    N1["Square previous residual"]
    N2["Add intercept and α shock term"]
    N3["Carry β times previous variance"]
    N0 --> N1 --> N2 --> N3
GARCH — 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["GARCH 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 Conditional Volatility family#