Parkinson Volatility

Parameters: period = 8

Overview

Parkinson Volatility estimates realized variance from the logarithm of each bar’s high-low ratio. Instead of using closes, it measures how much price ranged inside each bar, sums those squared log ranges across a rolling window, and converts the result into both variance and volatility.

The indicator accepts candles or explicit high and low slices. The streaming version keeps only the most recent range contributions, returns None until the full window is available, and yields NaN outputs when the active window still contains invalid bars.

Defaults: `period = 8`.

Implementation Examples

Run the estimator on candle highs and lows or on aligned high-low slices.

use vector_ta::indicators::parkinson_volatility::{
    parkinson_volatility,
    ParkinsonVolatilityInput,
    ParkinsonVolatilityParams,
};
use vector_ta::utilities::data_loader::{Candles, read_candles_from_csv};

let output = parkinson_volatility(&ParkinsonVolatilityInput::from_slices(
    &high,
    &low,
    ParkinsonVolatilityParams { period: Some(8) },
))?;

let candles: Candles = read_candles_from_csv("data/sample.csv")?;
let candle_output = parkinson_volatility(
    &ParkinsonVolatilityInput::with_default_candles(&candles),
)?;

println!("volatility = {:?}", output.volatility.last());
println!("variance = {:?}", candle_output.variance.last());

API Reference

Input Methods
ParkinsonVolatilityInput::from_candles(&Candles, ParkinsonVolatilityParams)
    -> ParkinsonVolatilityInput

ParkinsonVolatilityInput::from_slices(&[f64], &[f64], ParkinsonVolatilityParams)
    -> ParkinsonVolatilityInput

ParkinsonVolatilityInput::with_default_candles(&Candles)
    -> ParkinsonVolatilityInput
Parameters Structure
pub struct ParkinsonVolatilityParams {
    pub period: Option<usize>, // default 8
}
Output Structure
pub struct ParkinsonVolatilityOutput {
    pub volatility: Vec<f64>,
    pub variance: Vec<f64>,
}
Validation, Warmup & Invalid Bars
  • High and low arrays must have matching lengths and must not be empty.
  • period must be greater than 0.
  • Valid bars require finite high and low values with both greater than 0.
  • The estimator needs a valid run at least as long as period.
  • Warmup for the stream equals period; before that it returns None.
  • If the active stream window contains invalid bars after warmup, the stream returns (NaN, NaN).
  • Batch mode validates the period sweep and rejects non-batch kernels.
Builder, Streaming & Batch APIs
ParkinsonVolatilityBuilder::new()
    .period(usize)
    .kernel(Kernel)
    .apply(&Candles)
    .apply_slices(&[f64], &[f64])
    .into_stream()

ParkinsonVolatilityStream::try_new(params)
stream.update(high, low) -> Option<(f64, f64)>
stream.get_warmup_period() -> usize

ParkinsonVolatilityBatchBuilder::new()
    .period_range(start, end, step)
    .kernel(Kernel)
    .apply_slices(&[f64], &[f64])

Python Bindings

Python exposes a scalar high-low function, a stream class, and a batch helper. The scalar call returns volatility and variance arrays, the stream returns one tuple or None, and the batch helper returns reshaped matrices plus the swept period axis.

from vector_ta import (
    parkinson_volatility,
    parkinson_volatility_batch,
    ParkinsonVolatilityStream,
)

volatility, variance = parkinson_volatility(high, low, period=8)

stream = ParkinsonVolatilityStream(8)
point = stream.update(high[-1], low[-1])

batch = parkinson_volatility_batch(high, low, period_range=(5, 20, 5))

print(batch.keys())
# dict_keys(['volatility', 'variance', 'periods', 'rows', 'cols'])

JavaScript/WASM Bindings

The WASM surface includes scalar and batch helpers plus low-level allocation and into-buffer APIs. The high-level functions return plain JS objects, while the lower-level exports write volatility and variance arrays into caller-managed memory.

import init, {
  parkinson_volatility_js,
  parkinson_volatility_batch_js,
  parkinson_volatility_alloc,
  parkinson_volatility_free,
  parkinson_volatility_into,
  parkinson_volatility_into_host,
  parkinson_volatility_batch_into,
} from "vector-ta-wasm";

await init();

const out = parkinson_volatility_js(high, low, 8);
const batch = parkinson_volatility_batch_js(high, low, {
  period_range: [5, 20, 5],
});

CUDA Bindings (Rust)

Additional details for the CUDA bindings can be found inside the VectorTA repository.

Performance Analysis

Comparison:
View:
Placeholder data (no recorded benchmarks for this indicator)

Across sizes, Rust CPU runs about 1.14× faster than Tulip C in this benchmark.

Loading chart...

AMD Ryzen 9 9950X (CPU) | NVIDIA RTX 4090 (GPU)

Related Indicators