main content

expected shortfall (es) backtesting workflow with no model distribution information -凯发k8网页登录

this example shows an expected shortfall (es) backtesting workflow and the use of es backtesting tools. the esbacktest class supports two tests -- unconditional normal and unconditional t -- which are based on acerbi-szekely's unconditional test statistic (also known as the acerbi-szekely second test). these tests use presimulated critical values for the unconditional test statistic, with an assumption of normal distribution for the normal case and a t distribution with 3 degrees of freedom for the t case.

step 1. load the es backtesting data.

use the esbacktestdata.mat file to load the data into the workspace. this example works with the returns numeric array. this array represents the equity returns, varmodel1, varmodel2, and varmodel3, and the corresponding var data at 97.5% confidence levels, generated with three different models. the expected shortfall data is contained in esmodel1, esmodel2, and esmodel3. the three model distributions used to generate the expected shortfall data in this example are normal (model 1), t with 10 degrees of freedom (model 2), and t with 5 degrees of freedom (model 3). however, this distribution information is not needed in this example because the esbacktest object does not require it.

load('esbacktestdata')
whos
  name              size             bytes  class        attributes
  data           1966x13            223945  timetable              
  dates          1966x1              15728  datetime               
  esmodel1       1966x1              15728  double                 
  esmodel2       1966x1              15728  double                 
  esmodel3       1966x1              15728  double                 
  returns        1966x1              15728  double                 
  varlevel          1x1                  8  double                 
  varmodel1      1966x1              15728  double                 
  varmodel2      1966x1              15728  double                 
  varmodel3      1966x1              15728  double                 

step 2. generate an es backtesting plot.

use the plot function to visualize the es backtesting data. this type of visualization is a common first step when performing an es backtesting analysis. for illustration purposes only, visualize the returns, together with var and es, for a particular model.

the resulting plot shows some large violations in 1997, 1998, and 2000. the violations in 1996 look smaller in absolute terms, however relative to the volatility of that period, those violations are also significant. for the unconditional test, the magnitude of the violations and the number of violations make a difference, because the test statistic averages over the expected number of failures. if the expected number is small, but there are several violations, the effective severity for the test is larger. the year 2002 is an example of a year with small, but many var failures.

figure;
plot(dates,returns,dates,-varmodel1,dates,-esmodel1)
legend('returns','var','es')
title('test data, model 1, var level 95%')
grid on

figure contains an axes object. the axes object with title test data, model 1, var level 95% contains 3 objects of type line. these objects represent returns, var, es.

step 3. create an esbacktest object.

create an esbacktest object using .

load esbacktestdata
ebt = esbacktest(returns,[varmodel1 varmodel2 varmodel3],[esmodel1 esmodel2 esmodel3],...
    'portfolioid',"s&p",'varid',["model1","model2","model3"],'varlevel',varlevel)
ebt = 
  esbacktest with properties:
    portfoliodata: [1966x1 double]
          vardata: [1966x3 double]
           esdata: [1966x3 double]
      portfolioid: "s&p"
            varid: ["model1"    "model2"    "model3"]
         varlevel: [0.9750 0.9750 0.9750]

step 4. generate the es summary report.

generate the es summary report. the observedseverity column shows the average ratio of loss to var on periods when the var is violated. the expectedseverity column shows the average ratio of es to var for the var violation periods.

s = summary(ebt);   
disp(s)
    portfolioid     varid      varlevel    observedlevel    expectedseverity    observedseverity    observations    failures    expected    ratio     missing
    ___________    ________    ________    _____________    ________________    ________________    ____________    ________    ________    ______    _______
       "s&p"       "model1"     0.975         0.97101            1.1928              1.4221             1966           57        49.15      1.1597       0   
       "s&p"       "model2"     0.975         0.97202            1.2652              1.4134             1966           55        49.15       1.119       0   
       "s&p"       "model3"     0.975         0.97202              1.37              1.4146             1966           55        49.15       1.119       0   

step 5. run a report for all tests.

run all tests and generate a report only on the accept or reject results.

t = runtests(ebt);
disp(t)
    portfolioid     varid      varlevel    unconditionalnormal    unconditionalt
    ___________    ________    ________    ___________________    ______________
       "s&p"       "model1"     0.975            reject               reject    
       "s&p"       "model2"     0.975            reject               accept    
       "s&p"       "model3"     0.975            accept               accept    

step 6. run the unconditional normal test.

run the individual test for the unconditional normal test.

t = unconditionalnormal(ebt);
disp(t)
    portfolioid     varid      varlevel    unconditionalnormal     pvalue      teststatistic    criticalvalue    observations    testlevel
    ___________    ________    ________    ___________________    _________    _____________    _____________    ____________    _________
       "s&p"       "model1"     0.975            reject           0.0054099      -0.38265          -0.2403           1966          0.95   
       "s&p"       "model2"     0.975            reject            0.044967      -0.25011          -0.2403           1966          0.95   
       "s&p"       "model3"     0.975            accept               0.149      -0.15551          -0.2403           1966          0.95   

step 7. run the unconditional t test.

run the individual test for the unconditional t test.

t = unconditionalt(ebt);
disp(t)
    portfolioid     varid      varlevel    unconditionalt     pvalue     teststatistic    criticalvalue    observations    testlevel
    ___________    ________    ________    ______________    ________    _____________    _____________    ____________    _________
       "s&p"       "model1"     0.975          reject        0.018566      -0.38265         -0.28242           1966          0.95   
       "s&p"       "model2"     0.975          accept        0.073292      -0.25011         -0.28242           1966          0.95   
       "s&p"       "model3"     0.975          accept         0.17932      -0.15551         -0.28242           1966          0.95   

step 8. run es backtests for a particular year.

select a particular calendar year and run the tests for that year only by creating an esbacktest object and passing only the data of interest.

year = 1996;
ind = year(dates)==year;
portid = ['s&p, ' num2str(year)];
portfoliodata = returns(ind);
vardata = [varmodel1(ind) varmodel2(ind) varmodel3(ind)];
esdata = [esmodel1(ind) esmodel2(ind) esmodel3(ind)];
ebt = esbacktest(portfoliodata,vardata,esdata,...
   'portfolioid',portid,'varid',["model1","model2","model3"],'varlevel',varlevel);
disp(ebt)
  esbacktest with properties:
    portfoliodata: [262x1 double]
          vardata: [262x3 double]
           esdata: [262x3 double]
      portfolioid: "s&p, 1996"
            varid: ["model1"    "model2"    "model3"]
         varlevel: [0.9750 0.9750 0.9750]
tt = runtests(ebt);
disp(tt)
    portfolioid     varid      varlevel    unconditionalnormal    unconditionalt
    ___________    ________    ________    ___________________    ______________
    "s&p, 1996"    "model1"     0.975            reject               reject    
    "s&p, 1996"    "model2"     0.975            reject               reject    
    "s&p, 1996"    "model3"     0.975            reject               accept    

see also

| | | |

related examples

more about

    网站地图