Pairs Trading Any Position Loop Problem
1 view (last 30 days)
Show older comments
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 Comment
Jan
on 21 Jul 2012
I've deleted the duplicate post. Something at your fixing of the typos went wrong.
Answers (0)
See Also
Categories
Find more on Transaction Cost Analysis in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!