%  

load capm.txt ;
data = capm ;
clear capm ;
Close_tbill = data(:,1) ;
Close_msft = data(:,2) ;
Close_sp500	= data(:,3) ;
Close_ge = data(:,4) ;
Close_ford = data(:,5) ;
day = data(:,6) ;
month = data(:,7) ;
year = data(:,8) ;
n=length(year) ;
t = (1:n)' ;

Cl = Close_sp500 ;

% Cl = Close_msft ;


retn = Cl(2:n) ./ Cl(1:n-1) - 1;
new_n =1000 ;
ind = (n-new_n):n -1;
new_returns = retn(ind) ;

R_sort = sort(new_returns) ;
n=length(R_sort) 



c = linspace(-.03,-.01,50) ;
ahat = 0*c ;
n = c;
for i=1:length(c) ;
    ind = logical((R_sort < c(i))) ;
    n(i) = sum( (R_sort < c(i))) ;
ahat(i) = n(i) / sum(log(R_sort(ind)./c(i))) ;

end ;

figure(1)
clf
fsize = 14 ;
plot(n,ahat)
xlabel('n(c)','fontsize',fsize) ;
ylabel('Hill estimator','fontsize',fsize) ;
set(gca,'fontsize',fsize) ;

% print var_sp500_hill.ps -deps ;

