Skip to content

Documentation / @finchart/indicators / LinregFold

Interface: LinregFold ​

Defined in: indicators/src/kernels.ts:590

The end point of a least-squares line over the last period values — TradingView's linreg(source, length, 0), the Squeeze histogram. Fitted afresh each step, centered: with ȳ the window mean and k̄ = (n − 1)/2, slope = Σ(k − k̄)(y − ȳ) / Σ(k − k̄)² and the end point is ȳ + slope · (n − 1 − k̄). Every value is taken relative to the newest one: the end point sits near it, so what is added back to it is small, and for n = 2 the answer is that value exactly (a two-point line ends on its second point) — returned as such. No running sum is kept, so nothing is ever subtracted out — the rolling form (T' = T − S + y₀ + (n − 1)·y) drifted and lost its digits whenever a departing value dwarfed the rest. O(period) per step by design, like stddevFold. The state is just the ring.

Conditioning is the data's, not the kernel's: a window whose values span fourteen orders of magnitude (a 1e20 spike among 1e6 prices) has no double-precision fit to better than about n · max|y| · ε in absolute terms, whatever the algorithm — every one of the n shifted terms carries the spike's rounding. Relative to the end point that is still ~1e-10 (measured: period 4096, trailing 1e20 spike).

Methods ​

restore() ​

restore(state): void

Defined in: indicators/src/kernels.ts:593

Parameters ​

state ​

LinregState

Returns ​

void


snapshot() ​

snapshot(): LinregState

Defined in: indicators/src/kernels.ts:592

Returns ​

LinregState


step() ​

step(value): number | null

Defined in: indicators/src/kernels.ts:591

Parameters ​

value ​

number | null

Returns ​

number | null