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

Garman-Klass Volatility

Install and import#

bash
npm install fintech-algorithms
ts
import { calculate } from "fintech-algorithms/volatility-and-covariance/historical-estimators/garman-klass-volatility";

Signature#

calculate(data)

See the range term and body correction under valid OHLC geometry. 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(nw), 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
{
  "bars": [
    {
      "timestamp": "2026-01-01T09:00:00Z",
      "open": 99.50124791926824,
      "close": 100,
      "high": 101.00501670841679,
      "low": 98.51119396030626
    },
    {
      "timestamp": "2026-01-02T09:00:00Z",
      "open": 100.5012520859401,
      "close": 101.00501670841679,
      "high": 102.02013400267558,
      "low": 99.50124791926824
    },
    {
      "timestamp": "2026-01-03T09:00:00Z",
      "open": 98.51119396030626,
      "close": 99.0049833749168,
      "high": 100,
      "low": 97.53099120283326
    }
  ],
  "parameters": {
    "window": 2,
    "annualization_factor": 1
  }
}

Call#

calculate(data)

Returns#

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

{
  "topic_id": "D10-F01-A03",
  "title": "Garman-Klass Volatility",
  "parameters": {
    "window": 2,
    "annualization_factor": 1
  },
  "series": [
    null,
    {
      "timestamp": "2026-01-02T09:00:00Z",
      "variance": 0.00030284264097200084,
      "volatility": 0.01740237457854533,
      "contributions": [0.0003028426409720035, 0.00030284264097199813],
      "components": {},
      "window_start": 0,
      "window_end": 1
    },
    {
      "timestamp": "2026-01-03T09:00:00Z",
      "variance": 0.0003028426409720004,
      "volatility": 0.01740237457854532,
      "contributions": [0.00030284264097199813, 0.0003028426409720027],
      "components": {},
      "window_start": 1,
      "window_end": 2
    }
  ],
  "latest": {
    "timestamp": "2026-01-03T09:00:00Z",
    "variance": 0.0003028426409720004,
    "volatility": 0.01740237457854532,
    "contributions": [0.00030284264097199813, 0.0003028426409720027],
    "components": {},
    "window_start": 1,
    "window_end": 2
  },
  "ready": true,
  "ready_at": 1,
  "diagnostics": {
    "input_count": 3,
    "annualization_factor": 1,
    "causal": true
  }
}

Diagrams#

Garman-Klass Volatility — article hero
Garman-Klass Volatility — concept map
Garman-Klass Volatility — decision comparison
Garman-Klass Volatility — worked example

Calculation flow#

Garman-Klass Volatility — calculation-flow
flowchart TD
    N0["Measure log range and body"]
    N1["Half of squared log range"]
    N2["Subtract weighted squared body"]
    N3["Check nonnegative contribution"]
    N0 --> N1 --> N2 --> N3
Garman-Klass Volatility — 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["Garman-Klass Volatility 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 Historical Estimators family#