Arrary indices must be positive integers or logical values

4 Ansichten (letzte 30 Tage)
Thukten Tashi
Thukten Tashi am 13 Mär. 2021
Kommentiert: Thukten Tashi am 3 Apr. 2021
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.

Antworten (1)

Cris LaPierre
Cris LaPierre am 13 Mär. 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 Kommentare
Thukten Tashi
Thukten Tashi am 16 Mär. 2021
Thank you so much for your help. I managed to calculate somehow.
Thukten Tashi
Thukten Tashi am 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

Melden Sie sich an, um zu kommentieren.

Kategorien

Mehr zu Operators and Elementary Operations finden Sie in Help Center und File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by