| [Ntrading,nb,ns,yb,ys,yb_s,B,S,BS]=rob_forecasting(x,tax,time_lag,H)
|
function [Ntrading,nb,ns,yb,ys,yb_s,B,S,BS]=rob_forecasting(x,tax,time_lag,H)
% -----------------------------------------------------------------
% 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)
% 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.
% H: price history window
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
r=diff(log(x));
l=length(r);
coeff=garchfit(garchset('VarianceModel','EGARCH','R',1,'P',1,'Q',1),r); %Set the forecasting model here using "garchset" function
M=zeros(H,l-H+1);
for i=1:H,
M(i,:)=r(i:l-H+i);
end
[a,E_rdt]=garchpred(coeff,M);
Ib=E_rdt'>0;
Is=E_rdt'<=0;
t=length(Ib);
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);
|
|