value at risk estimation and backtesting

조회 수: 27 (최근 30일)
slaoui kawtar
slaoui kawtar 2018년 6월 19일
댓글: Lorena Díaz Muñoz 2018년 8월 25일
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.

답변 (1개)

Lorena Díaz Muñoz
Lorena Díaz Muñoz 2018년 8월 25일
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
Lorena Díaz Muñoz
Lorena Díaz Muñoz 2018년 8월 25일
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."

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 2-D and 3-D Plots에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by