# simulate

Simulate Du-Escanciano (DE) expected shortfall (ES) test statistics

## Syntax

``ebtde = simulate(ebtde)``
``ebtde = simulate(___,Name,Value)``

## Description

example

````ebtde = simulate(ebtde)` performs a simulation of the Du-Escanciano (DE) [1] expected shortfall (ES) test statistics. `simulate` simulates scenarios and calculates the supported test statistics for each scenario. The function uses the simulated test statistics to estimate the significance of the ES backtests when the `CriticalValueMethod` name-value pair argument for `unconditionalDE` or `conditionalDE` is set to `'simulation'`.```

example

````ebtde = simulate(___,Name,Value)` specifies options using one or more name-value pair arguments in addition to the input argument in the previous syntax.```

## Examples

collapse all

Create an `esbacktestbyde` object for a t model with 10 degrees of freedom. First, run a `conditionalDE` test based on 1000 scenarios and then use the `simulate` function to run a second simulation with 5000 scenarios.

```load ESBacktestDistributionData.mat rng('default'); % For reproducibility % Constructor runs simulation with 1000 scenarios ebtde = esbacktestbyde(Returns,"t",... 'DegreesOfFreedom',T10DoF,... 'Location',T10Location,... 'Scale',T10Scale,... 'PortfolioID',"S&P",... 'VaRID',["t(10) 95%","t(10) 97.5%","t(10) 99%"],... 'VaRLevel',VaRLevel); % Run conditionalDE tests conditionalDE(ebtde,'CriticalValueMethod','simulation')```
```ans=3×13 table PortfolioID VaRID VaRLevel ConditionalDE PValue TestStatistic CriticalValue AutoCorrelation Observations CriticalValueMethod NumLags Scenarios TestLevel ___________ _____________ ________ _____________ ______ _____________ _____________ _______________ ____________ ___________________ _______ _________ _________ "S&P" "t(10) 95%" 0.95 reject 0.003 15.285 3.2822 0.088175 1966 "simulation" 1 1000 0.95 "S&P" "t(10) 97.5%" 0.975 reject 0.006 16.177 3.9304 0.090711 1966 "simulation" 1 1000 0.95 "S&P" "t(10) 99%" 0.99 reject 0.037 6.9975 4.1995 0.05966 1966 "simulation" 1 1000 0.95 ```

The tests report 1000 scenarios, see the `Scenarios` column.

Run a second simulation with 5000 scenarios

```ebtde = simulate(ebtde,'NumScenarios',5000); conditionalDE(ebtde,'CriticalValueMethod','simulation')```
```ans=3×13 table PortfolioID VaRID VaRLevel ConditionalDE PValue TestStatistic CriticalValue AutoCorrelation Observations CriticalValueMethod NumLags Scenarios TestLevel ___________ _____________ ________ _____________ ______ _____________ _____________ _______________ ____________ ___________________ _______ _________ _________ "S&P" "t(10) 95%" 0.95 reject 0.0016 15.285 3.2535 0.088175 1966 "simulation" 1 5000 0.95 "S&P" "t(10) 97.5%" 0.975 reject 0.0046 16.177 3.7668 0.090711 1966 "simulation" 1 5000 0.95 "S&P" "t(10) 99%" 0.99 reject 0.0362 6.9975 3.8144 0.05966 1966 "simulation" 1 5000 0.95 ```

The tests show 5000 scenarios and updated p-values and critical values.

## Input Arguments

collapse all

`esbacktestbyde` object, which contains a copy of the 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 `esbacktestbyde` object, see `esbacktestbyde`.

### Name-Value Arguments

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`.

Example: ```ebtde = simulate(ebtde,'NumLags',10,'NumScenarios',1000000,'BlockSize',10000,'TestList','conditionalDE')```

Number of lags in the `conditionalDE` test statistic, specified as the comma-separated pair consisting of `'NumLags'` and a positive integer. The simulated test statistics are stored for all lags from `1` to `NumLags`, so that the `conditionalDE` test results are available for any number of lags between `1` and `NumLags` after running the `simulate` function.

Data Types: `double`

Number of scenarios to simulate, specified using the comma-separated pair consisting of `'NumScenarios'` and a scalar positive integer.

Data Types: `double`

Number of scenarios to simulate in a single simulation block, specified using the comma-separated pair consisting of `'BlockSize'` and a scalar positive integer.

Data Types: `double`

Indicator for which test statistics to simulate, specified as the comma-separated pair consisting of `'TestList'` and a cell array of character vectors or a string array with the value `'conditionalDE'`, `'unconditionalDE'`.

Data Types: `cell` | `string`

## Output Arguments

collapse all

`ebtde` is returned as an updated `esbacktestbyde` object. After you run `simulate`, the updated `esbacktestbyde` object stores the simulated test statistics, which `unconditionalDE` uses to calculate p-values and generate test results.

For more information on the `esbacktestbyde` object, see `esbacktestbyde`.

collapse all

### Simulation of Test Statistics

The simulation of test statistics requires simulating scenarios of returns, assuming the distribution of returns Xt ~ Pt is correct (null hypothesis), and computing the corresponding tests statistics for each scenario.

More specifically, the following steps describe the simulation process. The description uses the conditional test statistic CES for concreteness, but the same steps apply to the unconditional test statistic UES.

1. Simulate M scenarios of returns as

2. Compute the corresponding test statistic as

3. Define PC as the empirical distribution of the simulated test statistic values as

`${P}_{C}=P\left[{C}_{ES}\le x\right]=\frac{1}{M}I\left({C}_{ES}^{s}\le x\right),$`

where I(.) is the indicator function.

To compute the test statistic in step 2, the ranks or mapped returns Ut = Pt(Xt) need to be computed (see the definition of the test statistics for `unconditionalDE` and `conditionalDE`). Assuming that the model distribution is correct, the ranks Ut are always uniformly distributed in the unit interval. Therefore, in practice, directly simulating ranks is more efficient than simulating returns and then transforming the returns into ranks.

The `simulate` function implements the simulation process more efficiently as follows:

1. Simulated M scenarios of returns as

2. Compute the corresponding test statistic CES using the simulated ranks Us as

3. Define PC as the empirical distribution of the simulated test statistic values as

`${P}_{C}=P\left[{C}_{ES}\le x\right]=\frac{1}{M}I\left({C}_{ES}^{s}\le x\right).$`

After you determine the empirical distribution of the test statistic PC in step 3, the significance of the test follows the descriptions provided for `unconditionalDE` and `conditionalDE`. The same steps apply to the unconditional test statistic UES and its distribution function PU.

## References

[1] Du, Z., and J. C. Escanciano. "Backtesting Expected Shortfall: Accounting for Tail Risk." Management Science. Vol. 63, Issue 4, April 2017.

[2] Basel Committee on Banking Supervision. "Minimum Capital Requirements for Market Risk". January 2016 (https://www.bis.org/bcbs/publ/d352.pdf).

Introduced in R2019b