Chapter 9. Extreme Value Theory
Matlab and Python
Copyright 2011 - 2023 Jon Danielsson. This code is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. This code is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. The GNU General Public License is available at: www.gnu.org/licenses.
Listing 9.1/9.2
% Hill estimator in MATLAB
ysort = sort(y); % sort the returns
CT = 100; % set the threshold
iota = 1/mean(log(ysort(1:CT)/ysort(CT+1))) % get the tail index
Listing 9.1/9.2
Hill estimator in Python
ysort = np.sort(y) # sort the returns
CT = 100 # set the threshold
iota = 1/(np.mean(np.log(ysort[0:CT]/ysort[CT]))) # get the tail index
print(iota)
Financial Risk Forecasting
Market risk forecasting with R, Julia, Python and Matlab. Code, lecture slides, implementation notes, seminar assignments and questions.© All rights reserved, Jon Danielsson, 2025