fintech-algorithms
Using a coding agent? Give it the skill: npx skills add IslamBaraka90/Fintech-Algorithms-Library What it does →

Normal Distribution and Standard Normal

Install and import#

bash
npm install fintech-algorithms
ts
import { 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#

NameTypeNotes
inputD00InputOne 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#

input
{
  "x": 1,
  "mu": 0,
  "sigma": 1
}

Call#

normalDistributionAndStandardNormal(input)

Returns#

object with 2 fields: pdf, cdf

{
  "pdf": 0.24197072451914337,
  "cdf": 0.8413447460685428
}

Diagrams#

Normal Distribution and Standard Normal — article hero
Normal Distribution and Standard Normal — calculation ledger
Normal Distribution and Standard Normal — concept anatomy
Normal Distribution and Standard Normal — failure boundary
Normal Distribution and Standard Normal — method map
Normal Distribution and Standard Normal — scenario contrast

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.

Read the article →

References#

The rest of the Probability Distributions and Simulation Basics family#