This is an R Markdown Notebook. When you execute code within the notebook, the results appear beneath the code.

Try executing this chunk by clicking the Run button within the chunk or by placing your cursor inside it and pressing Ctrl+Shift+Enter.

library(evir)
library(fExtremes)
library(fBasics)
library(quantmod)

getSymbols("SPY")
[1] "SPY"
spy_r <- dailyReturn(SPY)
head(spy_r,10)
           daily.returns
2007-01-03 -0.0061863269
2007-01-04  0.0021221123
2007-01-05 -0.0079763183
2007-01-08  0.0046250821
2007-01-09 -0.0008498831
2007-01-10  0.0033315799
2007-01-11  0.0043804651
2007-01-12  0.0075970805
2007-01-16 -0.0019547472
2007-01-17  0.0004196768
str(spy_r)
An ‘xts’ object on 2007-01-03/2021-05-11 containing:
  Data: num [1:3614, 1] -0.00619 0.00212 -0.00798 0.00463 -0.00085 ...
 - attr(*, "dimnames")=List of 2
  ..$ : NULL
  ..$ : chr "daily.returns"
  Indexed by objects of class: [Date] TZ: UTC
  xts Attributes:  
 NULL
library(evir)
library(fExtremes)
library(fBasics)
emplot(spy_r)
1632 x values <= 0 omitted from logarithmic plot

meplot(spy_r)

fit <- gpd(spy_r, threshold = NA, nextremes = 20)
fit
$n
[1] 3614

$data
 [1] 0.14519772 0.06007938 0.11685533 0.06233976 0.05394301 0.06929077
 [7] 0.04706549 0.05960941 0.07182899 0.04404100 0.04649921 0.04488379
[13] 0.05052487 0.04330651 0.05174489 0.08548630 0.05399206 0.09060326
[19] 0.05838980 0.06716621

$threshold
[1] 0.04319229

$p.less.thresh
[1] 0.994466

$n.exceed
[1] 20

$method
[1] "ml"

$par.ests
        xi       beta 
0.14710750 0.01965206 

$par.ses
         xi        beta 
0.292072320 0.007151105 

$varcov
             [,1]          [,2]
[1,]  0.085306240 -0.0015001063
[2,] -0.001500106  0.0000511383

$information
[1] "observed"

$converged
[1] 0

$nllh.final
[1] -55.64207

attr(,"class")
[1] "gpd"
plot(fit)

Make a plot selection (or 0 to exit): 

1: plot: Excess Distribution
2: plot: Tail of Underlying Distribution
3: plot: Scatterplot of Residuals
4: plot: QQplot of Residuals
1
[1] "threshold = 0.0432   xi = 0.147   scale = 0.0197   location = 0.0432"

Make a plot selection (or 0 to exit): 

1: plot: Excess Distribution
2: plot: Tail of Underlying Distribution
3: plot: Scatterplot of Residuals
4: plot: QQplot of Residuals
2

[1] "threshold = 0.0432   xi = 0.147   scale = 0.00915   location = -0.0282"

Make a plot selection (or 0 to exit): 

1: plot: Excess Distribution
2: plot: Tail of Underlying Distribution
3: plot: Scatterplot of Residuals
4: plot: QQplot of Residuals
3


Make a plot selection (or 0 to exit): 

1: plot: Excess Distribution
2: plot: Tail of Underlying Distribution
3: plot: Scatterplot of Residuals
4: plot: QQplot of Residuals
4


Make a plot selection (or 0 to exit): 

1: plot: Excess Distribution
2: plot: Tail of Underlying Distribution
3: plot: Scatterplot of Residuals
4: plot: QQplot of Residuals
0

tp <-  tailplot(fit)
gpd.q(tp,pp = .999, ci.p = .95)
  Lower CI   Estimate   Upper CI 
0.06643009 0.08142510 0.11556476 
quantile(spy_r, probs = .999)
     99.9% 
0.07711437 
gpd.sfall(tp, .99)
  Lower CI   Estimate   Upper CI 
0.05013747 0.05317739 0.21779658 



library(bcp)

out <- bcp(spy_r)
# summary.bcp(out)
plot(out)

LS0tDQp0aXRsZTogIlIgTm90ZWJvb2siDQpvdXRwdXQ6IGh0bWxfbm90ZWJvb2sNCi0tLQ0KDQpUaGlzIGlzIGFuIFtSIE1hcmtkb3duXShodHRwOi8vcm1hcmtkb3duLnJzdHVkaW8uY29tKSBOb3RlYm9vay4gV2hlbiB5b3UgZXhlY3V0ZSBjb2RlIHdpdGhpbiB0aGUgbm90ZWJvb2ssIHRoZSByZXN1bHRzIGFwcGVhciBiZW5lYXRoIHRoZSBjb2RlLg0KDQpUcnkgZXhlY3V0aW5nIHRoaXMgY2h1bmsgYnkgY2xpY2tpbmcgdGhlICpSdW4qIGJ1dHRvbiB3aXRoaW4gdGhlIGNodW5rIG9yIGJ5IHBsYWNpbmcgeW91ciBjdXJzb3IgaW5zaWRlIGl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