Skip to content

What (One-liner)

Slope from numpy.polyfit 1st-order fit. Used to determine sequence direction. Library-level primitive.

How to use

python
from services.algo.statistics import trend_slope
s = trend_slope([10, 12, 14, 16, 18])   # 2.0

Core formulas

x = [0..n-1]
slope = polyfit(x, filter_none(series), deg=1)[0]

Assumptions & applicability

Assumptions: Equidistant indices + None filter + n≥3 valid points.

Applicability: Trend direction / earnings scoring / macro drift.

Not applicable: Non-linear, structural break, n<3.

Known limitations

  1. Outlier sensitive
  2. No R²/p-value output
  3. Unit = value per index step (caller must understand)

References

Standard OLS + numpy.polyfit + Greene (2017) Econometric Analysis.

Golden Test

tests/golden/fixtures/tier1/trend_slope/, 1e-12, 2026-04-20 passing.

Changelog

  • 1.0.0 (2026-04-20) — BUG-GOLDEN-001 fix + first Active

Verifiable intelligence for the decisions that demand scrutiny.