# Variance (variance)

The sample variance of a list of numbers, or the variance of a distribution.

## How to write it

### variance(data)

The sum of the squared deviations from the mean, divided by n - 1.

**data**

At least two numbers. Symbols are allowed. Takes a list.

### variance(distribution)

The variance of a distribution.

**distribution**

A distribution such as normal_distribution(mu, sigma). Takes an expression.

### variance(process)

The variance of a stochastic process at a time.

**process**

A process at a time, written construct(p, t), or p(t) for a stored process p. Takes an expression.

### variance(process, t)

The same, with the time written beside the process.

**process**

A process such as geometric_brownian_motion_process(mu, sigma, x0). Takes an expression.

**t**

The time, a variable or a number. Takes an expression.

## Examples

- $\displaystyle 2, 4, 4, 4, 5, 5, 7, 9 = \frac{32}{7}$

  `variance([2, 4, 4, 4, 5, 5, 7, 9])`

  In the solver, `variance([2, 4, 4, 4, 5, 5, 7, 9])` gives `32/7`.

  [Open in the solver](https://hilberon.com/?q=variance%28%5B2%2C%204%2C%204%2C%204%2C%205%2C%205%2C%207%2C%209%5D%29)
- $\displaystyle a, b, c = \frac{a^{2}-a b-a c+b^{2}-b c+c^{2}}{3}$

  `variance([a, b, c])`

  In the solver, `variance([a, b, c])` gives `(a^2 - a*b - a*c + b^2 - b*c + c^2)/3`.

  [Open in the solver](https://hilberon.com/?q=variance%28%5Ba%2C%20b%2C%20c%5D%29)
- $\displaystyle \operatorname{Var}(X),\ X \sim \mathrm{B}(n, p) = n p (1-p)$

  `variance(binomial_distribution(n, p))`

  In the solver, `variance(binomial_distribution(n, p))` gives `n*p*(1 - p)`.

  [Open in the solver](https://hilberon.com/?q=variance%28binomial_distribution%28n%2C%20p%29%29)
- $\displaystyle \operatorname{Var}(X),\ X \sim \mathrm{U}(a, b) = \frac{(b-a)^{2}}{12}$

  `variance(uniform_distribution(a, b))`

  In the solver, `variance(uniform_distribution(a, b))` gives `(b - a)^2/12`.

  [Open in the solver](https://hilberon.com/?q=variance%28uniform_distribution%28a%2C%20b%29%29)
- $\displaystyle \operatorname{construct}(\operatorname{OU}(\mu, \sigma, \theta, x_{0}), t) = \begin{cases} \frac{\sigma^{2} \left(1-\frac{1}{e^{2 t \theta}}\right)}{2 \theta} & \text{if } \theta \neq 0 \end{cases}$

  `variance(construct(ornstein_uhlenbeck_process(mu, sigma, theta, x0), t))`

  In the solver, `variance(construct(ornstein_uhlenbeck_process(mu, sigma, theta, x0), t))` gives `(1/2)sigma^2*(1 - e^(-2t*theta))/theta if theta != 0`.

  [Open in the solver](https://hilberon.com/?q=variance%28construct%28ornstein_uhlenbeck_process%28mu%2C%20sigma%2C%20theta%2C%20x0%29%2C%20t%29%29)
- $\displaystyle \operatorname{Var}(X_{t}),\ X \sim \operatorname{GBM}(\mu, \sigma, x_{0}) = x_{0}^{2} e^{2 \mu t} (e^{\sigma^{2} t}-1)$

  `variance(geometric_brownian_motion_process(mu, sigma, x0), t)`

  In the solver, `variance(geometric_brownian_motion_process(mu, sigma, x0), t)` gives `x0^2*e^(2mu*t)*(e^(sigma^2*t) - 1)`.

  [Open in the solver](https://hilberon.com/?q=variance%28geometric_brownian_motion_process%28mu%2C%20sigma%2C%20x0%29%2C%20t%29)
- $\displaystyle \operatorname{variance}(\operatorname{wiener\_process}(\mu, \sigma), t) = \sigma^{2} t$

  `variance(wiener_process(mu, sigma), t)`

  In the solver, `variance(wiener_process(mu, sigma), t)` gives `sigma^2*t`.

  [Open in the solver](https://hilberon.com/?q=variance%28wiener_process%28mu%2C%20sigma%29%2C%20t%29)

## Functions its examples use

- [binomial_distribution](https://hilberon.com/library/binomial_distribution)

  The number of successes in n independent trials that each succeed with chance p.
- [uniform_distribution](https://hilberon.com/library/uniform_distribution)

  The continuous distribution that is equally likely anywhere between a and b.
- [construct](https://hilberon.com/library/construct)

  Apply a head that is itself computed to arguments, as in f'(0) or (x => body)(a).
- [ornstein_uhlenbeck_process](https://hilberon.com/library/ornstein_uhlenbeck_process)

  A process pulled toward mu at rate theta, with noise sigma, started at x0.
- [geometric_brownian_motion_process](https://hilberon.com/library/geometric_brownian_motion_process)

  A process that grows at rate mu with relative noise sigma, started at x0.
- [wiener_process](https://hilberon.com/library/wiener_process)

  Brownian motion with drift mu and noise sigma, started at 0.

## Related functions

- [weibull_distribution](https://hilberon.com/library/weibull_distribution)

  The lifetime of a unit whose chance of surviving to time x is e^(-(x/scale)^shape).
- [stationary_distribution](https://hilberon.com/library/stationary_distribution)

  The law a process settles into over time, when it has one.
- [affine_sde_moments](https://hilberon.com/library/affine_sde_moments)

  The mean and variance at time t of dX = (a + b X) dt + sigma dW, started at x0.
- [standard_deviation](https://hilberon.com/library/standard_deviation)

  The sample standard deviation of a list of numbers, or that of a distribution.
- [quantile](https://hilberon.com/library/quantile)

  The smallest value with at least a share q of a list, or a chance q of a distribution, at or below it.
- [cdf](https://hilberon.com/library/cdf)

  The probability that a variable with a distribution is at most a value.

---
Source: https://hilberon.com/library/variance
