Arrary indices must be positive integers or logical values

4 ビュー (過去 30 日間)
Thukten Tashi
Thukten Tashi 2021 年 3 月 13 日
コメント済み: Thukten Tashi 2021 年 4 月 3 日
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.

回答 (1 件)

Cris LaPierre
Cris LaPierre 2021 年 3 月 13 日
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 件のコメント
Thukten Tashi
Thukten Tashi 2021 年 3 月 16 日
Thank you so much for your help. I managed to calculate somehow.
Thukten Tashi
Thukten Tashi 2021 年 4 月 3 日
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

サインインしてコメントする。

カテゴリ

Help Center および File ExchangeOperators and Elementary Operations についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by