Matlab“指数超过矩阵维度。”

时间:2012-11-03 19:17:03

标签: matlab trading

我一直收到这个错误:

  

???指数超过矩阵维度。

     

==>中的错误example3_6 at 48 results = regress(cl1(trainset),   CL2(车组)); %使用回归函数

GDX文件包含7列和386行,GLD文件包含7列和765行,但如果我从两者中取出250个样本,这应该不是问题。

有人可以告诉我这里有什么问题吗?

谢谢

clear; % make sure previously defined variables are erased.

[num, txt]=xlsread('GLD'); % read a spreadsheet named "GLD.xls" into MATLAB. 

tday1=txt(2:end, 1); % the first column (starting from the second row) is the trading days in format mm/dd/yyyy.

tday1=datestr(datenum(tday1,'mm/dd/yyyy'), 'yyyymmdd');

tday1=str2double(cellstr(tday1)); % convert the date strings first into cell arrays and then into numeric format.

adjcls1=num(:, end); % the last column contains the adjusted close prices.

[num, txt]=xlsread('GDX'); % read a spreadsheet named "GDX.xls" into MATLAB. 

tday2=txt(2:end, 1); % the first column (starting from the second row) is the trading days in format mm/dd/yyyy.

tday2=datestr(datenum(tday2,'mm/dd/yyyy'), 'yyyymmdd');

tday2=str2double(cellstr(tday2)); % convert the date strings first into cell arrays and then into numeric format.

adjcls2=num(:, end); % the last column contains the adjusted close prices.

[tday, idx1, idx2]=intersect(tday1, tday2); % find the intersection of the two data sets, and sort them in ascending order

cl1=adjcls1(idx1); 

cl2=adjcls2(idx2);  

trainset=1:252; % define indices for training set

testset=trainset(end)+1:length(tday); % define indices for test set

% determines the hedge ratio on the trainset
results=ols(cl1(trainset), cl2(trainset)); % use regression function 
hedgeRatio=results.beta;

1 个答案:

答案 0 :(得分:0)

您对回归功能的调用似乎有问题。

根据医生退步:

回归(y,X)返回系数估计的p-by-1向量b,用于y中对X的预测变量的响应的多线性回归.X是每个p个预测变量的n-by-p矩阵。 n个观察结果。 y是观察到的响应的n×1矢量。

但是因为我们不知道你在ols函数中如何使用回归函数,所以很难帮助你。只需对发送到regress()的两个参数进行大小(...)检查,我相信你会发现为什么MATLAB会抱怨。