Velocity

Parameters: length = 21 | smooth_length = 5

Overview

Velocity is the simpler companion to the acceleration-style indicators in this batch: it measures the rate component directly and returns one smoothed velocity line. It is useful when you want directional speed without the extra sensitivity of the acceleration transforms.

In VectorTA the indicator supports direct source slices, candles with a configurable source field, streaming updates, and batch sweeps across the base and smoothing lengths. That makes it a straightforward building block for price-speed studies, signal preprocessing, or more complex composite indicators.

Defaults: `length = 21` and `smooth_length = 5`.

Implementation Examples

Run Velocity on a source slice or on candles using the default `hlcc4` candle source.

use vector_ta::indicators::velocity::{velocity, VelocityInput, VelocityParams};

let output = velocity(&VelocityInput::from_slice(
    &close,
    VelocityParams {
        length: Some(21),
        smooth_length: Some(5),
    },
))?;

println!("velocity = {:?}", output.values.last());

API Reference

Input Methods
VelocityInput::from_candles(&Candles, "hlcc4", VelocityParams)
    -> VelocityInput

VelocityInput::from_slice(&[f64], VelocityParams)
    -> VelocityInput

VelocityInput::with_default_candles(&Candles)
    -> VelocityInput
Parameters Structure
pub struct VelocityParams {
    pub length: Option<usize>,
    pub smooth_length: Option<usize>,
}
Output Structure
pub struct VelocityOutput {
    pub values: Vec<f64>,
}
Validation, Warmup & NaNs
  • The source slice must not be empty or all NaN, and both resolved lengths must fit the available data.
  • The default candle helper uses hlcc4, while the builder also supports alternate candle sources.
  • Streaming returns None until the warmup is complete and exposes an explicit reset path.
  • Batch mode validates both range axes before generating the matrix.
Builder, Streaming & Batch APIs
VelocityBuilder::new()
    .length(usize)
    .smooth_length(usize)
    .kernel(Kernel)
    .apply(&Candles)
    .apply_slice(&[f64])
    .into_stream()

VelocityStream::try_new(params)
stream.update(value) -> Option<f64>
stream.reset()

VelocityBatchBuilder::new()
    .length_range(start, end, step)
    .smooth_length_range(start, end, step)
    .apply_slice(&[f64])

Python Bindings

Python exposes direct, stream, and batch helpers for the single velocity series.

from vector_ta import velocity, velocity_batch, VelocityStream

single = velocity(close, length=21, smooth_length=5)
stream = VelocityStream(length=21, smooth_length=5)
point = stream.update(close[-1])
batch = velocity_batch(close, length_range=(13, 34, 3), smooth_length_range=(3, 9, 2))

JavaScript/WASM Bindings

The WASM layer exposes direct, batch, allocation, and into-buffer helpers for velocity calculations.

import init, { velocity_js, velocity_batch_js, velocity_into } from "vector-ta-wasm";

await init();

const single = velocity_js(close, 21, 5);
const batch = velocity_batch_js(close, {
  length_range: [13, 34, 3],
  smooth_length_range: [3, 9, 2],
});

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