value at risk estimation and backtesting

2 views (last 30 days)
Hi, Please i really need your help as soon as possible. I'm trying to plot the Value at risk estimation for EUR/USD exchange rate using the normal method and following the exemple in this link : https://fr.mathworks.com/examples/risk-management/mw/risk-ex19733037-value-at-risk-estimation-and-backtesting?s_tid=srchtitle
here is my script :
% code
open 'EUR-USD.xlsx'
Returns = tick2ret(EURUSD);
DateReturns = Date(1:end);
SampleSize = length(Returns);
TestWindowStart = find(year(DateReturns)==2013,1);
TestWindow = TestWindowStart : SampleSize;
EstimationWindowSize = 1304;
pVaR = [0.05 0.01];
Zscore = norminv(pVaR);
Normal95 = zeros(length(TestWindow),1);
Normal99 = zeros(length(TestWindow),1);
P=input('Capital invested:')
P=100
for t = TestWindow
i = t - TestWindowStart + 1;
EstimationWindow = t-EstimationWindowSize:t-1;
Sigma = std(Returns(EstimationWindow*1));
Mu=mean(Returns(EstimationWindow));
Normal95(i) =P*(Mu-Zscore(1)*Sigma);
Normal99(i) =P*(Mu-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')
The problem is each time and after many tries i always get the same error : Subscript indices must either be real positive integers or logicals.
I'm joining screenshots of my workspace and some variables. I'm really stuck, i can't move forward. Please HELP.
Thank you.

Answers (1)

Lorena Díaz Muñoz
Lorena Díaz Muñoz on 25 Aug 2018
Check your the "TestWindowStart" and the "EstimationWindowSize", I don't know exactly, but the TestWindowStart must be greater than the EstimationWindowSize. Both give you a number output. The first one gives you the position where it start the Test Window, so, as I can see, your Estimation Window Size is 1304, so the Test Window Start should be 1500 or something greater than 1304. As I said before, I don't know exactly why it has to be like that but that was what it works for me. I hope it works for you too.
  1 Comment
Lorena Díaz Muñoz
Lorena Díaz Muñoz on 25 Aug 2018
As I can see in the image attached by you, you are trying to start your Test Window since the begining of your sample, and that gives you "1" as output for that variable because is the first input in your data, and as the EstimationWindowSize is 1304, when matlab does the calculation for EstimationWindow it starts from: "1-1304,2-1305, ... etc."

Sign in to comment.

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!