% X_TECH1 for panel A
clear
x = load('DJIA daily flag.txt');
tt = find(x(:,4) == 1);
x_date = x(tt,1);
st_date = 196507;  %start month of data % earliest is 1927:01
et_date = 201012;  % end month of data
st = find(x_date == st_date);
et = find(x_date == et_date);
L = 252;
max52 = NaN*x_date;
maxhist = NaN*x_date;
indx52 = NaN*x_date;
indxhist = NaN*x_date;
indx52hist = NaN*x_date;
for t = st:et
    td = max(find(x(:,1)==x_date(t)));
    max52(t) = x(td,3)/max(x(td-L+1:td,3)); 
    maxhist(t) = x(td,3)/max(x(1:td,3));
    indxhist(t) = (x(td,3)  >=  max(x(1:td,3)));
    indx52hist(t) = (max(x(td-L+1:td,3))==max(x(1:td,3)));
end
max52 = max52(st:et);
maxhist = maxhist(st:et);
indxhist=indxhist(st:et);
indx52hist = indx52hist(st:et);
X_TECH1=[max52.*100 maxhist.*100 indxhist indx52hist];

% X_TECH2 for panel B
clear
x = load('nyseamex_daily_flag_long.txt');
tt = find(x(:,4) == 1);
x_date = x(tt,2);
st_date = 196507;  %start month of data % earliest is 1927:01
et_date = 201012;  % end month of data
st = find(x_date == st_date);
et = find(x_date == et_date);
L = 252;
max52 = NaN*x_date;
maxhist = NaN*x_date;
indx52 = NaN*x_date;
indxhist = NaN*x_date;
indx52hist = NaN*x_date;
for t = st:et
    td = max(find(x(:,2)==x_date(t)));
    max52(t) = x(td,1)/max(x(td-L+1:td,1)); 
    maxhist(t) = x(td,1)/max(x(1:td,1));
    indxhist(t) = (x(td,1)  >=  max(x(1:td,1)));
    indx52hist(t) = (max(x(td-L+1:td,1))==max(x(1:td,1)));
end
max52 = max52(st:et);
maxhist = maxhist(st:et);
indxhist=indxhist(st:et);
indx52hist = indx52hist(st:et);
X_TECH2=[max52.*100 maxhist.*100 indxhist indx52hist];

% X_TECH3 for panel C
clear
x = load('sp500_daily_flag_long.txt');
tt = find(x(:,4) == 1);
x_date = x(tt,2);
st_date = 196507;  %start month of data % earliest is 1927:01
et_date = 201012;  % end month of data
st = find(x_date == st_date);
et = find(x_date == et_date);
L = 252;
max52 = NaN*x_date;
maxhist = NaN*x_date;
indx52 = NaN*x_date;
indxhist = NaN*x_date;
indx52hist = NaN*x_date;
for t = st:et
    td = max(find(x(:,2)==x_date(t)));
    max52(t) = x(td,1)/max(x(td-L+1:td,1)); 
    maxhist(t) = x(td,1)/max(x(1:td,1));
    indxhist(t) = (x(td,1)  >=  max(x(1:td,1)));
    indx52hist(t) = (max(x(td-L+1:td,1))==max(x(1:td,1)));
end
max52 = max52(st:et);
maxhist = maxhist(st:et);
indxhist=indxhist(st:et);
indx52hist = indx52hist(st:et);
X_TECH3=[max52.*100 maxhist.*100 indxhist indx52hist];

% r_vw pret
clear 
st_date = 196508;  %start month of data % earliest is 1927:01
et_date = 201101;  % end month of data
z  = load('PredictorData27Jan_12Dec.txt');
st = find(z(:,1)==st_date);
et = find(z(:,1)==et_date);
rf_lag= z(st-1:et-1,11);
rf = z(st:et,11);
x=load('nyseamex.txt');
dated6 = num2str(x(:,1));
yrmo = str2num(dated6(:,1:6)); % date without daily No
x=[yrmo x(:,2:3)];
st1 = find(x(:,1)==st_date);
et1 = find(x(:,1)==et_date);
r_vw=100*(log(1+x(st1:et1,2))-log(1+rf));
pret=100*log(1+x(st1-1:et1-1,2));