Chapter 9. Extreme Value Theory (in Python/Julia)


Copyright 2011 - 2019 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: https://www.gnu.org/licenses/.


Listing 9.1/9.2: Hill estimator in Python
Last updated June 2018

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)
		
Listing 9.1/9.2: Hill estimator in Julia
Last updated June 2018

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