Quantitate Finance - Var Backtesting
Autor: aluzhang • September 17, 2018 • Essay • 2,385 Words (10 Pages) • 662 Views
FM320 Homework Assignment 2
Zhang Lu 201653084
Hand in assignment 2: VaR Backtesting
- Pick one stock for analysis: Disney
Use command lines as follows
% BACKTESTING
clear
clc
%1 Select one stock for analysis
price = hist_stock_data('01012000','30082016','dis');
p=price(1).AdjClose(end:-1:1);
r=diff(log(p));
We first download the stock price information of Disney from finance.yahoo.com and change the order of it in order to make the oldest closing price the first one in the vector. Then we denote r as the continuously compounded returns of closing price.
- Backtest VaR with HS, MA and EWMA.
There are a lot of VaR forecasting methods and backtest can give us information about which one is better by assessing the accuracy of VaR forecasts from history data. By backtesting (and with formal test) we can identify the weakness of risk-forecasting models and providing ideas for improvement, but we need knowledge from previous lectures to gain more insight into the causes of weakness observed.
Use command lines as follows
%Set up
T=length(r);
WE=500;
WT=T-WE;
p=0.01; % 1%VaR
CV=chi2inv((1-p),1);
value=1;
VaR=NaN(T,4); % a matrix to store VaR forecast for EWMA, MA and HS
l1=WE*p;
lambda=0.94;
s11=var(r(1:30)); % for EWMA, we need to set initial variance of day 1, here we use first 30 days to generate the initial variance
for t=2:WE
s11=lambda*s11+(1-lambda)*r(t-1)^2; % update the variance to the last day of WE
end
%backtest VaR with EWMA, MA and HS
for t=WE+1:T
t1=t-WE;
t2=t-1;
window=r(t1:t2);
%MA
s11=lambda*s11+(1-lambda)*r(t-1)^2;
VaR(t,1) = -norminv(p)*sqrt(s11)*value;
%MA
VaR(t,2) = -std(window)* norminv(p)* value;
%HS
ys=sort(window);
VaR(t,3)=-ys(l1)*value;
end
%plot the results
plot(-VaR)
hold on
plot(r)
xlabel('Days')
title('Disney');
[pic 1]
Green line is the continuously compounded returns of Disney’s closing price. Blue line is the EWMA’s backtesting result from day 501-4191. Orange line (which is always above the yellow line) is MA’s backtesting result. Yellow line with sharp changes is the backtesting result of HS.
...