Main Content

Workflow for Expected Shortfall (ES) Backtesting by Du and Escanciano

此示例显示了使用DU-ESCANCIANO(DE)预期缺口(ES)回测的工作流程,并为具有多个VAR级别的单个DE模型演示了一个固定的测试窗口。

Load Data

数据中的数据ESBacktestDistributionData.mat文件具有三种模型的返回,VAR和ES数据以及分布信息:正常和twith 5 degrees of freedom andtwith 10 degrees of freedom. The data spans multiple years from January 1996 to July 2003 and includes a total of 1966 observations.

This example uses atdistribution with 10 degrees of freedom and focuses on one year of data to show the difference between the critical value methods for large-sample approximation and simulation supported by theEsbacktestbyde班级。

loadESBacktestDistributionData.matTargetYear = 1998;变化百分比来测试其他calendar yearsInd = year(Dates)==TargetYear; Dates = Dates(Ind); Returns = Returns(Ind); VaR = T10VaR(Ind,:); ES = T10ES(Ind,:); Mu = 0;% Always 0 in this data setSigma = T10Scale(Ind);

Plot Data

绘制数据的var级别0.975.

% Plot datatargetVarlevel = 0.975;varind = varlevel == targetVarlevel;failind =返回<-Var(:,varind);酒吧(日期,退货)举行onplot(Dates,-VaR(:,VaRInd),Dates,-ES(:,VaRInd)) plot(Dates(FailureInd),Returns(FailureInd),'.') holdoff传奇('Returns','VaR','ES','Location','最好的') title(['Test Data, VaR Level 'num2str(targetVarlevel*100)'%']) ylabel('Returns') gridon

Figure contains an axes object. The axes object with title Test Data, VaR Level 97.5% contains 4 objects of type bar, line. These objects represent Returns, VaR, ES.

创建一个EsbacktestbydeObject

创建一个Esbacktestbyde对象运行DE测试。请注意,不需要VAR和ES数据输入,因为DE测试在“映射返回”或“排名”上工作并通过使用分布信息执行映射。但是,为了方便起见,Esbacktestbydeobject computes the VaR and ES data internally using the distribution information and stores the data in theVaRDataand埃斯达塔properties of theEsbacktestbyde目的。VAR和ES数据仅用于估计由概括function and are not used for any of the DE tests.

默认情况下,创建一个Esbacktestbydeobject, a simulation runs and large-sample and simulation-based critical values are available immediately. Although the simulation processing is efficient, if you verify that large-sample approximation is appropriate for the sample size and VaR level under consideration, you can turn the simulation off to increase processing speed. To turn off the simulation, when usingEsbacktestbyde创建一个esbacktestbtde对象,设置名称值对参数'模拟'false.

rng('default');% For reproducibilitytic;ebtde = esbacktestbyde(返回,"t",...'DegreesOfFreedom',10,...'Location',Mu,...'Scale',Sigma,...'VaRLevel',VaRLevel,...'PortfolioID',"S&P",...'varid',"t(10)");至c;
Elapsed time is 0.224998 seconds.
disp(ebtde)
带有属性的esbacktestbyde:portfoliodata:[261x1 double] vardata:[261x3 double] esdata:[261x3 double]分布:[1x1 struct] portfolioid:“ s&p p”(10)“] VARLEVEL:[0.9500 0.9750 0.9900]
disp(ebtde.Distribution)
名称:“ t” DemeSoffreedom:10位置:0比例:[261x1 double]

Summary Statistics

Use概括至return a basic expected shortfall (ES) report on failures and severity. This is the same概括输出作为其他ES回测类esbacktestandesbacktestbysim. When theEsbacktestbyde创建对象,使用分布信息计算VAR和ES数据。此信息存储在VaRDataand埃斯达塔properties. The概括function uses theVaRDataand埃斯达塔properties to compute the observed severity ratio.

disp(摘要(EBTDE))
PortfolioID VaRID VaRLevel ObservedLevel ExpectedSeverity ObservedSeverity Observations Failures Expected Ratio Missing ___________ _______ ________ _____________ ________________ ________________ ____________ ________ ________ ______ _______ "S&P" "t(10)" 0.95 0.94253 1.3288 1.5295 261 15 13.05 1.1494 0 "S&P" "t(10)" 0.9750.96935 1.2652 1.5269 261 8 6.525 1.2261 0“ s&p”“ t(10)” 0.99 0.98467 1.2169 1.5786 1.5786 261 4 2.61 1.5326 0

Run Tests

Useruntests至run all expected shortfall (ES) backtests forEsbacktestbyde目的。The default critical value method is'large-sample'or asymptotic approximation.

disp(runtests(ebtde))
投资组合varid varlevel varlevelaldealde无条件___________ _______ ____________________________________________________________________________________________

Run the tests with'simulation'或有限样本临界值。

disp(runtests(ebtde,'CriticalValueMethod','simulation'))
投资组合varid varlevel varlevelaldealde无条件___________ _______ ____________________________________________________________________________________________

Theruntestsfunction accepts the name-value pair argument'ShowDetails'which includes extra columns in the output. Specifically, this output includes the critical value method used, number of lags, and test confidence level.

disp(runtests(ebtde,'CriticalValueMethod','simulation','ShowDetails',真的))
PortfolioID VaRID VaRLevel ConditionalDE UnconditionalDE CriticalValueMethod NumLags TestLevel ___________ _______ ________ _____________ _______________ ___________________ _______ _________ "S&P" "t(10)" 0.95 accept accept "simulation" 1 0.95 "S&P" "t(10)" 0.975 accept accept "simulation" 1 0.95 "S&P" "t(10)" 0.99 accept accept "simulation" 1 0.95

Unconditional DE Test Details

The unconditional DE test assesses the severity of the violations based on an evaluation of the observed average tail loss and determines whether the severity is consistent with the model assumptions. All the tests supported in the related classesesbacktestandesbacktestbysimare also severity tests.

To view the unconditional DE test details, use theunconditionalDE功能。默认情况下,此功能使用'large-sample'critical value method.

disp(unconditionalDE(ebtde))
PortfolioID VaRID VaRLevel UnconditionalDE PValue TestStatistic LowerCI UpperCI Observations CriticalValueMethod MeanLS StdLS Scenarios TestLevel ___________ _______ ________ _______________ ________ _____________ _________ ________ ____________ ___________________ ______ _________ _________ _________ "S&P" "t(10)" 0.95 accept 0.31715 0.032842 0.0096343 0.040366 261 "large-sample" 0.0250.0078398 NaN 0.95 "S&P" "t(10)" 0.975 accept 0.32497 0.018009 0.0015295 0.023471 261 "large-sample" 0.0125 0.0055973 NaN 0.95 "S&P" "t(10)" 0.99 accept 0.076391 0.011309 0 0.011978 261 "large-sample" 0.0050.0035603 NAN 0.95

比较结果'large-sample'至simulation-based critical values, use the name-value pair argument'CriticalValueMethod'. In this example, the results of both critical value methods, including the confidence interval and thep-values, look similar.

disp(无条件'CriticalValueMethod','simulation'))
PortfolioID VaRID VaRLevel UnconditionalDE PValue TestStatistic LowerCI UpperCI Observations CriticalValueMethod MeanLS StdLS Scenarios TestLevel ___________ _______ ________ _______________ ______ _____________ _________ ________ ____________ ___________________ ______ _____ _________ _________ "S&P" "t(10)" 0.95 accept 0.326 0.032842 0.010859 0.041709 261 "simulation" NaN NaN 1000 0.95 "S&P" "t(10)" 0.975 accept 0.336 0.018009 0.0032446 0.024657 261 "simulation" NaN NaN 1000 0.95 "S&P" "t(10)" 0.99 accept 0.126 0.011309 0 0.013311 261 "simulation" NaN NaN 1000 0.95

您可以可视化'simulation'and'large-sample'distributions to assess whether the'large-sample'approximation is accurate enough for the sample size and VaR level under consideration. TheunconditionalDE函数返回'simulated'测试统计作为可选输出。

In this example, higher VaR levels cause a noticeable mismatch between the'large-sample'and'simulation'distributions. However, the confidence intervals andp-values are comparable.

% Choose VaR leveltargetVarlevel = 0.975;varind = varlevel == targetVarlevel;[~,s] = unconditionalDE(ebtde,'CriticalValueMethod','simulation');直方图(s(varind,:),,'正常化',“ PDF”) holdont = unconditionalDE(ebtde,'CriticalValueMethod','large-sample');Mu = t.MeanLS(VaRInd); Sigma = t.StdLS(VaRInd); MinValPlot = min(s(VaRInd,:))-0.001; MaxValPlot = max(s(VaRInd,:))+0.001; xLS = linspace(MinValPlot,MaxValPlot,101); pdfLS = normpdf(xLS,Mu,Sigma); plot(xLS,pdfLS) holdoff传奇({'Simulation','Large-Sample'}) Title = sprintf('UnconditionalDE Test Distribution\nVaR Level: %g%%, Sample Size = %d',VaRLevel(VaRInd)*100,t.Observations(VaRInd)); title(Title)

Figure contains an axes object. The axes object with title UnconditionalDE Test Distribution VaR Level: 97.5%, Sample Size = 261 contains 2 objects of type histogram, line. These objects represent Simulation, Large-Sample.

DE测试条件Details

The conditional DE test assesses whether there is evidence of autocorrelation in the tail losses.

Although the names are similar, the conditional DE test and the conditional test supported inesbacktestbysimare qualitatively different tests. The conditional Acerbi-Szekely test supported inesbacktestbysim测试的严重性,wheth条件er the model passes a VaR test. The Acerbi-Szekely conditional test is a severity test, comparable to the tests supported inesbacktest,esbacktestbysim,和unconditionalDEtest.

但是,有条件的DE测试Esbacktestbydeis a test for independence across time periods.

To see the details of the conditional DE test results, use theconditionalDE功能。默认情况下,此功能使用'large-sample'critical value method and tests for one lag (correlation with the previous time period).

disp(prentyalde(ebtde))
PortfolioID VaRID VaRLevel ConditionalDE PValue TestStatistic CriticalValue AutoCorrelation Observations CriticalValueMethod NumLags Scenarios TestLevel ___________ _______ ________ _____________ _______ _____________ _____________ _______________ ____________ ___________________ _______ _________ _________ "S&P" "t(10)" 0.95 accept 0.45361 0.5616 3.8415 0.046387 261 "large-sample" 1 NaN 0.95 "S&P" "t(10)" 0.975 accept 0.54189 0.37205 3.8415 0.037755 261 "large-sample" 1 NaN 0.95 "S&P" "t(10)" 0.99 accept 0.87949 0.022989 3.8415 -0.0093851 261 "large-sample" 1 NaN 0.95

The results of the'large-sample'critical value method, particularly the simulation critical values andp- 值与'的结果有很大不同simulation'critical value method.

The critical value is similar for a 95% VaR level, but the simulation-based critical value is much larger for higher VaR levels, especially for a 99% VaR. The autocorrelation is1对于任何没有VAR失败的样本。因此,测试统计量等于任何情况没有var失败的任何场景的观察次数。对于99%的VAR级别,没有VAR失败的场景如下;因此,在测试统计量的模拟分布中,观测值的数量有一个质量点。

disp (conditionalDE (ebtde,'CriticalValueMethod','simulation'))
PortfolioID VaRID VaRLevel ConditionalDE PValue TestStatistic CriticalValue AutoCorrelation Observations CriticalValueMethod NumLags Scenarios TestLevel ___________ _______ ________ _____________ ______ _____________ _____________ _______________ ____________ ___________________ _______ _________ _________ "S&P" "t(10)" 0.95 accept 0.257 0.5616 3.6876 0.046387 261 "simulation" 1 1000 0.95 "S&P" "t(10)" 0.975 accept 0.141 0.37205 5.3504 0.037755 261 "simulation" 1 1000 0.95 "S&P" "t(10)" 0.99 accept 0.502 0.022989 261 -0.0093851 261 "simulation" 1 1000 0.95

您可以在视觉上比较'large-sample'and'simulation'distributions. TheconditionalDEfunction also returns the simulated test statistics as an optional output.

Notice that the tail of the distribution gets heavier as the VaR level increases.

% Choose VaR leveltargetVarlevel = 0.975;varind = varlevel == targetVarlevel;[t,s] = conditionalDE(ebtde,'CriticalValueMethod','simulation');XLS = 0:0.01:20;pdfls = chi2pdf(xls,t.numlags(1));直方图(s(varind,:),,'正常化',“ PDF”) holdonplot(xLS,pdfLS) holdoffylim([0 0.01]) legend({'Simulation','Large-Sample'}) Title = sprintf('ConditionalDE Test Distribution\nVaR Level: %g%%, Sample Size = %d',VaRLevel(VaRInd)*100,t.Observations(VaRInd)); title(Title)

Figure contains an axes object. The axes object with title ConditionalDE Test Distribution VaR Level: 97.5%, Sample Size = 261 contains 2 objects of type histogram, line. These objects represent Simulation, Large-Sample.

由于条件DE测试是基于自相关的,因此您可以对不同数量的滞后进行测试。

Run the conditional DE test for2lags. At a VaR level of 99%, the'large-sample'critical value method rejects the model but the'simulation'critical value method does not reject the model, with ap-value close to 10%. This shows that the'simulation'分布和'large-sample'approximation can lead to different results, depending on the sample size and VaR level.

disp (conditionalDE (ebtde,'NumLags',2,'CriticalValueMethod','large-sample'))
PortfolioID VaRID VaRLevel ConditionalDE PValue TestStatistic CriticalValue AutoCorrelation Observations CriticalValueMethod NumLags Scenarios TestLevel ___________ _______ ________ _____________ __________ _____________ _____________ _______________ ____________ ___________________ _______ _________ _________ "S&P" "t(10)" 0.95 reject 0.015812 8.294 5.9915 0.17212 261 "large-sample" 2 NaN 0.95 "S&P" "t(10)" 0.975 reject 0.00045758 15.379 5.9915 0.23979 261 "large-sample" 2 NaN 0.95 "S&P" "t(10)" 0.99 reject 2.5771e-07 30.343 5.9915 0.34083 261 "large-sample" 2 NaN 0.95
disp (conditionalDE (ebtde,'NumLags',2,'CriticalValueMethod','simulation'))
PortfolioID VaRID VaRLevel ConditionalDE PValue TestStatistic CriticalValue AutoCorrelation Observations CriticalValueMethod NumLags Scenarios TestLevel ___________ _______ ________ _____________ ______ _____________ _____________ _______________ ____________ ___________________ _______ _________ _________ "S&P" "t(10)" 0.95 reject 0.03 8.294 6.1397 0.17212 261 "simulation" 2 1000 0.95 "S&P" "t(10)" 0.975 reject 0.019 15.379 9.3364 0.23979 261 "simulation" 2 1000 0.95 "S&P" "t(10)" 0.99 accept 0.098 30.343 522 0.34083 261 "simulation" 2 1000 0.95

Running a New Simulation with模拟

If ap-value is near a rejection boundary, you can run a new simulation to request more scenarios to reduce a simulation error.

You can also run a new simulation to request a higher number of lags. By default, creating anEsbacktestbydeobject causes the simulation to run so that the simulation test results are available immediately. However, to avoid extra storage, only5lags are simulated. If you request more than5lags with the模拟功能,conditionalDEtest function displays the following message:

No simulation results available for the number of lags requested. Call 'simulate' with the desired number of lags.

You first need to run a new simulation usingEsbacktestbydeand specify the number of lags to use for that simulation. Displaying the size of theEsbacktestbyde新模拟之前和之后的对象说明了如何使用更多滞后模拟增加存储在该中的数据量Esbacktestbydeobject, as more simulated test statistics are stored with more lags.

% See bytes before new simulation, 5 lags storedwhosebtde
Name Size Bytes Class Attributes ebtde 1x1 164883 esbacktestbyde
%模拟6个滞后rng('default');% for reproducibilityebtde = simulate(ebtde,'NumLags',6);% See bytes after new simulation, 6 lags storedwhosebtde
名称大小字节类属性ebtde 1x1 188891 esbacktestbyde

在运行新的模拟之后Esbacktestbydethat increases the number of lags to6, the test results forconditionalDEare available for the'simulation'method using6lags.

disp (conditionalDE (ebtde,'NumLags',6,'CriticalValueMethod','simulation'))
PortfolioID VaRID VaRLevel ConditionalDE PValue TestStatistic CriticalValue AutoCorrelation Observations CriticalValueMethod NumLags Scenarios TestLevel ___________ _______ ________ _____________ ______ _____________ _____________ _______________ ____________ ___________________ _______ _________ _________ "S&P" "t(10)" 0.95 accept 0.136 9.5173 16.412 -0.022881 261 "simulation" 6 1000 0.95 "S&P" "t(10)" 0.975 accept 0.086 15.854 21.299 -0.021864 261 "simulation" 6 1000 0.95 "S&P" "t(10)" 0.99 accept 0.128 30.438 1566 -0.0096211 261 "simulation" 6 1000 0.95

Alternatively, theconditionalDEtest results are always available for the'large-sample'method for any number of lags.

disp (conditionalDE (ebtde,'NumLags',10,'CriticalValueMethod','large-sample'))
PortfolioID VaRID VaRLevel ConditionalDE PValue TestStatistic CriticalValue AutoCorrelation Observations CriticalValueMethod NumLags Scenarios TestLevel ___________ _______ ________ _____________ __________ _____________ _____________ _______________ ____________ ___________________ _______ _________ _________ "S&P" "t(10)" 0.95 reject 0.018711 21.361 18.307 0.15415 261 "large-sample" 10 NaN 0.95 "S&P" "t(10)" 0.975 accept 0.088587 16.406 18.307 0.027955 261 "large-sample" 10 NaN 0.95 "S&P" "t(10)" 0.99 reject 0.00070234 30.526 18.307 -0.0092432 261 "large-sample" 10 NaN 0.95

See Also

|||

Related Topics