我试着提前几步预测。我遇到了问题 指数超出矩阵维度 at volrv(索引2,索引1)=总和(rv1m(索引2-index1之间+ 1:index2,1)); 虽然我已检查矩阵大小是否正常。我不明白为什么。请帮助
load sp100_88_03_for.txt;
[y]=sp100_88_03_for;
T=3585; % In-Sample: 1/1/1988-9/28/2001
N = size(y,1);
dataf = 100*(log(y(2:N))-log(y(1:N-1))); % data to be forecast
N = N - 1; % You loose 1 obs'n in taking the lag
clear y;
%ERRORS
datafm = mean(dataf); %mean of all the sample for the forecast error
errors = dataf - datafm; % errors
errors2 = (dataf(T:N)-datafm).^2; % vector with squared errors
% Loading Realized Volatilities
load real_vol_adj.txt
RV_adj = real_vol_adj;
rv1m = RV_adj(:,1);
rv5m = RV_adj(:,2);
clear real_vol*;
clear RV_adj*;
% Calculating the proxy for the volatility process
volr2 = []; % volatilities from sum of squared daily returns
volrv = []; % volatilities from sum of daily realized volatilities
volrd = []; % volatilities from d-day period returns (d=1,2,...,22)
rsquared=(dataf(T:N)-mean(dataf(T:N))).^2;
volr2(:,1)=rsquared;
volrv(:,1)=rv1m;
for index1=2:22;
volr2(1:index1-1,index1) = 0;
volrv(1:index1-1,index1) = 0;
for index2=index1:N-T+1
volr2(index2,index1)=sum(rsquared(index2-index1+1:index2,1));
volrv(index2,index1)=sum(rv1m(index2-index1+1:index2,1));
end
end
==>中的错误 volrv(索引2,索引1)=总和(rv1m(索引2-index1之间+ 1:index2,1));
由于
答案 0 :(得分:0)
对我而言,您的代码符合30
行
所以,我在该行中设置breakpoint
并执行了
size(rsquared)
ans =
1 3585
但是,您尝试访问rsquared(1:2,1)
,在这种情况下会提供
Index exceeds matrix dimensions.
错误消息。
一个快速解决办法可能是:
volr2(index2,index1)=sum(rsquared(1,index2-index1+1:index2));
但这取决于您的具体问题 在修复之后,代码对我没有错误。