Main Content

bin

Binomial test for value-at-risk (VaR) backtesting

Description

example

TestResults = bin(vbt) generates the binomial test results for value-at-risk (VaR) backtesting.

example

TestResults = bin(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]
             Time: [1043x1 double]
      PortfolioID: "Portfolio"
            VaRID: "VaR"
         VaRLevel: 0.9500

Generate the bin test results.

TestResults = bin(vbt)
TestResults=1×9 table
    PortfolioID    VaRID    VaRLevel     Bin      ZScoreBin    PValueBin    Observations    Failures    TestLevel
    ___________    _____    ________    ______    _________    _________    ____________    ________    _________

    "Portfolio"    "VaR"      0.95      accept     0.68905      0.49079         1043           57         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]
             Time: [1043x1 double]
      PortfolioID: "Equity"
            VaRID: ["Normal95"    "Normal99"    "Historical95"    "Historical99"    "EWMA95"    "EWMA99"]
         VaRLevel: [0.9500 0.9900 0.9500 0.9900 0.9500 0.9900]

Generate the bin test results using the TestLevel optional argument.

TestResults = bin(vbt,'TestLevel',0.90)
TestResults=6×9 table
    PortfolioID        VaRID         VaRLevel     Bin      ZScoreBin    PValueBin    Observations    Failures    TestLevel
    ___________    ______________    ________    ______    _________    _________    ____________    ________    _________

     "Equity"      "Normal95"          0.95      accept     0.68905       0.49079        1043           57          0.9   
     "Equity"      "Normal99"          0.99      reject      2.0446      0.040896        1043           17          0.9   
     "Equity"      "Historical95"      0.95      accept      0.9732       0.33045        1043           59          0.9   
     "Equity"      "Historical99"      0.99      accept     0.48858       0.62514        1043           12          0.9   
     "Equity"      "EWMA95"            0.95      accept      0.9732       0.33045        1043           59          0.9   
     "Equity"      "EWMA99"            0.99      reject      3.6006     0.0003175        1043           22          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 Arguments

Specify optional pairs of arguments as Name1=Value1,...,NameN=ValueN, where Name is the argument name and Value is the corresponding value. Name-value arguments must appear after other arguments, but the order of the pairs does not matter.

Before R2021a, use commas to separate each name and value, and enclose Name in quotes.

Example: TestResults = bin(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

Bin 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 given data

  • 'VaRID' — VaR ID for each of the VaR data columns provided

  • 'VaRLevel' — VaR level for corresponding VaR data column

  • 'Bin' — Categorical array with categories accept and reject that indicate the result of the bin test

  • 'ZScoreBin' — Z-score of the number of failures

  • 'PValueBin' — P-value of the bin test

  • 'Observations' — Number of observations

  • 'Failures' — Number of failures.

  • 'TestLevel' — Test confidence level.

Note

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

More About

collapse all

Binomial Test (Bin)

The bin function performs a binomial test to assess if the number of failures is consistent with the VaR confidence level.

The binomial test is based on a normal approximation to the binomial distribution.

Algorithms

The result of the binomial test is based on a normal approximation to a binomial distribution. Suppose:

  • N is the number of observations.

  • p = 1 - VaRLevel is the probability of observing a failure if the model is correct.

  • x is the number of failures.

If the failures are independent, then the number of failures is distributed as a binomial distribution with parameters N and p. The expected number of failures is N*p, and the standard deviation of the number of failures is

Np(1p)

The test statistic for the bin test is the z-score, defined as:

ZScoreBin=(xNp)Np(1p)

The z-score approximately follows a standard normal distribution. This approximation is not reliable for small values of N or small values of p, but for typical uses in VaR backtesting analyses (N = 250 or much larger,p in the range 1 -10%) the approximation gives results in line with other tests.

The tail probability of the bin test is the probability that a standard normal distribution exceeds the absolute value of the z-score

TailProbability=1F(|ZScoreBin|)

where F is the standard normal cumulative distribution. When too few failures are observed, relative to the expected failures, PValueBin is (approximately) the probability of observing that many failures or fewer. For too many failures, this is (approximately) the probability of observing that many failures or more.

The p-value of the bin test is defined as two times the tail probability. This is because the binomial test is a two-sided test. If alpha is defined as 1 minus the test confidence level, the test rejects if the tail probability is less than one half of alpha, or equivalently if

PValueBin=2 TailProbability < alpha

References

[1] Jorion, P. Financial Risk Manager Handbook. 6th Edition. Wiley Finance, 2011.

Version History

Introduced in R2016b