- The Normal Distribution CDF transforms a z-score normalized price into the cumulative distribution function of the Gaussian distribution, producing...
The Normal Distribution CDF transforms a z-score normalized price into the cumulative distribution function of the Gaussian distribution, producing an output in $[0, 1]$. Unlike other distribution indicators in this library that use min-max normalization, NORMDIST computes a rolling mean and standard deviation over the lookback window, converting the raw price to a z-score, then applies optional $\mu$ and $\sigma$ parameters for further shaping. The result represents the probability that a standard normal random variable would fall at or below the observed z-score. This makes NORMDIST a direct percentile ranking under the assumption of normally distributed returns, with the output naturally centered at 0.5 when the price is at its rolling mean.
## Historical Context
The normal distribution was discovered independently by Abraham de Moivre (1733) as a limit of the binomial distribution, and by Carl Friedrich Gauss (1809) in the context of astronomical measurement errors. Pierre-Simon Laplace (1812) proved the central limit theorem, establishing that sums of independent random variables converge to the normal distribution regardless of the underlying distribution.
In finance, the normal distribution assumption for asset returns was formalized by Harry Markowitz (1952) in Modern Portfolio Theory and Louis Bachelier (1900) in his thesis on speculation. Despite well-known departures (fat tails, skewness, volatility clustering), the normal CDF remains the most widely used probability transform in quantitative finance. It underpins the Black-Scholes formula, Value-at-Risk calculations, and the Sharpe ratio.
The z-score normalization approach used here is more statistically grounded than the min-max normalization used by other distribution indicators: it captures the rolling distributional properties (mean, variance) of the price series rather than just the range. This means NORMDIST adapts to both the level and the volatility of the price, making readings directly interpretable as "number of standard deviations from the mean."
## Architecture and Physics
The computation follows a three-phase pipeline:
**Phase 1: Rolling statistics** computes the mean and standard deviation over the lookback window using a single-pass algorithm:
NaN values are excluded from the count. If fewer than 2 valid values exist, the output defaults to 0.5.
**Phase 2: Z-score with parameter adjustment** converts the price to a z-score relative to the rolling distribution, then applies the user-specified shift and scale:
With defaults $\mu = 0, \sigma = 1$, $z_{\text{final}} = z$ (standard z-score). Increasing $\sigma$ compresses the CDF curve (less sensitive to deviations); shifting $\mu$ moves the midpoint away from the rolling mean.
**Phase 3: Error function approximation** evaluates $\Phi(z)$ using the Abramowitz and Stegun formula (7.1.26) with 3 polynomial terms in the exponential approximation of `erf`:
where $t = 1/(1 + 0.47047|x|)$. The CDF is then $\Phi(z) = 0.5(1 + \text{erf}(z/\sqrt{2}))$.
**Accuracy**: The 3-term Abramowitz-Stegun approximation achieves maximum error of $\sim 2.5 \times 10^{-5}$, sufficient for indicator applications. For higher precision, the 5-term version (used in LOGNORMDIST) reduces error to $\sim 1.5 \times 10^{-7}$.
O(1) per evaluation. The rational polynomial erfc approximation has 7-term expansion, accurate to 1e-7. Division by sigma precomputed as multiplication by 1/sigma.