function[aRet_tsh, annual_tsh, Ret_tsh] = Func_TSHTab8(Ret,N, tdate)
         
T = length(tdate);
Xall = []; sigma_all = []; Xmean_all = []; Rf_all = [];

for s = 1:N
    X_s = nan*tdate; 
    Xmean_s = nan*tdate; 
    Rf_s = nan*tdate;
    sigma_s = nan*tdate;
    
    tX = Ret(Ret(:,6)==s,1);
    X = Ret(Ret(:,6)==s,2);
    sigma = Ret(Ret(:,6)==s,3);
    Rf = Ret(Ret(:,6)==s,4);
    Xmean = Ret(Ret(:,6)==s,8);
    
    % Date alignment %
    a = find(tdate(:)==tX(1));
    b = find(tdate(:)==tX(end));
    
    % Single out the positions %
    X_s(a:b) = X(1:end);
    sigma_s(a:b) = sigma(1:end);
    Rf_s(a:b) = Rf(1:end);
    Xmean_s(a:b) = Xmean(1:end);
    
    % Put them together into one matrix %
    Xall = [Xall, X_s];
    sigma_all = [sigma_all, sigma_s];
    Rf_all = [Rf_all, Rf_s];
    Xmean_all = [Xmean_all, Xmean_s];
end

% Calculate strategy returns for each asset %
Ret_tsh= []; 
for s = 1:N
    Ret_tsh_s = nan(T,1); 
    for t = 2:T
        Ret_tsh_s(t) = sign(Xmean_all(t-1,s))*Xall(t,s); 
    end
    Ret_tsh = [Ret_tsh, Ret_tsh_s];
end

% Generate aggregate time series return %
aRet_tsh = []; 
for t = 2:T
    Ret_tsh_t = Ret_tsh(t,:)';
    Ret_tsh_t = Ret_tsh_t(~isnan(Ret_tsh_t));
    aRet = mean(Ret_tsh_t);
    aRet_tsh = [aRet_tsh;aRet];  
end

% Generate annualized return %
% annual_bh = mean(aRet_bh(~isnan(aRet_bh),:))*1200;
annual_tsh = mean(aRet_tsh)*1200;

% Generate annualized sharpe ratio %
sharpe_tsh = mean(aRet_tsh)/std(aRet_tsh)*sqrt(12);
end
