main content

value-凯发k8网页登录

this example shows how to estimate the value-at-risk (var) using three methods and perform a var backtesting analysis. the three methods are:

  1. normal distribution

  2. historical simulation

  3. exponential weighted moving average (ewma)

value-at-risk is a statistical method that quantifies the risk level associated with a portfolio. the var measures the maximum amount of loss over a specified time horizon and at a given confidence level.

backtesting measures the accuracy of the var calculations. using var methods, the loss forecast is calculated and then compared to the actual losses at the end of the next day. the degree of difference between the predicted and actual losses indicates whether the var model is underestimating or overestimating the risk. as such, backtesting looks retrospectively at data and helps to assess the var model.

the three estimation methods used in this example estimate the var at 95% and 99% confidence levels.

load the data and define the test window

load the data. the data used in this example is from a time series of returns on the s&p index from 1993 through 2003.

load varexampledata.mat
returns = tick2ret(sp);
datereturns = dates(2:end);
samplesize = length(returns);

define the estimation window as 250 trading days. the test window starts on the first day in 1996 and runs through the end of the sample.

testwindowstart      = find(year(datereturns)==1996,1);
testwindow           = testwindowstart : samplesize;
estimationwindowsize = 250;

for a var confidence level of 95% and 99%, set the complement of the var level.

pvar = [0.05 0.01];

these values mean that there is at most a 5% and 1% probability, respectively, that the loss incurred will be greater than the maximum threshold (that is, greater than the var).

compute the var using the normal distribution method

for the normal distribution method, assume that the profit and loss of the portfolio is normally distributed. using this assumption, compute the var by multiplying the z-score, at each confidence level by the standard deviation of the returns. because var backtesting looks retrospectively at data, the var "today" is computed based on values of the returns in the last n = 250 days leading to, but not including, "today."

zscore   = norminv(pvar);
normal95 = zeros(length(testwindow),1);
normal99 = zeros(length(testwindow),1);
for t = testwindow
    i = t - testwindowstart   1;
    estimationwindow = t-estimationwindowsize:t-1;
    sigma = std(returns(estimationwindow)); 
    normal95(i) = -zscore(1)*sigma;
    normal99(i) = -zscore(2)*sigma;
end
figure;
plot(datereturns(testwindow),[normal95 normal99])
xlabel('date')
ylabel('var')
legend({'95% confidence level','99% confidence level'},'location','best')
title('var estimation using the normal distribution method')

figure contains an axes object. the axes object with title var estimation using the normal distribution method, xlabel date, ylabel var contains 2 objects of type line. these objects represent 95% confidence level, 99% confidence level.

the normal distribution method is also known as parametric var because its estimation involves computing a parameter for the standard deviation of the returns. the advantage of the normal distribution method is its simplicity. however, the weakness of the normal distribution method is the assumption that returns are normally distributed. another name for the normal distribution method is the variance-covariance approach.

compute the var using the historical simulation method

unlike the normal distribution method, the historical simulation (hs) is a nonparametric method. it does not assume a particular distribution of the asset returns. historical simulation forecasts risk by assuming that past profits and losses can be used as the distribution of profits and losses for the next period of returns. the var "today" is computed as the p th-quantile of the last n returns prior to "today."

historical95 = zeros(length(testwindow),1);
historical99 = zeros(length(testwindow),1);
for t = testwindow
    i = t - testwindowstart   1;
    estimationwindow = t-estimationwindowsize:t-1;
    x = returns(estimationwindow);
    historical95(i) = -quantile(x,pvar(1)); 
    historical99(i) = -quantile(x,pvar(2)); 
end
figure;
plot(datereturns(testwindow),[historical95 historical99])
ylabel('var')
xlabel('date')
legend({'95% confidence level','99% confidence level'},'location','best')
title('var estimation using the historical simulation method')

figure contains an axes object. the axes object with title var estimation using the historical simulation method, xlabel date, ylabel var contains 2 objects of type line. these objects represent 95% confidence level, 99% confidence level.

the preceding figure shows that the historical simulation curve has a piecewise constant profile. the reason for this is that quantiles do not change for several days until extreme events occur. thus, the historical simulation method is slow to react to changes in volatility.

compute the var using the exponential weighted moving average method (ewma)

the first two var methods assume that all past returns carry the same weight. the exponential weighted moving average (ewma) method assigns nonequal weights, particularly exponentially decreasing weights. the most recent returns have higher weights because they influence "today's" return more heavily than returns further in the past. the formula for the ewma variance over an estimation window of size we is:

σˆt2=1ci=1weλi-1yt-i2

where c is a normalizing constant:

c=i=1weλi-1=1-λwe1-λ11-λaswe

for convenience, we assume an infinitely large estimation window to approximate the variance:

σˆt2(1-λ)(yt-12 i=2λi-1yt-i2)=(1-λ)yt-12 λσˆt-12

a value of the decay factor frequently used in practice is 0.94. this is the value used in this example. for more information, see references.

initiate the ewma using a warm-up phase to set up the standard deviation.

lambda = 0.94;
sigma2     = zeros(length(returns),1);
sigma2(1)  = returns(1)^2;
for i = 2 : (testwindowstart-1)
    sigma2(i) = (1-lambda) * returns(i-1)^2   lambda * sigma2(i-1);
end

use the ewma in the test window to estimate the var.

zscore = norminv(pvar);
ewma95 = zeros(length(testwindow),1);
ewma99 = zeros(length(testwindow),1);
for t = testwindow 
    k     = t - testwindowstart   1;
    sigma2(t) = (1-lambda) * returns(t-1)^2   lambda * sigma2(t-1);
    sigma = sqrt(sigma2(t));
    ewma95(k) = -zscore(1)*sigma;
    ewma99(k) = -zscore(2)*sigma;
end
figure;
plot(datereturns(testwindow),[ewma95 ewma99])
ylabel('var')
xlabel('date')
legend({'95% confidence level','99% confidence level'},'location','best')
title('var estimation using the ewma method')

figure contains an axes object. the axes object with title var estimation using the ewma method, xlabel date, ylabel var contains 2 objects of type line. these objects represent 95% confidence level, 99% confidence level.

in the preceding figure, the ewma reacts very quickly to periods of large (or small) returns.

var backtesting

in the first part of this example, var was estimated over the test window with three different methods and at two different var confidence levels. the goal of var backtesting is to evaluate the performance of var models. a var estimate at 95% confidence is violated only about 5% of the time, and var failures do not cluster. clustering of var failures indicates the lack of independence across time because the var models are slow to react to changing market conditions.

a common first step in var backtesting analysis is to plot the returns and the var estimates together. plot all three methods at the 95% confidence level and compare them to the returns.

returnstest = returns(testwindow);
datestest   = datereturns(testwindow);
figure;
plot(datestest,[returnstest -normal95 -historical95 -ewma95])
ylabel('var')
xlabel('date')
legend({'returns','normal','historical','ewma'},'location','best')
title('comparison of returns and var at 95% for different models')

figure contains an axes object. the axes object with title comparison of returns and var at 95% for different models, xlabel date, ylabel var contains 4 objects of type line. these objects represent returns, normal, historical, ewma.

to highlight how the different approaches react differently to changing market conditions, you can zoom in on the time series where there is a large and sudden change in the value of returns. for example, around august 1998:

zoomind   = (datestest >= datetime(1998,8,5)) & (datestest <= datetime(1998,10,31));
vardata   = [-normal95(zoomind) -historical95(zoomind) -ewma95(zoomind)];
varformat = {'-','--','-.'};
d = datestest(zoomind);
r = returnstest(zoomind);
n = normal95(zoomind);
h = historical95(zoomind);
e = ewma95(zoomind);
indn95    = (r < -n);
indhs95   = (r < -h);
indewma95 = (r < -e);
figure;
bar(d,r,0.5,'facecolor',[0.7 0.7 0.7]);
hold on
for i = 1 : size(vardata,2)
    stairs(d-0.5,vardata(:,i),varformat{i});
end
ylabel('var')
xlabel('date')
legend({'returns','normal','historical','ewma'},'location','best','autoupdate','off')
title('95% var violations for different models')
ax = gca;
ax.colororderindex = 1;
plot(d(indn95),-n(indn95),'o',d(indhs95),-h(indhs95),'o',...
   d(indewma95),-e(indewma95),'o','markersize',8,'linewidth',1.5)
xlim([d(1)-1, d(end) 1])
hold off;

figure contains an axes object. the axes object with title 95% var violations for different models, xlabel date, ylabel var contains 7 objects of type bar, stair, line. one or more of the lines displays its values using only markers these objects represent returns, normal, historical, ewma.

a var failure or violation happens when the returns have a negative var. a closer look around august 27 to august 31 shows a significant dip in the returns. on the dates starting from august 27 onward, the ewma follows the trend of the returns closely and more accurately. consequently, ewma has fewer var violations (two (2) violations, yellow diamonds) compared to the normal distribution approach (seven (7) violations, blue stars) or the historical simulation method (eight (8) violations, red squares).

besides visual tools, you can use statistical tests for var backtesting. in risk management toolbox™, a object supports multiple statistical tests for var backtesting analysis. in this example, start by comparing the different test results for the normal distribution approach at the 95% and 99% var levels.

vbt = varbacktest(returnstest,[normal95 normal99],'portfolioid','s&p','varid',...
    {'normal95','normal99'},'varlevel',[0.95 0.99]);
summary(vbt)
ans=2×10 table
    portfolioid      varid       varlevel    observedlevel    observations    failures    expected    ratio     firstfailure    missing
    ___________    __________    ________    _____________    ____________    ________    ________    ______    ____________    _______
       "s&p"       "normal95"      0.95         0.94863           1966          101         98.3      1.0275         7             0   
       "s&p"       "normal99"      0.99         0.98372           1966           32        19.66      1.6277         7             0   

the summary report shows that the observed level is close enough to the defined var level. the 95% and 99% var levels have at most (1-var_level) x n expected failures, where n is the number of observations. the failure ratio shows that the normal95 var level is within range, whereas the normal99 var level is imprecise and under-forecasts the risk. to run all tests supported in , use .

runtests(vbt)
ans=2×11 table
    portfolioid      varid       varlevel      tl       bin       pof       tuff       cc       cci       tbf       tbfi 
    ___________    __________    ________    ______    ______    ______    ______    ______    ______    ______    ______
       "s&p"       "normal95"      0.95      green     accept    accept    accept    accept    reject    reject    reject
       "s&p"       "normal99"      0.99      yellow    reject    reject    accept    reject    accept    reject    reject

the 95% var passes the frequency tests, such as traffic light, binomial and proportion of failures tests (, , and columns). the 99% var does not pass these same tests, as indicated by the yellow and reject results. both confidence levels got rejected in the conditional coverage independence, and time between failures independence ( and columns). this result suggests that the var violations are not independent, and there are probably periods with multiple failures in a short span. also, one failure may make it more likely that other failures will follow in subsequent days. for more information on the tests methodologies and the interpretation of results, see and the individual tests.

using a varbacktest object, run the same tests on the portfolio for the three approaches at both var confidence levels.

vbt = varbacktest(returnstest,[normal95 historical95 ewma95 normal99 historical99 ...
    ewma99],'portfolioid','s&p','varid',{'normal95','historical95','ewma95',...
    'normal99','historical99','ewma99'},'varlevel',[0.95 0.95 0.95 0.99 0.99 0.99]);
runtests(vbt)
ans=6×11 table
    portfolioid        varid         varlevel      tl       bin       pof       tuff       cc       cci       tbf       tbfi 
    ___________    ______________    ________    ______    ______    ______    ______    ______    ______    ______    ______
       "s&p"       "normal95"          0.95      green     accept    accept    accept    accept    reject    reject    reject
       "s&p"       "historical95"      0.95      yellow    accept    accept    accept    accept    accept    reject    reject
       "s&p"       "ewma95"            0.95      green     accept    accept    accept    accept    accept    reject    reject
       "s&p"       "normal99"          0.99      yellow    reject    reject    accept    reject    accept    reject    reject
       "s&p"       "historical99"      0.99      yellow    reject    reject    accept    reject    accept    reject    reject
       "s&p"       "ewma99"            0.99      red       reject    reject    accept    reject    accept    reject    reject

the results are similar to the previous results, and at the 95% level, the frequency results are generally acceptable. however, the frequency results at the 99% level are generally rejections. regarding independence, most tests pass the conditional coverage independence test (), which tests for independence on consecutive days. notice that all tests fail the time between failures independence test (), which takes into account the times between all failures. this result suggests that all methods have issues with the independence assumption.

to better understand how these results change given market conditions, look at the years 2000 and 2002 for the 95% var confidence level.

ind2000 = (year(datestest) == 2000);
vbt2000 = varbacktest(returnstest(ind2000),[normal95(ind2000) historical95(ind2000) ewma95(ind2000)],...
   'portfolioid','s&p, 2000','varid',{'normal','historical','ewma'});
runtests(vbt2000)
ans=3×11 table
    portfolioid       varid        varlevel     tl       bin       pof       tuff       cc       cci       tbf       tbfi 
    ___________    ____________    ________    _____    ______    ______    ______    ______    ______    ______    ______
    "s&p, 2000"    "normal"          0.95      green    accept    accept    accept    accept    accept    accept    accept
    "s&p, 2000"    "historical"      0.95      green    accept    accept    accept    accept    accept    accept    accept
    "s&p, 2000"    "ewma"            0.95      green    accept    accept    accept    accept    accept    accept    accept
ind2002 = (year(datestest) == 2002);
vbt2002 = varbacktest(returnstest(ind2002),[normal95(ind2002) historical95(ind2002) ewma95(ind2002)],...
   'portfolioid','s&p, 2002','varid',{'normal','historical','ewma'});
runtests(vbt2002)
ans=3×11 table
    portfolioid       varid        varlevel      tl       bin       pof       tuff       cc       cci       tbf       tbfi 
    ___________    ____________    ________    ______    ______    ______    ______    ______    ______    ______    ______
    "s&p, 2002"    "normal"          0.95      yellow    reject    reject    accept    reject    reject    reject    reject
    "s&p, 2002"    "historical"      0.95      yellow    reject    accept    accept    reject    reject    reject    reject
    "s&p, 2002"    "ewma"            0.95      green     accept    accept    accept    accept    reject    reject    reject

for the year 2000, all three methods pass all the tests. however, for the year 2002, the test results are mostly rejections for all methods. the ewma method seems to perform better in 2002, yet all methods fail the independence tests.

to get more insight into the independence tests, look into the conditional coverage independence () and the time between failures independence () test details for the year 2002. to access the test details for all tests, run the individual test functions.

cci(vbt2002)
ans=3×13 table
    portfolioid       varid        varlevel     cci      lratiocci    pvaluecci    observations    failures    n00    n10    n01    n11    testlevel
    ___________    ____________    ________    ______    _________    _________    ____________    ________    ___    ___    ___    ___    _________
    "s&p, 2002"    "normal"          0.95      reject     12.591      0.0003877        261            21       225    14     14      7       0.95   
    "s&p, 2002"    "historical"      0.95      reject     6.3051       0.012039        261            20       225    15     15      5       0.95   
    "s&p, 2002"    "ewma"            0.95      reject     4.6253       0.031504        261            14       235    11     11      3       0.95   

in the cci test, the probability p 01 of having a failure at time t, knowing that there was no failure at time t-1 is given by

p01=n01n01 n00

the probability p 11 of having a failure at time t, knowing that there was failure at time t-1 is given by

p11=n11n11 n10

from the n00, n10, n01, n11 columns in the test results, the value of p 01 is at around 5% for the three methods, yet the values of p 11 are above 20%. because there is evidence that a failure is followed by another failure much more frequently than 5% of the time, this cci test fails.

in the time between failures independence test, look at the minimum, maximum, and quartiles of the distribution of times between failures, in the columns tbfmin, tbfq1, tbfq2, tbfq3, tbfmax.

tbfi(vbt2002)
ans=3×14 table
    portfolioid       varid        varlevel     tbfi     lratiotbfi    pvaluetbfi    observations    failures    tbfmin    tbfq1    tbfq2    tbfq3    tbfmax    testlevel
    ___________    ____________    ________    ______    __________    __________    ____________    ________    ______    _____    _____    _____    ______    _________
    "s&p, 2002"    "normal"          0.95      reject      53.936      0.00010087        261            21         1          1        5      17        48        0.95   
    "s&p, 2002"    "historical"      0.95      reject      45.274       0.0010127        261            20         1        1.5      5.5      17        48        0.95   
    "s&p, 2002"    "ewma"            0.95      reject      25.756        0.027796        261            14         1          4      7.5      20        48        0.95   

for a var level of 95%, you expect an average time between failures of 20 days, or one failure every 20 days. however, the median of the time between failures for the year 2002 ranges between 5 and 7.5 for the three methods. this result suggests that half of the time, two consecutive failures occur within 5 to 7 days, much more frequently than the 20 expected days. consequently, more test failures occur. for the normal method, the first quartile is 1, meaning that 25% of the failures occur on consecutive days.

references

nieppola, o. backtesting value-at-risk models. helsinki school of economics. 2009.

danielsson, j. financial risk forecasting: the theory and practice of forecasting market risk, with implementation in r and matlab®. wiley finance, 2012.

see also

| | | | | | | | | |

related examples

    more about

      网站地图