The *quantile* test (also known as the
third Acerbi-Szekely test) uses a sample estimator of the expected
shortfall.

The expected shortfall for a sample
`Y`

_{1},…,`Y`

_{N} is:

where

`N`

is the number of periods in the test window
(*t* = `1`

,…,`N`

).

`P`

_{VaR} is the probability of VaR
failure defined as 1-VaR level.

`Y`

_{[1]},…,`Y`

_{[N]}
are the sorted sample values (from smallest to largest), and $$\lfloor N{p}_{VaR}\rfloor $$ is the largest integer less than or equal to
`Np`

_{VaR}.

To compute the quantile test statistic, a sample of size `N`

is created at each time *t* as follows. First, convert the
portfolio outcomes to `X`

_{t} to ranks $${U}_{1}={P}_{1}({X}_{1}),\mathrm{...},{U}_{N}={P}_{N}({X}_{N})$$ using the cumulative distribution function
`P`

_{t}. If the distribution
assumptions are correct, the rank values
`U`

_{1},…,`U`

_{N}
are uniformly distributed in the interval (0,1). Then at each time
*t*:

Invert the ranks U =
(`U`

_{1},…,`U`

_{N})
to get `N`

quantiles $${P}_{t}^{-1}(U)=({P}_{t}^{-1}({U}_{1}),\mathrm{...},{P}_{t}^{-1}({U}_{N}))$$.

Compute the sample estimator $$\stackrel{\u2322}{ES}({P}_{t}^{-1}(U))$$.

Compute the expected value of the sample estimator $$E\left[\stackrel{\u2322}{ES}({P}_{t}^{-1}(V))\right]$$

where `V`

=
(`V`

_{1},…,`V`

_{N}
is a sample of `N`

independent uniform random
variables in the interval (0,1). This value can be computed
analytically.

Define the quantile test statistic as

The denominator inside the sum can be computed analytically as

where
`I`

_{x}(`z`

,`w`

)
is the regularized incomplete beta function. For more information, see `betainc`

.