Z Score (simple)
systemic:core-zscrsimpleStatisticsfunction1 crInputs
| Name | Type | Description |
|---|---|---|
| Data | floatarray | - **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
| Name | Type | Description |
|---|---|---|
| Z Score | floatarray | - **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.
Where:
- = Current value
- = Mean over the lookback period
- = 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 |
|---|---|---|---|
| null | 100 | 5 | null |
| 110 | null | 5 | null |
| 110 | 100 | 0 | null |
| 110 | 100 | 5 | 2.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-Score | Interpretation |
|---|---|
| > +2 | Significantly above average (potential overbought) |
| +1 to +2 | Above average |
| -1 to +1 | Normal range |
| -2 to -1 | Below average |
| < -2 | Significantly 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-Score | Signal |
|---|---|
| < -2 | Consider buying (price abnormally low) |
| > +2 | Consider selling (price abnormally high) |
| Approaching 0 | Take 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 Range | Data 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
| Parameter | Common Values | Description |
|---|---|---|
| Lookback | 20, 50, 100 | Periods for mean and std dev |
Shorter lookbacks = more reactive but noisier
Longer lookbacks = smoother but slower to adapt
Z-Score vs Other Normalization
| Method | Formula | Use Case |
|---|---|---|
| Z-Score | (X - μ) / σ | Mean reversion, outlier detection |
| Min-Max | (X - min) / (max - min) | Bounded 0-1 scaling |
| Percentile | Rank / N | Distribution-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