Quantile expected shortfall (ES) backtest by Acerbi and Szekely

runs the quantile ES backtest of Acerbi-Szekely (2014).`TestResults`

= quantile(`ebts`

)

`[`

adds an optional name-value pair argument for `TestResults`

,`SimTestStatistic`

] = quantile(`ebts`

,`Name,Value`

)`TestLevel`

.

Create an `esbacktestbysim`

object.

load ESBacktestBySimData rng('default'); % for reproducibility ebts = esbacktestbysim(Returns,VaR,ES,"t",... 'DegreesOfFreedom',10,... 'Location',Mu,... 'Scale',Sigma,... 'PortfolioID',"S&P",... 'VaRID',["t(10) 95%","t(10) 97.5%","t(10) 99%"],... 'VaRLevel',VaRLevel);

Generate the ES quantile test report.

TestResults = quantile(ebts)

`TestResults=`*3×10 table*
PortfolioID VaRID VaRLevel Quantile PValue TestStatistic CriticalValue Observations Scenarios TestLevel
___________ _____________ ________ ________ ______ _____________ _____________ ____________ _________ _________
"S&P" "t(10) 95%" 0.95 reject 0.002 -0.10602 -0.055798 1966 1000 0.95
"S&P" "t(10) 97.5%" 0.975 reject 0 -0.15697 -0.073513 1966 1000 0.95
"S&P" "t(10) 99%" 0.99 reject 0 -0.26561 -0.10117 1966 1000 0.95

`ebts`

— `esbacktestbysim`

objectobject

`esbacktestbysim`

(`ebts`

) object,
which contains a copy of the given data (the
`PortfolioData`

, `VarData`

,
`ESData`

, and `Distribution`

properties) and all combinations of portfolio ID, VaR ID, and VaR levels
to be tested. For more information on creating an
`esbacktestbysim`

object, see `esbacktestbysim`

.

Specify optional
comma-separated pairs of `Name,Value`

arguments. `Name`

is
the argument name and `Value`

is the corresponding value.
`Name`

must appear inside quotes. You can specify several name and value
pair arguments in any order as
`Name1,Value1,...,NameN,ValueN`

.

```
[TestResults,SimTestStatistic] =
quantile(ebts,'TestLevel',0.99)
```

`'TestLevel'`

— Test confidence level`0.95`

(default) | numeric with values between `0`

and
`1`

Test confidence level, specified as the comma-separated pair
consisting of `'TestLevel'`

and a numeric value
between `0`

and `1`

.

**Data Types: **`double`

`TestResults`

— Resultstable

Results, returned as a table where the rows correspond to all combinations of portfolio ID, VaR ID, and VaR levels to be tested. The columns correspond to the following information:

`'PortfolioID'`

— Portfolio ID for the given data`'VaRID'`

— VaR ID for each of the VaR data columns provided`'VaRLevel'`

— VaR level for the corresponding VaR data column`'Quantile'`

— Categorical array with categories 'accept' and 'reject' indicating the result of the quantile test`'PValue'`

—*P*-value of the quantile test`'TestStatistic'`

— Quantile test statistic`'CriticalValue'`

— Critical value for the quantile test`'Observations'`

— Number of observations`'Scenarios'`

— Number of scenarios simulated to get the*p*-values`'TestLevel'`

— Test confidence level

`SimTestStatistic`

— Simulated values of test statisticnumeric array

Simulated values of the test statistic, returned as a
`NumVaRs`

-by-`NumScenarios`

numeric array.

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:

$$\stackrel{\u2322}{ES}(Y)=-\frac{1}{\lfloor N{p}_{VaR}\rfloor}{\displaystyle \sum _{i=1}^{\lfloor N{p}_{VaR}\rfloor}{Y}_{\left[i\right]}}$$

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

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

$${Z}_{quantile}=-\frac{1}{N}{\displaystyle \sum _{t=1}^{N}\frac{\stackrel{\u2322}{ES}({P}_{t}^{-1}(U))}{E[\stackrel{\u2322}{ES}({P}_{t}^{-1}(V))]}+1}$$

The denominator inside the sum can be computed analytically as

$$E[\stackrel{\u2322}{ES}({P}_{t}^{-1}(V))]=-\frac{N}{\lfloor {N}_{pVaR}\rfloor}{\displaystyle {\int}_{0}^{1}{I}_{1-p}(N-\lfloor {N}_{pVaR}\rfloor},\lfloor {N}_{pVaR}\rfloor ){P}_{t}^{-1}(p)dp$$

where
`I`

_{x}(`z`

,`w`

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

.

Assuming that the distributional assumptions are correct, the
expected value of the test statistic
`Z`

_{quantile} is
`0`

.

This is expressed as:

$$E[{Z}_{quantile}]=0$$

Negative values of the test statistic indicate risk underestimation. The
quantile test is a one-sided test that rejects the model when there is evidence
that the model underestimates risk. (For technical details on the null and
alternative hypotheses, see Acerbi-Szekely, 2014). The quantile test rejects the
model when the *p*-value is less than `1`

minus the test confidence level.

For more information on simulating the test statistics and computing the
*p*-values and critical values, see `simulate`

.

The quantile test statistic is well-defined when there are no VaR failures in the data.

However, when the expected number of failures
`Np`

_{VaR} is small, an adjustment is
required. The sample estimator of the expected shortfall takes the average of
the smallest `N`

_{tail} observations in the
sample, where $${N}_{tail}=\lfloor {N}_{pVaR}\rfloor $$. If `Np`

_{VaR} <
`1`

, then `N`

_{tail} =
`0`

, the sample estimator of the expected shortfall becomes
an empty sum, and the quantile test statistic is undefined.

To account for this, whenever `Np`

_{VaR}
< `1`

, the value of
`N`

_{tail} is set to
`1`

. Thus, the sample estimator of the expected shortfall
has a single term and is equal to the minimum value of the sample. With this
adjustment, the quantile test statistic is then well-defined and the
significance analysis is unchanged.

[1] Acerbi, C., and B. Szekely. *Backtesting Expected
Shortfall.* MSCI Inc. December, 2014.

`conditional`

| `esbacktestbyde`

| `esbacktestbysim`

| `runtests`

| `simulate`

| `summary`

| `unconditional`

A modified version of this example exists on your system. Do you want to open this version instead?

You clicked a link that corresponds to this MATLAB command:

Run the command by entering it in the MATLAB Command Window. Web browsers do not support MATLAB commands.

Choose a web site to get translated content where available and see local events and offers. Based on your location, we recommend that you select: .

Select web siteYou can also select a web site from the following list:

Select the China site (in Chinese or English) for best site performance. Other MathWorks country sites are not optimized for visits from your location.

- América Latina (Español)
- Canada (English)
- United States (English)

- Belgium (English)
- Denmark (English)
- Deutschland (Deutsch)
- España (Español)
- Finland (English)
- France (Français)
- Ireland (English)
- Italia (Italiano)
- Luxembourg (English)

- Netherlands (English)
- Norway (English)
- Österreich (Deutsch)
- Portugal (English)
- Sweden (English)
- Switzerland
- United Kingdom (English)