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
답변 (0개)
참고 항목
카테고리
Help Center 및 File Exchange에서 Transaction Cost Analysis에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!