| [Ntrading,nb,ns,yb,ys,yb_s,B,S,BS]=rob_TRB(x,H,tax,time_lag)
|
function [Ntrading,nb,ns,yb,ys,yb_s,B,S,BS]=rob_TRB(x,H,tax,time_lag)
% -----------------------------------------------------------------
% Elaborated by : BEN HASSEN Anis
% "Institut Suprieur de Gestion de Tunis" (ISG Tunis)
% University of Tunis
% 41, rue de la Libert - Cit Bouchoucha - C.P. : 2000 Le Bardo
% Tunisia
% University e-mail: http://www.isg.rnu.tn/
% Personal e-mail: benhassenanis@yahoo.com
% _________________________________________________________________
% January 14, 2004.
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Output:
% 1: number of trading days
% 2: number of buy signals
% 3: number of sell signals
% 4: average return on buy signals
% 5: average return on sell signals
% 6: average buy-sell excess return (spread) relative to a buy-and-hold
% strategy and net of transaction costs
% 7: t-statistic of the difference between buys & buy-and-hold returns
% 8: t-statistic of the difference between sells & buy-and-hold returns
% 9: t-statistic of the difference between buy-sell & buy-and-hold
% returns
%******************************************************************
% Input:
% x: a column vector of time series (prices Pt)
% H: canal length
% tax: transaction cost on each transaction (in percentage)
% time_lag: introduced if a delay between decision and action is present.
% For example, 1 means that there in no time lag and 2 means that we skeep
% one trading day before we make a transaction.
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
T=length(x);
r=diff(log(x));
M=zeros(H,T-H+1); % initialisation
for i=1:H,
M(i,:)=x(i:T-H+i);
end
xmax=max(M);
xmin=min(M);
xmax=xmax(1:T-H);
xmin=xmin(1:T-H);
p=x(H+1:T);
Ib=(p>xmax');
Is=(p<xmin');
t=length(Ib);
for i=1:t-1,
if Ib(i+1)+Is(i+1)==0 & Ib(i)+Is(i)~=0
Ib(i+1)=Ib(i);
Is(i+1)=Is(i);
end
end
for i=1:t,
if Ib(i)==1
I(i)=1;
else
I(i)=-1;
end
end
TC=[1;abs(diff(I))'];
Ib=Ib(1:end-time_lag);
Is=Is(1:end-time_lag);
TC=TC(1:end-time_lag);
nb=sum(Ib);
ns=sum(Is);
Ntrading=sum(TC);
%Lb=mean(averday(Ib));
%Ls=mean(averday(Is));
%stdLb=std(averday(Ib));
%stdLs=std(averday(Is));
n=length(Ib);
rt=r(end-n+1:end);
y=mean(rt);
v=var(rt);
Rbuy=(rt-TC*tax).*Ib;
Rsell=(rt+TC*tax).*Is;
yb=1/nb*sum(Rbuy);
ys=1/ns*sum(Rsell);
yb_s=yb-ys;
vb=1/nb*sum(Ib.*(Rbuy-yb).^2);
vs=1/ns*sum(Is.*(Rsell-ys).^2);
B=(yb-y)/sqrt(v/n+vb/nb);
S=(ys-y)/sqrt(v/n+vs/ns);
BS=(yb-ys)/sqrt(vb/nb+vs/ns);
|
|