Documentation

# tbfi

Time between failures independence test for value-at-risk (VaR) backtesting

## Syntax

``TestResults = tbfi(vbt)``
``TestResults = tbfi(vbt,Name,Value)``

## Description

example

````TestResults = tbfi(vbt)` generates the time between failures independence (TBFI) test for value-at-risk (VaR) backtesting.```

example

````TestResults = tbfi(vbt,Name,Value)` adds an optional name-value pair argument for `TestLevel`.```

## Examples

collapse all

Create a `varbacktest` object.

```load VaRBacktestData vbt = varbacktest(EquityIndex,Normal95)```
```vbt = varbacktest with properties: PortfolioData: [1043x1 double] VaRData: [1043x1 double] PortfolioID: "Portfolio" VaRID: "VaR" VaRLevel: 0.9500 ```

Generate the `tbfi` test results.

`TestResults = tbfi(vbt)`
```TestResults=1×14 table PortfolioID VaRID VaRLevel TBFI LRatioTBFI PValueTBFI Observations Failures TBFMin TBFQ1 TBFQ2 TBFQ3 TBFMax TestLevel ___________ _____ ________ ______ __________ __________ ____________ ________ ______ _____ _____ _____ ______ _________ "Portfolio" "VaR" 0.95 reject 88.491 0.0047475 1043 57 1 3 9 25.25 85 0.95 ```

Use the `varbacktest` constructor with name-value pair arguments to create a `varbacktest` object.

```load VaRBacktestData vbt = varbacktest(EquityIndex,... [Normal95 Normal99 Historical95 Historical99 EWMA95 EWMA99],... 'PortfolioID','Equity',... 'VaRID',{'Normal95' 'Normal99' 'Historical95' 'Historical99' 'EWMA95' 'EWMA99'},... 'VaRLevel',[0.95 0.99 0.95 0.99 0.95 0.99])```
```vbt = varbacktest with properties: PortfolioData: [1043x1 double] VaRData: [1043x6 double] PortfolioID: "Equity" VaRID: [1x6 string] VaRLevel: [0.9500 0.9900 0.9500 0.9900 0.9500 0.9900] ```

Generate the `tbfi` test results using the `TestLevel` optional input.

`TestResults = tbfi(vbt,'TestLevel',0.90)`
```TestResults=6×14 table PortfolioID VaRID VaRLevel TBFI LRatioTBFI PValueTBFI Observations Failures TBFMin TBFQ1 TBFQ2 TBFQ3 TBFMax TestLevel ___________ ______________ ________ ______ __________ __________ ____________ ________ ______ _____ _____ _____ ______ _________ "Equity" "Normal95" 0.95 reject 88.491 0.0047475 1043 57 1 3 9 25.25 85 0.9 "Equity" "Normal99" 0.99 accept 22.929 0.15157 1043 17 3 21.25 48 78.25 215 0.9 "Equity" "Historical95" 0.95 reject 82.719 0.022513 1043 59 1 3 13 25 85 0.9 "Equity" "Historical99" 0.99 accept 16.228 0.18101 1043 12 3 19.5 45 152.5 200 0.9 "Equity" "EWMA95" 0.95 accept 71.635 0.12517 1043 59 1 4 13 25.75 82 0.9 "Equity" "EWMA99" 0.99 reject 31.83 0.080339 1043 22 2 16 40 56 143 0.9 ```

## Input Arguments

collapse all

`varbacktest` (`vbt`) object, contains a copy of the given data (the `PortfolioData` and `VarData` properties) and all combinations of portfolio ID, VaR ID, and VaR levels to be tested. For more information on creating a `varbacktest` object, see `varbacktest`.

### Name-Value Pair 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: ```TestResults = tbfi(vbt,'TestLevel',0.99)```

Test confidence level, specified as the comma-separated pair consisting of `'TestLevel'` and a numeric between `0` and `1`.

Data Types: `double`

## Output Arguments

collapse all

`tbfi` test 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

• `'TBFI'` — Categorical array with the categories `accept` and `reject` that indicate the result of the `tbfi` test

• `'LRatioTBFI'` — Likelihood ratio of the `tbfi` test

• `'PValueTBFI'` — P-value of the `tbfi` test

• `'Observations'` — Number of observations

• `'Failures'` — Number of failures

• `'TBFMin'` — Minimum value of observed times between failures

• `'TBFQ1'` — First quartile of observed times between failures

• `'TBFQ2'` — Second quartile of observed times between failures

• `'TBFQ3'` — Third quartile of observed times between failures

• `'TBFMax'` — Maximum value of observed times between failures

• `'TestLevel'` — Test confidence level

### Note

For `tbfi` test results, the terms `accept` and `reject` are used for convenience, technically a `tbfi` test does not accept a model. Rather, the test fails to reject it.

collapse all

### Time Between Failures Independence (TBIF) Test

The `tbfi` function performs the time between failures independence test. This test is an extension of Kupiec's time until first failure (TUFF) test.

TBFI was proposed by Haas (2001) to test for independence. It takes into account not only the time until the first failure, but also the time between all failures. For the time between failures mixed test, see the `tbf` function.

## Algorithms

The likelihood ratio (test statistic) of the TBFI test is the sum of TUFF likelihood ratios for each time between failures. If x is the number of failures, and n1 is the number of periods until the first failure, n2 the number of periods between the first and the second failure, and, in general, ni is the number of periods between failure i`1` and failure i, then a likelihood ratio LRatioTBFIi for each ni is based on the TUFF formula

`$\begin{array}{l}LRatioTBF{I}_{i}=LRatioTUFF\left({n}_{i}\right)=-2{\sum }_{i=1}^{x}\mathrm{log}\left(\frac{pVaR{\left(1-pVaR\right)}^{{n}_{i}-1}}{\left(\frac{1}{{n}_{i}}\right){\left(1-\frac{1}{{n}_{i}}\right)}^{{n}_{i}-1}}\right)\\ =-2\left(\mathrm{log}\left(pVaR\right)+\left({n}_{i}-1\right)\mathrm{log}\left(1-pVaR\right)+{n}_{i}\mathrm{log}\left({n}_{i}\right)-\left({n}_{i}-1\right)\mathrm{log}\left({n}_{i}-1\right)\right)\end{array}$`

As with the `tuff` test, LRatioTBFIi = `−2`log(pVaR) if ni = `1`.

The TBFI likelihood ratio LRatioTBFI is then the sum of the individual likelihood ratios for all times between failures

`$LRatioTBFI=\sum _{i=1}^{x}LRatioTBF{I}_{i}$`

which is asymptotically distributed as a chi-square distribution with x degrees of freedom, where x is the number of failures.

The p-value of the `tbfi` test is the probability that a chi-square distribution with x degrees of freedom exceeds the likelihood ratio LRatioTBFI

`$PValueTBFI=1-F\left(LRatioTBFI\right)$`

where F is the cumulative distribution of a chi-square variable with x degrees of freedom and x is the number of failures.

The result of the test is to accept if

`$F\left(LRatioTBFI\right)`

and reject otherwise, where F is the cumulative distribution of a chi-square variable with x degrees of freedom and x is the number of failures.

If there are no failures in the sample, the test statistic is not defined. This is handled the same as a TUFF test with no failures. For more information, see `tuff`.

## References

[1] Haas, M. "New Methods in Backtesting." Financial Engineering, Research Center Caesar, Bonn, 2001.