Systemicalpha

Z Score (simple)

systemic:core-zscrsimpleStatisticsfunction1 cr

Inputs

NameTypeDescription
Datafloatarray- **Description**; The dataset refers to the series of historical values or prices of an asset over a specific period. This dataset can be a series of closing prices, volume data, or any other financial metric relevant to the analysis.

Outputs

NameTypeDescription
Z Scorefloatarray- **Description**; The primary output of the Z Score (ZSCR) trading indicator is a numerical value that represents how many standard deviations a current data point (e.g., the current price of an asset) is away from the mean of a historical dataset. The Z Score is a dimensionless quantity that can be positive or negative.

The Z-Score measures how many standard deviations a value is from the mean. In trading, it quantifies how "unusual" the current price is relative to recent history, enabling mean-reversion strategies.

Z=X−μσZ = \frac{X - \mu}{\sigma}

Where:

  • XX = Current value
  • μ\mu = Mean over the lookback period
  • σ\sigma = Standard deviation over the lookback period

How It Works

flowchart TD
    subgraph Input["Price Data"]
        P["Prices over n periods"]
    end
    
    subgraph Stats["Statistical Calculation"]
        MEAN["μ = Mean of prices"]
        STD["σ = Standard deviation"]
        CURR["X = Current price"]
    end
    
    subgraph Calc["Z-Score"]
        DIFF["X - μ"]
        DIV["÷ σ"]
        Z["Z-Score"]
    end
    
    P --> MEAN & STD
    CURR & MEAN --> DIFF
    DIFF & STD --> DIV --> Z

Missing Data

If any value the calculation needs at a position is missing (null) — a data gap or a closed-market day — the Z-Score at that position is null. The math is never faked with substitute values: a gap in your inputs stays a gap in the output.

Separate from missing data, the Z-Score is mathematically undefined when the standard deviation is zero — a flat series has no "distance from the mean" to measure — so that position is also null, never a fabricated 0 that would falsely read as "exactly at the mean".

XμσZ-Score
null1005null
110null5null
1101000null
11010052.0

In live execution the module returns exactly one datapoint — the newest position — which is null when it cannot be determined.


Interpreting Z-Score

Z-ScoreInterpretation
> +2Significantly above average (potential overbought)
+1 to +2Above average
-1 to +1Normal range
-2 to -1Below average
< -2Significantly below average (potential oversold)
flowchart LR
    subgraph Zones["Z-Score Distribution"]
        EXT2[">+2 σ<br/>Extreme high"]
        HIGH["+1 to +2 σ<br/>Above normal"]
        NORM["-1 to +1 σ<br/>Normal (68%)"]
        LOW["-2 to -1 σ<br/>Below normal"]
        EXT1["<-2 σ<br/>Extreme low"]
    end
    
    EXT2 --> HIGH --> NORM --> LOW --> EXT1

Trading Applications

1. Mean Reversion Strategy

Z-ScoreSignal
< -2Consider buying (price abnormally low)
> +2Consider selling (price abnormally high)
Approaching 0Take profits (returning to mean)

2. Pairs Trading

Compare Z-Scores of two correlated assets:

  • Diverging Z-Scores → Trade the spread
  • Converging Z-Scores → Close position

3. Risk Management

Flag positions where Z-Score exceeds thresholds for review or automatic stop-loss.


Statistical Context

The Z-Score assumes a normal distribution:

Z-Score RangeData Within Range
±1σ~68%
±2σ~95%
±3σ~99.7%

In practice, financial data often has "fat tails," meaning extreme events occur more frequently than a normal distribution predicts.


Parameters

ParameterCommon ValuesDescription
Lookback20, 50, 100Periods for mean and std dev

Shorter lookbacks = more reactive but noisier
Longer lookbacks = smoother but slower to adapt


Z-Score vs Other Normalization

MethodFormulaUse Case
Z-Score(X - μ) / σMean reversion, outlier detection
Min-Max(X - min) / (max - min)Bounded 0-1 scaling
PercentileRank / NDistribution-free ranking

Advantages

  • Standardized — Comparable across different assets
  • Statistical foundation — Rooted in probability theory
  • Mean reversion — Ideal for reversion strategies
  • Outlier detection — Identifies unusual price behavior

Disadvantages

  • Assumes normality — Markets often have fat tails
  • Backward-looking — Mean and std dev from history
  • Parameter sensitive — Lookback period matters
  • Trending markets — May give premature signals

Further Reading

Rendering diagrams...
© 2026 WanoLabs. All rights reservedAlpha build v0.1.5