我尝试预测未来几步。并且我遇到了 的问题索引超过了矩阵维度在 volrv(index2,index1)= sum(rv1m(index2-index1 + 1:index2,1)); 虽然我已检查矩阵大小是好的。我不明白为什么。 HELP请指标超出矩阵尺寸
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));
感谢
如何添加一些调试输出?在违规行之前,打印'index2-index1 + 1:index2'和'size(rsquared)'的值。这应该立即告诉你它在哪里出界,并且可以追溯到找出原因。 – jazzbassrob
我试过了。但我认为没有错误。感谢您的建议 – user2451341
您的陈述与错误明显矛盾。在出错前使用'dbstop if error'或提供大小细节。 – Oleg