Savitzky-Golay Filter

Savitzky-Golay Filter, also known as SG filter, Savitzky-Golay smoothing, polynomial smoothing filter, is a Trend concept. The Library holds 1 implementation, a working definition you can pull into Quant.

Top Savitzky-Golay Filter indicator

The top custom implementation, built on the original standard Savitzky-Golay Filter formula.

1 total

This Savitzky-Golay Filter implementation is strategy-ready: open it in Quant, set your rules, and it backtests automatically.

What is a Savitzky-Golay Filter?

A Savitzky-Golay filter smooths a series by fitting a low-degree polynomial, by least squares, to a sliding window of points and taking the fitted value at the window's center. Abraham Savitzky and Marcel Golay published it in Analytical Chemistry in 1964 to clean noisy spectra. Their key observation was that, for evenly spaced data, the fit collapses into a fixed set of weights: the filter is a weighted moving average whose coefficients depend only on the window length and the polynomial degree.

That is the source of its reputation for preserving peaks. A centered SMA is the degree-zero (and degree-one) case and flattens every peak it spans; a quadratic or quartic fit can bend with the data, so turning points keep more of their height and width at the same window length, at the cost of passing more noise. On a price chart the centered form needs bars on both sides, so its newest values are provisional and revise as bars arrive, the end-point problem it shares with LOESS and the Whittaker–Henderson smoother.

How it's calculated

A centered least-squares polynomial fit, equivalent to a fixed weighted average over the window.

y^t=∑j=−mmcj×yt+j\hat{y}_t = \sum_{j=-m}^{m} c_j \times y_{t+j}
c=first row of (AT×A)−1×AT, with Aj,k=jkc = \text{first row of } (A^T \times A)^{-1} \times A^T\text{, with } A_{j,k} = j^k
Window 5, degree 2 or 3: c=(−3,12,17,12,−3)/35\text{Window 5, degree 2 or 3: } c = (-3, 12, 17, 12, -3) / 35
Window 7, degree 2 or 3: c=(−2,3,6,7,6,3,−2)/21\text{Window 7, degree 2 or 3: } c = (-2, 3, 6, 7, 6, 3, -2) / 21
t: bar index of the point being smoothed
y_t: input value at bar t (typically the close)
y_hat_t: smoothed value at bar t
m: half-window; the window spans 2m + 1 bars
j: offset from the center bar, -m to m
c_j: filter weight for offset j (c is the vector of weights)
p: polynomial degree (commonly 2 to 4, below 2m + 1)
A: (2m + 1) × (p + 1) matrix of powers j^k; A^T is its transpose
k: polynomial power, 0 to p

Degrees 2 and 3 give identical center weights, as do degrees 0 and 1 (the plain centered average).

The centered form uses m future bars, so the newest m values revise; evaluating the fit at the newest bar of a trailing window is causal, and with degree 1 that endpoint fit is the LSMA.

Other weight sets from the same fit return smoothed first and second derivatives.

How traders use it

  • As a peak-preserving smoother for analysis, where the height and timing of past swings matter, such as cycle studies and swing labeling.
  • As a derivative estimator: smoothed slope and curvature from the same fit feed momentum and trend acceleration reads with less noise than raw differences.
  • As an oscillator pre-filter: a short, low-degree window removes jitter while keeping turning points near where they occurred, provided the end-point revisions are handled.

Savitzky-Golay filter vs related smoothers

LSMA: The LSMA fits a straight line to a trailing window and plots its endpoint. Savitzky-Golay usually fits a curve and plots the center; its causal endpoint form with degree one is the LSMA.

LOESS Smoothing: LOESS refits a distance-weighted local polynomial at every point, which suits uneven spacing and, in its robust form, outliers. Savitzky-Golay uses an unweighted fit on evenly spaced data, which collapses into one fixed set of coefficients.

Windowed FIR Smoothing: Both are fixed-weight symmetric FIR filters. Tapered windows keep every weight positive and smooth harder; from degree 2 up, Savitzky-Golay weights turn negative near the edges, which is what lets them preserve peaks.

Concept family

Trend

104 concepts mapped · 104 in the Library

Savitzky-Golay Filter FAQ

Turn Savitzky-Golay Filter into a trading strategy.

Take the implementation from this page into Quant, then build on it, backtest it on real data, and keep refining it in conversation.