Statistic

Statistic Functions — Standard statistical math applied to rolling windows of price data.

Functions

STDDEV — Standard Deviation VAR — Variance LINEARREG — Linear Regression LINEARREG_SLOPE — Linear Regression Slope LINEARREG_INTERCEPT — Linear Regression Intercept LINEARREG_ANGLE — Linear Regression Angle (degrees) TSF — Time Series Forecast BETA — Beta CORREL — Pearson’s Correlation Coefficient (r) DTW — Dynamic Time Warping (distance + warping path) DTW_DISTANCE — Dynamic Time Warping distance only (faster) BATCH_DTW — Batch DTW: N series vs 1 reference, in parallel MEDIAN — Rolling median MEDIAN_BANDS — Median of (high+low)/2 with ATR bands and median EMA MODE — Rolling mode via equal-width binning

ferro_ta.statistic.BATCH_DTW(matrix, reference, window=None)[source]

Batch Dynamic Time Warping — N series vs 1 reference, computed in parallel.

Parameters:
  • matrix (array-like, shape (N, L)) – N time series of length L. Each row is compared against reference.

  • reference (array-like, shape (L,)) – The reference series.

  • window (int, optional) – Sakoe-Chiba band width. None (default) = unconstrained.

Returns:

DTW distance from each row of matrix to reference.

Return type:

numpy.ndarray, shape (N,)

ferro_ta.statistic.BETA(real0, real1, timeperiod=5)[source]

Beta — regression slope of real0 relative to real1.

Parameters:
  • real0 (array-like) – Sequence of prices for asset 0 (dependent variable).

  • real1 (array-like) – Sequence of prices for asset 1 (independent variable).

  • timeperiod (int, optional) – Rolling window (default 5).

Returns:

Array of BETA values; leading timeperiod entries are NaN.

Return type:

numpy.ndarray

ferro_ta.statistic.CORREL(real0, real1, timeperiod=30)[source]

Pearson’s Correlation Coefficient (r).

Parameters:
  • real0 (array-like) – First data series.

  • real1 (array-like) – Second data series.

  • timeperiod (int, optional) – Rolling window (default 30).

Returns:

Array of CORREL values (-1 to 1); leading timeperiod - 1 entries are NaN.

Return type:

numpy.ndarray

ferro_ta.statistic.DTW(series1, series2, window=None)[source]

Dynamic Time Warping — distance and optimal warping path.

Parameters:
  • series1 (array-like) – First time series.

  • series2 (array-like) – Second time series (may differ in length from series1).

  • window (int, optional) – Sakoe-Chiba band width. None (default) = unconstrained.

Returns:

  • distance (float) – DTW distance (accumulated Euclidean cost along the optimal path).

  • path (numpy.ndarray, shape (N, 2)) – Warping path as (i, j) index pairs from (0, 0) to (len(series1)-1, len(series2)-1).

Return type:

tuple[float, ndarray]

ferro_ta.statistic.DTW_DISTANCE(series1, series2, window=None)[source]

Dynamic Time Warping distance only (faster — no path reconstruction).

Parameters:
  • series1 (array-like) – First time series.

  • series2 (array-like) – Second time series (may differ in length from series1).

  • window (int, optional) – Sakoe-Chiba band width. None (default) = unconstrained.

Returns:

DTW distance (accumulated Euclidean cost along the optimal path).

Return type:

float

ferro_ta.statistic.LINEARREG(close, timeperiod=14)[source]

Linear Regression.

Parameters:
  • close (array-like) – Sequence of closing prices.

  • timeperiod (int, optional) – Regression window (default 14).

Returns:

Array of linear regression end-point values; leading timeperiod - 1 entries are NaN.

Return type:

numpy.ndarray

ferro_ta.statistic.LINEARREG_ANGLE(close, timeperiod=14)[source]

Linear Regression Angle (in degrees).

Parameters:
  • close (array-like) – Sequence of closing prices.

  • timeperiod (int, optional) – Regression window (default 14).

Returns:

Array of angle values in degrees; leading timeperiod - 1 entries are NaN.

Return type:

numpy.ndarray

ferro_ta.statistic.LINEARREG_INTERCEPT(close, timeperiod=14)[source]

Linear Regression Intercept.

Parameters:
  • close (array-like) – Sequence of closing prices.

  • timeperiod (int, optional) – Regression window (default 14).

Returns:

Array of intercept values; leading timeperiod - 1 entries are NaN.

Return type:

numpy.ndarray

ferro_ta.statistic.LINEARREG_SLOPE(close, timeperiod=14)[source]

Linear Regression Slope.

Parameters:
  • close (array-like) – Sequence of closing prices.

  • timeperiod (int, optional) – Regression window (default 14).

Returns:

Array of slope values; leading timeperiod - 1 entries are NaN.

Return type:

numpy.ndarray

ferro_ta.statistic.MEDIAN(close, timeperiod=3)[source]

Rolling median.

Parameters:
  • close (array-like) – Input series.

  • timeperiod (int, optional) – Window length (default 3). Even windows average the two central values.

Returns:

Rolling median; leading timeperiod - 1 entries are NaN.

Return type:

numpy.ndarray

ferro_ta.statistic.MEDIAN_BANDS(high, low, close, timeperiod=3, atr_period=14, multiplier=2.0)[source]

Median of (high + low) / 2 with ATR envelopes and an EMA of the median.

Parameters:
  • high (array-like) – Price series of equal length.

  • low (array-like) – Price series of equal length.

  • close (array-like) – Price series of equal length.

  • timeperiod (int, optional) – Median and median-EMA window (default 3).

  • atr_period (int, optional) – ATR period (default 14).

  • multiplier (float, optional) – ATR band width (default 2.0).

Returns:

median, upper, lower, median_ema – Midline, upper band, lower band, and EMA of the midline.

Return type:

numpy.ndarray

ferro_ta.statistic.MODE(close, timeperiod=20, bins=10)[source]

Rolling mode via equal-width discretization of each window.

Parameters:
  • close (array-like) – Input series.

  • timeperiod (int, optional) – Window length (default 20).

  • bins (int, optional) – Number of equal-width bins between the window min and max (default 10).

Returns:

Centre of the most populous bin; leading timeperiod - 1 entries are NaN. A constant window returns that constant.

Return type:

numpy.ndarray

ferro_ta.statistic.STDDEV(close, timeperiod=5, nbdev=1.0)[source]

Standard Deviation.

Parameters:
  • close (array-like) – Sequence of closing prices.

  • timeperiod (int, optional) – Rolling window size (default 5).

  • nbdev (float, optional) – Number of standard deviations (default 1.0).

Returns:

Array of STDDEV values; leading timeperiod - 1 entries are NaN.

Return type:

numpy.ndarray

ferro_ta.statistic.TSF(close, timeperiod=14)[source]

Time Series Forecast — linear regression extrapolated one period ahead.

Parameters:
  • close (array-like) – Sequence of closing prices.

  • timeperiod (int, optional) – Regression window (default 14).

Returns:

Array of TSF values; leading timeperiod - 1 entries are NaN.

Return type:

numpy.ndarray

ferro_ta.statistic.VAR(close, timeperiod=5, nbdev=1.0)[source]

Variance.

Parameters:
  • close (array-like) – Sequence of closing prices.

  • timeperiod (int, optional) – Rolling window size (default 5).

  • nbdev (float, optional) – Number of deviations (default 1.0).

Returns:

Array of VAR values; leading timeperiod - 1 entries are NaN.

Return type:

numpy.ndarray