New upstream version 4021.83
Dirk Eddelbuettel
1 year, 8 months ago
0 | 0 | Package: fExtremes |
1 | 1 | Title: Rmetrics - Modelling Extreme Events in Finance |
2 | Date: 2017-11-12 | |
3 | Version: 3042.82 | |
4 | Author: Diethelm Wuertz [aut], | |
5 | Tobias Setz [cre], | |
6 | Yohan Chalabi [ctb] | |
7 | Maintainer: Tobias Setz <tobias.setz@live.com> | |
2 | Date: 2022-08-06 | |
3 | Version: 4021.83 | |
4 | Authors@R: c(person("Diethelm", "Wuertz", role = "aut") | |
5 | , person("Tobias", "Setz", role = "aut") | |
6 | , person("Yohan", "Chalabi", role = "aut") | |
7 | , person(given = c("Paul", "J."), family = "Northrop", | |
8 | role = c("cre", "ctb"), email = "p.northrop@ucl.ac.uk") ) | |
8 | 9 | Description: Provides functions for analysing |
9 | 10 | and modelling extreme events in financial time Series. The |
10 | 11 | topics include: (i) data pre-processing, (ii) explorative |
11 | 12 | data analysis, (iii) peak over threshold modelling, (iv) block |
12 | 13 | maxima modelling, (v) estimation of VaR and CVaR, and (vi) the |
13 | 14 | computation of the extreme index. |
14 | Depends: R (>= 2.15.1), timeDate, timeSeries, fBasics, fGarch | |
15 | Imports: methods, graphics, stats | |
15 | Depends: R (>= 2.15.1) | |
16 | Imports: fBasics, fGarch, graphics, methods, stats, timeDate, | |
17 | timeSeries | |
16 | 18 | Suggests: RUnit, tcltk |
17 | 19 | LazyData: yes |
18 | 20 | License: GPL (>= 2) |
19 | URL: http://www.rmetrics.org | |
21 | URL: https://www.rmetrics.org | |
22 | BugReports: https://r-forge.r-project.org/projects/rmetrics | |
20 | 23 | NeedsCompilation: no |
21 | Packaged: 2017-11-17 06:59:49 UTC; Tobias Setz | |
24 | Packaged: 2022-08-06 07:26:34 UTC; paul | |
25 | Author: Diethelm Wuertz [aut], | |
26 | Tobias Setz [aut], | |
27 | Yohan Chalabi [aut], | |
28 | Paul J. Northrop [cre, ctb] | |
29 | Maintainer: Paul J. Northrop <p.northrop@ucl.ac.uk> | |
22 | 30 | Repository: CRAN |
23 | Date/Publication: 2017-11-17 08:38:27 UTC | |
31 | Date/Publication: 2022-08-06 14:10:02 UTC |
0 | 0 | 8f23146c12b8b6957d6b2ddbc2ee30c3 *ChangeLog |
1 | 0ba152f26445dbe7cd65b4a2f60ad8da *DESCRIPTION | |
1 | 86bf4b368df08fff7262189df2ca5f2e *DESCRIPTION | |
2 | 2 | f4b3f22b776f1bfe7de2a986067df082 *NAMESPACE |
3 | b0496cc5388d91d3b6135eb66a1965d1 *R/DataPreprocessing.R | |
4 | 14d35601f9078cd7b60b3b0e83dbfa25 *R/ExtremeIndex.R | |
5 | 110122200f4fece7acd844e27248a8dc *R/ExtremesData.R | |
3 | 64db85d4ec6f74f05e0f3e5226079fae *NEWS.md | |
4 | c75a4e9fbabd7ccd62050c4b931f0e41 *R/DataPreprocessing.R | |
5 | 4288b214c0cfd8759f5fb92984e519cf *R/ExtremeIndex.R | |
6 | 90b0b96c0c47d0ebaddda5de70e06ecb *R/ExtremesData.R | |
6 | 7 | 6a13bc0742419999232390871e92d301 *R/GevDistribution.R |
7 | 8 | c31e7ed7d662bc6510ce3767599d58d3 *R/GevFit.R |
8 | 9 | 723138ddd14a272c6c6eb03cf4cca5de *R/GevMdaEstimation.R |
12 | 13 | 512ce05b3576ca3abedf8ca2dd55b4f2 *R/GpdDistribution.R |
13 | 14 | 7ec085102d4bf59dadf279a1ec57545e *R/GpdFit.R |
14 | 15 | c2de8f0daa283e46cded29f6752561b1 *R/GpdPlot.R |
15 | 4bdc9bdc1763fc063c768e5f73772218 *R/GpdRisk.R | |
16 | 99b148a01d755b9dc530fb6705cf884f *R/GpdRisk.R | |
16 | 17 | 1386d919c59b76dc9ec8ffab0eb3acc8 *R/GpdShow.R |
17 | 18 | b790b17afe8a9fc642263d9d226723c7 *R/GpdSim.R |
18 | 19 | 11aba9bc6b7051e535c17b1629559dc1 *R/GpdSow.R |
22 | 23 | 2717fc29227f4154e68b1baf36c2fe3c *R/meanExcessPlot.R |
23 | 24 | e3faa8aba12c0b0d6a1e64c39ff3095b *R/metrics.R |
24 | 25 | 1e141bc51586b3c49fea4c3627dd4034 *R/zzz.R |
26 | 140447df49241762b6153cf9722077f8 *README.md | |
25 | 27 | 1ee0fad00bab85f51ec7945e1d5ce861 *data/bmwRet.csv |
26 | 28 | 9666f10bfd745b92382bacc25f0a6e5f *data/danishClaims.csv |
27 | 29 | 6042b9c5e5bec3ecc1b6959cd2858b64 *inst/COPYRIGHT.html |
28 | 30 | e278deadbe366f8e25fb878bf5c05c7c *inst/unitTests/Makefile |
29 | 31 | ef6862244177aa0c9690e037b2823bbd *inst/unitTests/runTests.R |
30 | 32 | f0e530000f96bc971e3fb89a25272c17 *inst/unitTests/runit.DataPreprocessing.R |
31 | 3d8fa2217c7cdf803edc8cb3f531ad9c *inst/unitTests/runit.ExtremeIndex.R | |
32 | 5c4d0101ecf88db0530fd53f5c2f7b32 *inst/unitTests/runit.ExtremesData.R | |
33 | 85029d526149a5366b3967f8d50b06e7 *inst/unitTests/runit.ExtremeIndex.R | |
34 | ccfde54505edd42248e3b8220fd00c27 *inst/unitTests/runit.ExtremesData.R | |
33 | 35 | df54978979460d89018b2c7e8d9ed82e *inst/unitTests/runit.GevDistribution.R |
34 | 36 | aeed009908a914715e5d4947d8c4e098 *inst/unitTests/runit.GevMdaEstimation.R |
35 | 37 | 2cb05c2f27012611715b74e9daf89ba0 *inst/unitTests/runit.GevModelling.R |
37 | 39 | 9f0952a7794071690346f36d017c8c7f *inst/unitTests/runit.GpdDistribution.R |
38 | 40 | 9ccbeecb2cd8580869caac1b8dae64c6 *inst/unitTests/runit.GpdModelling.R |
39 | 41 | 69a26b861bd2d71074818864bd74029a *inst/unitTests/runit.GpdRisk.R |
40 | 63e7f709080902a953c5eafd95f4ec8b *man/00Extremes-package.Rd | |
41 | e6e5619fd05d40ead76567d3db8c6afc *man/DataPreprocessing.Rd | |
42 | 889ac9f50477b81bd1e5f26e54f08e47 *man/ExtremeIndex.Rd | |
43 | 053bd8de255d74a0c1dfd70121968a33 *man/ExtremesData.Rd | |
44 | 92957faa1992251453a248bca84052bc *man/GevDistribution.Rd | |
45 | 45054a04d74c5dc6bb8fe4d063716779 *man/GevMdaEstimation.Rd | |
46 | 2cb16bcd6748e1b232bde82f6dc7ae0a *man/GevModelling.Rd | |
47 | ba2f4fb3503eca13e674108cfe8634f3 *man/GevRisk.Rd | |
42 | 4dee6aa74016e1e9cb6b79e9388fd53a *man/00Extremes-package.Rd | |
43 | a345e9b2187113736f912e452d1cc036 *man/DataPreprocessing.Rd | |
44 | 6c9628e192a19805b0803b6719c37cd5 *man/ExtremeIndex.Rd | |
45 | 2a9d03b7c9439c4d79bb6ec87344f279 *man/ExtremesData.Rd | |
46 | 30f9c2985227e9b102f244885d2257f3 *man/GevDistribution.Rd | |
47 | ea3e15acda0d721fb5cfd6281f67d6c2 *man/GevMdaEstimation.Rd | |
48 | 3ee334becfa1b4fde8dbf240c2855a80 *man/GevModelling.Rd | |
49 | 99f29b46f5fbc2e854ba236eb570ca43 *man/GevRisk.Rd | |
48 | 50 | bf840a931840784b022298a7f530bc4c *man/GpdDistribution.Rd |
49 | ece6d6aaabd8a777f0ccce399af7c7aa *man/GpdModelling.Rd | |
50 | 1828c67556c2c7ebf111064d91126782 *man/GpdRisk.Rd | |
51 | 79605e94b04f8ac2e743bd30d4d44e58 *man/ValueAtRisk.Rd | |
52 | 246ce117b00d8707bef1634cb9768a5a *man/data.Rd | |
53 | ca566e590ec30abd0718c5375e1a446f *tests/doRUnit.R | |
51 | 267a78a6f044014c4f9c3d9ae8944fc5 *man/GpdModelling.Rd | |
52 | 13a7bca308c9370bbdc6e7e51cf046db *man/GpdRisk.Rd | |
53 | e7cc9d24a47e39163a2d9b04fdefa147 *man/ValueAtRisk.Rd | |
54 | c2fab3230bb9e5352ff5b284547ebb97 *man/data.Rd | |
55 | ab7ff992a1a19f94a9f6d2a69de573ff *tests/doRUnit.R |
0 | # fExtremes 4021.83 | |
1 | ||
2 | * New maintainer: Paul Northrop | |
3 | * Updated DESCRIPTION with links and moved timeDate, timeSeries, fBasics and fGarch from Depends: to Imports:. | |
4 | * Corrected some minor typos. | |
5 | * Added documentation in `TimeSeriesData` to describe the `bmwRet` and `danishClaims` datasets. | |
6 | ||
7 | # fExtremes 3042.82 and older versions | |
8 | ||
9 | See file ChangeLog on [the CRAN fExtremes page](https://CRAN.R-project.org/package=fExtremes) for changes before 4021.83. |
50 | 50 | # FUNCTION: |
51 | 51 | |
52 | 52 | # Check Type: |
53 | if (class(x) == "timeSeries") { | |
53 | if (inherits(x, "timeSeries")) { | |
54 | 54 | stopifnot(isUnivariate(x)) |
55 | 55 | } else { |
56 | 56 | x = as.vector(x) |
135 | 135 | # FUNCTION: |
136 | 136 | |
137 | 137 | # Check Type: |
138 | if (class(x) == "timeSeries") { | |
138 | if (inherits(x, "timeSeries")) { | |
139 | 139 | stopifnot(isUnivariate(x)) |
140 | 140 | } else { |
141 | 141 | x = as.vector(x) |
23 | 23 | # blockTheta Computes theta from Block Method |
24 | 24 | # clusterTheta Computes theta from Reciprocal Cluster Method |
25 | 25 | # runTheta Computes theta from Run Method |
26 | # ferrosegersTheta Computes Theta according to Ferro and Seegers | |
26 | # ferrosegersTheta Computes Theta according to Ferro and Segers | |
27 | 27 | # FUNCTION: DESCRIPTION: |
28 | 28 | # exindexesPlot Computes and Plot Theta(1,2,3) |
29 | 29 | # exindexPlot Computes Theta(1,2) and Plot Theta(1) |
156 | 156 | keepK = keepN = NULL |
157 | 157 | for ( u in thresholds ) { |
158 | 158 | run = run + 1 |
159 | # N # of exceedences | K # of blocks with exceedences: | |
159 | # N # of exceedances | K # of blocks with exceedances: | |
160 | 160 | N = length(X[X > u]) |
161 | 161 | K = floor(sum(sign(apply(X, 1, max) - u) + 1) / 2) |
162 | 162 | if (K/k < 1) { |
228 | 228 | keepK = keepN = NULL |
229 | 229 | for ( u in thresholds ) { |
230 | 230 | run = run + 1 |
231 | # N # of exceedences | K # of blocks with exceedences: | |
231 | # N # of exceedances | K # of blocks with exceedances: | |
232 | 232 | N = length(X[X > u]) |
233 | 233 | K = floor(sum(sign(apply(X, 1, max) - u) + 1) / 2) |
234 | 234 | theta2[run] = K/N |
298 | 298 | keepN = NULL |
299 | 299 | for ( u in thresholds ) { |
300 | 300 | run = run + 1 |
301 | # N # of exceedences | K # of blocks with exceedences: | |
301 | # N # of exceedances | K # of blocks with exceedances: | |
302 | 302 | N = length(X[X > u]) |
303 | 303 | Y = diff(Count[X > u]) |
304 | 304 | Y = Y[Y > block] |
471 | 471 | run = 0 |
472 | 472 | for ( z in z0 ) { |
473 | 473 | run = run + 1 |
474 | # N - number of exceedences: | |
474 | # N - number of exceedances: | |
475 | 475 | N = length(resid1[resid1 > z]) |
476 | # K - number of blocks with exceedences: | |
476 | # K - number of blocks with exceedances: | |
477 | 477 | # DW: floor() |
478 | 478 | K = floor(sum(sign(apply(resid1, 1, max)-z)+1) / 2) |
479 | 479 | if (K/k < 1) { |
26 | 26 | # msratioPlot Plots ratio of maximums and sums |
27 | 27 | # sllnPlot Verifies Kolmogorov's Strong Law of large numbers |
28 | 28 | # lilPlot Verifies Hartman-Wintner's Law of the iterated logarithm |
29 | # xacfPlot Plots autocorrelations of exceedences | |
29 | # xacfPlot Plots autocorrelations of exceedances | |
30 | 30 | ################################################################################ |
31 | 31 | |
32 | 32 | |
720 | 720 | { # A function implemented by Diethelm Wuertz |
721 | 721 | |
722 | 722 | # Description: |
723 | # Creates plots of exceedences, one for the | |
723 | # Creates plots of exceedances, one for the | |
724 | 724 | # heights and one for the distances. |
725 | 725 | |
726 | 726 | # Arguments: |
166 | 166 | # if (q < x$plotmax) abline(v = q, lty = 2) |
167 | 167 | out = as.numeric(q) |
168 | 168 | if (ci.type == "wald") { |
169 | if (class(x$lastfit) != "gpd") | |
169 | if (!inherits(x$lastfit, "gpd")) | |
170 | 170 | stop("Wald method requires model be fitted with gpd (not pot)") |
171 | 171 | scaling = threshold |
172 | 172 | betahat = betahat/scaling |
861 | 861 | abline(v = u, lty = 3, col = "red") |
862 | 862 | abline(v = U, lty = 3, col = "red") |
863 | 863 | |
864 | # Fit line to mean excess within thresolds: | |
864 | # Fit line to mean excess within thresholds: | |
865 | 865 | X = as.vector(ans[, 1]) |
866 | 866 | Y = as.vector(ans[, 2]) |
867 | 867 | Y = Y[X > u & X < U] |
0 | ||
1 | <!-- README.md is generated from README.Rmd. Please edit that file --> | |
2 | ||
3 | # fExtremes | |
4 | ||
5 | [![AppVeyor Build | |
6 | Status](https://ci.appveyor.com/api/projects/status/github/paulnorthrop/fExtremes?branch=main&svg=true)](https://ci.appveyor.com/project/paulnorthrop/fExtremes) | |
7 | [![R-CMD-check](https://github.com/paulnorthrop/fExtremes/workflows/R-CMD-check/badge.svg)](https://github.com/paulnorthrop/fExtremes/actions) | |
8 | [![Coverage | |
9 | Status](https://codecov.io/github/paulnorthrop/fExtremes/coverage.svg?branch=main)](https://codecov.io/github/paulnorthrop/fExtremes?branch=main) | |
10 | [![CRAN_Status_Badge](https://www.r-pkg.org/badges/version/fExtremes)](https://cran.r-project.org/package=fExtremes) | |
11 | [![Downloads | |
12 | (monthly)](https://cranlogs.r-pkg.org/badges/fExtremes?color=brightgreen)](https://cran.r-project.org/package=fExtremes) | |
13 | [![Downloads | |
14 | (total)](https://cranlogs.r-pkg.org/badges/grand-total/fExtremes?color=brightgreen)](https://cran.r-project.org/package=fExtremes) | |
15 | ||
16 | ## Rmetrics - Modelling Extreme Events in Finance | |
17 | ||
18 | The **fExtremes** package provides functions for analysing and modelling | |
19 | extreme events in financial time Series. The topics include: (i) data | |
20 | pre-processing, (ii) explorative data analysis, (iii) peak over | |
21 | threshold modelling, (iv) block maxima modelling, (v) estimation of VaR | |
22 | and CVaR, and (vi) the computation of the extreme index. It is part of | |
23 | the [Rmetrics software project](https://www.rmetrics.org/). | |
24 | ||
25 | ### An example | |
26 | ||
27 | The following code simulates data from a GEV distribution, fits a GEV | |
28 | distribution to these data and creates model diagnostic plots. | |
29 | ||
30 | ``` r | |
31 | library(fExtremes) | |
32 | # Simulate GEV Data, use default length n=1000 | |
33 | x <- gevSim(model = list(xi = 0.25, mu = 0 , beta = 1), n = 1000) | |
34 | ||
35 | # Fit GEV data using maximum likelihood estimation | |
36 | fit <- gevFit(x, type = "mle") | |
37 | fit | |
38 | #> | |
39 | #> Title: | |
40 | #> GEV Parameter Estimation | |
41 | #> | |
42 | #> Call: | |
43 | #> gevFit(x = x, type = "mle") | |
44 | #> | |
45 | #> Estimation Type: | |
46 | #> gev mle | |
47 | #> | |
48 | #> Estimated Parameters: | |
49 | #> xi mu beta | |
50 | #> 0.18304217 0.04548892 0.99014748 | |
51 | #> | |
52 | #> Description | |
53 | #> Fri Aug 5 17:30:44 2022 | |
54 | ``` | |
55 | ||
56 | ### Installation | |
57 | ||
58 | To get the current released version from CRAN: | |
59 | ||
60 | ``` r | |
61 | install.packages("fExtremes") | |
62 | ``` |
35 | 35 | # blockTheta Computes theta from Block Method |
36 | 36 | # clusterTheta Computes theta from Reciprocal Cluster Method |
37 | 37 | # runTheta Computes theta from Run Method |
38 | # ferrosegersTheta Computes Theta according to Ferro and Seegers | |
38 | # ferrosegersTheta Computes Theta according to Ferro and Segers | |
39 | 39 | # FUNCTION: DESCRIPTION: |
40 | 40 | # exindexesPlot Computes and Plot Theta(1,2,3) |
41 | 41 | # exindexPlot Computes Theta(1,2) and Plot Theta(1) |
38 | 38 | # msratioPlot Plots ratio of maximums and sums |
39 | 39 | # sllnPlot Verifies Kolmogorov's Strong Law of large numbers |
40 | 40 | # lilPlot Verifies Hartman-Wintner's Law of the iterated logarithm |
41 | # xacfPlot Plots autocorrelations of exceedences | |
41 | # xacfPlot Plots autocorrelations of exceedances | |
42 | 42 | ################################################################################ |
43 | 43 | |
44 | 44 | |
260 | 260 | test.xacf = |
261 | 261 | function() |
262 | 262 | { |
263 | # xacfPlot - Plots autocorrelations of exceedences | |
263 | # xacfPlot - Plots autocorrelations of exceedances | |
264 | 264 | |
265 | 265 | # Create an Artificial Data Set: |
266 | 266 | RNGkind(kind = "Marsaglia-Multicarry", normal.kind = "Inversion") |
0 | \name{fExtremes-package} | |
1 | ||
2 | ||
3 | \alias{fExtremes-package} | |
4 | \alias{fExtremes} | |
5 | ||
6 | ||
7 | \docType{package} | |
8 | ||
9 | ||
10 | \title{Modelling Extreme Events in Finance} | |
11 | ||
12 | ||
13 | \description{ | |
14 | ||
15 | The Rmetrics "fExtemes" package is a collection of functions to | |
16 | analyze and model extreme events in Finance and Insurance. | |
17 | ||
18 | } | |
19 | ||
20 | ||
21 | \details{ | |
22 | ||
23 | \preformatted{ | |
24 | Package: \tab fExtremes\cr | |
25 | Type: \tab Package\cr | |
26 | %Version: \tab R 3.0.1\cr | |
27 | %Date: \tab 2014\cr | |
28 | License: \tab GPL Version 2 or later\cr | |
29 | Copyright: \tab (c) 1999-2014 Rmetrics Assiciation\cr | |
30 | URL: \tab \url{https://www.rmetrics.org} | |
31 | } | |
32 | ||
33 | } | |
34 | ||
35 | ||
36 | \section{1 Introduction}{ | |
37 | ||
38 | The \code{fExtremes} package provides functions for analyzing | |
39 | and modeling extreme events in financial time Series. The | |
40 | topics include: (i) data proeprocessing, (ii) explorative | |
41 | data analysis, (iii) peak over threshold modeling, (iv) block | |
42 | maxima modeling, (v) estimation of VaR and CVaR, and (vi) the | |
43 | computation of the extreme index. | |
44 | ||
45 | } | |
46 | ||
47 | ||
48 | \section{2 Data and their Preprocessing}{ | |
49 | ||
50 | \emph{Data Sets:} | |
51 | ||
52 | Data sets used in the examples of the timeSeries packages. | |
53 | ||
54 | \emph{Data Preprocessing:} | |
55 | ||
56 | These are tools for data preprocessing, including functions to | |
57 | separate data beyond a threshold value, to compute blockwise data | |
58 | like block maxima, and to decluster point process data. | |
59 | ||
60 | \preformatted{ | |
61 | blockMaxima extracts block maxima from a vector or a time series | |
62 | findThreshold finds upper threshold for a given number of extremes | |
63 | pointProcess extracts peaks over Threshold from a vector or a time series | |
64 | deCluster de-clusters clustered point process data | |
65 | } | |
66 | ||
67 | } | |
68 | ||
69 | ||
70 | \section{2 Explorative Data Analysis of Extremes}{ | |
71 | ||
72 | This section contains a collection of functions for explorative data | |
73 | analysis of extreme values in financial time series. The tools include | |
74 | plot functions for emprical distributions, quantile plots, graphs | |
75 | exploring the properties of exceedences over a threshold, plots for | |
76 | mean/sum ratio and for the development of records. The functions are: | |
77 | ||
78 | \preformatted{ | |
79 | emdPlot plots of empirical distribution function | |
80 | qqparetoPlot exponential/Pareto quantile plot | |
81 | mePlot plot of mean excesses over a threshold | |
82 | mrlPlot another variant, mean residual life plot | |
83 | mxfPlot another variant, with confidence intervals | |
84 | msratioPlot plot of the ratio of maximum and sum | |
85 | } | |
86 | ||
87 | \preformatted{ | |
88 | recordsPlot Record development compared with iid data | |
89 | ssrecordsPlot another variant, investigates subsamples | |
90 | sllnPlot verifies Kolmogorov's strong law of large numbers | |
91 | lilPlot verifies Hartman-Wintner's law of the iterated logarithm | |
92 | } | |
93 | ||
94 | \preformatted{ | |
95 | xacfPlot plots ACF of exceedences over a threshold | |
96 | } | |
97 | ||
98 | ||
99 | \emph{Parameter Fitting of Mean Excesses:} | |
100 | ||
101 | \preformatted{ | |
102 | normMeanExcessFit fits mean excesses with a normal density | |
103 | ghMeanExcessFit fits mean excesses with a GH density | |
104 | hypMeanExcessFit fits mean excesses with a HYP density | |
105 | nigMeanExcessFit fits mean excesses with a NIG density | |
106 | ghtMeanExcessFit fits mean excesses with a GHT density | |
107 | } | |
108 | ||
109 | } | |
110 | ||
111 | ||
112 | \section{3 GPD Peak over Threshold Modeling}{ | |
113 | ||
114 | \emph{GPD Distribution:} | |
115 | ||
116 | A collection of functions to compute the generalized Pareto | |
117 | distribution. The functions compute density, distribution | |
118 | function, quantile function and generate random deviates | |
119 | for the GPD. In addition functions to compute the true | |
120 | moments and to display the distribution and random variates | |
121 | changing parameters interactively are available. | |
122 | ||
123 | \preformatted{ | |
124 | dgpd returns the density of the GPD distribution | |
125 | pgpd returns the probability function of the GPD | |
126 | qgpd returns quantile function of the GPD distribution | |
127 | rgpd generates random variates from the GPD distribution | |
128 | gpdSlider displays density or rvs from a GPD | |
129 | } | |
130 | ||
131 | ||
132 | \emph{GPD Moments:} | |
133 | ||
134 | \preformatted{ | |
135 | gpdMoments computes true mean and variance of GDP | |
136 | } | |
137 | ||
138 | ||
139 | \emph{GPD Parameter Estimation:} | |
140 | ||
141 | This section contains functions to fit and to simulate processes that | |
142 | are generated from the generalized Pareto distribution. Two | |
143 | approaches for parameter estimation are provided: Maximum likelihood | |
144 | estimation and the probability weighted moment method. | |
145 | ||
146 | \preformatted{ | |
147 | gpdSim generates data from the GPD distribution | |
148 | gpdFit fits data to the GPD istribution | |
149 | } | |
150 | ||
151 | ||
152 | \emph{GPD print, plot and summary methods:} | |
153 | ||
154 | \preformatted{ | |
155 | print print method for a fitted GPD object | |
156 | plot plot method for a fitted GPD object | |
157 | summary summary method for a fitted GPD object | |
158 | } | |
159 | ||
160 | ||
161 | \emph{GDP Tail Risk:} | |
162 | ||
163 | The following functions compute tail risk under the GPD approach. | |
164 | ||
165 | \preformatted{ | |
166 | gpdQPlot estimation of high quantiles | |
167 | gpdQuantPlot variation of high quantiles with threshold | |
168 | gpdRiskMeasures prescribed quantiles and expected shortfalls | |
169 | gpdSfallPlot expected shortfall with confidence intervals | |
170 | gpdShapePlot variation of GPD shape with threshold | |
171 | gpdTailPlot plot of the GPD tail | |
172 | } | |
173 | ||
174 | % \preformatted{ | |
175 | % tailPlot | |
176 | % tailSlider | |
177 | % tailRisk | |
178 | % } | |
179 | ||
180 | } | |
181 | ||
182 | ||
183 | \section{4 GEV Block Maxima Modeling}{ | |
184 | ||
185 | \emph{GEV Distribution:} | |
186 | ||
187 | This section contains functions to fit and to simulate processes | |
188 | that are generated from the generalized extreme value distribution | |
189 | including the Frechet, Gumbel, and Weibull distributions. | |
190 | ||
191 | \preformatted{ | |
192 | dgev returns density of the GEV distribution | |
193 | pgev returns probability function of the GEV | |
194 | qgev returns quantile function of the GEV distribution | |
195 | rgev generates random variates from the GEV distribution | |
196 | gevSlider displays density or rvs from a GEV | |
197 | } | |
198 | ||
199 | ||
200 | \emph{GEV Moments:} | |
201 | ||
202 | \preformatted{ | |
203 | gevMoments computes true mean and variance | |
204 | } | |
205 | ||
206 | ||
207 | \emph{GEV Parameter Estimation:} | |
208 | ||
209 | ||
210 | A collection to simulate and to estimate the parameters of | |
211 | processes generated from GEV distribution. | |
212 | ||
213 | \preformatted{ | |
214 | gevSim generates data from the GEV distribution | |
215 | gumbelSim generates data from the Gumbel distribution | |
216 | gevFit fits data to the GEV distribution | |
217 | gumbelFit fits data to the Gumbel distribution | |
218 | } | |
219 | ||
220 | \preformatted{ | |
221 | print print method for a fitted GEV object | |
222 | plot plot method for a fitted GEV object | |
223 | summary summary method for a fitted GEV object | |
224 | } | |
225 | ||
226 | ||
227 | \emph{GEV MDA Estimation:} | |
228 | ||
229 | Here we provide Maximum Domain of Attraction estimators and visualize | |
230 | the results by a Hill plot and a common shape parameter plot from | |
231 | the Pickands, Einmal-Decker-deHaan, and Hill estimators. | |
232 | ||
233 | \preformatted{ | |
234 | hillPlot shape parameter and Hill estimate of the tail index | |
235 | shaparmPlot variation of shape parameter with tail depth | |
236 | } | |
237 | ||
238 | ||
239 | \emph{GEV Risk Estimation:} | |
240 | ||
241 | \preformatted{ | |
242 | gevrlevelPlot k-block return level with confidence intervals | |
243 | } | |
244 | ||
245 | } | |
246 | ||
247 | ||
248 | \section{4 Value at Risk}{ | |
249 | ||
250 | Two functions to compute Value-at-Risk and conditional | |
251 | Value-at-Risk. | |
252 | ||
253 | \preformatted{ | |
254 | VaR computes Value-at-Risk | |
255 | CVaR computes conditional Value-at-Risk | |
256 | } | |
257 | ||
258 | } | |
259 | ||
260 | ||
261 | \section{5 Extreme Index}{ | |
262 | ||
263 | A collection of functions to simulate time series with a known extremal | |
264 | index, and to estimate the extremal index by four different kind of | |
265 | methods, the blocks method, the reciprocal mean cluster size method, | |
266 | the runs method, and the method of Ferro and Segers. | |
267 | ||
268 | \preformatted{ | |
269 | thetaSim simulates a time Series with known theta | |
270 | blockTheta computes theta from Block Method | |
271 | clusterTheta computes theta from Reciprocal Cluster Method | |
272 | runTheta computes theta from Run Method | |
273 | ferrosegersTheta computes theta according to Ferro and Seegers | |
274 | } | |
275 | ||
276 | \preformatted{ | |
277 | exindexPlot calculatess and plots Theta(1,2,3) | |
278 | exindexesPlot calculates Theta(1,2) and plots Theta(1) | |
279 | } | |
280 | ||
281 | } | |
282 | ||
283 | ||
284 | \section{About Rmetrics}{ | |
285 | ||
286 | The \code{fExtremes} Rmetrics package is written for educational | |
287 | support in teaching "Computational Finance and Financial Engineering" | |
288 | and licensed under the GPL. | |
289 | ||
290 | } | |
291 | ||
292 | ||
293 | \keyword{package} | |
294 | ||
295 | ||
0 | \name{fExtremes-package} | |
1 | ||
2 | ||
3 | \alias{fExtremes-package} | |
4 | \alias{fExtremes} | |
5 | ||
6 | ||
7 | \docType{package} | |
8 | ||
9 | ||
10 | \title{Modelling Extreme Events in Finance} | |
11 | ||
12 | ||
13 | \description{ | |
14 | ||
15 | The Rmetrics "fExtremes" package is a collection of functions to | |
16 | analyze and model extreme events in Finance and Insurance. | |
17 | ||
18 | } | |
19 | ||
20 | ||
21 | \details{ | |
22 | ||
23 | \preformatted{ | |
24 | Package: \tab fExtremes\cr | |
25 | Type: \tab Package\cr | |
26 | %Version: \tab R 3.0.1\cr | |
27 | %Date: \tab 2014\cr | |
28 | License: \tab GPL Version 2 or later\cr | |
29 | Copyright: \tab (c) 1999-2014 Rmetrics Assiciation\cr | |
30 | URL: \tab \url{https://www.rmetrics.org} | |
31 | } | |
32 | ||
33 | } | |
34 | ||
35 | ||
36 | \section{1 Introduction}{ | |
37 | ||
38 | The \code{fExtremes} package provides functions for analyzing | |
39 | and modeling extreme events in financial time Series. The | |
40 | topics include: (i) data pre-processing, (ii) explorative | |
41 | data analysis, (iii) peak over threshold modeling, (iv) block | |
42 | maxima modeling, (v) estimation of VaR and CVaR, and (vi) the | |
43 | computation of the extreme index. | |
44 | ||
45 | } | |
46 | ||
47 | ||
48 | \section{2 Data and their Preprocessing}{ | |
49 | ||
50 | \emph{Data Sets:} | |
51 | ||
52 | Data sets used in the examples of the timeSeries packages. | |
53 | ||
54 | \emph{Data Preprocessing:} | |
55 | ||
56 | These are tools for data preprocessing, including functions to | |
57 | separate data beyond a threshold value, to compute blockwise data | |
58 | like block maxima, and to decluster point process data. | |
59 | ||
60 | \preformatted{ | |
61 | blockMaxima extracts block maxima from a vector or a time series | |
62 | findThreshold finds upper threshold for a given number of extremes | |
63 | pointProcess extracts peaks over Threshold from a vector or a time series | |
64 | deCluster de-clusters clustered point process data | |
65 | } | |
66 | ||
67 | } | |
68 | ||
69 | ||
70 | \section{2 Explorative Data Analysis of Extremes}{ | |
71 | ||
72 | This section contains a collection of functions for explorative data | |
73 | analysis of extreme values in financial time series. The tools include | |
74 | plot functions for emprical distributions, quantile plots, graphs | |
75 | exploring the properties of exceedances over a threshold, plots for | |
76 | mean/sum ratio and for the development of records. The functions are: | |
77 | ||
78 | \preformatted{ | |
79 | emdPlot plots of empirical distribution function | |
80 | qqparetoPlot exponential/Pareto quantile plot | |
81 | mePlot plot of mean excesses over a threshold | |
82 | mrlPlot another variant, mean residual life plot | |
83 | mxfPlot another variant, with confidence intervals | |
84 | msratioPlot plot of the ratio of maximum and sum | |
85 | } | |
86 | ||
87 | \preformatted{ | |
88 | recordsPlot Record development compared with iid data | |
89 | ssrecordsPlot another variant, investigates subsamples | |
90 | sllnPlot verifies Kolmogorov's strong law of large numbers | |
91 | lilPlot verifies Hartman-Wintner's law of the iterated logarithm | |
92 | } | |
93 | ||
94 | \preformatted{ | |
95 | xacfPlot plots ACF of exceedances over a threshold | |
96 | } | |
97 | ||
98 | ||
99 | \emph{Parameter Fitting of Mean Excesses:} | |
100 | ||
101 | \preformatted{ | |
102 | normMeanExcessFit fits mean excesses with a normal density | |
103 | ghMeanExcessFit fits mean excesses with a GH density | |
104 | hypMeanExcessFit fits mean excesses with a HYP density | |
105 | nigMeanExcessFit fits mean excesses with a NIG density | |
106 | ghtMeanExcessFit fits mean excesses with a GHT density | |
107 | } | |
108 | ||
109 | } | |
110 | ||
111 | ||
112 | \section{3 GPD Peak over Threshold Modeling}{ | |
113 | ||
114 | \emph{GPD Distribution:} | |
115 | ||
116 | A collection of functions to compute the generalized Pareto | |
117 | distribution. The functions compute density, distribution | |
118 | function, quantile function and generate random deviates | |
119 | for the GPD. In addition functions to compute the true | |
120 | moments and to display the distribution and random variates | |
121 | changing parameters interactively are available. | |
122 | ||
123 | \preformatted{ | |
124 | dgpd returns the density of the GPD distribution | |
125 | pgpd returns the probability function of the GPD | |
126 | qgpd returns quantile function of the GPD distribution | |
127 | rgpd generates random variates from the GPD distribution | |
128 | gpdSlider displays density or rvs from a GPD | |
129 | } | |
130 | ||
131 | ||
132 | \emph{GPD Moments:} | |
133 | ||
134 | \preformatted{ | |
135 | gpdMoments computes true mean and variance of GDP | |
136 | } | |
137 | ||
138 | ||
139 | \emph{GPD Parameter Estimation:} | |
140 | ||
141 | This section contains functions to fit and to simulate processes that | |
142 | are generated from the generalized Pareto distribution. Two | |
143 | approaches for parameter estimation are provided: Maximum likelihood | |
144 | estimation and the probability weighted moment method. | |
145 | ||
146 | \preformatted{ | |
147 | gpdSim generates data from the GPD distribution | |
148 | gpdFit fits data to the GPD istribution | |
149 | } | |
150 | ||
151 | ||
152 | \emph{GPD print, plot and summary methods:} | |
153 | ||
154 | \preformatted{ | |
155 | print print method for a fitted GPD object | |
156 | plot plot method for a fitted GPD object | |
157 | summary summary method for a fitted GPD object | |
158 | } | |
159 | ||
160 | ||
161 | \emph{GDP Tail Risk:} | |
162 | ||
163 | The following functions compute tail risk under the GPD approach. | |
164 | ||
165 | \preformatted{ | |
166 | gpdQPlot estimation of high quantiles | |
167 | gpdQuantPlot variation of high quantiles with threshold | |
168 | gpdRiskMeasures prescribed quantiles and expected shortfalls | |
169 | gpdSfallPlot expected shortfall with confidence intervals | |
170 | gpdShapePlot variation of GPD shape with threshold | |
171 | gpdTailPlot plot of the GPD tail | |
172 | } | |
173 | ||
174 | % \preformatted{ | |
175 | % tailPlot | |
176 | % tailSlider | |
177 | % tailRisk | |
178 | % } | |
179 | ||
180 | } | |
181 | ||
182 | ||
183 | \section{4 GEV Block Maxima Modeling}{ | |
184 | ||
185 | \emph{GEV Distribution:} | |
186 | ||
187 | This section contains functions to fit and to simulate processes | |
188 | that are generated from the generalized extreme value distribution | |
189 | including the Frechet, Gumbel, and Weibull distributions. | |
190 | ||
191 | \preformatted{ | |
192 | dgev returns density of the GEV distribution | |
193 | pgev returns probability function of the GEV | |
194 | qgev returns quantile function of the GEV distribution | |
195 | rgev generates random variates from the GEV distribution | |
196 | gevSlider displays density or rvs from a GEV | |
197 | } | |
198 | ||
199 | ||
200 | \emph{GEV Moments:} | |
201 | ||
202 | \preformatted{ | |
203 | gevMoments computes true mean and variance | |
204 | } | |
205 | ||
206 | ||
207 | \emph{GEV Parameter Estimation:} | |
208 | ||
209 | ||
210 | A collection to simulate and to estimate the parameters of | |
211 | processes generated from GEV distribution. | |
212 | ||
213 | \preformatted{ | |
214 | gevSim generates data from the GEV distribution | |
215 | gumbelSim generates data from the Gumbel distribution | |
216 | gevFit fits data to the GEV distribution | |
217 | gumbelFit fits data to the Gumbel distribution | |
218 | } | |
219 | ||
220 | \preformatted{ | |
221 | print print method for a fitted GEV object | |
222 | plot plot method for a fitted GEV object | |
223 | summary summary method for a fitted GEV object | |
224 | } | |
225 | ||
226 | ||
227 | \emph{GEV MDA Estimation:} | |
228 | ||
229 | Here we provide Maximum Domain of Attraction estimators and visualize | |
230 | the results by a Hill plot and a common shape parameter plot from | |
231 | the Pickands, Einmal-Decker-deHaan, and Hill estimators. | |
232 | ||
233 | \preformatted{ | |
234 | hillPlot shape parameter and Hill estimate of the tail index | |
235 | shaparmPlot variation of shape parameter with tail depth | |
236 | } | |
237 | ||
238 | ||
239 | \emph{GEV Risk Estimation:} | |
240 | ||
241 | \preformatted{ | |
242 | gevrlevelPlot k-block return level with confidence intervals | |
243 | } | |
244 | ||
245 | } | |
246 | ||
247 | ||
248 | \section{4 Value at Risk}{ | |
249 | ||
250 | Two functions to compute Value-at-Risk and conditional | |
251 | Value-at-Risk. | |
252 | ||
253 | \preformatted{ | |
254 | VaR computes Value-at-Risk | |
255 | CVaR computes conditional Value-at-Risk | |
256 | } | |
257 | ||
258 | } | |
259 | ||
260 | ||
261 | \section{5 Extreme Index}{ | |
262 | ||
263 | A collection of functions to simulate time series with a known extremal | |
264 | index, and to estimate the extremal index by four different kind of | |
265 | methods, the blocks method, the reciprocal mean cluster size method, | |
266 | the runs method, and the method of Ferro and Segers. | |
267 | ||
268 | \preformatted{ | |
269 | thetaSim simulates a time Series with known theta | |
270 | blockTheta computes theta from Block Method | |
271 | clusterTheta computes theta from Reciprocal Cluster Method | |
272 | runTheta computes theta from Run Method | |
273 | ferrosegersTheta computes theta according to Ferro and Segers | |
274 | } | |
275 | ||
276 | \preformatted{ | |
277 | exindexPlot calculatess and plots Theta(1,2,3) | |
278 | exindexesPlot calculates Theta(1,2) and plots Theta(1) | |
279 | } | |
280 | ||
281 | } | |
282 | ||
283 | ||
284 | \section{About Rmetrics}{ | |
285 | ||
286 | The \code{fExtremes} Rmetrics package is written for educational | |
287 | support in teaching "Computational Finance and Financial Engineering" | |
288 | and licensed under the GPL. | |
289 | ||
290 | } | |
291 | ||
292 | ||
293 | \keyword{package} | |
294 | ||
295 |
0 | \name{DataPreprocessing} | |
1 | ||
2 | \alias{DataPreprocessing} | |
3 | ||
4 | \alias{blockMaxima} | |
5 | \alias{findThreshold} | |
6 | \alias{pointProcess} | |
7 | \alias{deCluster} | |
8 | ||
9 | ||
10 | \title{Extremes Data Preprocessing} | |
11 | ||
12 | ||
13 | \description{ | |
14 | ||
15 | A collection and description of functions for data | |
16 | preprocessing of extreme values. This includes tools | |
17 | to separate data beyond a threshold value, to compute | |
18 | blockwise data like block maxima, and to decluster | |
19 | point process data. | |
20 | \cr | |
21 | ||
22 | The functions are: | |
23 | ||
24 | \tabular{ll}{ | |
25 | \code{blockMaxima} \tab Block Maxima from a vector or a time series, \cr | |
26 | \code{findThreshold} \tab Upper threshold for a given number of extremes, \cr | |
27 | \code{pointProcess} \tab Peaks over Threshold from a vector or a time series, \cr | |
28 | \code{deCluster} \tab Declusters clustered point process data. } | |
29 | ||
30 | } | |
31 | ||
32 | ||
33 | \usage{ | |
34 | blockMaxima(x, block = c("monthly", "quarterly"), doplot = FALSE) | |
35 | findThreshold(x, n = floor(0.05*length(as.vector(x))), doplot = FALSE) | |
36 | pointProcess(x, u = quantile(x, 0.95), doplot = FALSE) | |
37 | deCluster(x, run = 20, doplot = TRUE) | |
38 | } | |
39 | ||
40 | ||
41 | \arguments{ | |
42 | ||
43 | \item{block}{ | |
44 | the block size. A numeric value is interpreted as the number | |
45 | of data values in each successive block. All the data is used, | |
46 | so the last block may not contain \code{block} observations. | |
47 | If the \code{data} has a \code{times} attribute containing (in | |
48 | an object of class \code{"POSIXct"}, or an object that can be | |
49 | converted to that class, see \code{\link{as.POSIXct}}) the | |
50 | times/dates of each observation, then \code{block} may instead | |
51 | take the character values \code{"month"}, \code{"quarter"}, | |
52 | \code{"semester"} or \code{"year"}. By default monthly blocks | |
53 | from daily data are assumed. | |
54 | } | |
55 | \item{doplot}{ | |
56 | a logical value. Should the results be plotted? By | |
57 | default \code{TRUE}. | |
58 | } | |
59 | \item{n}{ | |
60 | a numeric value or vector giving number of extremes above | |
61 | the threshold. By default, \code{n} is | |
62 | set to an integer representing 5\% of the data from the | |
63 | whole data set \code{x}. | |
64 | } | |
65 | \item{run}{ | |
66 | parameter to be used in the runs method; any two consecutive | |
67 | threshold exceedances separated by more than this number of | |
68 | observations/days are considered to belong to different clusters. | |
69 | } | |
70 | \item{u}{ | |
71 | a numeric value at which level the data are to be truncated. By | |
72 | default the threshold value which belongs to the 95\% quantile, | |
73 | \code{u=quantile(x,0.95)}. | |
74 | } | |
75 | \item{x}{ | |
76 | a numeric data vector from which \code{findThreshold} and | |
77 | \code{blockMaxima} determine the threshold values and block | |
78 | maxima values. | |
79 | For the function \code{deCluster} the argument | |
80 | \code{x} represents a numeric vector of threshold exceedances | |
81 | with a \code{times} attribute which should be a numeric | |
82 | vector containing either the indices or the times/dates | |
83 | of each exceedance (if times/dates, the attribute should | |
84 | be an object of class \code{"POSIXct"} or an object that | |
85 | can be converted to that class; see \code{\link{as.POSIXct}}). | |
86 | } | |
87 | ||
88 | } | |
89 | ||
90 | ||
91 | \details{ | |
92 | ||
93 | \bold{Computing Block Maxima:} | |
94 | \cr\cr | |
95 | The function \code{blockMaxima} calculates block maxima from a vector | |
96 | or a time series, whereas the function | |
97 | \code{blocks} is more general and allows for the calculation of | |
98 | an arbitrary function \code{FUN} on blocks. | |
99 | \cr | |
100 | ||
101 | ||
102 | \bold{Finding Thresholds:} | |
103 | \cr\cr | |
104 | The function \code{findThreshold} finds a threshold so that a given | |
105 | number of extremes lie above. When the data are tied a threshold is | |
106 | found so that at least the specified number of extremes lie above. | |
107 | \cr | |
108 | ||
109 | ||
110 | \bold{De-Clustering Point Processes:} | |
111 | \cr\cr | |
112 | The function \code{deCluster} declusters clustered point process | |
113 | data so that Poisson assumption is more tenable over a high threshold. | |
114 | ||
115 | } | |
116 | ||
117 | ||
118 | \value{ | |
119 | ||
120 | \code{blockMaxima} | |
121 | \cr | |
122 | returns a timeSeries object or a numeric vector of block | |
123 | maxima data. | |
124 | ||
125 | \code{findThreshold} | |
126 | \cr | |
127 | returns a numeric value or vector of suitable thresholds. | |
128 | ||
129 | \code{pointProcess} | |
130 | \cr | |
131 | returns a timeSeries object or a numeric vector of peaks over | |
132 | a threshold. | |
133 | ||
134 | \code{deCluster} | |
135 | \cr | |
136 | returns a timeSeries object or a numeric vector for the | |
137 | declustered point process. | |
138 | ||
139 | } | |
140 | ||
141 | ||
142 | \references{ | |
143 | ||
144 | Coles S. (2001); | |
145 | \emph{Introduction to Statistical Modelling of Extreme Values}, | |
146 | Springer. | |
147 | ||
148 | Embrechts, P., Klueppelberg, C., Mikosch, T. (1997); | |
149 | \emph{Modelling Extremal Events}, Springer. | |
150 | ||
151 | } | |
152 | ||
153 | ||
154 | \author{ | |
155 | ||
156 | Some of the functions were implemented from Alec Stephenson's | |
157 | R-package \code{evir} ported from Alexander McNeil's S library | |
158 | \code{EVIS}, \emph{Extreme Values in S}, some from Alec Stephenson's | |
159 | R-package \code{ismev} based on Stuart Coles code from his book, | |
160 | \emph{Introduction to Statistical Modeling of Extreme Values} and | |
161 | some were written by Diethelm Wuertz. | |
162 | ||
163 | } | |
164 | ||
165 | \examples{ | |
166 | ## findThreshold - | |
167 | # Threshold giving (at least) fifty exceedances for Danish data: | |
168 | x <- as.timeSeries(data(danishClaims)) | |
169 | findThreshold(x, n = c(10, 50, 100)) | |
170 | ||
171 | ## blockMaxima - | |
172 | # Block Maxima (Minima) for left tail of BMW log returns: | |
173 | BMW <- as.timeSeries(data(bmwRet)) | |
174 | colnames(BMW) <- "BMW.RET" | |
175 | head(BMW) | |
176 | x <- blockMaxima( BMW, block = 65) | |
177 | head(x) | |
178 | \dontrun{ | |
179 | y <- blockMaxima(-BMW, block = 65) | |
180 | head(y) | |
181 | y <- blockMaxima(-BMW, block = "monthly") | |
182 | head(y)} | |
183 | ||
184 | ## pointProcess - | |
185 | # Return Values above threshold in negative BMW log-return data: | |
186 | PP = pointProcess(x = -BMW, u = quantile(as.vector(x), 0.75)) | |
187 | PP | |
188 | nrow(PP) | |
189 | ||
190 | ## deCluster - | |
191 | # Decluster the 200 exceedances of a particular | |
192 | DC = deCluster(x = PP, run = 15, doplot = TRUE) | |
193 | DC | |
194 | nrow(DC) | |
195 | } | |
196 | ||
197 | ||
198 | \keyword{programming} | |
199 | ||
0 | \name{DataPreprocessing} | |
1 | ||
2 | \alias{DataPreprocessing} | |
3 | ||
4 | \alias{blockMaxima} | |
5 | \alias{findThreshold} | |
6 | \alias{pointProcess} | |
7 | \alias{deCluster} | |
8 | ||
9 | ||
10 | \title{Extremes Data Preprocessing} | |
11 | ||
12 | ||
13 | \description{ | |
14 | ||
15 | A collection and description of functions for data | |
16 | preprocessing of extreme values. This includes tools | |
17 | to separate data beyond a threshold value, to compute | |
18 | blockwise data like block maxima, and to decluster | |
19 | point process data. | |
20 | \cr | |
21 | ||
22 | The functions are: | |
23 | ||
24 | \tabular{ll}{ | |
25 | \code{blockMaxima} \tab Block Maxima from a vector or a time series, \cr | |
26 | \code{findThreshold} \tab Upper threshold for a given number of extremes, \cr | |
27 | \code{pointProcess} \tab Peaks over Threshold from a vector or a time series, \cr | |
28 | \code{deCluster} \tab Declusters clustered point process data. } | |
29 | ||
30 | } | |
31 | ||
32 | ||
33 | \usage{ | |
34 | blockMaxima(x, block = c("monthly", "quarterly"), doplot = FALSE) | |
35 | findThreshold(x, n = floor(0.05*length(as.vector(x))), doplot = FALSE) | |
36 | pointProcess(x, u = quantile(x, 0.95), doplot = FALSE) | |
37 | deCluster(x, run = 20, doplot = TRUE) | |
38 | } | |
39 | ||
40 | ||
41 | \arguments{ | |
42 | ||
43 | \item{block}{ | |
44 | the block size. A numeric value is interpreted as the number | |
45 | of data values in each successive block. All the data is used, | |
46 | so the last block may not contain \code{block} observations. | |
47 | If the \code{data} has a \code{times} attribute containing (in | |
48 | an object of class \code{"POSIXct"}, or an object that can be | |
49 | converted to that class, see \code{\link{as.POSIXct}}) the | |
50 | times/dates of each observation, then \code{block} may instead | |
51 | take the character values \code{"month"}, \code{"quarter"}, | |
52 | \code{"semester"} or \code{"year"}. By default monthly blocks | |
53 | from daily data are assumed. | |
54 | } | |
55 | \item{doplot}{ | |
56 | a logical value. Should the results be plotted? By | |
57 | default \code{TRUE}. | |
58 | } | |
59 | \item{n}{ | |
60 | a numeric value or vector giving number of extremes above | |
61 | the threshold. By default, \code{n} is | |
62 | set to an integer representing 5\% of the data from the | |
63 | whole data set \code{x}. | |
64 | } | |
65 | \item{run}{ | |
66 | parameter to be used in the runs method; any two consecutive | |
67 | threshold exceedances separated by more than this number of | |
68 | observations/days are considered to belong to different clusters. | |
69 | } | |
70 | \item{u}{ | |
71 | a numeric value at which level the data are to be truncated. By | |
72 | default the threshold value which belongs to the 95\% quantile, | |
73 | \code{u=quantile(x,0.95)}. | |
74 | } | |
75 | \item{x}{ | |
76 | a numeric data vector from which \code{findThreshold} and | |
77 | \code{blockMaxima} determine the threshold values and block | |
78 | maxima values. | |
79 | For the function \code{deCluster} the argument | |
80 | \code{x} represents a numeric vector of threshold exceedances | |
81 | with a \code{times} attribute which should be a numeric | |
82 | vector containing either the indices or the times/dates | |
83 | of each exceedance (if times/dates, the attribute should | |
84 | be an object of class \code{"POSIXct"} or an object that | |
85 | can be converted to that class; see \code{\link{as.POSIXct}}). | |
86 | } | |
87 | ||
88 | } | |
89 | ||
90 | ||
91 | \details{ | |
92 | ||
93 | \bold{Computing Block Maxima:} | |
94 | \cr\cr | |
95 | The function \code{blockMaxima} calculates block maxima from a vector | |
96 | or a time series, whereas the function | |
97 | \code{blocks} is more general and allows for the calculation of | |
98 | an arbitrary function \code{FUN} on blocks. | |
99 | \cr | |
100 | ||
101 | ||
102 | \bold{Finding Thresholds:} | |
103 | \cr\cr | |
104 | The function \code{findThreshold} finds a threshold so that a given | |
105 | number of extremes lie above. When the data are tied a threshold is | |
106 | found so that at least the specified number of extremes lie above. | |
107 | \cr | |
108 | ||
109 | ||
110 | \bold{De-Clustering Point Processes:} | |
111 | \cr\cr | |
112 | The function \code{deCluster} declusters clustered point process | |
113 | data so that Poisson assumption is more tenable over a high threshold. | |
114 | ||
115 | } | |
116 | ||
117 | ||
118 | \value{ | |
119 | ||
120 | \code{blockMaxima} | |
121 | \cr | |
122 | returns a timeSeries object or a numeric vector of block | |
123 | maxima data. | |
124 | ||
125 | \code{findThreshold} | |
126 | \cr | |
127 | returns a numeric value or vector of suitable thresholds. | |
128 | ||
129 | \code{pointProcess} | |
130 | \cr | |
131 | returns a timeSeries object or a numeric vector of peaks over | |
132 | a threshold. | |
133 | ||
134 | \code{deCluster} | |
135 | \cr | |
136 | returns a timeSeries object or a numeric vector for the | |
137 | declustered point process. | |
138 | ||
139 | } | |
140 | ||
141 | ||
142 | \references{ | |
143 | ||
144 | Coles S. (2001); | |
145 | \emph{Introduction to Statistical Modelling of Extreme Values}, | |
146 | Springer. | |
147 | ||
148 | Embrechts, P., Klueppelberg, C., Mikosch, T. (1997); | |
149 | \emph{Modelling Extremal Events}, Springer. | |
150 | ||
151 | } | |
152 | ||
153 | ||
154 | \author{ | |
155 | ||
156 | Some of the functions were implemented from Alec Stephenson's | |
157 | R-package \code{evir} ported from Alexander McNeil's S library | |
158 | \code{EVIS}, \emph{Extreme Values in S}, some from Alec Stephenson's | |
159 | R-package \code{ismev} based on Stuart Coles code from his book, | |
160 | \emph{Introduction to Statistical Modeling of Extreme Values} and | |
161 | some were written by Diethelm Wuertz. | |
162 | ||
163 | } | |
164 | ||
165 | \examples{ | |
166 | ## findThreshold - | |
167 | # Threshold giving (at least) fifty exceedances for Danish data: | |
168 | library(timeSeries) | |
169 | x <- as.timeSeries(data(danishClaims)) | |
170 | findThreshold(x, n = c(10, 50, 100)) | |
171 | ||
172 | ## blockMaxima - | |
173 | # Block Maxima (Minima) for left tail of BMW log returns: | |
174 | BMW <- as.timeSeries(data(bmwRet)) | |
175 | colnames(BMW) <- "BMW.RET" | |
176 | head(BMW) | |
177 | x <- blockMaxima( BMW, block = 65) | |
178 | head(x) | |
179 | \dontrun{ | |
180 | y <- blockMaxima(-BMW, block = 65) | |
181 | head(y) | |
182 | y <- blockMaxima(-BMW, block = "monthly") | |
183 | head(y)} | |
184 | ||
185 | ## pointProcess - | |
186 | # Return Values above threshold in negative BMW log-return data: | |
187 | PP = pointProcess(x = -BMW, u = quantile(as.vector(x), 0.75)) | |
188 | PP | |
189 | nrow(PP) | |
190 | ||
191 | ## deCluster - | |
192 | # Decluster the 200 exceedances of a particular | |
193 | DC = deCluster(x = PP, run = 15, doplot = TRUE) | |
194 | DC | |
195 | nrow(DC) | |
196 | } | |
197 | ||
198 | ||
199 | \keyword{programming} | |
200 |
29 | 29 | Segers. |
30 | 30 | \cr |
31 | 31 | |
32 | The functiona are: | |
32 | The functions are: | |
33 | 33 | |
34 | 34 | \tabular{ll}{ |
35 | 35 | \code{thetaSim} \tab Simulates a time Series with known theta, \cr |
36 | 36 | \code{blockTheta} \tab Computes theta from Block Method, \cr |
37 | 37 | \code{clusterTheta} \tab Computes theta from Reciprocal Cluster Method, \cr |
38 | 38 | \code{runTheta} \tab Computes theta from Run Method, \cr |
39 | \code{ferrosegersTheta} \tab Computes Theta according to Ferro and Seegers, \cr | |
39 | \code{ferrosegersTheta} \tab Computes Theta according to Ferro and Segers, \cr | |
40 | 40 | \code{exindexPlot} \tab Calculate and Plot Theta(1,2,3), \cr |
41 | 41 | \code{exindexesPlot} \tab Calculate Theta(1,2) and Plot Theta(1). } |
42 | 42 | |
76 | 76 | the block size. Either \code{"monthly"}, \code{"quarterly"} or |
77 | 77 | an integer value. An integer value is interpreted as the number |
78 | 78 | of data values in each successive block. The default value is |
79 | \code{"monthly"} which correpsond for daily data to an approximately | |
79 | \code{"monthly"} which corresponds for daily data to an approximately | |
80 | 80 | 22-day periods. |
81 | 81 | } |
82 | 82 | \item{description}{ |
87 | 87 | } |
88 | 88 | \item{labels}{ |
89 | 89 | whether or not axes should be labelled. If set to \code{FALSE} |
90 | then user specified lables can be passed through the \code{"..."} | |
90 | then user specified labels can be passed through the \code{"..."} | |
91 | 91 | argument. |
92 | 92 | } |
93 | 93 | \item{model}{ |
192 | 192 | ## of the BMW log returns: |
193 | 193 | data(bmwRet) |
194 | 194 | par(mfrow = c(2, 2), cex = 0.7) |
195 | library(timeSeries) | |
195 | 196 | exindexPlot( as.timeSeries(bmwRet), block = "quarterly") |
196 | 197 | exindexPlot(-as.timeSeries(bmwRet), block = "quarterly") |
197 | 198 |
33 | 33 | A collection and description of functions for |
34 | 34 | explorative data analysis. The tools include |
35 | 35 | plot functions for emprical distributions, quantile |
36 | plots, graphs exploring the properties of exceedences | |
36 | plots, graphs exploring the properties of exceedances | |
37 | 37 | over a threshold, plots for mean/sum ratio and for |
38 | 38 | the development of records. |
39 | 39 | \cr |
51 | 51 | \code{ssrecordsPlot} \tab another variant, investigates subsamples, \cr |
52 | 52 | \code{sllnPlot} \tab verifies Kolmogorov's strong law of large numbers, \cr |
53 | 53 | \code{lilPlot} \tab verifies Hartman-Wintner's law of the iterated logarithm, \cr |
54 | \code{xacfPlot} \tab ACF of exceedences over a threshold, \cr | |
54 | \code{xacfPlot} \tab ACF of exceedances over a threshold, \cr | |
55 | 55 | \code{normMeanExcessFit} \tab fits mean excesses with a normal density, \cr |
56 | 56 | \code{ghMeanExcessFit} \tab fits mean excesses with a GH density, \cr |
57 | 57 | \code{hypMeanExcessFit} \tab fits mean excesses with a HYP density, \cr |
145 | 145 | \item{threshold, trim}{ |
146 | 146 | [qPlot][xacfPlot] - \cr |
147 | 147 | a numeric value at which data are to be left-truncated, value |
148 | at which data are to be right-truncated or the thresold value, | |
148 | at which data are to be right-truncated or the threshold value, | |
149 | 149 | by default 95\%. |
150 | 150 | } |
151 | 151 | \item{trace}{ |
241 | 241 | with the help of the function \code{ssrecordsPlot}. |
242 | 242 | \cr |
243 | 243 | |
244 | \bold{Plot of Kolmogorov's and Hartman-Wintern's Laws:} | |
244 | \bold{Plot of Kolmogorov's and Hartman-Wintner's Laws:} | |
245 | 245 | \cr\cr |
246 | 246 | The function \code{sllnPlot} verifies Kolmogorov's strong law of |
247 | 247 | large numbers, and the function \code{lilPlot} verifies |
248 | 248 | Hartman-Wintner's law of the iterated logarithm. |
249 | 249 | \cr |
250 | 250 | |
251 | \bold{ACF Plot of Exceedences over a Thresold:} | |
251 | \bold{ACF Plot of Exceedances over a Threshold:} | |
252 | 252 | \cr\cr |
253 | 253 | This function plots the autocorrelation functions of heights and |
254 | distances of exceedences over a threshold. | |
254 | distances of exceedances over a threshold. | |
255 | 255 | \cr |
256 | 256 | } |
257 | 257 | |
301 | 301 | \examples{ |
302 | 302 | ## Danish fire insurance data: |
303 | 303 | data(danishClaims) |
304 | library(timeSeries) | |
304 | 305 | danishClaims = as.timeSeries(danishClaims) |
305 | 306 | |
306 | 307 | ## emdPlot - |
55 | 55 | probabilities are \code{P[X <= x]}, otherwise, \code{P[X > x]}. |
56 | 56 | } |
57 | 57 | \item{method}{ |
58 | a character sgtring denoting what should be displayed. Either | |
58 | a character string denoting what should be displayed. Either | |
59 | 59 | the density and \code{"dist"} or random variates \code{"rvs"}. |
60 | 60 | } |
61 | 61 | \item{n}{ |
65 | 65 | \cr |
66 | 66 | [shaparmPlot] - \cr |
67 | 67 | a vector of logicals of the same lengths as tails |
68 | defining for wich tail depths plots should be created, | |
68 | defining for which tail depths plots should be created, | |
69 | 69 | by default plots will be generated for a tail depth of 5 |
70 | 70 | percent. By default \code{c(FALSE, FALSE, FALSE, FALSE, |
71 | 71 | TRUE, FALSE, FALSE, FALSE, FALSE, FALSE)}. |
264 | 264 | |
265 | 265 | \examples{ |
266 | 266 | ## Load Data: |
267 | library(timeSeries) | |
267 | 268 | x = as.timeSeries(data(danishClaims)) |
268 | 269 | colnames(x) <- "Danish" |
269 | 270 | head(x) |
73 | 73 | \cr |
74 | 74 | [shaparmPlot] - \cr |
75 | 75 | a vector of logicals of the same lengths as tails |
76 | defining for wich tail depths plots should be created, | |
76 | defining for which tail depths plots should be created, | |
77 | 77 | by default plots will be generated for a tail depth of 5 |
78 | 78 | percent. By default \code{c(FALSE, FALSE, FALSE, FALSE, |
79 | 79 | TRUE, FALSE, FALSE, FALSE, FALSE, FALSE)}. |
109 | 109 | \item{type}{ |
110 | 110 | a character string denoting the type of parameter estimation, |
111 | 111 | either by maximum likelihood estimation \code{"mle"}, the |
112 | default value, or by the probability weighted moment menthod | |
112 | default value, or by the probability weighted moment method | |
113 | 113 | \code{"pwm"}. |
114 | 114 | } |
115 | 115 | \item{which}{ |
116 | 116 | [plot][summary] - \cr |
117 | 117 | a vector of logicals, one for each plot, denoting which plot |
118 | should be displayed. Alkternatively if \code{which="ask"} the | |
118 | should be displayed. Alternatively if \code{which="ask"} the | |
119 | 119 | user will be interactively asked which of the plots should be |
120 | desplayed. By default \code{which="all"}. | |
120 | displayed. By default \code{which="all"}. | |
121 | 121 | } |
122 | 122 | \item{x}{ |
123 | 123 | [dgev][devd] - \cr |
139 | 139 | \item{xi, mu, beta}{ |
140 | 140 | [*gev] - \cr |
141 | 141 | \code{xi} is the shape parameter, \code{mu} the location parameter, |
142 | and \code{sigma} is the scale parameter. The default values are | |
142 | and \code{beta} is the scale parameter. The default values are | |
143 | 143 | \code{xi=1}, \code{mu=0}, and \code{beta=1}. Note, if \code{xi=0} |
144 | 144 | the distribution is of type Gumbel. |
145 | 145 | } |
213 | 213 | \examples{ |
214 | 214 | ## Load Data: |
215 | 215 | # BMW Stock Data - negative returns |
216 | library(timeSeries) | |
216 | 217 | x = -as.timeSeries(data(bmwRet)) |
217 | 218 | colnames(x)<-"BMW" |
218 | 219 | head(x) |
84 | 84 | a character string which allows for a project title. |
85 | 85 | } |
86 | 86 | \item{type}{ |
87 | a character string selecting the desired estimation mehtod, either | |
88 | \code{"mle"} for the maximum likelihood mehtod or \code{"pwm"} for | |
87 | a character string selecting the desired estimation method, either | |
88 | \code{"mle"} for the maximum likelihood method or \code{"pwm"} for | |
89 | 89 | the probability weighted moment method. By default, the first will |
90 | 90 | be selected. Note, the function \code{gpd} uses \code{"ml"}. |
91 | 91 | } |
108 | 108 | the data vector. Note, there are two different names |
109 | 109 | for the first argument \code{x} and \code{data} depending |
110 | 110 | which function name is used, either \code{gpdFit} or the |
111 | EVIS synonyme \code{gpd}. | |
111 | EVIS synonym \code{gpd}. | |
112 | 112 | \cr |
113 | 113 | [print][plot] - \cr |
114 | 114 | a fitted object of class \code{"gpdFit"}. |
227 | 227 | representation to an existing plot is added. Expected shortfall is |
228 | 228 | the expected size of the loss, given that a particular quantile of the |
229 | 229 | loss distribution is exceeded. The GPD approximation in the tail is used |
230 | to estimate expected shortfall. The likelihood is reparametrised in | |
230 | to estimate expected shortfall. The likelihood is reparametrized in | |
231 | 231 | terms of the unknown expected shortfall and profile likelihood arguments |
232 | 232 | are used to construct a confidence interval. |
233 | 233 | \cr |
116 | 116 | the lowest and maximum number of exceedances to be considered. |
117 | 117 | } |
118 | 118 | \item{type}{ |
119 | a character string selecting the desired estimation mehtod, either | |
120 | \code{"mle"} for the maximum likelihood mehtod or \code{"pwm"} for | |
119 | a character string selecting the desired estimation method, either | |
120 | \code{"mle"} for the maximum likelihood method or \code{"pwm"} for | |
121 | 121 | the probability weighted moment method. By default, the first will |
122 | 122 | be selected. Note, the function \code{gpd} uses \code{"ml"}. |
123 | 123 | } |
129 | 129 | the data vector. Note, there are two different names |
130 | 130 | for the first argument \code{x} and \code{data} depending |
131 | 131 | which function name is used, either \code{gpdFit} or the |
132 | EVIS synonyme \code{gpd}. | |
132 | EVIS synonym \code{gpd}. | |
133 | 133 | \cr |
134 | 134 | [print][plot] - \cr |
135 | 135 | a fitted object of class \code{"gpdFit"}. |
243 | 243 | representation to an existing plot is added. Expected shortfall is |
244 | 244 | the expected size of the loss, given that a particular quantile of the |
245 | 245 | loss distribution is exceeded. The GPD approximation in the tail is used |
246 | to estimate expected shortfall. The likelihood is reparametrised in | |
246 | to estimate expected shortfall. The likelihood is reparametrized in | |
247 | 247 | terms of the unknown expected shortfall and profile likelihood arguments |
248 | 248 | are used to construct a confidence interval. |
249 | 249 | \cr |
285 | 285 | |
286 | 286 | \examples{ |
287 | 287 | ## Load Data: |
288 | library(timeSeries) | |
288 | 289 | danish = as.timeSeries(data(danishClaims)) |
289 | 290 | |
290 | 291 | ## Tail Plot: |
14 | 14 | Value-at-Risk and conditional Value-at-Risk |
15 | 15 | \cr |
16 | 16 | |
17 | The functiona are: | |
17 | The functions are: | |
18 | 18 | |
19 | 19 | \tabular{ll}{ |
20 | 20 | \code{VaR} \tab Computes Value-at-Risk, \cr |
7 | 7 | |
8 | 8 | \title{Time Series Data Sets} |
9 | 9 | |
10 | \usage{ | |
11 | bmwRet | |
12 | danishClaims | |
13 | } | |
10 | 14 | |
11 | 15 | \description{ |
12 | Data sets used in the examples of the timeSeries packages. | |
16 | Data sets used in the examples of the fExtremes packages. | |
13 | 17 | } |
18 | ||
19 | \format{ | |
20 | \code{bmwRet}. A data frame with 6146 observations on 2 variables. The first column contains dates (Tuesday 2nd January 1973 until Tuesday 23rd July 1996) and the second column contains the respective value of daily log returns on the BMW share price made on each of those dates. These data are an irregular time series because there is no trading at weekends. | |
21 | ||
22 | \code{danishClaims}. A data frame with 2167 observations on 2 variables. The first column contains dates and the second column contains the respective value of a fire insurance claim in Denmark made on each of those dates. These data are an irregular time series. | |
23 | } | |
24 | ||
25 | \examples{ | |
26 | head(bmwRet) | |
27 | head(danishClaims) | |
28 | } |
0 | 0 | #### doRUnit.R --- Run RUnit tests |
1 | 1 | ####------------------------------------------------------------------------ |
2 | 2 | |
3 | ### Origianlly follows Gregor Gojanc's example in CRAN package 'gdata' | |
3 | ### Originally follows Gregor Gojanc's example in CRAN package 'gdata' | |
4 | 4 | ### and the corresponding section in the R Wiki: |
5 | 5 | ### http://wiki.r-project.org/rwiki/doku.php?id=developers:runit |
6 | 6 | |
21 | 21 | |
22 | 22 | stopifnot(file.exists(path), file.info(path.expand(path))$isdir) |
23 | 23 | |
24 | # Make sure that required packages are loaded | |
25 | library(fBasics) | |
26 | library(timeDate) | |
27 | library(timeSeries) | |
28 | ||
24 | 29 | source(file.path(path, "runTests.R"), echo = TRUE) |
25 | 30 | } |