Rank Correlation Index

Parameters: length = 12

Overview

Rank Correlation Index measures how closely the ordering of recent prices matches their ordering in time. When the most recent values also rank highly inside the lookback window, the indicator pushes toward its upper bound; when the recent sequence lines up with lower ranks, it pushes toward its lower bound. That makes it a useful way to detect strongly ordered momentum without relying on moving-average differences.

VectorTA exposes Rank Correlation Index as a single bounded series with support for direct slices, candle sources, streaming updates, and a single-axis batch sweep over the length parameter. The stream path resets naturally on non-finite input and resumes once enough fresh data has accumulated again.

Defaults: `length = 12`.

Implementation Examples

Run the oscillator from a raw slice or from candles with an explicit source field.

use vector_ta::indicators::rank_correlation_index::{
    rank_correlation_index,
    RankCorrelationIndexInput,
    RankCorrelationIndexParams,
};
use vector_ta::utilities::data_loader::{Candles, read_candles_from_csv};

let direct = rank_correlation_index(&RankCorrelationIndexInput::from_slice(
    &close,
    RankCorrelationIndexParams {
        length: Some(12),
    },
))?;

let candles: Candles = read_candles_from_csv("data/sample.csv")?;
let from_candles = rank_correlation_index(&RankCorrelationIndexInput::from_candles(
    &candles,
    "close",
    RankCorrelationIndexParams::default(),
))?;

println!("rci = {:?}", direct.values.last());
println!("candle rci = {:?}", from_candles.values.last());

API Reference

Input Methods
RankCorrelationIndexInput::from_candles(&Candles, "close", RankCorrelationIndexParams)
    -> RankCorrelationIndexInput

RankCorrelationIndexInput::from_slice(&[f64], RankCorrelationIndexParams)
    -> RankCorrelationIndexInput

RankCorrelationIndexInput::with_default_candles(&Candles)
    -> RankCorrelationIndexInput
Parameters Structure
pub struct RankCorrelationIndexParams {
    pub length: Option<usize>, // default 12
}
Output Structure
pub struct RankCorrelationIndexOutput {
    pub values: Vec<f64>,
}
Validation & Warmup
  • The input slice must not be empty and must contain at least one finite value.
  • length must be greater than 1 and no larger than the available data length.
  • Warmup begins at first_valid + length - 1, so earlier vector entries remain NaN.
  • The stream path returns None until the rolling window is full, and non-finite values interrupt the stream output.
  • Batch mode validates the length sweep and rejects non-batch kernels.
Builder, Streaming & Batch APIs
RankCorrelationIndexBuilder::new()
    .length(usize)
    .kernel(Kernel)
    .apply_slice(&[f64])
    .apply_candles(&Candles, "close")
    .into_stream()

RankCorrelationIndexStream::try_new(params)
stream.update(f64) -> Option<f64>

RankCorrelationIndexBatchBuilder::new()
    .length_range((start, end, step))
    .kernel(Kernel)
    .apply_slice(&[f64])
    .apply_candles(&Candles, "close")

Python Bindings

Python exposes a scalar function returning a NumPy array, a stream class returning the latest oscillator value, and a batch helper that reshapes the output matrix and includes the resolved length axis.

from vector_ta import (
    rank_correlation_index,
    rank_correlation_index_batch,
    RankCorrelationIndexStream,
)

values = rank_correlation_index(close, length=12)

stream = RankCorrelationIndexStream(length=12)
point = stream.update(close[-1])

batch = rank_correlation_index_batch(
    close,
    length_range=(12, 24, 6),
)

print(values[-1])
print(batch["rows"], batch["cols"])

JavaScript/WASM Bindings

The WASM layer exposes a vector-returning scalar call, a batch helper that returns values plus combo metadata, and lower-level allocation and into-buffer helpers for caller-managed memory.

import init, {
  rank_correlation_index_js,
  rank_correlation_index_batch_js,
  rank_correlation_index_alloc,
  rank_correlation_index_free,
  rank_correlation_index_into,
  rank_correlation_index_batch_into,
} from "vector-ta-wasm";

await init();

const single = rank_correlation_index_js(close, 12);

const batch = rank_correlation_index_batch_js(close, {
  length_range: [12, 24, 6],
});

const ptrIn = rank_correlation_index_alloc(close.length);
const ptrOut = rank_correlation_index_alloc(close.length);
rank_correlation_index_into(ptrIn, ptrOut, close.length, 12);
rank_correlation_index_free(ptrIn, close.length);
rank_correlation_index_free(ptrOut, close.length);

console.log(single, batch.rows, batch.cols);

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