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

HAR-RV

Install and import#

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

Signature#

calculate(data)

Watch one elevated session enter and leave three overlapping horizons. 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
{
  "realized_variance": [0.0001, 0.0001, 0.0001, 0.0001, 0.0001, 0.0001],
  "parameters": {
    "beta0": 0,
    "beta_daily": 0.5,
    "beta_weekly": 0.3,
    "beta_monthly": 0.2
  }
}

Call#

calculate(data)

Returns#

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

{
  "topic_id": "D10-F03-A06",
  "title": "HAR-RV",
  "parameters": {
    "beta0": 0,
    "beta_daily": 0.5,
    "beta_weekly": 0.3,
    "beta_monthly": 0.2
  },
  "series": [null, null, null, null, null, null],
  "latest": {
    "index": 21,
    "forecast_index": 22,
    "forecast_raw": 0.00027072727272727274,
    "forecast": 0.00027072727272727274,
    "valid": true,
    "daily": 0.0004,
    "weekly": 0.00016,
    "monthly": 0.00011363636363636366,
    "contributions": [0, 0.0002, 0.000048, 0.000022727272727272733],
    "baseline": 0.0004
  },
  "ready": true,
  "ready_at": 21,
  "diagnostics": {
    "causal": true,
    "input_count": 22,
    "fitted_parameters": false
  }
}

Diagrams#

HAR-RV — article hero
HAR-RV — concept map
HAR-RV — decision comparison
HAR-RV — worked example

Calculation flow#

HAR-RV — calculation-flow
flowchart TD
    N0["Observe RV through current session"]
    N1["Build 1 / 5 / 22 session features"]
    N2["Multiply by supplied coefficients"]
    N3["Forecast next session; flag negative raw value"]
    N0 --> N1 --> N2 --> N3
HAR-RV — 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["HAR-RV 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#