-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathnet_Value_Kal.m
37 lines (25 loc) · 962 Bytes
/
net_Value_Kal.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
function V=net_Value_Kal(ZScore,Y,X,thY,thX)
cost=0.005; %Transaction Cost
T=length(Y);
val=100; %market value of each position
pos=zeros(T,2);
for t=2:T
if (ZScore(t)<thY)&&(pos(t-1,1)<=0)
% position(t,:)=[val/Y(t) , -val/X(t)];
% position(t,:)=[val/Y(t) , -val*abs(beta(1,t))/X(t)];
pos(t,:)=[val/Y(t) , -val/Y(t)*beta(1,t)];
% position(t,:)=[val/Y(t) , 0];
elseif (ZScore(t)>thX)&&(pos(t-1,1)>=0)
% position(t,:)=[-val/Y(t) , val/X(t)];
% position(t,:)=[-val/Y(t) , val*abs(beta(1,t))/X(t)];
pos(t,:)=[-val/Y(t) , val/Y(t)*beta(1,t)];
% position(t,:)=[0 , val/X(t)];
else
pos(t,:)=pos(t-1,:);
end
end
PnL=pos(1:end-1,1).*(Y(2:end)-Y(1:end-1)) + pos(1:end-1,2).*(X(2:end)-X(1:end-1))...
-cost/2*abs(pos(2:end,1)-pos(1:end-1,1)).*Y(2:end)-cost/2*abs(pos(2:end,2)-pos(1:end-1,2)).*X(2:end);
PnL=[0;PnL];
V=sum(PnL);
end