Polynomial Regression Extrapolation
length = 100 | extrapolate = 10 | degree = 3 Overview
Polynomial Regression Extrapolation fits a polynomial to the most recent length bars and evaluates
that curve at a future offset. Instead of returning the fitted line over the historical window, it returns the
projected value for each bar once enough data is available to support the fit.
The indicator can work from candle closes or direct numeric slices. The streaming version keeps a circular buffer of
the latest window, returns None until the buffer is full, and returns NaN whenever the
active window contains missing data.
Defaults: `length = 100`, `extrapolate = 10`, and `degree = 3`.
Implementation Examples
Project a polynomial fit forward from a close slice or from the default candle close source.
use vector_ta::indicators::polynomial_regression_extrapolation::{
polynomial_regression_extrapolation,
PolynomialRegressionExtrapolationInput,
PolynomialRegressionExtrapolationParams,
};
use vector_ta::utilities::data_loader::{Candles, read_candles_from_csv};
let output = polynomial_regression_extrapolation(
&PolynomialRegressionExtrapolationInput::from_slice(
&close,
PolynomialRegressionExtrapolationParams {
length: Some(100),
extrapolate: Some(10),
degree: Some(3),
},
),
)?;
let candles: Candles = read_candles_from_csv("data/sample.csv")?;
let candle_output = polynomial_regression_extrapolation(
&PolynomialRegressionExtrapolationInput::with_default_candles(&candles),
)?;
println!("forecast = {:?}", output.values.last());
println!("default forecast = {:?}", candle_output.values.last()); API Reference
Input Methods ▼
PolynomialRegressionExtrapolationInput::from_candles(
&Candles,
"close",
PolynomialRegressionExtrapolationParams,
) -> PolynomialRegressionExtrapolationInput
PolynomialRegressionExtrapolationInput::from_slice(
&[f64],
PolynomialRegressionExtrapolationParams,
) -> PolynomialRegressionExtrapolationInput
PolynomialRegressionExtrapolationInput::with_default_candles(&Candles)
-> PolynomialRegressionExtrapolationInput Parameters Structure ▼
pub struct PolynomialRegressionExtrapolationParams {
pub length: Option<usize>, // default 100
pub extrapolate: Option<usize>, // default 10
pub degree: Option<usize>, // default 3
} Output Structure ▼
pub struct PolynomialRegressionExtrapolationOutput {
pub values: Vec<f64>,
} Validation, Warmup & Fit Constraints ▼
- The input slice must not be empty and must contain at least one finite value.
lengthmust be greater than0and fit inside the available data.degreemust not exceed8and must not exceedlength.- The solver can reject singular fits through
SingularFit. - The direct output path warms up until
first_valid_index + length - 1, so earlier values are set toNaN. - The stream returns
Noneuntil the buffer is full and returnsNaNif the active window contains missing values. - Batch mode validates all three sweep axes and rejects non-batch kernels.
Builder, Streaming & Batch APIs ▼
PolynomialRegressionExtrapolationBuilder::new()
.length(usize)
.extrapolate(usize)
.degree(usize)
.kernel(Kernel)
.apply(&Candles)
.apply_slice(&[f64])
.into_stream()
PolynomialRegressionExtrapolationStream::try_new(params)
stream.update(f64) -> Option<f64>
PolynomialRegressionExtrapolationBatchBuilder::new()
.length_range(start, end, step)
.extrapolate_range(start, end, step)
.degree_range(start, end, step)
.kernel(Kernel)
.apply_slice(&[f64]) Python Bindings
Python exposes a scalar forecasting function, a stream class, and a batch helper. The scalar call returns one
forecast array, the stream returns one projected value or None, and the batch helper returns a
reshaped value matrix along with the swept length, extrapolation, and degree axes.
from vector_ta import (
polynomial_regression_extrapolation,
polynomial_regression_extrapolation_batch,
PolynomialRegressionExtrapolationStream,
)
values = polynomial_regression_extrapolation(
close,
length=100,
extrapolate=10,
degree=3,
)
stream = PolynomialRegressionExtrapolationStream(100, 10, 3)
point = stream.update(close[-1])
batch = polynomial_regression_extrapolation_batch(
close,
length_range=(50, 100, 25),
extrapolate_range=(5, 15, 5),
degree_range=(1, 3, 1),
)
print(batch.keys())
# dict_keys(['values', 'lengths', 'extrapolates', 'degrees', 'rows', 'cols']) JavaScript/WASM Bindings
The WASM surface exposes a scalar forecast function, a batch function, and low-level allocation and into-buffer helpers. The scalar helper returns the projected values directly, and the batch helper returns row-major values with combo metadata.
import init, {
polynomial_regression_extrapolation_js,
polynomial_regression_extrapolation_batch,
polynomial_regression_extrapolation_alloc,
polynomial_regression_extrapolation_free,
polynomial_regression_extrapolation_into,
polynomial_regression_extrapolation_batch_into,
} from "vector-ta-wasm";
await init();
const values = polynomial_regression_extrapolation_js(close, 100, 10, 3);
const batch = polynomial_regression_extrapolation_batch(close, {
length_range: [50, 100, 25],
extrapolate_range: [5, 15, 5],
degree_range: [1, 3, 1],
}); CUDA Bindings (Rust)
Additional details for the CUDA bindings can be found inside the VectorTA repository.
Performance Analysis
Across sizes, Rust CPU runs about 1.14× faster than Tulip C in this benchmark.
AMD Ryzen 9 9950X (CPU) | NVIDIA RTX 4090 (GPU)