- Joined
- 7/16/13
- Messages
- 1
- Points
- 11
Hello every,
First, As a non-nativ english speaker, I would like to apologize for my english.
I'm currently working on a trading algorithm in University and I need to build an optimal portfolio rebalancing strategy on MATLAB.
I wanted to try the ANTICOR Algorithm (ref: http://arxiv.org/pdf/1107.0036.pdf).
However I'm having some troubles to compute transfers value (or maybe elsewhere ?)
The main symptom is that the new portfolio composition doesn't sum to 1....
Here's a draft from my code :
function [ Porttrans ] = ANTICOR( window,t,price,Port)
%Port : Initial portfolio from a mean-variance optimization
%Price : log-growth rate of stocks
%Porttrans is meant to be the new weights
if t<2*window
Porttrans=Port;
else
l1=price(t-2*window+1:t-window,;
l2=price(t-window+1:t,;
w1=size(l1,1);
w2=size(l2,2);
moy1=mean(l1);
moy2=mean(l2)
sig1=std(l1);
sig2=std(l2);
Mcov=(l1-repmat(moy1,w1,1))'*(l2-repmat(moy2,w2,1));%cross correlation
Mcov=(1/(window-1))*Mcov;%standardize
Mcor=zeros(p,p);
for j=1:p
for i=1:p
if sig1(1,i)&&sig2(1,j)~=0
Mcor(i,j)=Mcov(i,j)/(sig1(1,i)*sig2(1,j));
else
Mcor(i,j)=0;
end
end
end
claim=zeros(p,p);
for j=1:p
for i=1:p
if moy2(1,i)>=moy2(1,j)&&Mcor(i,j)>0
claim(i,j)=Mcor(i,j)+max(0,-Mcor(i,i))+max(0,-Mcor(j,j));
else
claim(i,j)=0;
end
end
end
for i=1:p
for j=1:p
if claim(i,j)~=0
trans(i,j)=Port(1,i)*(claim(i,j)/sum(claim(i,));
else
trans(i,j)=0;
end
end
end
%I think here is the problem, I know this formula is not the right one, but the others I tried give even more unrealistic results
for i=1:p
for j=1:p
Porttrans(1,i)=Port(1,i)+sum(trans(i,j))-sum(trans(j,i));
end
end
end
end
Best regards,
First, As a non-nativ english speaker, I would like to apologize for my english.
I'm currently working on a trading algorithm in University and I need to build an optimal portfolio rebalancing strategy on MATLAB.
I wanted to try the ANTICOR Algorithm (ref: http://arxiv.org/pdf/1107.0036.pdf).
However I'm having some troubles to compute transfers value (or maybe elsewhere ?)
The main symptom is that the new portfolio composition doesn't sum to 1....
Here's a draft from my code :
function [ Porttrans ] = ANTICOR( window,t,price,Port)
%Port : Initial portfolio from a mean-variance optimization
%Price : log-growth rate of stocks
%Porttrans is meant to be the new weights
if t<2*window
Porttrans=Port;
else
l1=price(t-2*window+1:t-window,;
l2=price(t-window+1:t,;
w1=size(l1,1);
w2=size(l2,2);
moy1=mean(l1);
moy2=mean(l2)
sig1=std(l1);
sig2=std(l2);
Mcov=(l1-repmat(moy1,w1,1))'*(l2-repmat(moy2,w2,1));%cross correlation
Mcov=(1/(window-1))*Mcov;%standardize
Mcor=zeros(p,p);
for j=1:p
for i=1:p
if sig1(1,i)&&sig2(1,j)~=0
Mcor(i,j)=Mcov(i,j)/(sig1(1,i)*sig2(1,j));
else
Mcor(i,j)=0;
end
end
end
claim=zeros(p,p);
for j=1:p
for i=1:p
if moy2(1,i)>=moy2(1,j)&&Mcor(i,j)>0
claim(i,j)=Mcor(i,j)+max(0,-Mcor(i,i))+max(0,-Mcor(j,j));
else
claim(i,j)=0;
end
end
end
for i=1:p
for j=1:p
if claim(i,j)~=0
trans(i,j)=Port(1,i)*(claim(i,j)/sum(claim(i,));
else
trans(i,j)=0;
end
end
end
%I think here is the problem, I know this formula is not the right one, but the others I tried give even more unrealistic results
for i=1:p
for j=1:p
Porttrans(1,i)=Port(1,i)+sum(trans(i,j))-sum(trans(j,i));
end
end
end
end
Best regards,