Why is my matlab code to estimate VaR not working
이전 댓글 표시
load VaRExampleData.mat
Returns = tick2ret(sp);
DateReturns = dates(2:end);
SampleSize = length(Returns);
TestWindowStart = find(year(DateReturns)==1996,1);
TestWindow = TestWindowStart : TestWindowStart + SampleSize -1;
EstimationWindowSize = 250;
pVaR = [0.05 0.01];
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')
Why is my matlab code to estimate VaR not working where it says Normal95(i) and Normal 99(i), the graph is blank and the normal 99(i)and Normal 95(i) is only output zeros
%computing VaR using Normal linear without drift at 99 and 95% CI
Returns = tick2ret(Price);
DateReturns = Date(1:end);
SampleSize = length(Returns);
TestWindowStart = find(year(DateReturns)==2013,1);
TestWindow = TestWindowStart : SampleSize;
EstimationWindowSize = 250;
pVaR = [0.05 0.01];
Zscore = norminv(pVaR);
Normal95 = zeros(length(TestWindow),1);
Normal99 = zeros(length(TestWindow),1);
for t = TestWindow(end)
i = t - TestWindowStart + 1;
EstimationWindow = t-EstimationWindowSize:t-1;
Sigma = std(Returns(EstimationWindow));
Mean = mean(Returns(EstimationWindow));
Normal95(i) = -Zscore(1)*Sigma+Mean;
Normal99(i) = -Zscore(2)*Sigma+Mean;
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')
답변 (1개)
Walter Roberson
2023년 7월 3일
0 개 추천
TestWindow = TestWindowStart : TestWindowStart+ SampleSize-1;
댓글 수: 3
Shagoofa
2023년 7월 4일
Rik
2023년 7월 4일
We can see that. Your current code returns the error "Unrecognized function or variable 'Price'."
Try to make a MWE so we can run your code without any other dependencies and can reproduce your issue. The best way to do this is to use the code section in the editor and use the run button. That way you can make sure we will see the same error message as you do.
카테고리
도움말 센터 및 File Exchange에서 Shifting and Sorting Matrices에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!