Pairs Trading Any Position Loop Problem

1 次查看(过去 30 天)
I am modifying perlin's pairs trading code.
I am having a problem with the anyPos part of the for loop. i do not know if anyPos1 and anyPos 2 line I have added is correct. I have % excluded in code below. When I run the code at the moment it is composing a 1's matrix.
I need a -1 and 1 matrix for individual buy (long) 1 and sell (short) -1 positions as defined in the
directionTrade(k,assetsNumber) =[-1 1];
and
directionTrade(k,assetsNumber)=[1 -1];
Because there are two possible options to take to form anyPos I don't know how to combine the final matrix to compose -1 and 1's based on the below code. I have been trying for days and no end result. Please if anyone can provide an answer or guidance I would be very grateful.
for i=1:length(idx)
if (k==1)||(anyPos(k-1,idx(i))==0)% if any position is already open, dont trade
myTrades{idxTrades,1}.assetsNumber=[idx(i) p(idx(i))];
myTrades{idxTrades,1}.obsNumber=d+k-1;
total_idx(idxTrades,:)=[idx(i) p(idx(i))];
if (dist(k,idx(i))>0)
myTrades{idxTrades,1}.directionTrade=[-1 1];
assetsNumber=[idx(i) p(idx(i))];
directionTrade(k,assetsNumber) =[-1 1];
% anyPos1(k,:)= directionTrade(k,:);
else
myTrades{idxTrades,1}.directionTrade=[ 1 -1];
assetsNumber=[idx(i) p(idx(i))];
directionTrade(k,assetsNumber)=[1 -1];
% anyPos2(k,:)= directionTrade(k,:);
end
idxTrades=idxTrades+1;
end
anyPos(k,idx(i))=1;
anyPos(k,p(idx(i)))=1;
end
  1 个评论
Jan
Jan 2012-7-21
I've deleted the duplicate post. Something at your fixing of the typos went wrong.

请先登录,再进行评论。

回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Transaction Cost Analysis 的更多信息

标签

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by