# Wald's equation

In probability theory, Wald's equation, Wald's identity or Wald's lemma is an important identity that simplifies the calculation of the expected value of the sum of a random number of random quantities. In its simplest form, it relates the expectation of a sum of randomly many finite-mean, independent and identically distributed random variables to the expected number of terms in the sum and the random variables' common expectation under the condition that the number of terms in the sum is independent of the summands.
The equation is named after the mathematician Abraham Wald. An identity for the second moment is given by the Blackwell–Girshick equation.

## Basic version

Let (X$_n$)$_{n∈N{\displaystyle\mathbb{N}}}$ be a sequence of real-valued, independent and identically distributed random variables and let N ≥ 0 be an integer-valued random variable that is independent of the sequence (X$_n$)$_{n∈N{\displaystyle\mathbb{N}}}$. Suppose that N and the X$_n$ have finite expectations. Then
    $\operatorname {E} [X_{1}+\dots +X_{N}]=\operatorname {E} [N]\operatorname {E} [X_{1}]\,.$

## Example

Roll a six-sided dice. Take the number on the die (call it N) and roll that number of six-sided dice to get the numbers X$_1$, . . . , X$_N$, and add up their values. By Wald's equation, the resulting value on average is
    $\operatorname {E} [N]\operatorname {E} [X]={\frac {1+2+3+4+5+6}{6}}\cdot {\frac {1+2+3+4+5+6}{6}}={\frac {441}{36}}={\frac {49}{4}}=12.25\,.$

## General version

Let (X$_n$)$_{n∈N{\displaystyle\mathbb{N}}}$ be an infinite sequence of real-valued random variables and let N be a nonnegative integer-valued random variable.
Assume that:
    1. (X$_n$)$_{n∈N{\displaystyle\mathbb{N}}}$ are all integrable (finite-mean) random variables,
    2. E[X$_n$1$_{{N≥n}}$] = E[X$_n$] P(N ≥ n) for every natural number n, and
    3. the infinite series satisfies
          $\sum _{n=1}^{\infty }\operatorname {E} \!{\bigl|X_{n}|1_{\{N\geq n\}}{\bigr ]}<\infty .$
Then the random sums
    $S_{N}:=\sum _{n=1}^{N}X_{n},\qquad T_{N}:=\sum _{n=1}^{N}\operatorname {E} [X_{n}]$
are integrable and
    $\operatorname {E} [S_{N}]=\operatorname {E} [T_{N}].$
If, in addition,
    4. (X$_n$)$_{n∈N{\displaystyle\mathbb{N}}}$ all have the same expectation, and
    5. N has finite expectation,
then
    $\operatorname {E} [S_{N}]=\operatorname {E} [N]\,\operatorname {E} [X_{1}].$
Remark: Usually, the name Wald's equation refers to this last equality.

## Discussion of assumptions

Clearly, assumption (1) is needed to formulate assumption (2) and Wald's equation. Assumption (2) controls the amount of dependence allowed between the sequence (X$_n$)$_{n∈N{\displaystyle\mathbb{N}}}$ and the number N of terms; see the counterexample below for the necessity. Note that assumption (2) is satisfied when N is a stopping time for a sequence of independent random variables (X$_n$)$_{n∈N{\displaystyle\mathbb{N}}}$. Assumption (3) is of more technical nature, implying absolute convergence and therefore allowing arbitrary rearrangement of an infinite series in the proof.
If assumption (5) is satisfied, then assumption (3) can be strengthened to the simpler condition
    6. there exists a real constant C such that E[|X$_n$| 1$_{{N≥n}}$] ≤ C P(N ≥ n) for all natural numbers n.
Indeed, using assumption (6),
    $\sum _{n=1}^{\infty }\operatorname {E} \!{\bigl|X_{n}|1_{\{N\geq n\}}{\bigr ]}\leq C\sum _{n=1}^{\infty }\operatorname {P} (N\geq n),$
and the last series equals the expectation of N, which is finite by assumption (5). Therefore, (5) and (6) imply assumption (3).
Assume in addition to (1) and (5) that
    7. N is independent of the sequence (X$_n$)$_{n∈N{\displaystyle\mathbb{N}}}$ and
    8. there exists a constant C such that E[|X$_n$|] ≤ C for all natural numbers n.
Then all the assumptions (1), (2), (5) and (6), hence also (3) are satisfied. In particular, the conditions (4) and (8) are satisfied if
    9. the random variables (X$_n$)$_{n∈N{\displaystyle\mathbb{N}}}$ all have the same distribution.
Note that the random variables of the sequence (X$_n$)$_{n∈N{\displaystyle\mathbb{N}}}$ don't need to be independent.
The interesting point is to admit some dependence between the random number N of terms and the sequence (X$_n$)$_{n∈N{\displaystyle\mathbb{N}}}$. A standard version is to assume (1), (5), (8) and the existence of a filtration (F$_n$)$_{n∈N{\displaystyle\mathbb{N}}0}$ such that
    10. N is a stopping time with respect to the filtration, and
    11. X$_n$ and F$_{n–1}$ are independent for every n ∈ $\mathbb {N}$.
Then (10) implies that the event {N ≥ n} = {N ≤ n – 1}$^c$ is in F$_{n–1}$, hence by (11) independent of X$_n$. This implies (2), and together with (8) it implies (6).
For convenience (see the proof below using the optional stopping theorem) and to specify the relation of the sequence (X$_n$)$_{n∈N{\displaystyle\mathbb{N}}}$ and the filtration (F$_n$)$_{n∈N{\displaystyle\mathbb{N}}0}$, the following additional assumption is often imposed:
    12. the sequence (X$_n$)$_{n∈N{\displaystyle\mathbb{N}}}$ is adapted to the filtration (F$_n$)$_{n∈N{\displaystyle\mathbb{N}}}$, meaning the X$_n$ is F$_n$-measurable for every n ∈ $\mathbb {N}$.
Note that (11) and (12) together imply that the random variables (X$_n$)$_{n∈N{\displaystyle\mathbb{N}}}$ are independent.

## Application

An application is in actuarial science when considering the total claim amount follows a compound Poisson process
    $S_{N}=\sum _{n=1}^{N}X_{n}$
within a certain time period, say one year, arising from a random number N of individual insurance claims, whose sizes are described by the random variables (X$_n$)$_{n∈N{\displaystyle\mathbb{N}}}$. Under the above assumptions, Wald's equation can be used to calculate the expected total claim amount when information about the average claim number per year and the average claim size is available. Under stronger assumptions and with more information about the underlying distributions, Panjer's recursion can be used to calculate the distribution of S$_N$.

## Examples
### Example with dependent terms

Let N be an integrable, $\mathbb {N}$$_0$-valued random variable, which is independent of the integrable, real-valued random variable Z with E[Z] = 0. Define X$_n$ = (–1)$^n$ Z for all n ∈ $\mathbb {N}$. Then assumptions (1), (5), (7), and (8) with C := E[|Z|] are satisfied, hence also (2) and (6), and Wald's equation applies. If the distribution of Z is not symmetric, then (9) does not hold. Note that, when Z is not almost surely equal to the zero random variable, then (11) and (12) cannot hold simultaneously for any filtration (F$_n$)$_{n∈N{\displaystyle\mathbb{N}}}$, because Z cannot be independent of itself as E[Z$^2$] = (E[Z])$^2$ = 0 is impossible.

### Example where the number of terms depends on the sequence

Let (X$_n$)$_{n∈N{\displaystyle\mathbb{N}}}$ be a sequence of independent, symmetric, and {–1, +1}-valued random variables. For every n ∈ $\mathbb {N}$ let F$_n$ be the σ-algebra generated by X$_1$, . . . , X$_n$ and define N = n when X$_n$ is the first random variable taking the value +1. Note that P(N = n) = 1/2$^n$, hence E[N] < ∞ by the ratio test. The assumptions (1), (5) and (9), hence (4) and (8) with C = 1, (10), (11), and (12) hold, hence also (2), and (6) and Wald's equation applies. However, (7) does not hold, because N is defined in terms of the sequence (X$_n$)$_{n∈N{\displaystyle\mathbb{N}}}$. Intuitively, one might expect to have E[S$_N$] > 0 in this example, because the summation stops right after a one, thereby apparently creating a positive bias. However, Wald's equation shows that this intuition is misleading.

## Counterexamples
### A counterexample illustrating the necessity of assumption (2)

Consider a sequence (X$_n$)$_{n∈N{\displaystyle\mathbb{N}}}$ of i.i.d. (Independent and identically distributed random variables) random variables, taking each of the two values 0 and 1 with probability ⁠1/2⁠ (actually, only X$_1$ is needed in the following). Define N = 1 – X$_1$. Then S$_N$ is identically equal to zero, hence E[S$_N$] = 0, but E[X$_1$] = ⁠1/2⁠ and E[N] = ⁠1/2⁠ and therefore Wald's equation does not hold. Indeed, the assumptions (1), (3), (4) and (5) are satisfied, however, the equation in assumption (2) holds for all n ∈ $\mathbb {N}$ except for n = 1.

### A counterexample illustrating the necessity of assumption (3)

Very similar to the second example above, let (X$_n$)$_{n∈N{\displaystyle\mathbb{N}}}$ be a sequence of independent, symmetric random variables, where X$_n$ takes each of the values 2$^n$ and –2$^n$ with probability ⁠1/2⁠. Let N be the first n ∈ $\mathbb {N}$ such that X$_n$ = 2$^n$. Then, as above, N has finite expectation, hence assumption (5) holds. Since E[X$_n$] = 0 for all n ∈ $\mathbb {N}$, assumptions (1) and (4) hold. However, since S$_N$ = 1 almost surely, Wald's equation cannot hold.
Since N is a stopping time with respect to the filtration generated by (X$_n$)$_{n∈N{\displaystyle\mathbb{N}}}$, assumption (2) holds, see above. Therefore, only assumption (3) can fail, and indeed, since
    $\{N\geq n\}=\{X_{i}=-2^{i}{\text{ for }}i=1,\ldots ,n-1\}$
and therefore P(N ≥ n) = 1/2$^{n–1}$ for every n ∈ $\mathbb {N}$, it follows that
    $\sum _{n=1}^{\infty }\operatorname {E} \!{\bigl|X_{n}|1_{\{N\geq n\}}{\bigr ]}=\sum _{n=1}^{\infty }2^{n}\,\operatorname {P} (N\geq n)=\sum _{n=1}^{\infty }2=\infty .$

## A proof using the optional stopping theorem

Assume (1), (5), (8), (10), (11) and (12). Using assumption (1), define the sequence of random variables
    $M_{n}=\sum _{i=1}^{n}(X_{i}-\operatorname {E} [X_{i}]),\quad n\in {\mathbb {N} }_{0}.$
Assumption (11) implies that the conditional expectation of X$_n$ given F$_{n–1}$ equals E[X$_n$] almost surely for every n ∈ $\mathbb {N}$, hence (M$_n$)$_{n∈N{\displaystyle\mathbb{N}}0}$ is a martingale with respect to the filtration (F$_n$)$_{n∈N{\displaystyle\mathbb{N}}0}$ by assumption (12). Assumptions (5), (8) and (10) make sure that we can apply the optional stopping theorem, hence M$_N$ = S$_N$ – T$_N$ is integrable and
| $\operatorname {E} [S_{N}-T_{N}]=\operatorname {E} [M_{0}]=0.$ | (13) |
Due to assumption (8),
    $|T_{N}|={\biggl |}\sum _{i=1}^{N}\operatorname {E} [X_{i}]{\biggr |}\leq \sum _{i=1}^{N}\operatorname {E} [|X_{i}|]\leq CN,$
and due to assumption (5) this upper bound is integrable. Hence we can add the expectation of T$_N$ to both sides of Equation (13) and obtain by linearity
    $\operatorname {E} [S_{N}]=\operatorname {E} [T_{N}].$
Remark: Note that this proof does not cover the above example with dependent terms.

## General proof

This proof uses only Lebesgue's monotone and dominated convergence theorems. We prove the statement as given above in three steps.

### Step 1: Integrability of the random sum S$_N$

We first show that the random sum S$_N$ is integrable. Define the partial sums
| $S_{i}=\sum _{n=1}^{i}X_{n},\quad i\in {\mathbb {N} }_{0}.$ | (14) |
Since N takes its values in $\mathbb {N}$$_0$ and since S$_0$ = 0, it follows that
    $|S_{N}|=\sum _{i=1}^{\infty }|S_{i}|\,1_{\{N=i\}}.$
The Lebesgue monotone convergence theorem implies that
    $\operatorname {E} [|S_{N}|]=\sum _{i=1}^{\infty }\operatorname {E} [|S_{i}|\,1_{\{N=i\}}].$
By the triangle inequality,
    $|S_{i}|\leq \sum _{n=1}^{i}|X_{n}|,\quad i\in {\mathbb {N} }.$
Using this upper estimate and changing the order of summation (which is permitted because all terms are non-negative), we obtain
| $\operatorname {E} [|S_{N}|]\leq \sum _{n=1}^{\infty }\sum _{i=n}^{\infty }\operatorname {E} [|X_{n}|\,1_{\{N=i\}}]=\sum _{n=1}^{\infty }\operatorname {E} [|X_{n}|\,1_{\{N\geq n\}}],$ | (15) |
where the second inequality follows using the monotone convergence theorem. By assumption (3), the infinite sequence on the right-hand side of (15) converges, hence S$_N$ is integrable.

### Step 2: Integrability of the random sum T$_N$

We now show that the random sum T$_N$ is integrable. Define the partial sums
| $T_{i}=\sum _{n=1}^{i}\operatorname {E} [X_{n}],\quad i\in {\mathbb {N} }_{0},$ | (16) |
of real numbers. Since N takes its values in $\mathbb {N}$$_0$ and since T$_0$ = 0, it follows that
    $|T_{N}|=\sum _{i=1}^{\infty }|T_{i}|\,1_{\{N=i\}}.$
As in step 1, the Lebesgue monotone convergence theorem implies that
    $\operatorname {E} [|T_{N}|]=\sum _{i=1}^{\infty }|T_{i}|\operatorname {P} (N=i).$
By the triangle inequality,
    $|T_{i}|\leq \sum _{n=1}^{i}{\bigl |}\!\operatorname {E} [X_{n}]{\bigr |},\quad i\in {\mathbb {N} }.$
Using this upper estimate and changing the order of summation (which is permitted because all terms are non-negative), we obtain
| $\operatorname {E} [|T_{N}|]\leq \sum _{n=1}^{\infty }{\bigl |}\!\operatorname {E} [X_{n}]{\bigr |}\underbrace {\sum _{i=n}^{\infty }\operatorname {P} (N=i)} _{=\,\operatorname {P} (N\geq n)},$ | (17) |
By assumption (2),
    ${\bigl |}\!\operatorname {E} [X_{n}]{\bigr |}\operatorname {P} (N\geq n)={\bigl |}\!\operatorname {E} [X_{n}1_{\{N\geq n\}}]{\bigr |}\leq \operatorname {E} [|X_{n}|1_{\{N\geq n\}}],\quad n\in {\mathbb {N} }.$
Substituting this into (17) yields
    $\operatorname {E} [|T_{N}|]\leq \sum _{n=1}^{\infty }\operatorname {E} [|X_{n}|1_{\{N\geq n\}}],$
which is finite by assumption (3), hence T$_N$ is integrable.

### Step 3: Proof of the identity

To prove Wald's equation, we essentially go through the same steps again without the absolute value, making use of the integrability of the random sums S$_N$ and T$_N$ in order to show that they have the same expectation.
Using the dominated convergence theorem with dominating random variable |S$_N$| and the definition of the partial sum S$_i$ given in (14), it follows that
    $\operatorname {E} [S_{N}]=\sum _{i=1}^{\infty }\operatorname {E} [S_{i}1_{\{N=i\}}]=\sum _{i=1}^{\infty }\sum _{n=1}^{i}\operatorname {E} [X_{n}1_{\{N=i\}}].$
Due to the absolute convergence proved in (15) above using assumption (3), we may rearrange the summation and obtain that
    $\operatorname {E} [S_{N}]=\sum _{n=1}^{\infty }\sum _{i=n}^{\infty }\operatorname {E} [X_{n}1_{\{N=i\}}]=\sum _{n=1}^{\infty }\operatorname {E} [X_{n}1_{\{N\geq n\}}],$
where we used assumption (1) and the dominated convergence theorem with dominating random variable |X$_n$| for the second equality. Due to assumption (2) and the σ-additivity of the probability measure,
    ${\begin{aligned}\operatorname {E} [X_{n}1_{\{N\geq n\}}]&=\operatorname {E} [X_{n}]\operatorname {P} (N\geq n)\\&=\operatorname {E} [X_{n}]\sum _{i=n}^{\infty }\operatorname {P} (N=i)=\sum _{i=n}^{\infty }\operatorname {E} \!{\bigl\operatorname {E} [X_{n}]1_{\{N=i\}}{\bigr ]}.\end{aligned}}$
Substituting this result into the previous equation, rearranging the summation (which is permitted due to absolute convergence, see (15) above), using linearity of expectation and the definition of the partial sum T$_i$ of expectations given in (16),
    $\operatorname {E} [S_{N}]=\sum _{i=1}^{\infty }\sum _{n=1}^{i}\operatorname {E} \!{\bigl\operatorname {E} [X_{n}]1_{\{N=i\}}{\bigr ]}=\sum _{i=1}^{\infty }\operatorname {E} [\underbrace {T_{i}1_{\{N=i\}}} _{=\,T_{N}1_{\{N=i\}}}].$
By using dominated convergence again with dominating random variable |T$_N$|,
    $\operatorname {E} [S_{N}]=\operatorname {E} \!{\bigglT_{N}\underbrace {\sum _{i=1}^{\infty }1_{\{N=i\}}} _{=\,1_{\{N\geq 1\}}}{\biggr ]}=\operatorname {E} [T_{N}].$
If assumptions (4) and (5) are satisfied, then by linearity of expectation,
    $\operatorname {E} [T_{N}]=\operatorname {E} \!{\biggl\sum _{n=1}^{N}\operatorname {E} [X_{n}]{\biggr ]}=\operatorname {E} [X_{1}]\operatorname {E} \!{\biggl\underbrace {\sum _{n=1}^{N}1} _{=\,N}{\biggr ]}=\operatorname {E} [N]\operatorname {E} [X_{1}].$
This completes the proof.

## Further generalizations

* Wald's equation can be transferred to R$^d$-valued random variables (X$_n$)$_{n∈N{\displaystyle\mathbb{N}}}$ by applying the one-dimensional version to every component.
* If (X$_n$)$_{n∈N{\displaystyle\mathbb{N}}}$ are Bochner-integrable random variables taking values in a Banach space, then the general proof above can be adjusted accordingly.