# Gaussian Process Regression

Also known as: GPR.
A Machine Learning concept (Learned models) in the LuxAlgo Library, with 2 indicator implementations.

## What is Gaussian Process Regression?

Gaussian process regression (GPR) is a Bayesian, nonparametric way to fit a smooth curve through data. A Gaussian process treats the unknown curve as a random function: any finite set of its values is jointly Gaussian, fully described by a mean function and a covariance kernel that encodes how strongly nearby points move together. Conditioning that prior on observed prices yields a posterior whose mean is the fitted curve and whose variance gives an uncertainty band at every bar, so the method outputs both an estimate and how unsure it is.

The mathematics predates machine learning by decades. Mining engineer Danie Krige used the approach in the 1950s to estimate ore grades between drill samples, and Georges Matheron formalized it in the 1960s as kriging, still the standard name in geostatistics. Rasmussen and Williams' 2006 book Gaussian Processes for Machine Learning brought the method to the wider modeling world; charting tools now apply the same posterior-mean-plus-variance construction to price windows.

On charts, GPR is fitted to a recent window of price to draw a smooth path with confidence envelopes, sometimes extended a few bars forward. The kernel's length-scale hyperparameter controls smoothness, and a noise term controls how tightly the curve hugs the data. Beyond the observed window, with the stationary kernels commonly used, the posterior mean relaxes toward the prior and the bands widen quickly, which is the model's own admission that forward projections are scenarios, not forecasts. It differs from [kernel regression](https://www.luxalgo.com/library/concept/kernel-regression/) chiefly by producing that uncertainty estimate.

Two practical properties shape chart use. Exact GPR inverts a matrix that grows with the window, so computing cost rises roughly with the cube of the bar count and implementations keep training windows modest. Because the fit refreshes as new bars arrive, the curve over past bars can change after the fact; treat the drawn history as an in-sample fit, not a track record. The payoff is honest uncertainty, something point-output models such as [neural networks](https://www.luxalgo.com/library/concept/neural-networks/) do not provide without extra machinery.

## How to identify Gaussian process regression on a chart

GPR appears as an overlay: a smooth fitted curve through a recent price window, usually wrapped in probability bands and often extended a few bars past the last candle.

1. Add a GPR indicator such as LuxAlgo's Machine Learning: Gaussian Process Regression, or the anchored variant that fits from a chosen starting bar.
2. Locate the training window or anchor: the curve is fitted only to those bars, and everything drawn beyond the last observation is extrapolation.
3. Find the length-scale and noise settings: a longer length-scale flattens the curve toward a broad trend line, a shorter one chases wiggles, and more assumed noise loosens the curve's grip on closes.
4. Read the bands where the tool draws them: tight across the fitted window, flaring quickly beyond the last bar, the visual signature that separates GPR from fixed-width envelopes.
5. Test for repainting by stepping the chart forward: if the historical curve shifts as new bars arrive, the tool refits every bar, normal for GPR but important when judging past signals.

## How it's calculated

A Bayesian regression that treats the series as a draw from a distribution over smooth functions and outputs a posterior mean curve with a variance band.

```
k(x, x') = σ_f^2 × exp(-(x - x')^2 / (2 × l^2))
K = [k(x_i, x_j)] for i, j = 1..n
k_* = [k(x_i, x_*)] for i = 1..n
μ_* = k_*^T × (K + σ_n^2 × I)^(-1) × y
σ_*^2 = k(x_*, x_*) - k_*^T × (K + σ_n^2 × I)^(-1) × k_*
95% band: μ_* ± 1.96 × sqrt(σ_*^2)

  x_i: i-th training input (bar time), with indices i, j = 1..n
  x_*: query input where the fit is evaluated
  y: n-vector of training targets (prices, often demeaned first)
  n: training window length in bars
  k(x, x'): kernel, the assumed prior covariance between any two inputs x and x' (RBF form shown, the common default)
  exp(): exponential function
  σ_f: signal standard deviation, the kernel's output scale
  l: kernel length scale in bars, controlling smoothness
  K: n × n matrix of kernel values over training input pairs
  k_*: n-vector of kernel values between each training input and x_*
  σ_n: observation noise standard deviation
  I: n × n identity matrix
  μ_*: posterior mean at x_*, the plotted regression value
  σ_*^2: posterior variance at x_* (^T is transpose, ^(-1) is the matrix inverse)
```

Kernel choice and hyperparameters (σ_f, l, σ_n) control the fit; they are either user inputs or set by maximizing the log marginal likelihood.

The exact solution needs an n × n matrix inverse costing O(n^3), so indicator implementations keep the training window short.

Beyond the last bar the posterior mean extrapolates the fitted structure and σ_*^2 widens quickly, so the projected segment is an estimate, not a price forecast.

## How traders use it

- As an adaptive smoother: the posterior mean acts as a flexible fitted line through recent price, an alternative to polynomial fits that does not force a fixed curve shape.
- As uncertainty bands: price pressing the outer posterior band flags a statistically stretched move relative to the fitted curve, similar in spirit to regression-channel readings.
- As a short-horizon projection: the curve is extended forward with widening bands and read as a scenario envelope rather than a point prediction.
- As a stretch score: the gap between price and the posterior mean, divided by the posterior standard deviation, standardizes how stretched the move is; fading extreme readings is a common mean-reversion framing inside ranges.
- As a scenario tool alongside analog methods: the projected envelope pairs naturally with [kNN analog forecasting](https://www.luxalgo.com/library/concept/knn-analog-forecasting/), one extrapolating a fitted function and the other replaying similar historical windows; disagreement between the two is informative.
- As a pipeline component: the smoothed curve or its residuals become inputs via [feature engineering](https://www.luxalgo.com/library/concept/feature-engineering/), with evaluation pinned to an explicit [label definition and prediction horizon](https://www.luxalgo.com/library/concept/label-definition-and-prediction-horizon/) so smoothing does not quietly leak future information.

## GPR vs adjacent modeling approaches

- **Kernel Regression** (https://www.luxalgo.com/library/concept/kernel-regression/): Kernel regression returns a locally weighted average, a point estimate with no error bars; GPR returns a full posterior with variance at every bar, its kernel defining covariance rather than averaging weights.
- **Gaussian Mixture Models** (https://www.luxalgo.com/library/concept/gaussian-mixture-models/): The shared Gaussian name misleads: a mixture model describes how observations are distributed and sorts them into regimes, while GPR fits a curve through data as a function of time.
- **Neural Networks** (https://www.luxalgo.com/library/concept/neural-networks/): Networks fit flexible parametric functions and scale to large datasets, but output point predictions and need substantial data. GPR is nonparametric and data-efficient on small windows, with uncertainty built in, though its cost grows steeply with window size.

## FAQ

### How is Gaussian process regression different from kernel regression?

Kernel regression, such as the Nadaraya-Watson estimator, computes a locally weighted average of observations and returns only a point estimate. GPR is probabilistic: it places a Gaussian prior over whole functions and returns a posterior mean plus a variance, so uncertainty bands come built in. Both rely on kernels, but in GPR the kernel defines covariance between points rather than averaging weights.

### Can Gaussian process regression predict future prices?

It can extrapolate, but its own math argues for caution: outside the observed window the posterior variance climbs toward its prior level and the mean drifts back toward the prior, so forward paths carry wide error bands within a few bars. Treat projections as smoothed scenarios for planning, not forecasts, and remember the fit changes whenever the window or kernel settings change.

### Does Gaussian process regression repaint?

Typically yes. Most chart implementations refit the posterior as each new bar arrives, updating in the spirit of [online learning](https://www.luxalgo.com/library/concept/online-incremental-learning/), so the curve and bands over recent history shift after the fact; anchored variants reduce this by fixing the training set. Repainting here is refitting, not a bug, but historical crossings of the curve should not be read as signals that were available in real time.

### What does the length-scale hyperparameter control?

How far correlation reaches along the time axis. A long length-scale says distant bars still move together, producing a stiff, slowly bending curve; a short one lets correlation decay quickly, so the fit follows local wiggles. Together with the noise parameter it sets the balance between smoothing and tracking.

### Is the GPR curve itself a buy or sell signal?

No. It is a smoother with an uncertainty estimate, and any rule built on it, such as fading band touches or following slope changes, needs its own testing. The bands describe statistical stretch relative to the fitted curve, not support or resistance, and the model knows nothing about news, liquidity, or regime shifts outside its window.

## Implementations in the Library

- Machine Learning: Gaussian Process Regression (LuxAlgo): https://www.luxalgo.com/library/indicator/machine-learning-gaussian-process-regression/
- Machine Learning: Anchored Gaussian Process Regression (LuxAlgo): https://www.luxalgo.com/library/indicator/machine-learning-anchored-gaussian-process-regression/

## Related concepts

- Kernel Regression: https://www.luxalgo.com/library/concept/kernel-regression/
- Kernel Density Estimation: https://www.luxalgo.com/library/concept/kernel-density-estimation/
- Support Vector Machines: https://www.luxalgo.com/library/concept/support-vector-machines/
- Decision Trees: https://www.luxalgo.com/library/concept/decision-trees/
- Gradient Boosting: https://www.luxalgo.com/library/concept/gradient-boosting/
- Random Forest: https://www.luxalgo.com/library/concept/random-forest/
- Neural Networks: https://www.luxalgo.com/library/concept/neural-networks/
- LSTM / Recurrent Networks: https://www.luxalgo.com/library/concept/lstm-recurrent-networks/
- Bayesian Classifiers: https://www.luxalgo.com/library/concept/bayesian-classifiers/
- Self-organizing Maps: https://www.luxalgo.com/library/concept/self-organizing-maps/

---

Source: https://www.luxalgo.com/library/concept/gaussian-process-regression/ (LuxAlgo Library, the encyclopedia of trading & technical analysis). Free to use with attribution: https://www.luxalgo.com/library/license/