Arrary indices must be positive integers or logical values

4 views (last 30 days)
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
Array indices must be positive integers or logical values.

Answers (1)

Cris LaPierre
Cris LaPierre on 13 Mar 2021
One of your indices is <= 0. You haven't shared enough information for us to say exactly what the problem is.
See Ch 5 of MATLAB Onrmap to learn how to properly index an array.
  13 Comments
Thukten Tashi
Thukten Tashi on 16 Mar 2021
Thank you so much for your help. I managed to calculate somehow.
Thukten Tashi
Thukten Tashi on 3 Apr 2021
I have calculated VaR using exponential weight moving average. The figure for first failire under EWMA at 95% confidence level appears as '1'. I thougth that this value should be 77 instead. I am not sure which one is correct. I have used the following steps.
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
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

Sign in to comment.

Categories

Find more on Operators and Elementary Operations in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!