我试着提前预测几步。我 在volrv (index2,index1)=sum(rv1m(index2-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(index2,index1)=sum(rv1m(index2-index1+1:index2,1)) 中的错误;
谢谢