-1

我试着提前预测几步。我 在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)) 中的错误;

谢谢

4

1 回答 1

0

对我来说,您的代码在 line 中中断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));

但这取决于您的具体问题。
修复后,代码对我来说没有错误。

于 2013-06-05T00:52:27.303 回答