Normal Distribution and Standard Normal
Install and import#
npm install fintech-algorithmsimport { normalDistributionAndStandardNormal } from "fintech-algorithms/foundations/probability-distributions-and-simulation-basics/normal-distribution-and-standard-normal";Signature#
normalDistributionAndStandardNormal(input)Evaluates the normal density and cumulative probability at input.x for a distribution with mean mu and standard deviation sigma, and returns the standardised score that maps x onto the standard normal.
Parameters#
| Name | Type | Notes |
|---|---|---|
input | D00Input | One record carrying x (the point to evaluate), mu and sigma (the distribution's mean and standard deviation). Those three fields are the whole input. The shared F07 branch also reads p, n, k and lambda before dispatching, and validates p; none of them affect the normal density, so the topic facade fills them when they are absent.sigma: strictly positive · p: optional; between 0 and 1 inclusive when supplied, otherwise 0 |
Returns#
D00Output
An object with pdf (the density at x), cdf (the cumulative probability at x) and z (the standardised score). The two languages reach cdf differently: Python calls the platform error function and TypeScript uses the Abramowitz-Stegun 7.1.26 approximation, so compare them with a tolerance near 1e-7 rather than bit for bit. Neither is an exact integral.
Errors#
- When a supplied p falls outside 0 to 1 — this check runs for every topic in the family — throws RangeError
- When sigma is zero or negative — this check runs for every topic from A05 onward — throws RangeError
Complexity: time O(1),
space O(1).
Worked example#
verified This is the worked example published in the article, replayed by the test suite on every run. The output cannot drift.
Input#
{
"x": 1,
"mu": 0,
"sigma": 1
}Call#
normalDistributionAndStandardNormal(input)Returns#
object with 2 fields: pdf, cdf
{
"pdf": 0.24197072451914337,
"cdf": 0.8413447460685428
}Diagrams#
Calculation flow#
Reasoning flow — D00-F07-A05
flowchart LR
A["Synthetic input + metadata"] --> B{"Contract valid?"}
B -->|No| C["Reject or route with reason"]
B -->|Yes| D["Apply Normal Distribution and Standard Normal"]
D --> E["Formula: f(x)=exp(−z²/2)/(σ√(2π)); z=(x−μ)/σ"]
E --> F["Verified fixture output"]
F --> G{"Interpretation within boundary?"}
G -->|Yes| H["Report value + convention + audit"]
G -->|No| I["Add companion view or narrower claim"]
How it works#
This page states the contract — how to call it correctly. The article explains the concept: why it works, and where it breaks.
References#
- Probability Distributions — NIST/SEMATECH e-Handbook
- Probability Distributions — SciPy User Guide
- Random Sampling — NumPy Documentation
- Historical-example decision