Skip to main content

Zscore Close Deviation

Quick Reference

PropertyValue
Dimensionsignal
Categorymean_reversion
Versionv0.9.0 (Beta)
Output Columnzscore_close

Z-score of close deviation: (close - mean(close, window=window)) / std(close, window=window)

Formula

(close - rolling_mean(close, window)) / rolling_std(close, window)

CDM Inputs

ColumnCDM TableDescription
closecdm_*CDM source table

Parameters

ParameterTypeDefaultDescription
windowinteger [2, 1000]-Window size for mean and standard deviation calculation

Output

Column: zscore_close

Z-score of close deviation from rolling mean

Market Intuition & Trading Rationale

Z-score price deviation measures how many standard deviations the current price is from its rolling mean: (close - μ) / σ. A z-score of +2 means price is two standard deviations above its recent average — statistically unusual and likely to mean-revert. A z-score of -2 means price is two standard deviations below. The feature self-calibrates to each instrument's volatility — a $1 deviation in a $10 stock (high vol) produces a smaller z-score than a $1 deviation in a $100 stock (low vol).

This is the foundational mean-reversion feature. It assumes that prices oscillate around a locally stationary mean and that extreme deviations will revert. This assumption holds well during range-bound, sideways markets and breaks down during trending markets where the "mean" is a moving target. The window parameter is critical: too short and the z-score is noisy (mean and std estimated from too few samples); too long and it's slow to adapt to regime changes.

A common enhancement is to clip extreme z-scores (e.g., to ±3) to prevent individual outliers from dominating downstream signals. The rolling_zscore normalization available in feature set feature definitions provides this automatically.

Usage Cases

  • Mean reversion entry/exit: Buy when zscore < -2 (oversold), sell when zscore > +2 (overbought). Exit when zscore crosses 0 (mean reversion complete). This is the classic Bollinger Band / z-score mean reversion strategy.
  • Pairs trading: Compute the z-score of the spread between two cointegrated assets. When the spread's z-score is extreme, go long the undervalued, short the overvalued. Exit when the z-score normalizes to zero.
  • Anomaly detection: Z-scores beyond ±4 are statistically very unlikely under normality. These extreme events signal either a genuine regime change (trend initiation) or a data error. Investigate before trading.
  • normalization: Many feature set features use rolling_zscore normalization (which is equivalent to this feature applied to the signal column). Understanding this feature helps interpret normalized outputs.

YAML Definition

name: zscore_close_deviation
description: 'Z-score of close deviation: (close - mean(close, window=window)) / std(close,
window=window)'
category: mean_reversion
version: v0.9.0 (Beta)
dimension: signal
status: Pre-release
required_inputs:
- close
output_column: zscore_close
output_description: Z-score of close deviation from rolling mean
tags:
- zscore
- deviation
- normalization
- window
parameters:
window:
type: integer
description: Window size for mean and standard deviation calculation
required: true
constraints:
min: 2
max: 1000
formula: (close - rolling_mean(close, window)) / rolling_std(close, window)