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

Parkinson Volatility

Install and import#

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

Signature#

calculate(data)

Change intraday range while keeping endpoint prices fixed. 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-A02",
  "title": "Parkinson Volatility",
  "parameters": {
    "window": 2,
    "annualization_factor": 1
  },
  "series": [
    null,
    {
      "timestamp": "2026-01-02T09:00:00Z",
      "variance": 0.00022542110013889886,
      "volatility": 0.015014030109830568,
      "contributions": [0.00022542110013890082, 0.00022542110013889694],
      "components": {},
      "window_start": 0,
      "window_end": 1
    },
    {
      "timestamp": "2026-01-03T09:00:00Z",
      "variance": 0.00022542110013889886,
      "volatility": 0.015014030109830568,
      "contributions": [0.00022542110013889694, 0.00022542110013890082],
      "components": {},
      "window_start": 1,
      "window_end": 2
    }
  ],
  "latest": {
    "timestamp": "2026-01-03T09:00:00Z",
    "variance": 0.00022542110013889886,
    "volatility": 0.015014030109830568,
    "contributions": [0.00022542110013889694, 0.00022542110013890082],
    "components": {},
    "window_start": 1,
    "window_end": 2
  },
  "ready": true,
  "ready_at": 1,
  "diagnostics": {
    "input_count": 3,
    "annualization_factor": 1,
    "causal": true
  }
}

Diagrams#

Parkinson Volatility — article hero
Parkinson Volatility — concept map
Parkinson Volatility — decision comparison
Parkinson Volatility — worked example

Calculation flow#

Parkinson Volatility — calculation-flow
flowchart TD
    N0["Validate bracketed prices"]
    N1["Log high/low range"]
    N2["Square and divide by 4 ln 2"]
    N3["Average same-session contributions"]
    N0 --> N1 --> N2 --> N3
Parkinson 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["Parkinson 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#