Important: You only need to type the quoted commands in R console

Content

  1. Data Loading
  2. RiskMetrics-IGARCH
  3. RiskMetrics-IGARCH
  4. Empirical Quantile
  5. Quantile Regression
  6. Extreme Value Approach
  7. Peaks over the threshold
  8. Generalized Pareto Distribution

1. Data Loading

  • Loading data and t-test
da=read.table("d-ibm-0110.txt",header=T)
head(da)
##       date    return
## 1 20010102 -0.002206
## 2 20010103  0.115696
## 3 20010104 -0.015192
## 4 20010105  0.008719
## 5 20010108 -0.004654
## 6 20010109 -0.010688
ibm=log(da$return+1)
xt = -ibm*100 ##xt is then the loss variable (in percentage)
t.test(xt)
## 
##  One Sample t-test
## 
## data:  xt
## t = -0.78176, df = 2514, p-value = 0.4344
## alternative hypothesis: true mean is not equal to 0
## 95 percent confidence interval:
##  -0.09296051  0.03996638
## sample estimates:
##   mean of x 
## -0.02649706

2. RiskMetrics-IGARCH

  • Fit model
require(rugarch)
## Loading required package: rugarch
## Loading required package: parallel
## 
## Attaching package: 'rugarch'
## The following object is masked from 'package:stats':
## 
##     sigma
require(fGarch)
## Loading required package: fGarch
## Loading required package: timeDate
## Loading required package: timeSeries
## Loading required package: fBasics
spec3 = ugarchspec(variance.model=list(model="iGARCH", garchOrder=c(1,1)), mean.model=list(armaOrder=c(0,0), include.mean=FALSE),distribution.model="norm", fixed.pars=list(omega=0))
fit = ugarchfit(spec3, data = xt)
summary(fit)
##    Length     Class      Mode 
##         1 uGARCHfit        S4
fit
## 
## *---------------------------------*
## *          GARCH Model Fit        *
## *---------------------------------*
## 
## Conditional Variance Dynamics    
## -----------------------------------
## GARCH Model  : iGARCH(1,1)
## Mean Model   : ARFIMA(0,0,0)
## Distribution : norm 
## 
## Optimal Parameters
## ------------------------------------
##         Estimate  Std. Error  t value Pr(>|t|)
## omega   0.000000          NA       NA       NA
## alpha1  0.057143    0.007172   7.9675        0
## beta1   0.942857          NA       NA       NA
## 
## Robust Standard Errors:
##         Estimate  Std. Error  t value Pr(>|t|)
## omega   0.000000          NA       NA       NA
## alpha1  0.057143    0.021965   2.6015 0.009282
## beta1   0.942857          NA       NA       NA
## 
## LogLikelihood : -4501.827 
## 
## Information Criteria
## ------------------------------------
##                    
## Akaike       3.5808
## Bayes        3.5831
## Shibata      3.5808
## Hannan-Quinn 3.5816
## 
## Weighted Ljung-Box Test on Standardized Residuals
## ------------------------------------
##                         statistic p-value
## Lag[1]                    0.06978  0.7917
## Lag[2*(p+q)+(p+q)-1][2]   2.40452  0.2037
## Lag[4*(p+q)+(p+q)-1][5]   4.59023  0.1891
## d.o.f=0
## H0 : No serial correlation
## 
## Weighted Ljung-Box Test on Standardized Squared Residuals
## ------------------------------------
##                         statistic p-value
## Lag[1]                     0.0508  0.8217
## Lag[2*(p+q)+(p+q)-1][5]    2.0768  0.6004
## Lag[4*(p+q)+(p+q)-1][9]    3.5069  0.6732
## d.o.f=2
## 
## Weighted ARCH LM Tests
## ------------------------------------
##             Statistic Shape Scale P-Value
## ARCH Lag[3]   0.06369 0.500 2.000  0.8008
## ARCH Lag[5]   2.89044 1.440 1.667  0.3061
## ARCH Lag[7]   3.50081 2.315 1.543  0.4243
## 
## Nyblom stability test
## ------------------------------------
## Joint Statistic:  0.074
## Individual Statistics:              
## alpha1 0.07404
## 
## Asymptotic Critical Values (10% 5% 1%)
## Joint Statistic:          0.353 0.47 0.748
## Individual Statistic:     0.35 0.47 0.75
## 
## Sign Bias Test
## ------------------------------------
##                    t-value   prob sig
## Sign Bias           0.3907 0.6961    
## Negative Sign Bias  0.6239 0.5328    
## Positive Sign Bias  0.8428 0.3994    
## Joint Effect        3.4079 0.3329    
## 
## 
## Adjusted Pearson Goodness-of-Fit Test:
## ------------------------------------
##   group statistic p-value(g-1)
## 1    20     45.64    0.0005565
## 2    30     63.01    0.0002572
## 3    40     63.85    0.0072739
## 4    50     87.33    0.0006231
## 
## 
## Elapsed time : 0.8119991
head(sigma(fit))
##                         [,1]
## 1970-01-02 07:30:00 1.699656
## 1970-01-03 07:30:00 1.651224
## 1970-01-04 07:30:00 3.069140
## 1970-01-05 07:30:00 3.002544
## 1970-01-06 07:30:00 2.922872
## 1970-01-07 07:30:00 2.840322
tail(sigma(fit))
##                          [,1]
## 1976-11-15 07:30:00 0.8289833
## 1976-11-16 07:30:00 0.8050096
## 1976-11-17 07:30:00 0.7868684
## 1976-11-18 07:30:00 0.7664697
## 1976-11-19 07:30:00 0.7559542
## 1976-11-20 07:30:00 0.7344453
coef(fit)
##      omega     alpha1      beta1 
## 0.00000000 0.05714296 0.94285704
vt = coef(fit)[3]*sigma(fit)[2515]^2+coef(fit)[2]*xt[2515]^2 ## volatility prediction; xt[2515]^2 because mean equation=0
  • Calculate VaR
sqrt(vt)*qnorm(.95) #VaR 0.95
##                        [,1]
## 1976-11-20 07:30:00 1.17328
sqrt(vt)*qnorm(.99) #VaR 0.99
##                         [,1]
## 1976-11-20 07:30:00 1.659392
sqrt(vt)*qnorm(.999) #VaR 0.999
##                         [,1]
## 1976-11-20 07:30:00 2.204273

3. IGARCH

  • Fit model
xt1 = -ibm #loss variable: negative log returns
(m1 = garchFit(~garch(1,1),data=xt1,trace=F))
## 
## Title:
##  GARCH Modelling 
## 
## Call:
##  garchFit(formula = ~garch(1, 1), data = xt1, trace = F) 
## 
## Mean and Variance Equation:
##  data ~ garch(1, 1)
## <environment: 0x00000000236edd80>
##  [data = xt1]
## 
## Conditional Distribution:
##  norm 
## 
## Coefficient(s):
##          mu        omega       alpha1        beta1  
## -6.0097e-04   4.3781e-06   1.0113e-01   8.8412e-01  
## 
## Std. Errors:
##  based on Hessian 
## 
## Error Analysis:
##          Estimate  Std. Error  t value Pr(>|t|)    
## mu     -6.010e-04   2.393e-04   -2.511 0.012044 *  
## omega   4.378e-06   1.160e-06    3.774 0.000161 ***
## alpha1  1.011e-01   1.851e-02    5.463 4.67e-08 ***
## beta1   8.841e-01   1.991e-02   44.413  < 2e-16 ***
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Log Likelihood:
##  7114.066    normalized:  2.828654 
## 
## Description:
##  Mon Apr 15 17:33:02 2019 by user: Sirius
predict(m1,3)
##    meanForecast   meanError standardDeviation
## 1 -0.0006009667 0.007824302       0.007824302
## 2 -0.0006009667 0.008043298       0.008043298
## 3 -0.0006009667 0.008253382       0.008253382
  • VaR
-.000601+qnorm(.95)*.0078243 #VaR 0.95
## [1] 0.01226883
-.000601+qnorm(.99)*.0078243  #VaR 0.99
## [1] 0.01760104
-.000601+qnorm(.999)*.0078243 #VaR 0.999
## [1] 0.0235779
  • Fit another model
m2=garchFit(~garch(1,1),data=xt1,trace=F,cond.dist="std")
m2
## 
## Title:
##  GARCH Modelling 
## 
## Call:
##  garchFit(formula = ~garch(1, 1), data = xt1, cond.dist = "std", 
##     trace = F) 
## 
## Mean and Variance Equation:
##  data ~ garch(1, 1)
## <environment: 0x00000000240e8238>
##  [data = xt1]
## 
## Conditional Distribution:
##  std 
## 
## Coefficient(s):
##          mu        omega       alpha1        beta1        shape  
## -4.1127e-04   1.9223e-06   6.4480e-02   9.2863e-01   5.7513e+00  
## 
## Std. Errors:
##  based on Hessian 
## 
## Error Analysis:
##          Estimate  Std. Error  t value Pr(>|t|)    
## mu     -4.113e-04   2.254e-04   -1.824  0.06811 .  
## omega   1.922e-06   7.417e-07    2.592  0.00954 ** 
## alpha1  6.448e-02   1.323e-02    4.874 1.09e-06 ***
## beta1   9.286e-01   1.407e-02   65.993  < 2e-16 ***
## shape   5.751e+00   6.080e-01    9.459  < 2e-16 ***
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Log Likelihood:
##  7218.69    normalized:  2.870254 
## 
## Description:
##  Mon Apr 15 17:33:03 2019 by user: Sirius
predict(m2,3)
##    meanForecast   meanError standardDeviation
## 1 -0.0004112737 0.008100874       0.008100874
## 2 -0.0004112737 0.008191121       0.008191121
## 3 -0.0004112737 0.008279774       0.008279774
  • VaR
-.0004113+qstd(.95,nu=5.751)*.0081009
## [1] 0.01240096
-.0004113+qstd(.99,nu=5.751)*.0081009 
## [1] 0.02045082
-.0004113+qstd(.999,nu=5.751)*.0081009
## [1] 0.03456563

5. Quantile Regression

require(quantreg)
## Loading required package: quantreg
## Loading required package: SparseM
## 
## Attaching package: 'SparseM'
## The following object is masked from 'package:base':
## 
##     backsolve
da = read.table("d-ibm-rq.txt",header=T)
head(da)
##           nibm        vol   vix
## 1 -0.109478400 0.01700121 29.99
## 2  0.015308580 0.01614694 26.60
## 3 -0.008681209 0.03786369 26.97
## 4  0.004664864 0.03602087 28.67
## 5  0.010745530 0.03403132 29.84
## 6 -0.009408600 0.03211091 27.99
nibm=da$nibm
vol=da$vol
vix=da$vix/100
length(nibm)
## [1] 2514
length(vol)
## [1] 2514
length(vix)
## [1] 2514
fit1 <- rq(nibm ~ vol + vix, tau = 0.95)
summary(fit1)
## 
## Call: rq(formula = nibm ~ vol + vix, tau = 0.95)
## 
## tau: [1] 0.95
## 
## Coefficients:
##             Value    Std. Error t value  Pr(>|t|)
## (Intercept) -0.00104  0.00257   -0.40317  0.68686
## vol          1.17724  0.22268    5.28661  0.00000
## vix          0.02809  0.01615    1.73977  0.08202
names(fit1)
##  [1] "coefficients"  "x"             "y"             "residuals"    
##  [5] "dual"          "fitted.values" "formula"       "terms"        
##  [9] "xlevels"       "call"          "tau"           "rho"          
## [13] "method"        "model"
fit1$coefficients
##  (Intercept)          vol          vix 
## -0.001036872  1.177238592  0.028091939
coef(fit1)
##  (Intercept)          vol          vix 
## -0.001036872  1.177238592  0.028091939
plot(nibm,type='l',main='Negative daily log returns of IBM stock with 95th quantiles(red line)')
lines(1:2514,fit1$fitted.values,col='red')

tail(volatility(m1))#volatility of GARCH(1,1)
## [1] 0.008923548 0.008653557 0.008516047 0.008299314 0.008230775 0.008018202
vfit=-.00104+1.17724*volatility(m1)[2515]+0.02809*17.75/100 #17.75 is 2010-12-31 VIX
vfit
## [1] 0.01338532
fit2 <- rq(nibm ~ vol + vix, tau = 0.99)
summary(fit2)
## 
## Call: rq(formula = nibm ~ vol + vix, tau = 0.99)
## 
## tau: [1] 0.99
## 
## Coefficients:
##             Value   Std. Error t value Pr(>|t|)
## (Intercept) 0.01182 0.00831    1.42190 0.15518 
## vol         1.03129 0.73125    1.41032 0.15857 
## vix         0.04409 0.05335    0.82641 0.40865

6. Extreme Value Approach

require(evir)
## Loading required package: evir
## Warning: package 'evir' was built under R version 3.4.4
par(mfcol=c(2,1))
(m2=gev(xt,block=21))
## $n.all
## [1] 2515
## 
## $n
## [1] 120
## 
## $data
##   [1]  4.0335654  4.6038703  6.9818569  4.6158081  2.9868660  1.8749682
##   [7]  5.1245927  3.6876663  3.3919828  2.3115108  2.0342513  2.4236342
##  [13]  4.8790114  4.7451211 10.6674712  7.3298915  3.1040820  6.3058018
##  [19]  4.9832257  4.1026182  7.0740111  5.3694069  3.2279420  3.3725360
##  [25]  5.6782014  2.8647448  3.1710505  1.7130900  4.1022015  2.0702832
##  [31]  4.0106625  1.2247698  2.1467793  3.8022791  1.2162666  1.2266932
##  [37]  2.0414975  1.9473382  2.0080266  1.8147677  1.4965425  2.0119037
##  [43]  1.8123238  1.7842230  1.6585787  1.1930891  1.6205604  1.2909976
##  [49]  1.9149181  1.5308581  1.0340277  8.6620544  2.2660828  2.3848119
##  [55]  1.1244989  1.7883969  1.4590932  1.2093837  0.6296783  2.6523663
##  [61]  2.1040814  1.4236865  1.5996261  1.8530637  2.7150255  2.1617994
##  [67]  1.6564436  1.1022525  2.1935841  0.8557511  2.0563997  0.9094227
##  [73]  3.3537135  3.0913950  1.4987757  2.4177945  3.2943735  2.0471111
##  [79]  3.4377182  1.7755704  1.6698650  3.2461210  5.6767196  3.6600708
##  [85]  2.7332143  2.5186535  1.4527008  2.3683247  2.7861553  2.8494129
##  [91]  1.7898222  2.8629954  6.0170475  6.1018324  5.9323344  2.7901656
##  [97]  3.5234509  5.1061742  4.8006072  1.9594729  2.0101692  3.0112876
## [103]  1.2639544  1.4527008  1.4558462  5.0808149  1.2491697  1.2677015
## [109]  2.9428811  0.8985247  0.7097125  2.2935008  4.0058744  3.0624170
## [115]  2.5279860  2.0077205  0.9940241  3.4183660  1.5317720  0.7572600
## 
## $block
## [1] 21
## 
## $par.ests
##       xi    sigma       mu 
## 0.251353 1.028910 1.965850 
## 
## $par.ses
##         xi      sigma         mu 
## 0.08847742 0.09013351 0.10932034 
## 
## $varcov
##              [,1]         [,2]         [,3]
## [1,]  0.007828254 -0.001080741 -0.003453668
## [2,] -0.001080741  0.008124049  0.006145413
## [3,] -0.003453668  0.006145413  0.011950936
## 
## $converged
## [1] 0
## 
## $nllh.final
## [1] 210.1579
## 
## attr(,"class")
## [1] "gev"
#### Model checking ####
#plot(m2)
aa=1.0-(-21*log(1.0-0.05))^{-0.251353} #aa=1.0-(-n*log(1.0-prob))^{-xi}

1.965850 - (1.028910/0.251353)*aa  #mu - (sigma/xi)*aa. VaR 0.95 with evt
## [1] 1.890084
aaa=1.0-(-21*log(1.0-0.01))^{-0.251353} #aaa=1.0-(-n*log(1.0-prob))^{-xi}
1.965850 - (1.028910/0.251353)*aaa  #mu - (sigma/xi)*aaa. VaR 0.99 with evt
## [1] 3.924483
10^(0.251353)*3.924483 #VaR 0.99 for 10 trading days
## [1] 7.000603

7. Peaks over the threshold

require(evir)
(m3=pot(xt,1.0))  ## Threshold is set to 1%.
## $n
## [1] 2515
## 
## $period
## [1]    1 2515
## 
## $data
##   [1]  1.530858  1.074553  1.139063  2.445357  4.033565  3.370467  2.432958
##   [8]  1.857648  1.005943  1.535935  3.090776  3.644098  4.603870  2.607296
##  [15]  2.657090  3.600134  1.009276  6.981857  3.902361  3.548315  5.883429
##  [22]  4.754874  5.251088  1.593021  4.615808  2.010883  1.649022  1.270436
##  [29]  2.495377  2.659349  1.484058  1.533295  2.986866  1.516440  2.171099
##  [36]  2.299129  1.874968  1.535631  1.841349  1.205335  5.124593  1.685526
##  [43]  2.670955  3.994738  1.273981  1.233982  1.555739  1.823627  1.126825
##  [50]  1.102960  2.145860  1.803567  3.687666  1.129657  2.369656  1.449251
##  [57]  3.298301  2.745650  3.154124  3.391983  1.434135  1.390320  1.606638
##  [64]  2.311511  2.034251  1.847970  1.811407  1.271145  1.043324  2.423634
##  [71]  1.591091  1.241778  1.905745  1.509638  1.896368  1.227503  4.826945
##  [78]  3.337376  2.381023  1.039383  4.879011  1.117319  2.584000  4.745121
##  [85]  3.310084  2.994800  1.176797  2.466674  1.224061  1.868651  1.111252
##  [92]  1.950703  1.102253  1.874357  3.625017 10.667471  5.567234  1.625642
##  [99]  1.209485  2.333516  2.511578  7.329891  3.104082  1.153123  1.457673
## [106]  1.191166  1.492990  1.234995  2.212803  2.951738  1.111049  1.722042
## [113]  1.934287  1.720415  1.118937  1.567826  3.470118  2.442692  4.033878
## [120]  1.590786  6.305802  3.038911  2.312636  1.314806  2.842828  4.983226
## [127]  2.139525  4.346925  1.955190  3.101606  2.823796  1.490046  1.958351
## [134]  1.226390  1.855407  2.467289  1.631639  4.102618  2.124713  1.869262
## [141]  3.190561  3.114191  7.074011  1.367305  5.882156  1.583674  2.713073
## [148]  3.455314  2.549834  5.833593  3.532256  5.369407  1.413037  3.408640
## [155]  3.227942  1.737609  1.042819  1.028269  1.331323  2.423122  1.799901
## [162]  3.372536  1.571687  1.618020  1.480201  1.592310  1.462848  1.445294
## [169]  2.127062  1.123892  1.773840  5.678201  1.048477  2.574457  2.547064
## [176]  1.404010  1.156664  1.753891  2.134724  2.864745  3.171051  2.303119
## [183]  3.038911  1.376835  1.713090  1.073845  1.561427  1.206246  1.432715
## [190]  1.017358  2.895827  4.102201  2.828940  2.284804  1.439714  2.070283
## [197]  1.372476  1.108623  1.109027  1.699154  4.010663  1.467921  1.216267
## [204]  1.032209  1.590278  1.224770  1.098006  1.782696  2.047009  2.146779
## [211]  1.260005  3.802279  1.216267  1.136231  1.226693  1.986501  2.041497
## [218]  1.057168  1.447729  1.336390  1.397013  1.947338  1.567319  2.008027
## [225]  1.599016  1.333552  1.814768  1.413037  1.482028  1.026854  1.496543
## [232]  1.023621  1.551473  2.011904  1.322507  1.234995  1.415978  1.136939
## [239]  1.812324  1.541419  1.784223  1.658579  1.193089  1.079607  1.328181
## [246]  1.620560  1.290998  1.080011  1.914918  1.530858  1.023722  1.034028
## [253]  1.611109  1.385656  1.105791  8.662054  1.538169  4.706226  1.490655
## [260]  2.071100  2.266083  2.030884  2.037415  1.047871  2.384812  1.873949
## [267]  1.124499  1.788397  1.465182  1.348654  1.126724  1.459093  1.209384
## [274]  1.195214  1.087189  1.384642  1.168096  2.652366  1.446512  2.104081
## [281]  1.563357  1.100332  1.423686  1.491264  1.599626  1.151504  1.755825
## [288]  1.853064  1.089210  1.460615  2.715026  1.427744  2.161799  1.303053
## [295]  1.656444  1.654207  1.102253  2.193584  2.056400  1.186208  3.353714
## [302]  1.079910  3.091395  1.091536  1.495933  1.005640  1.498776  1.356864
## [309]  2.417795  1.055248  1.555942  3.294373  2.047111  1.338316  3.437718
## [316]  1.190458  2.011598  1.394174  1.526492  1.277526  1.775570  1.157068
## [323]  1.669865  3.246121  2.219551  1.519994  2.150049  1.043930  1.504562
## [330]  4.577486  5.676720  1.753688  2.483075  1.167084  2.019250  2.181728
## [337]  2.218426  2.252990  1.179327  1.772517  1.824137  3.205326  3.660071
## [344]  1.073643  2.489533  2.277540  1.074452  2.130842  2.260866  1.059897
## [351]  2.733214  1.214040  2.134826  1.098714  1.053126  1.204728  2.518653
## [358]  1.249271  1.196125  1.452701  2.368325  1.135725  1.765595  1.045951
## [365]  1.041101  1.254030  1.612227  2.786155  2.159040  1.278741  1.840534
## [372]  2.808368  1.274183  2.849413  1.137242  1.789822  1.052520  1.730589
## [379]  1.095984  1.410704  1.642719  1.670780  2.314274  2.765181  2.862995
## [386]  1.936938  3.228872  4.026590  2.246342  4.242119  6.017047  5.018023
## [393]  1.248967  2.764050  5.065560  5.479310  1.726621  1.414456  5.840378
## [400]  4.025445  6.101832  2.740203  2.980478  3.774860  4.887307  2.821431
## [407]  1.356458  3.693166  4.717023  3.612367  5.268795  5.729019  5.932334
## [414]  4.086366  2.590465  2.790166  2.166807  1.848887  1.709835  1.626964
## [421]  2.885946  2.551578  3.523451  1.487712  2.466366  3.735509  1.302242
## [428]  3.436476  2.859908  5.106174  3.291686  1.447831  2.271709  1.927457
## [435]  2.752845  1.038676  4.800607  2.805797  1.735676  1.108016  1.330005
## [442]  1.959473  1.077989  1.629505  1.190357  1.393464  1.189142  2.010169
## [449]  1.431294  1.093760  1.302242  1.341255  3.011288  1.446715  1.232059
## [456]  1.263954  1.452701  1.018267  1.158788  1.455846  1.439917  5.080815
## [463]  1.600439  1.917365  1.856425  1.249170  1.114487  1.023015  1.267701
## [470]  1.215356  1.052520  2.942881  2.750687  2.063443  1.105084  2.139525
## [477]  1.939589  1.471778  1.125409  1.148571  2.293501  1.479592  4.005874
## [484]  1.041404  2.116644  1.038676  1.486697  3.062417  1.295455  2.079268
## [491]  2.527986  1.016650  1.536342  1.185499  1.092041  1.249170  2.007720
## [498]  1.072026  1.285831  3.418366  1.168905  1.531772  1.172750  1.005842
## attr(,"times")
##   [1]    3    6   10   14   21   23   27   28   30   33   34   35   37   39
##  [15]   40   42   46   47   48   50   52   54   60   63   64   68   70   71
##  [29]   77   84   85   90   91  101  102  103  115  118  125  127  129  130
##  [43]  131  137  141  144  150  152  157  159  161  166  168  171  172  173
##  [57]  175  178  179  182  183  191  198  205  217  225  226  229  232  237
##  [71]  248  252  255  256  257  259  261  262  263  266  267  271  274  280
##  [85]  281  283  286  293  297  302  304  305  309  310  313  314  317  321
##  [99]  324  328  333  334  337  341  344  345  348  349  352  353  356  357
## [113]  358  359  360  364  365  366  367  369  373  377  378  379  383  387
## [127]  388  391  394  395  397  408  411  412  413  414  416  417  419  423
## [141]  424  428  429  430  432  434  435  436  438  440  443  448  452  454
## [155]  464  465  471  472  477  481  482  485  488  491  492  497  498  499
## [169]  505  510  511  512  514  516  520  523  529  536  538  546  556  558
## [183]  561  565  568  575  579  585  592  594  595  605  607  608  613  619
## [197]  621  623  624  631  636  638  643  645  649  663  671  674  682  684
## [211]  688  700  716  725  753  758  760  769  770  776  787  797  799  800
## [225]  802  806  825  827  834  835  841  846  879  881  885  890  892  899
## [239]  902  905  906  934  949  973  982  987  995 1006 1016 1031 1039 1066
## [253] 1072 1074 1075 1076 1078 1079 1085 1090 1093 1107 1110 1111 1124 1125
## [267] 1153 1157 1161 1173 1184 1186 1201 1207 1213 1241 1243 1244 1261 1269
## [281] 1279 1285 1292 1312 1323 1325 1330 1337 1350 1361 1365 1375 1385 1388
## [295] 1389 1402 1428 1438 1484 1513 1519 1534 1545 1546 1548 1552 1555 1575
## [309] 1580 1605 1606 1614 1626 1649 1652 1655 1659 1664 1666 1672 1679 1682
## [323] 1697 1707 1709 1712 1718 1720 1722 1723 1724 1727 1730 1732 1734 1738
## [337] 1745 1748 1749 1756 1758 1759 1761 1762 1763 1766 1768 1772 1775 1781
## [351] 1782 1784 1789 1791 1798 1799 1803 1812 1817 1821 1828 1839 1841 1854
## [365] 1855 1856 1863 1867 1870 1874 1877 1881 1883 1889 1901 1902 1906 1912
## [379] 1913 1917 1918 1922 1926 1927 1929 1932 1936 1938 1941 1946 1948 1949
## [393] 1950 1951 1952 1953 1954 1955 1958 1962 1963 1965 1966 1973 1974 1976
## [407] 1977 1978 1980 1981 1983 1984 1990 1993 1996 1998 2003 2005 2006 2015
## [421] 2017 2020 2023 2025 2030 2038 2041 2042 2044 2046 2051 2052 2054 2055
## [435] 2056 2063 2070 2077 2080 2088 2089 2098 2099 2102 2103 2107 2108 2111
## [449] 2115 2123 2129 2135 2137 2139 2142 2150 2168 2177 2179 2197 2200 2211
## [463] 2214 2216 2221 2240 2252 2254 2263 2265 2269 2275 2277 2281 2282 2286
## [477] 2337 2342 2345 2347 2349 2350 2359 2363 2369 2381 2383 2386 2387 2398
## [491] 2400 2401 2416 2417 2423 2425 2427 2429 2434 2464 2482 2489 2491 2493
## 
## $span
## [1] 2514
## 
## $threshold
## [1] 1
## 
## $p.less.thresh
## [1] 0.7996024
## 
## $n.exceed
## [1] 504
## 
## $run
## [1] NA
## 
## $par.ests
##         xi      sigma         mu       beta 
##  0.1073161  0.8913773 -0.5633651  1.0591516 
## 
## $par.ses
##         xi      sigma         mu 
## 0.05468298 0.13084522 0.16921433 
## 
## $varcov
##              [,1]         [,2]        [,3]
## [1,]  0.002990229 -0.006738203  0.00795378
## [2,] -0.006738203  0.017120472 -0.02111842
## [3,]  0.007953780 -0.021118424  0.02863349
## 
## $intensity
## [1] 0.2004773
## 
## $nllh.final
## [1] 1900.967
## 
## $converged
## [1] 0
## 
## attr(,"class")
## [1] "potd"
## Model checking
#plot(m3)
  • VaR and CVaR calculation
riskmeasures(m3,c(.95,.99,.999))
##          p quantile     sfall
## [1,] 0.950 2.585581  3.962676
## [2,] 0.990 4.745218  6.381938
## [3,] 0.999 8.561586 10.657100

8. Generalized Pareto distribution

(m4=gpd(xt,1.0))  ### Threshold 1%
## $n
## [1] 2515
## 
## $data
##   [1]  1.530858  1.074553  1.139063  2.445357  4.033565  3.370467  2.432958
##   [8]  1.857648  1.005943  1.535935  3.090776  3.644098  4.603870  2.607296
##  [15]  2.657090  3.600134  1.009276  6.981857  3.902361  3.548315  5.883429
##  [22]  4.754874  5.251088  1.593021  4.615808  2.010883  1.649022  1.270436
##  [29]  2.495377  2.659349  1.484058  1.533295  2.986866  1.516440  2.171099
##  [36]  2.299129  1.874968  1.535631  1.841349  1.205335  5.124593  1.685526
##  [43]  2.670955  3.994738  1.273981  1.233982  1.555739  1.823627  1.126825
##  [50]  1.102960  2.145860  1.803567  3.687666  1.129657  2.369656  1.449251
##  [57]  3.298301  2.745650  3.154124  3.391983  1.434135  1.390320  1.606638
##  [64]  2.311511  2.034251  1.847970  1.811407  1.271145  1.043324  2.423634
##  [71]  1.591091  1.241778  1.905745  1.509638  1.896368  1.227503  4.826945
##  [78]  3.337376  2.381023  1.039383  4.879011  1.117319  2.584000  4.745121
##  [85]  3.310084  2.994800  1.176797  2.466674  1.224061  1.868651  1.111252
##  [92]  1.950703  1.102253  1.874357  3.625017 10.667471  5.567234  1.625642
##  [99]  1.209485  2.333516  2.511578  7.329891  3.104082  1.153123  1.457673
## [106]  1.191166  1.492990  1.234995  2.212803  2.951738  1.111049  1.722042
## [113]  1.934287  1.720415  1.118937  1.567826  3.470118  2.442692  4.033878
## [120]  1.590786  6.305802  3.038911  2.312636  1.314806  2.842828  4.983226
## [127]  2.139525  4.346925  1.955190  3.101606  2.823796  1.490046  1.958351
## [134]  1.226390  1.855407  2.467289  1.631639  4.102618  2.124713  1.869262
## [141]  3.190561  3.114191  7.074011  1.367305  5.882156  1.583674  2.713073
## [148]  3.455314  2.549834  5.833593  3.532256  5.369407  1.413037  3.408640
## [155]  3.227942  1.737609  1.042819  1.028269  1.331323  2.423122  1.799901
## [162]  3.372536  1.571687  1.618020  1.480201  1.592310  1.462848  1.445294
## [169]  2.127062  1.123892  1.773840  5.678201  1.048477  2.574457  2.547064
## [176]  1.404010  1.156664  1.753891  2.134724  2.864745  3.171051  2.303119
## [183]  3.038911  1.376835  1.713090  1.073845  1.561427  1.206246  1.432715
## [190]  1.017358  2.895827  4.102201  2.828940  2.284804  1.439714  2.070283
## [197]  1.372476  1.108623  1.109027  1.699154  4.010663  1.467921  1.216267
## [204]  1.032209  1.590278  1.224770  1.098006  1.782696  2.047009  2.146779
## [211]  1.260005  3.802279  1.216267  1.136231  1.226693  1.986501  2.041497
## [218]  1.057168  1.447729  1.336390  1.397013  1.947338  1.567319  2.008027
## [225]  1.599016  1.333552  1.814768  1.413037  1.482028  1.026854  1.496543
## [232]  1.023621  1.551473  2.011904  1.322507  1.234995  1.415978  1.136939
## [239]  1.812324  1.541419  1.784223  1.658579  1.193089  1.079607  1.328181
## [246]  1.620560  1.290998  1.080011  1.914918  1.530858  1.023722  1.034028
## [253]  1.611109  1.385656  1.105791  8.662054  1.538169  4.706226  1.490655
## [260]  2.071100  2.266083  2.030884  2.037415  1.047871  2.384812  1.873949
## [267]  1.124499  1.788397  1.465182  1.348654  1.126724  1.459093  1.209384
## [274]  1.195214  1.087189  1.384642  1.168096  2.652366  1.446512  2.104081
## [281]  1.563357  1.100332  1.423686  1.491264  1.599626  1.151504  1.755825
## [288]  1.853064  1.089210  1.460615  2.715026  1.427744  2.161799  1.303053
## [295]  1.656444  1.654207  1.102253  2.193584  2.056400  1.186208  3.353714
## [302]  1.079910  3.091395  1.091536  1.495933  1.005640  1.498776  1.356864
## [309]  2.417795  1.055248  1.555942  3.294373  2.047111  1.338316  3.437718
## [316]  1.190458  2.011598  1.394174  1.526492  1.277526  1.775570  1.157068
## [323]  1.669865  3.246121  2.219551  1.519994  2.150049  1.043930  1.504562
## [330]  4.577486  5.676720  1.753688  2.483075  1.167084  2.019250  2.181728
## [337]  2.218426  2.252990  1.179327  1.772517  1.824137  3.205326  3.660071
## [344]  1.073643  2.489533  2.277540  1.074452  2.130842  2.260866  1.059897
## [351]  2.733214  1.214040  2.134826  1.098714  1.053126  1.204728  2.518653
## [358]  1.249271  1.196125  1.452701  2.368325  1.135725  1.765595  1.045951
## [365]  1.041101  1.254030  1.612227  2.786155  2.159040  1.278741  1.840534
## [372]  2.808368  1.274183  2.849413  1.137242  1.789822  1.052520  1.730589
## [379]  1.095984  1.410704  1.642719  1.670780  2.314274  2.765181  2.862995
## [386]  1.936938  3.228872  4.026590  2.246342  4.242119  6.017047  5.018023
## [393]  1.248967  2.764050  5.065560  5.479310  1.726621  1.414456  5.840378
## [400]  4.025445  6.101832  2.740203  2.980478  3.774860  4.887307  2.821431
## [407]  1.356458  3.693166  4.717023  3.612367  5.268795  5.729019  5.932334
## [414]  4.086366  2.590465  2.790166  2.166807  1.848887  1.709835  1.626964
## [421]  2.885946  2.551578  3.523451  1.487712  2.466366  3.735509  1.302242
## [428]  3.436476  2.859908  5.106174  3.291686  1.447831  2.271709  1.927457
## [435]  2.752845  1.038676  4.800607  2.805797  1.735676  1.108016  1.330005
## [442]  1.959473  1.077989  1.629505  1.190357  1.393464  1.189142  2.010169
## [449]  1.431294  1.093760  1.302242  1.341255  3.011288  1.446715  1.232059
## [456]  1.263954  1.452701  1.018267  1.158788  1.455846  1.439917  5.080815
## [463]  1.600439  1.917365  1.856425  1.249170  1.114487  1.023015  1.267701
## [470]  1.215356  1.052520  2.942881  2.750687  2.063443  1.105084  2.139525
## [477]  1.939589  1.471778  1.125409  1.148571  2.293501  1.479592  4.005874
## [484]  1.041404  2.116644  1.038676  1.486697  3.062417  1.295455  2.079268
## [491]  2.527986  1.016650  1.536342  1.185499  1.092041  1.249170  2.007720
## [498]  1.072026  1.285831  3.418366  1.168905  1.531772  1.172750  1.005842
## 
## $threshold
## [1] 1
## 
## $p.less.thresh
## [1] 0.7996024
## 
## $n.exceed
## [1] 504
## 
## $method
## [1] "ml"
## 
## $par.ests
##        xi      beta 
## 0.1072777 1.0591719 
## 
## $par.ses
##         xi       beta 
## 0.05465781 0.07450330 
## 
## $varcov
##              [,1]         [,2]
## [1,]  0.002987476 -0.002914008
## [2,] -0.002914008  0.005550741
## 
## $information
## [1] "observed"
## 
## $converged
## [1] 0
## 
## $nllh.final
## [1] 587.0113
## 
## attr(,"class")
## [1] "gpd"
names(m4)
##  [1] "n"             "data"          "threshold"     "p.less.thresh"
##  [5] "n.exceed"      "method"        "par.ests"      "par.ses"      
##  [9] "varcov"        "information"   "converged"     "nllh.final"
par(mfcol=c(2,2))
#plot(m4)
riskmeasures(m4,c(.95,.99,.999))
##          p quantile     sfall
## [1,] 0.950 2.585569  3.962557
## [2,] 0.990 4.745063  6.381556
## [3,] 0.999 8.560890 10.655928
m5=gpd(xt,1.2)  ### Threshold 1.2%
riskmeasures(m5,c(.95,.99,.999))
##          p quantile     sfall
## [1,] 0.950 2.611388  3.960077
## [2,] 0.990 4.745530  6.266801
## [3,] 0.999 8.282208 10.089481
m6=gpd(xt,0.8)  ### Threshold 0.8%
riskmeasures(m6,c(.95,.99,.999))
##          p quantile     sfall
## [1,] 0.950 2.586713  3.961958
## [2,] 0.990 4.744087  6.375946
## [3,] 0.999 8.548816 10.633237