fExtremes/ 0000755 0001760 0000144 00000000000 12254146514 012250 5 ustar ripley users fExtremes/inst/ 0000755 0001760 0000144 00000000000 12251673345 013231 5 ustar ripley users fExtremes/inst/COPYRIGHT.html 0000644 0001760 0000144 00000020411 11370220752 015454 0 ustar ripley users
Rmetrics::COPYRIGHT
Rmetrics
Copyrights
2005-12-18 Built 221.10065
________________________________________________________________________________
Copyrights (C) for
R:
see R's copyright and license file
Version R 2.0.0 claims:
- The stub packages from 1.9.x have been removed.
- All the datasets formerly in packages 'base' and 'stats' have
been moved to a new package 'datasets'.
- Package 'graphics' has been split into 'grDevices' (the graphics
devices shared between base and grid graphics) and 'graphics'
(base graphics).
- Packages must have been re-installed for this version, and
library() will enforce this.
- Package names must now be given exactly in library() and
require(), regardless of whether the underlying file system is
case-sensitive or not.
________________________________________________________________________________
for
Rmetrics:
(C) 1999-2005, Diethelm Wuertz, GPL
Diethelm Wuertz
www.rmetrics.org
info@rmetrics.org
________________________________________________________________________________
for non default loaded basic packages part of R's basic distribution
MASS:
Main Package of Venables and Ripley's MASS.
We assume that MASS is available.
Package 'lqs' has been returned to 'MASS'.
S original by Venables & Ripley.
R port by Brian Ripley .
Earlier work by Kurt Hornik and Albrecht Gebhardt.
methods:
Formally defined methods and classes for R objects, plus other
programming tools, as described in the reference "Programming
with Data" (1998), John M. Chambers, Springer NY.
R Development Core Team.
mgcv:
Routines for GAMs and other generalized ridge regression
with multiple smoothing parameter selection by GCV or UBRE.
Also GAMMs by REML or PQL. Includes a gam() function.
Simon Wood
nnet:
Feed-forward Neural Networks and Multinomial Log-Linear Models
Original by Venables & Ripley.
R port by Brian Ripley .
Earlier work by Kurt Hornik and Albrecht Gebhardt.
________________________________________________________________________________
for the code partly included as builtin functions from other R ports:
fBasics:CDHSC.F
GRASS program for distributional testing.
By James Darrell McCauley
Original Fortran Source by Paul Johnson EZ006244@ALCOR.UCDAVIS.EDU>
fBasics:nortest
Five omnibus tests for the composite hypothesis of normality
R-port by Juergen Gross
fBasics:SYMSTB.F
Fast numerical approximation to the Symmetric Stable distribution
and density functions.
By Hu McCulloch
fBasics:tseries
Functions for time series analysis and computational finance.
Compiled by Adrian Trapletti
fCalendar:date
The tiny C program from Terry Therneau is used
R port by Th. Lumley ,
K. Halvorsen , and
Kurt Hornik
fCalendar:holidays
The holiday information was collected from the internet and
governmental sources obtained from a few dozens of websites
fCalendar:libical
Libical is an Open Source implementation of the IETF's
iCalendar Calendaring and Scheduling protocols. (RFC 2445, 2446,
and 2447). It parses iCal components and provides a C API for
manipulating the component properties, parameters, and subcomponents.
fCalendar:vtimezone
Olsen's VTIMEZONE database consists of data files are released under
the GNU General Public License, in keeping with the license options of
libical.
fSeries:bdstest.c
C Program to compute the BDS Test.
Blake LeBaron
fSeries:fracdiff
R functions, help pages and the Fortran Code for the 'fracdiff'
function are included.
S original by Chris Fraley
R-port by Fritz Leisch
since 2003-12: Martin Maechler
fSeries:lmtest
R functions and help pages for the linear modelling tests are included .
Compiled by Torsten Hothorn ,
Achim Zeileis , and
David Mitchell
fSeries:mda
R functions, help pages and the Fortran Code for the 'mars' function
are implemeted.
S original by Trevor Hastie & Robert Tibshirani,
R port by Friedrich Leisch, Kurt Hornik and Brian D. Ripley
fSeries:modreg
Brian Ripley and the R Core Team
fSeries:polspline
R functions, help pages and the C/Fortran Code for the 'polymars'
function are implemented
Charles Kooperberg
fSeries:systemfit
Simultaneous Equation Estimation Package.
R port by Jeff D. Hamann and
Arne Henningsen
fSeries:tseries
Functions for time series analysis and computational finance.
Compiled by Adrian Trapletti
fSeries:UnitrootDistribution:
The program uses the Fortran routine and the tables
from J.G. McKinnon.
fSeries:urca
Unit root and cointegration tests for time series data.
R port by Bernhard Pfaff .
fExtremes:evd
Functions for extreme value distributions.
R port by Alec Stephenson
Function 'fbvpot' by Chris Ferro.
fExtremes:evir
Extreme Values in R
Original S functions (EVIS) by Alexander McNeil
R port by Alec Stephenson
fExtremes:ismev
An Introduction to Statistical Modeling of Extreme Values
Original S functions by Stuart Coles
R port/documentation by Alec Stephenson
fOptions
Option Pricing formulas are implemented along the book and
the Excel spreadsheets of E.G. Haug, "The Complete Guide to Option
Pricing"; documentation is partly taken from www.derivicom.com which
implements a C Library based on Haug. For non-academic and commercial
use we recommend the professional software from "www.derivicom.com".
fOptions:SOBOL.F
ACM Algorithm 659 by P. Bratley and B.L. Fox
Extension on Algorithm 659 by S. Joe and F.Y. Kuo
fOptions:CGAMA.F
Complex gamma and related functions.
Fortran routines by Jianming Jin.
fOptions:CONHYP.F
Confluenet Hypergeometric and related functions.
ACM Algorithm 707 by mark Nardin, W.F. Perger, A. Bhalla
fPortfolio:mvtnorm
Multivariate Normal and T Distribution.
Alan Genz ,
Frank Bretz
R port by Torsten Hothorn
fPortfolio:quadprog
Functions to solve Quadratic Programming Problems.
S original by Berwin A. Turlach
R port by Andreas Weingessel
fPortfolio:sn
The skew-normal and skew-t distributions.
R port by Adelchi Azzalini
fPortfolio:tseries
Functions for time series analysis and computational finance.
Compiled by Adrian Trapletti
fExtremes/inst/unitTests/ 0000755 0001760 0000144 00000000000 12251673345 015233 5 ustar ripley users fExtremes/inst/unitTests/Makefile 0000644 0001760 0000144 00000000421 11370220752 016657 0 ustar ripley users PKG=fExtremes
TOP=../..
SUITE=doRUnit.R
R=R
all: inst test
inst: # Install package -- but where ?? -- will that be in R_LIBS ?
cd ${TOP}/..;\
${R} CMD INSTALL ${PKG}
test: # Run unit tests
export RCMDCHECK=FALSE;\
cd ${TOP}/tests;\
${R} --vanilla --slave < ${SUITE} fExtremes/inst/unitTests/runit.GevMdaEstimation.R 0000644 0001760 0000144 00000005611 11370220752 021710 0 ustar ripley users
# This library is free software; you can redistribute it and/or
# modify it under the terms of the GNU Library General Public
# License as published by the Free Software Foundation; either
# version 2 of the License, or (at your option) any later version.
#
# This library is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Library General Public License for more details.
#
# You should have received a copy of the GNU Library General
# Public License along with this library; if not, write to the
# Free Foundation, Inc., 59 Temple Place, Suite 330, Boston,
# MA 02111-1307 USA
# Copyrights (C)
# for this R-port:
# 1999 - 2007, Diethelm Wuertz, GPL
# Diethelm Wuertz
# info@rmetrics.org
# www.rmetrics.org
# for the code accessed (or partly included) from other R-ports:
# see R's copyright and license files
# for the code accessed (or partly included) from contributed R-ports
# and other sources
# see Rmetrics's copyright file
################################################################################
# FUNCTION: MDA ESTIMATORS:
# hillPlot Plot Hill's estimator
# shaparmPlot Pickands, Hill & Decker-Einmahl-deHaan Estimator
# shaparmPickands Auxiliary function called by shaparmPlot
# shaparmHill ... called by shaparmPlot
# shaparmDehaan ... called by shaparmPlot
################################################################################
test.hillPlot =
function()
{
# hillPlot Plot Hill's estimator
# Graph Frame:
par(mfrow = c(2, 2), cex = 0.7)
par(ask = FALSE)
# Hill Plot:
hillPlot(gevSim(n=1000), plottype = "alpha")
hillPlot(gevSim(n=1000), plottype = "xi"); grid()
# Don't Plot Return Value:
hillPlot(gevSim(n=1000), plottype = "alpha", doplot = FALSE)
hillPlot(gevSim(n=1000), plottype = "xi", doplot = FALSE); grid()
# Return Value:
return()
}
# ------------------------------------------------------------------------------
test.shaparmPlot =
function()
{
# shaparmPlot Pickands, Hill & Decker-Einmahl-deHaan Estimator
# Graph Frame:
par(mfrow = c(2, 2), cex = 0.7)
par(ask = FALSE)
# shaparmPlot(x, p = 0.01*(1:10), xiRange = NULL, alphaRange = NULL,
# doplot = TRUE, plottype = c("both", "upper"))
# Graph Frame:
par(mfcol = c(3, 2), cex = 0.7)
par(ask = FALSE)
shaparmPlot(as.timeSeries(data(bmwRet)))
# Print (Results:
shaparmPlot(as.timeSeries(data(bmwRet)), doplot = FALSE)
# Tailored p:
shaparmPlot(as.timeSeries(data(bmwRet)), p = 0.005*(2:20))
# Return Value:
return()
}
################################################################################
fExtremes/inst/unitTests/runit.ExtremeIndex.R 0000644 0001760 0000144 00000011153 11370220752 021107 0 ustar ripley users
# This library is free software; you can redistribute it and/or
# modify it under the terms of the GNU Library General Public
# License as published by the Free Software Foundation; either
# version 2 of the License, or (at your option) any later version.
#
# This library is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Library General Public License for more details.
#
# You should have received a copy of the GNU Library General
# Public License along with this library; if not, write to the
# Free Foundation, Inc., 59 Temple Place, Suite 330, Boston,
# MA 02111-1307 USA
# Copyrights (C)
# for this R-port:
# 1999 - 2004, Diethelm Wuertz, GPL
# Diethelm Wuertz
# info@rmetrics.org
# www.rmetrics.org
# for the code accessed (or partly included) from other R-ports:
# see R's copyright and license files
# for the code accessed (or partly included) from contributed R-ports
# and other sources
# see Rmetrics's copyright file
################################################################################
# FUNCTION: DESCRIPTION:
# 'fTHETA' Class representation for extremal index
# show.fTHETA S4: Print Method for extremal index
# thetaSim Simulates a time series with known theta
# FUNCTION: DESCRIPTION:
# blockTheta Computes theta from Block Method
# clusterTheta Computes theta from Reciprocal Cluster Method
# runTheta Computes theta from Run Method
# ferrosegersTheta Computes Theta according to Ferro and Seegers
# FUNCTION: DESCRIPTION:
# exindexesPlot Computes and Plot Theta(1,2,3)
# exindexPlot Computes Theta(1,2) and Plot Theta(1)
################################################################################
test.fTHETA =
function()
{
# Slot Names:
slotNames("fTHETA")
# [1] "call" "data" "theta" "title" "description"
# Return Value:
return()
}
# ------------------------------------------------------------------------------
test.thetaSim =
function()
{
# Simulation:
# thetaSim(model = c("max", "pair"), n = 100, theta = 0.5)
# Max Frechet Series:
x = thetaSim("max")
class(x)
print(x)
# Paired Exponential Series:
x = thetaSim("pair")
class(x)
print(x)
# Return Value:
return()
}
# ------------------------------------------------------------------------------
test.thetaFit =
function()
{
# Parameter Estimation:
x.ts = thetaSim("max", n=22000)
class(x.ts)
# Parameter Estimation:
# blockTheta(x, block = 22, quantiles = seq(0.95, 0.995, length = 10),
# title = NULL, description = NULL)
# clusterTheta(x, block = 22, quantiles = seq(0.95, 0.995, length = 10),
# title = NULL, description = NULL)
# runTheta(x, block = 22, quantiles = seq(0.95, 0.995, length = 10),
# title = NULL, description = NULL)
# ferrosegersTheta(x, quantiles = seq(0.95, 0.995, length = 10),
# title = NULL, description = NULL)
# time series ts as input:
blockTheta(x.ts)
clusterTheta(x.ts)
runTheta(x.ts)
ferrosegersTheta(x.ts)
# Numeric Vector as input:
x.vec = as.vector(x.ts)
blockTheta(x.vec)
clusterTheta(x.vec)
runTheta(x.vec)
ferrosegersTheta(x.vec)
# timeSeries object as input:
x.tS = as.timeSeries(x.ts)
blockTheta(x.tS)
clusterTheta(x.tS)
runTheta(x.tS)
ferrosegersTheta(x.tS)
# Return Value:
return()
}
# ------------------------------------------------------------------------------
test.exindexesPlot =
function()
{
# Graphics Frame:
par(mfrow = c(2, 2), cex = 0.7)
par(ask = FALSE)
# Parameter Estimation:
x = thetaSim("max", n = 22000)
exindexesPlot(x)
# Parameter Estimation:
y = thetaSim("pair", n = 22000)
exindexesPlot(y)
# Return Value:
return()
}
# ------------------------------------------------------------------------------
test.exindexPlot =
function()
{
# Graphics Frame:
par(mfrow = c(2, 2), cex = 0.7)
par(ask = FALSE)
# Parameter Estimation:
x = thetaSim("max", n=22000)
exindexPlot(x, block = 22)
# Parameter Estimation:
y = thetaSim("pair", n=22000)
exindexPlot(y, block = 22)
# Return Value:
return()
}
################################################################################
fExtremes/inst/unitTests/runit.GpdModelling.R 0000644 0001760 0000144 00000010772 11370220752 021061 0 ustar ripley users
# This library is free software; you can redistribute it and/or
# modify it under the terms of the GNU Library General Public
# License as published by the Free Software Foundation; either
# version 2 of the License, or (at your option) any later version.
#
# This library is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Library General Public License for more details.
#
# You should have received a copy of the GNU Library General
# Public License along with this library; if not, write to the
# Free Foundation, Inc., 59 Temple Place, Suite 330, Boston,
# MA 02111-1307 USA
# Copyrights (C)
# for this R-port:
# 1999 - 2007, Diethelm Wuertz, GPL
# Diethelm Wuertz
# info@rmetrics.org
# www.rmetrics.org
# for the code accessed (or partly included) from other R-ports:
# see R's copyright and license files
# for the code accessed (or partly included) from contributed R-ports
# and other sources
# see Rmetrics's copyright file
# ##############################################################################
# FUNCTION: GPD SIMULATION:
# gpdSim Simulates a GPD distributed process
# FUNCTION: GPD PARAMETER ESTIMATION:
# 'fGPDFIT' S4 class representation
# gpdFit Fits Parameters of GPD distribution
# METHODS: PRINT, PLOT, AND SUMMARY:
# show.fGPDFIT S4 Print Method for object of class "fGPDFIT"
# plot.fGPDFIT S3 Plot Method for object of class "fGPDFIT"
# summary.fGPDFIT S3 Summary Method for object of class "fGPDFIT"
################################################################################
test.gpdSim =
function()
{
# Generate Artificial Data Set:
x = gpdSim(model = list(xi = 0.25, mu = 0, beta = 1), n = 1000, seed = 4711)
class(x)
# Plot Series:
par(mfrow = c(2, 1), cex = 0.7)
par(ask = FALSE)
seriesPlot(as.timeSeries(x))
# Return Value:
return()
}
# ------------------------------------------------------------------------------
test.fGPDFIT =
function()
{
# Slot names:
slotNames("fGPDFIT")
# [1] "call" "method" "parameter" "data" "fit"
# [6] "residuals" "title" "description"
# Return Value:
return()
}
# ------------------------------------------------------------------------------
test.gpdFit =
function()
{
# Generate Artificial Data Set:
model = list(xi = -0.25, mu = 0, beta = 1)
ts = gpdSim(model = model, n = 5000, seed = 4711)
class(ts)
# Transform As timeSeries:
tS = as.timeSeries(ts)
class(tS)
# As numeric vector:
x = as.vector(ts)
class(x)
# GPD Fit:
# gpdFit(x, u = quantile(x, 0.95), type = c("mle", "pwm"),
# information = c("observed", "expected"), title = NULL,
# description = NULL, ...)
# PWM Fit:
fit = gpdFit(tS, u = min(series(tS)), "pwm")
print(fit)
fit = gpdFit(ts, u = min(ts), "pwm")
print(fit)
fit = gpdFit(x, u = min(x), "pwm")
print(fit)
# MLE Fit:
fit = gpdFit(tS, u = min(series(tS)), "mle")
print(fit)
fit = gpdFit(ts, u = min(ts), "mle")
print(fit)
fit = gpdFit(x, u = min(x), "mle")
print(fit)
# Information:
fit = gpdFit(tS, u = min(series(tS)), type = "mle", information = "observed")
print(fit)
fit = gpdFit(tS, u = min(series(tS)), type = "mle", information = "expected")
print(fit)
# Return Value:
return()
}
# ------------------------------------------------------------------------------
test.plot =
function()
{
# Artificial Data Set:
model = list(xi = -0.25, mu = 0, beta = 1)
ts = gpdSim(model = model, n = 5000, seed = 4711)
class(ts)
# Fit:
fit = gpdFit(ts, u = min(ts), type = "mle")
print(fit)
par(mfrow = c(2, 2), cex = 0.7)
par(ask = FALSE)
plot(fit, which = "all")
# Try:
# plot(fit, which = "ask")
# Return Value:
return()
}
# ------------------------------------------------------------------------------
test.summary =
function()
{
# Artificial Data Set:
model = list(xi = -0.25, mu = 0, beta = 1)
ts = gpdSim(model = model, n = 5000, seed = 4711)
class(ts)
# Fit:
fit = gpdFit(ts, u = min(ts), type = "mle")
summary(fit, doplot = FALSE)
# Return Value:
return()
}
################################################################################
fExtremes/inst/unitTests/runit.GpdDistribution.R 0000644 0001760 0000144 00000006024 11370220752 021621 0 ustar ripley users
# This library is free software; you can redistribute it and/or
# modify it under the terms of the GNU Library General Public
# License as published by the Free Software Foundation; either
# version 2 of the License, or (at your option) any later version.
#
# This library is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Library General Public License for more details.
#
# You should have received a copy of the GNU Library General
# Public License along with this library; if not, write to the
# Free Foundation, Inc., 59 Temple Place, Suite 330, Boston,
# MA 02111-1307 USA
# Copyrights (C)
# for this R-port:
# 1999 - 2007, Diethelm Wuertz, GPL
# Diethelm Wuertz
# info@rmetrics.org
# www.rmetrics.org
# for the code accessed (or partly included) from other R-ports:
# see R's copyright and license files
# for the code accessed (or partly included) from contributed R-ports
# and other sources
# see Rmetrics's copyright file
################################################################################
# FUNCTION: GPD DISTRIBUTION FAMILY:
# dgpd Density for the Generalized Pareto DF [USE FROM EVIS]
# pgpd Probability for the Generalized Pareto DF
# qgpd Quantiles for the Generalized Pareto DF
# rgpd Random variates for the Generalized Pareto DF
# gpdMoments Computes true statistics for GPD distribution
# gpdSlider Displays distribution and rvs for GPD distribution
################################################################################
test.gpd =
function()
{
# Check Distribution:
set.seed(1985)
.distCheck(fun = "gpd", n = 500, xi = 1, mu = 0, beta = 1)
# Return Value:
return()
}
# ------------------------------------------------------------------------------
test.gpdMoments =
function()
{
# gpdMoments(xi = 1, mu = 0, beta = 1)
# Compute Moments:
xi = seq(-2, 2, length = 401)
mom = gpdMoments(xi)
# Plot Mean:
par(mfrow = c(2, 1), cex = 0.7)
par(ask = FALSE)
plot(xi, mom$mean, main = "Mean", pch = 19, cex = 0.5)
abline(v = 1, col = "red", lty = 3)
abline(h = 0, col = "red", lty = 3)
# Plot Variance:
plot(xi, log(mom$var), main = "log Variance", pch = 19, cex = 0.5)
abline(v = 1/2, col = "red", lty = 3)
abline(h = 0.0, col = "red", lty = 3)
# Return Value:
return()
}
# ------------------------------------------------------------------------------
test.gpdSlider =
function()
{
# Distribution Slider:
# print("Activate Slider manually!")
# gpdSlider(method = "dist")
# Random Variates Slider:
# print("Activate Slider manually!")
# gpdSlider(method = "rvs")
NA
# Return Value:
return()
}
################################################################################
fExtremes/inst/unitTests/runit.GevRisk.R 0000644 0001760 0000144 00000003702 11370220752 020061 0 ustar ripley users
# This library is free software; you can redistribute it and/or
# modify it under the terms of the GNU Library General Public
# License as published by the Free Software Foundation; either
# version 2 of the License, or (at your option) any later version.
#
# This library is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Library General Public License for more details.
#
# You should have received a copy of the GNU Library General
# Public License along with this library; if not, write to the
# Free Foundation, Inc., 59 Temple Place, Suite 330, Boston,
# MA 02111-1307 USA
# Copyrights (C)
# for this R-port:
# 1999 - 2007, Diethelm Wuertz, GPL
# Diethelm Wuertz
# info@rmetrics.org
# www.rmetrics.org
# for the code accessed (or partly included) from other R-ports:
# see R's copyright and license files
# for the code accessed (or partly included) from contributed R-ports
# and other sources
# see Rmetrics's copyright file
################################################################################
# FUNCTION: ADDITIONAL FUNCTIONS:
# gevrlevelPlot Calculates Return Levels Based on GEV Fit
# .gevrlevelLLH Computes log-likelihood function for gevrlevelPlot
################################################################################
test.returnLevel =
function()
{
# gevrlevelPlot(object, kBlocks = 20, ci = c(0.90, 0.95, 0.99),
# plottype = c("plot", "add"), labels = TRUE,...)
# Artificial Data Set:
model = list(xi = -0.25, mu = 0, beta = 1)
x = gevSim(model = model, n = 1000, seed = 4711)
class(x)
# Empirical distribution plot:
fit = gevFit(x)
gevrlevelPlot(fit)
# Return Value:
return()
}
################################################################################
fExtremes/inst/unitTests/runit.DataPreprocessing.R 0000644 0001760 0000144 00000011164 11370220752 022125 0 ustar ripley users
# This library is free software; you can redistribute it and/or
# modify it under the terms of the GNU Library General Public
# License as published by the Free Software Foundation; either
# version 2 of the License, or (at your option) any later version.
#
# This library is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Library General Public License for more details.
#
# You should have received a copy of the GNU Library General
# Public License along with this library; if not, write to the
# Free Foundation, Inc., 59 Temple Place, Suite 330, Boston,
# MA 02111-1307 USA
# Copyrights (C)
# for this R-port:
# 1999 - 2007, Diethelm Wuertz, GPL
# Diethelm Wuertz
# info@rmetrics.org
# www.rmetrics.org
# for the code accessed (or partly included) from other R-ports:
# see R's copyright and license files
# for the code accessed (or partly included) from contributed R-ports
# and other sources
# see Rmetrics's copyright file
################################################################################
# FUNCTION DATA PREPROCESSING:
# blockMaxima Returns block maxima from a time series
# findThreshold Upper threshold for a given number of extremes
# pointProcess Returns peaks over a threshold from a time series
# deCluster Declusters a point process
################################################################################
test.blockMaxima =
function()
{
# blockMaxima - Returns block maxima from a time series
# blockMaxima(x, block = c("monthly", "quarterly"), doplot = FALSE)
# Time Series Data:
x = MSFT[, "Close"]
x.ret = 100*returns(x)
head(x.ret)
class(x.ret)
# Monthly Block Maxima:
ans = blockMaxima(x.ret, block = "monthly", doplot = TRUE)
print(ans)
# Quarterly Block Maxima:
ans = blockMaxima(x.ret, block = "q", doplot = TRUE)
print(ans)
# 20-Days Block Maxima:
ans = blockMaxima(x.ret, block = 20, doplot = TRUE)
print(ans)
# Numerical Data Vector:
x.ret = as.vector(x.ret)
head(x.ret)
ans = blockMaxima(x.ret, block = 20, doplot = TRUE)
print(ans)
# Stops by stopifnot() - Check:
# blockMaxima(x.ret, block = "month", doplot = TRUE)
# Return Value:
return()
}
# ------------------------------------------------------------------------------
test.findThreshold =
function()
{
# findThreshold - Upper threshold for a given number of extremes
# findThreshold(x, n = floor(0.05*length(as.vector(x))), doplot = FALSE)
# Time Series Data:
x = MSFT[, "Close"]
x.ret = 100*returns(x)
head(x.ret)
class(x.ret)
# Find 99% Threshold:
par(mfrow = c(2, 2), cex = 0.7)
par(ask = FALSE)
findThreshold(x.ret, n = floor(0.01*length(as.vector(x))), doplot = TRUE)
# Remark - Alternative use ...
quantile(x.ret, probs = 1 - 0.01)
quantile(x.ret, probs = 1 - 0.01, type = 1)
# Find 95% Threshold:
findThreshold(x.ret, doplot = TRUE)
# Find 90% Threshold:
findThreshold(x.ret, n = floor(0.1*length(as.vector(x))), doplot = TRUE)
# Try if x is a numeric vector:
findThreshold(as.vector(x.ret), doplot = TRUE)
# Return Value:
return()
}
# ------------------------------------------------------------------------------
test.pointProcess =
function()
{
# pointProcess - Returns peaks over a threshold from a time series
# pointProcess(x, u = quantile(x, 0.95), doplot = FALSE)
# Time Series Data:
x = MSFT[, "Close"]
x.ret = 100*returns(x)
head(x.ret)
class(x.ret)
# Plot Series:
par(mfrow = c(2, 1), cex = 0.7)
par(ask = FALSE)
# plot(x.ret, type = "l", main = "Series")
# abline(h = 0, col = "red", lty = 3)
# or use ...
seriesPlot(x.ret)
# Point Process:
pp = pointProcess(x.ret, u = quantile(x.ret, 0.8))
pp
plot(pp, type = "b", main = "Point Process")
abline(h = 0, col = "red", lty = 3)
# Try seriesPlot(pp)
# ... add points in graph
# Return Value:
return()
}
# ------------------------------------------------------------------------------
test.deCluster =
function()
{
# deCluster - Declusters a point process
# deCluster(x, run = 20, doplot = TRUE)
# Time Series Data:
x = MSFT[, "Close"]
x.ret = 100*returns(x)
head(x.ret)
class(x.ret)
# Decluster Time Series:
tS = deCluster(x = x.ret, run = 3)
print(tS)
# Return Value:
return()
}
################################################################################
fExtremes/inst/unitTests/runit.GevModelling.R 0000644 0001760 0000144 00000023277 12157313044 021075 0 ustar ripley users
# This library is free software; you can redistribute it and/or
# modify it under the terms of the GNU Library General Public
# License as published by the Free Software Foundation; either
# version 2 of the License, or (at your option) any later version.
#
# This library is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Library General Public License for more details.
#
# You should have received a copy of the GNU Library General
# Public License along with this library; if not, write to the
# Free Foundation, Inc., 59 Temple Place, Suite 330, Boston,
# MA 02111-1307 USA
# Copyrights (C)
# for this R-port:
# 1999 - 2007, Diethelm Wuertz, GPL
# Diethelm Wuertz
# info@rmetrics.org
# www.rmetrics.org
# for the code accessed (or partly included) from other R-ports:
# see R's copyright and license files
# for the code accessed (or partly included) from contributed R-ports
# and other sources
# see Rmetrics's copyright file
################################################################################
# FUNCTION: GEV SIMULATION:
# gevSim Simulates a GEV distributed process
# gumbelSim Simulates a Gumbel distributed process
# FUNCTION: GEV PARAMETER ESTIMATION:
# 'fGEVFIT' S4 class representation
# gevFit Fits Parameters of GEV distribution
# gumbelFit Fits Parameters of Gumbel distribution
# METHODS: PRINT, PLOT, AND SUMMARY:
# show.fGEVFIT S4 Show method for object of class "fGEVFIT"
# plot.fGEVFIT S3 Plot method for object of class "fGEVFIT"
# summary.fGEVFIT S3 Summary Method for object of class "fGEVFIT"
################################################################################
test.gevSim =
function()
{
# gevSim(model = list(xi=-0.25, mu=0, beta=1), n = 1000, seed = NULL)
# RVs:
RNGkind(kind = "Marsaglia-Multicarry", normal.kind = "Inversion")
set.seed(4711, kind = "Marsaglia-Multicarry")
# Artificial Data Set:
model = list(xi = -0.25, mu = 0, beta = 1)
x.ts = gevSim(model, n = 50, seed = 4711)
class(x.ts)
print(x.ts)
# Create a daily timeSeries object with dummy dates:
as.timeSeries(x.ts)
# Create a daily timeSeries object starting 2007-01-01
Calendar = timeSequence(from = "2007-01-01", length.out = length(x.ts))
x.tS = timeSeries(data = x.ts, charvec = Calendar, units = "x")
print(x.tS)
# Return Value:
return()
}
# ------------------------------------------------------------------------------
test.gumbelSim =
function()
{
# gumbelSim(model = list(mu=0, beta=1), n = 1000, seed = NULL)
# RVs:
RNGkind(kind = "Marsaglia-Multicarry", normal.kind = "Inversion")
set.seed(4711, kind = "Marsaglia-Multicarry")
# Artificial Data Set:
model = list(mu = 0, beta = 1)
x.ts = gumbelSim(model, n = 50, seed = 4711)
class(x.ts)
print(x.ts)
# Create a daily timeSeries object with dummy dates:
x.tS = as.timeSeries(x.ts)
print(x.tS)
# Create a daily timeSeries object starting 2007-01-01
Calendar = timeSequence(from = "2007-01-01", length.out = length(x.ts))
x.tS = timeSeries(data = x.ts, charvec = Calendar, units = "x")
print(x.tS)
# Return Value:
return()
}
# ------------------------------------------------------------------------------
test.numericVectorBlocks =
function()
{
# RVs:
RNGkind(kind = "Marsaglia-Multicarry", normal.kind = "Inversion")
set.seed(4711, kind = "Marsaglia-Multicarry")
# Check numeric vector as input:
X = rt(5000, df = 4)
x.vec = blockMaxima(X, 20)
class(x.vec)
head(x.vec)
# Internal Fit - GEV PWM:
fit = .gevpwmFit(x.vec)
fit
fit$par.ests
# Internal Fit - GEV MLE:
fit = .gevmleFit(x.vec)
fit
fit$par.ests
# Internal Fit - Gumbel PWM:
fit = .gumpwmFit(x.vec)
fit
fit$par.ests
# Internal Fit - Gumbel MLE:
fit = .gummleFit(x.vec)
fit
fit$par.ests
# Return Value:
return()
}
# ------------------------------------------------------------------------------
test.timeSeriesBlocks =
function()
{
# RVs:
RNGkind(kind = "Marsaglia-Multicarry", normal.kind = "Inversion")
set.seed(4711, kind = "Marsaglia-Multicarry")
# Create an artificial timeSeries with dummy positions:
xx <- rt(5000, df = 4)
charvec <- timeSequence("2013-01-01", length.out = NROW(xx))
X = timeSeries(xx, charvec = charvec)
# Compute Block Maxima:
x.tS = blockMaxima(X, "monthly")
class(x.tS)
head(x.tS)
# Convert to Vector:
x.vec = as.vector(x.tS)
# Internal Fit - GEV PWM:
fit = .gevpwmFit(x.vec)
fit
fit$par.ests
# Internal Fit - GEV MLE:
fit = .gevmleFit(x.vec)
fit
fit$par.ests
# Internal Fit - Gumbel PWM:
fit = .gumpwmFit(x.vec)
fit
fit$par.ests
# Internal Fit - Gumbel MLE:
fit = .gummleFit(x.vec)
fit
fit$par.ests
# Return Value:
return()
}
# ------------------------------------------------------------------------------
test.gevFit =
function()
{
# gevFit(x, block = 1, type = c("mle", "pwm"),
# title = NULL, description = NULL, ...)
# RVs:
RNGkind(kind = "Marsaglia-Multicarry", normal.kind = "Inversion")
set.seed(4711, kind = "Marsaglia-Multicarry")
# Simulate Series:
model = list(xi = -0.25, mu = 0, beta = 1)
x.ts = gevSim(model = model, n = 5000, seed = 4711)
class(x.ts)
# Check time series input:
fit = gevFit(x.ts, block = 1, type = "pwm")
class(fit)
print(fit)
fit = gevFit(x.ts, block = 1, type = "mle")
class(fit)
print(fit)
# Check numeric vector input:
fit = gevFit(as.vector(x.ts), block = 1, type = "pwm")
class(fit)
print(fit)
fit = gevFit(as.vector(x.ts), block = 1, type = "mle")
class(fit)
print(fit)
# Check timeSeries objerct input:
fit = gevFit(as.timeSeries(x.ts), block = 1, type = "pwm")
class(fit)
print(fit)
fit = gevFit(as.timeSeries(x.ts), block = 1, type = "mle")
class(fit)
print(fit)
# Return Value:
return()
}
# ------------------------------------------------------------------------------
test.gumbelFit =
function()
{
# gevFit(x, block = 1, type = c("mle", "pwm"),
# title = NULL, description = NULL, ...)
# RVs:
RNGkind(kind = "Marsaglia-Multicarry", normal.kind = "Inversion")
set.seed(4711, kind = "Marsaglia-Multicarry")
# Simulate Series:
model = list(mu = 0, beta = 1)
x.ts = gumbelSim(model = model, n = 5000, seed = 4711)
class(x.ts)
# Check time series input:
fit = gumbelFit(x.ts, block = 1, type = "pwm")
class(fit)
print(fit)
fit = gumbelFit(x.ts, block = 1, type = "mle")
class(fit)
print(fit)
# Check numeric vector input:
fit = gumbelFit(as.vector(x.ts), block = 1, type = "pwm")
class(fit)
print(fit)
fit = gumbelFit(as.vector(x.ts), block = 1, type = "mle")
class(fit)
print(fit)
# Check timeSeries objerct input:
fit = gumbelFit(as.timeSeries(x.ts), block = 1, type = "pwm")
class(fit)
print(fit)
fit = gumbelFit(as.timeSeries(x.ts), block = 1, type = "mle")
class(fit)
print(fit)
# Return Value:
return()
}
# ------------------------------------------------------------------------------
test.gevFitByBlocks <-
function()
{
# gevFit(x, block = 1, type = c("mle", "pwm"),
# title = NULL, description = NULL, ...)
# RVs:
RNGkind(kind = "Marsaglia-Multicarry", normal.kind = "Inversion")
set.seed(4711, kind = "Marsaglia-Multicarry")
# Simulate Series:
model = list(xi = -0.25, mu = 0, beta = 1)
x.ts = gevSim(model = model, n = 5000, seed = 4711)
class(x.ts)
x.vec = as.vector(x.ts)
class(x.vec)
charvec <- timeSequence("2013-01-01", length.out = NROW(x.vec))
x.tS = timeSeries(x.vec, charvec)
# ts as input & 20 Days Blocks:
fit = gevFit(x.ts, block = 20, type = "pwm")
fit
fit = gevFit(x.ts, block = 20, type = "mle")
fit
# Numeric Vector as input & 20 Days Blocks:
fit = gevFit(x.vec, block = 20, type = "pwm")
fit
fit = gevFit(x.vec, block = 20, type = "mle")
fit
# timeSeries o bject as input & Monthly Blocks:
fit = gevFit(x.tS, block = "monthly", type = "pwm")
fit
fit = gevFit(x.tS, block = "quarterly", type = "mle")
fit
# timeSeries object as input & 20 Days Blocks:
fit = gevFit(x.tS, block = 20, type = "pwm")
fit
fit = gevFit(x.tS, block = 20, type = "mle")
fit
# Return Value:
return()
}
# ------------------------------------------------------------------------------
test.plot =
function()
{
# Load Data:
x = as.timeSeries(data(danishClaims))
# Parameter Estimation with Declustering:
# gevFit(x, block = 1, type = c("mle", "pwm"),
# title = NULL, description = NULL, ...)
fit = gevFit(x, block = "month")
print(fit)
# Plot:
par(mfrow = c(2, 2), cex = 0.7)
par(ask = FALSE)
plot(fit, which = 1:4)
# Try Interactive:
# plot(fit)
# Return Value:
return()
}
# ------------------------------------------------------------------------------
test.summary =
function()
{
# Summary Report:
# summary(object, doplot = TRUE, which = "all", ...)
# Load Data:
x = as.timeSeries(data(danishClaims))
# Parameter Estimation with Declustering:
fit = gevFit(x, block = "month")
print(fit)
# Summary:
summary(fit, doplot = FALSE)
# Return Value:
return()
}
################################################################################
fExtremes/inst/unitTests/runit.GpdRisk.R 0000644 0001760 0000144 00000012253 11370220752 020053 0 ustar ripley users
# This library is free software; you can redistribute it and/or
# modify it under the terms of the GNU Library General Public
# License as published by the Free Software Foundation; either
# version 2 of the License, or (at your option) any later version.
#
# This library is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Library General Public License for more details.
#
# You should have received a copy of the GNU Library General
# Public License along with this library; if not, write to the
# Free Foundation, Inc., 59 Temple Place, Suite 330, Boston,
# MA 02111-1307 USA
# Copyrights (C)
# for this R-port:
# 1999 - 2007, Diethelm Wuertz, GPL
# Diethelm Wuertz
# info@rmetrics.org
# www.rmetrics.org
# for the code accessed (or partly included) from other R-ports:
# see R's copyright and license files
# for the code accessed (or partly included) from contributed R-ports
# and other sources
# see Rmetrics's copyright file
################################################################################
# FUNCTION: ADDITIONAL PLOTS:
# gpdTailPlot Plots Tail Estimate From GPD Model
# gpdQuantPlot Plots of GPD Tail Estimate of a High Quantile
# gpdShapePlot Plots for GPD Shape Parameter
# gpdQPlot Adds Quantile Estimates to plot.gpd
# gpdSfallPlot Adds Expected Shortfall Estimates to a GPD Plot
# gpdRiskMeasures Calculates Quantiles and Expected Shortfalls
# FUNCTION: NEW STYLE FUNCTIONS:
# tailPlot Plots GPD VaR and Expected Shortfall risk
# tailSlider Interactive view to find proper threshold value
# tailRiskMeasures Calculates VaR and Expected Shortfall risks
################################################################################
test.gpdTailPlot =
function()
{
# Artificial Data Set:
x = gpdSim(seed = 1985)
fit = gpdFit(x)
par(mfrow = c(1, 1))
par(ask = FALSE)
gpdTailPlot(fit)
# Danish Fire Claims:
x = as.timeSeries(data(danishClaims))
fit = gpdFit(x)
par(mfrow = c(1, 1))
par(ask = FALSE)
gpdTailPlot(fit)
# Return Value:
return()
}
# ------------------------------------------------------------------------------
test.gpdQuantPlot =
function()
{
# Artificial Data Set:
x = gpdSim(seed = 1985)
par(mfrow = c(1, 1))
par(ask = FALSE)
gpdQuantPlot(x)
# Danish Fire Claims:
x = as.timeSeries(data(danishClaims))
fit = gpdFit(x)
par(mfrow = c(1, 1))
par(ask = FALSE)
gpdQuantPlot(x)
# Return Value:
return()
}
# ------------------------------------------------------------------------------
test.gpdShapePlot =
function()
{
# Artificial Data Set:
x = gpdSim(seed = 1985)
par(mfrow = c(1, 1))
par(ask = FALSE)
gpdShapePlot(x)
# Danish Fire Claims:
x = as.timeSeries(data(danishClaims))
par(mfrow = c(1, 1))
par(ask = FALSE)
gpdShapePlot(x)
# Return Value:
return()
}
# ------------------------------------------------------------------------------
test.gpdQPlot =
function()
{
# Artificial Data Set:
x = gpdSim(seed = 1985)
fit = gpdFit(x)
tp = gpdTailPlot(fit)
gpdQPlot(tp)
# Danish Fire Claims:
x = as.timeSeries(data(danishClaims))
fit = gpdFit(x, u =10)
tp = gpdTailPlot(fit)
gpdQPlot(tp)
# Return Value:
return()
}
# ------------------------------------------------------------------------------
test.gpdSfallPlot =
function()
{
# Artificial Data Set:
x = gpdSim(seed = 1985)
fit = gpdFit(x)
### tp = gpdTailPlot(fit) # CHECK
### gpdSfallPlot(tp) # CHECK
# Danish Fire Claims:
x = as.timeSeries(data(danishClaims))
fit = gpdFit(as.vector(x), u =10)
### tp = gpdTailPlot(fit) # CHECK
### gpdSfallPlot(tp) # CHECK
# Return Value:
return()
}
# ------------------------------------------------------------------------------
test.tailPlot =
function()
{
# Danish Fire Claims:
x = as.timeSeries(data(danishClaims))
fit = gpdFit(x, u = 10)
### tailPlot(fit) # CHECK
# Return Value:
return()
}
# ------------------------------------------------------------------------------
test.tailSlider =
function()
{
# Danish Fire Claims:
# x = as.timeSeries(data(danishClaims))
# tailSlider(x)
NA
# Return Value:
return()
}
# ------------------------------------------------------------------------------
test.tailRisk =
function()
{
# Danish Fire Claims:
x = as.timeSeries(data(danishClaims))
fit = gpdFit(x, u = 10)
tailRisk(fit)
# Return Value:
return()
}
################################################################################
fExtremes/inst/unitTests/runit.ExtremesData.R 0000644 0001760 0000144 00000020443 11370220752 021076 0 ustar ripley users
# This library is free software; you can redistribute it and/or
# modify it under the terms of the GNU Library General Public
# License as published by the Free Software Foundation; either
# version 2 of the License, or (at your option) any later version.
#
# This library is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Library General Public License for more details.
#
# You should have received a copy of the GNU Library General
# Public License along with this library; if not, write to the
# Free Foundation, Inc., 59 Temple Place, Suite 330, Boston,
# MA 02111-1307 USA
# Copyrights (C)
# for this R-port:
# 1999 - 2007, Diethelm Wuertz, GPL
# Diethelm Wuertz
# info@rmetrics.org
# www.rmetrics.org
# for the code accessed (or partly included) from other R-ports:
# see R's copyright and license files
# for the code accessed (or partly included) from contributed R-ports
# and other sources
# see Rmetrics's copyright file
################################################################################
# FUNCTION EXPLORATIVE DATA ANALYSIS:
# emdPlot Creates an empirical distribution plot
# qqparetoPlot Creates exploratory QQ plot for EV analysis
# mePlot Creates a sample mean excess function plot
# mxfPlot Creates another view of a sample mean excess plot
# mrlPlot Returns a mean residual life plot with confidence levels
# recordsPlot Plots records development
# ssrecordsPlot Plots records development of data subsamples
# msratioPlot Plots ratio of maximums and sums
# sllnPlot Verifies Kolmogorov's Strong Law of large numbers
# lilPlot Verifies Hartman-Wintner's Law of the iterated logarithm
# xacfPlot Plots autocorrelations of exceedences
################################################################################
test.emd =
function()
{
# emdPlot - Creates an empirical distribution plot
# Artificial Data Set:
RNGkind(kind = "Marsaglia-Multicarry", normal.kind = "Inversion")
set.seed(4711, kind = "Marsaglia-Multicarry")
x = rgpd(1000)
# Empirical distribution plot:
par(ask = FALSE)
par(mfrow = c(2, 2))
emdPlot(x, plottype = "xy")
emdPlot(x, plottype = "x")
emdPlot(x, plottype = "y")
# emdPlot(x, plottype = " ") # CHECK !!!
# Artificial Data Set:
x = rt(1000, df = 3)
# Empirical distribution plot:
par(ask = FALSE)
par(mfrow = c(2, 2))
emdPlot(x, plottype = "xy")
emdPlot(x, plottype = "x")
emdPlot(x, plottype = "y")
# emdPlot(x, plottype = " ") # CHECK !!!
# Artificial Data Set:
x = rnorm(1000)
# Empirical distribution plot:
par(ask = FALSE)
par(mfrow = c(2, 2))
emdPlot(x, plottype = "xy")
emdPlot(x, plottype = "x")
emdPlot(x, plottype = "y")
# emdPlot(x, plottype = " ") # CHECK !!!
# Return Value:
return()
}
# ------------------------------------------------------------------------------
test.qqpareto =
function()
{
# qqparetoPlot - Creates exploratory QQ plot for EV analysis
# Artificial Data Set -
RNGkind(kind = "Marsaglia-Multicarry", normal.kind = "Inversion")
set.seed(4711, kind = "Marsaglia-Multicarry")
r0 = rgpd(n = 1000, xi = 0)
r1 = rgpd(n = 1000, xi = 1)
# Graph Frame:
par(ask = FALSE)
par(mfrow = c(2, 2))
# Empirical Pareto Distribution Plot:
qqparetoPlot(x = r0, xi = 0)
qqparetoPlot(x = r1, xi = 1)
# Empirical Normal Distribution Plot:
qqnormPlot(x = r0)
qqnormPlot(x = r1)
# Return Value:
return()
}
# ------------------------------------------------------------------------------
test.me =
function()
{
# mePlot - Creates a sample mean excess function plot
# mxfPlot - Creates another view of a sample mean excess plot
# mrlPlot - Returns a mean residual life plot with confidence levels
# Artificial Data Set -
RNGkind(kind = "Marsaglia-Multicarry", normal.kind = "Inversion")
set.seed(4711, kind = "Marsaglia-Multicarry")
r = rgpd(n = 1000)
# Mean Excess Function Plot:
par(ask = FALSE)
par(mfrow = c(2, 2))
mePlot(x = r) # Check, the largest point is missing ...
mxfPlot(x = r)
mrlPlot(x = r)
# No Labels:
par(mfrow = c(2, 2))
par(ask = FALSE)
mePlot(x = r, labels = FALSE)
mxfPlot(x = r, labels = FALSE)
mrlPlot(x = r, labels = FALSE)
# Return Value:
return()
}
# ------------------------------------------------------------------------------
test.records =
function()
{
# recordsPlot - Plots records development
# ssrecordsPlot - Plots records development of data subsamples
# Artificial Data Set -
RNGkind(kind = "Marsaglia-Multicarry", normal.kind = "Inversion")
set.seed(4711, kind = "Marsaglia-Multicarry")
r = rgpd(n = 1000)
# Records Plot:
par(mfrow = c(2, 2))
par(ask = FALSE)
recordsPlot(x = r)
recordsPlot(x = r, ci = 0.99)
ans = recordsPlot(x = r, labels = FALSE)
print(ans)
# Subrecords Plot:
set.seed(1985)
r = rgpd(n = 10000)
par(mfrow = c(2, 2))
par(ask = FALSE)
recordsPlot(r)
ssrecordsPlot(r, subsamples = 1)
ssrecordsPlot(r, subsamples = 1, plottype = "log")
ans = ssrecordsPlot(r, subsamples = 1, plottype = "lin")
print(ans)
# Subrecords Plot:
set.seed(1985)
r = rgpd(n = 10000)
par(mfrow = c(2, 2))
par(ask = FALSE)
ssrecordsPlot(r, subsamples = 10)
ssrecordsPlot(r, subsamples = 50)
ssrecordsPlot(r, subsamples = 10, plottype = "log")
ans = ssrecordsPlot(r, subsamples = 50, plottype = "log", labels = FALSE)
print(ans)
# Return Value:
return()
}
# ------------------------------------------------------------------------------
test.msratio =
function()
{
# msratioPlot - Plots ratio of maximums and sums
# Artificial Data Set -
RNGkind(kind = "Marsaglia-Multicarry", normal.kind = "Inversion")
set.seed(4711, kind = "Marsaglia-Multicarry")
r = rgpd(n = 1000)
# Mean Excess Function Plot:
par(ask = FALSE)
par(mfrow = c(2, 2))
msratioPlot(x = r, p = 1:4)
ans = msratioPlot(x = r, p = 1:4, labels = FALSE)
print(head(ans))
# Return Value:
return()
}
# ------------------------------------------------------------------------------
test.laws =
function()
{
# sllnPlot - Verifies Kolmogorov's Strong Law of large numbers
# lilPlot - Verifies Hartman-Wintner's Law of the iterated logarithm
# Artificial Data Set -
RNGkind(kind = "Marsaglia-Multicarry", normal.kind = "Inversion")
set.seed(4711, kind = "Marsaglia-Multicarry")
r = rgpd(n = 1000)
# Strong Law of Large Numbers:
par(ask = FALSE)
par(mfrow = c(2, 2))
sllnPlot(x = r)
ans = sllnPlot(x = r, labels = FALSE)
print(ans)
# Law of the Iterated Logarithm:
lilPlot(x = r)
ans = lilPlot(x = r, labels = FALSE)
print(ans)
# Return Value:
return()
}
# ------------------------------------------------------------------------------
test.xacf =
function()
{
# xacfPlot - Plots autocorrelations of exceedences
# Create an Artificial Data Set:
RNGkind(kind = "Marsaglia-Multicarry", normal.kind = "Inversion")
set.seed(4711, kind = "Marsaglia-Multicarry")
r = rgpd(n = 1000)
# ACF of Exceedances Plot:
par(ask = FALSE)
par(mfrow = c(2, 2))
ans = xacfPlot(x = r)
print(ans)
# ACF of Exceedances Plot:
par(ask = FALSE)
par(mfrow = c(2, 2))
xacfPlot(x = r, labels = FALSE)
# ACF of Exceedances Plot:
par(ask = FALSE)
par(mfrow = c(2, 2))
xacfPlot(x = r, labels = FALSE, which = 1); title(main = "1")
xacfPlot(x = r, labels = FALSE, which = 2); title(main = "2")
xacfPlot(x = r, labels = FALSE, which = "3"); title(main = "3")
xacfPlot(x = r, labels = FALSE, which = "4"); title(main = "4")
# Return Value:
return()
}
################################################################################
fExtremes/inst/unitTests/runTests.R 0000644 0001760 0000144 00000004531 11370220752 017177 0 ustar ripley users pkg <- "fExtremes"
if(require("RUnit", quietly = TRUE))
{
library(package=pkg, character.only = TRUE)
if(!(exists("path") && file.exists(path)))
path <- system.file("unitTests", package = pkg)
## --- Testing ---
## Define tests
testSuite <- defineTestSuite(name = paste(pkg, "unit testing"),
dirs = path)
if(interactive()) {
cat("Now have RUnit Test Suite 'testSuite' for package '",
pkg, "' :\n", sep='')
str(testSuite)
cat('', "Consider doing",
"\t tests <- runTestSuite(testSuite)", "\nand later",
"\t printTextProtocol(tests)", '', sep = "\n")
} else {
## run from shell / Rscript / R CMD Batch / ...
## Run
tests <- runTestSuite(testSuite)
if(file.access(path, 02) != 0) {
## cannot write to path -> use writable one
tdir <- tempfile(paste(pkg, "unitTests", sep="_"))
dir.create(tdir)
pathReport <- file.path(tdir, "report")
cat("RUnit reports are written into ", tdir, "/report.(txt|html)",
sep = "")
} else {
pathReport <- file.path(path, "report")
}
## Print Results:
printTextProtocol(tests, showDetails = FALSE)
printTextProtocol(tests, showDetails = FALSE,
fileName = paste(pathReport, "Summary.txt", sep = ""))
printTextProtocol(tests, showDetails = TRUE,
fileName = paste(pathReport, ".txt", sep = ""))
## Print HTML Version to a File:
## printHTMLProtocol has problems on Mac OS X
if (Sys.info()["sysname"] != "Darwin")
printHTMLProtocol(tests,
fileName = paste(pathReport, ".html", sep = ""))
## stop() if there are any failures i.e. FALSE to unit test.
## This will cause R CMD check to return error and stop
tmp <- getErrors(tests)
if(tmp$nFail > 0 | tmp$nErr > 0) {
stop(paste("\n\nunit testing failed (#test failures: ", tmp$nFail,
", R errors: ", tmp$nErr, ")\n\n", sep=""))
}
}
} else {
cat("R package 'RUnit' cannot be loaded -- no unit tests run\n",
"for package", pkg,"\n")
}
################################################################################
fExtremes/inst/unitTests/runit.GevDistribution.R 0000644 0001760 0000144 00000007653 11370220752 021641 0 ustar ripley users
# This library is free software; you can redistribute it and/or
# modify it under the terms of the GNU Library General Public
# License as published by the Free Software Foundation; either
# version 2 of the License, or (at your option) any later version.
#
# This library is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Library General Public License for more details.
#
# You should have received a copy of the GNU Library General
# Public License along with this library; if not, write to the
# Free Foundation, Inc., 59 Temple Place, Suite 330, Boston,
# MA 02111-1307 USA
# Copyrights (C)
# for this R-port:
# 1999 - 2007, Diethelm Wuertz, GPL
# Diethelm Wuertz
# info@rmetrics.org
# www.rmetrics.org
# for the code accessed (or partly included) from other R-ports:
# see R's copyright and license files
# for the code accessed (or partly included) from contributed R-ports
# and other sources
# see Rmetrics's copyright file
################################################################################
# FUNCTION: GEV DISTRIBUTION FAMILY: [CALLING EVD]
# dgev Density for the GEV Distribution
# pgev Probability for the GEV Distribution
# qgev Quantiles for the GEV Distribution
# rgev Random variates for the GEV Distribution
# gevMoments Computes true statistics for GEV distribution
# gevSlider Displays distribution and rvs for GEV distribution
################################################################################
test.gev =
function()
{
# Check Distribution:
RNGkind(kind = "Marsaglia-Multicarry", normal.kind = "Inversion")
set.seed(4711, kind = "Marsaglia-Multicarry")
.distCheck(fun = "gev", n = 2000, xi = 0.0, mu = 0, beta = 1)
# Check Distribution:
RNGkind(kind = "Marsaglia-Multicarry", normal.kind = "Inversion")
set.seed(4711, kind = "Marsaglia-Multicarry")
.distCheck(fun = "gev", n = 5000, xi = 0.3, mu = 0, beta = 2)
# Return Value:
return()
}
# ------------------------------------------------------------------------------
test.gevMoments =
function()
{
# gevMoments(xi = 0, mu = 0, beta = 1)
# Compute Moments:
xi = seq(-4.5, 1.5, by = 0.25)
mom = gevMoments(xi)
print(mom)
# Plot Mean:
par(mfrow = c(2, 1), cex = 0.7)
par(ask = FALSE)
xi = seq(-5, 2, length = 351)
mom = gevMoments(xi)
plot(xi, mom$mean, main = "Mean GEV", pch = 19, col = "steelblue")
abline(v = 1, col = "red", lty = 3)
abline(h = 0, col = "red", lty = 3)
# Plot Variance:
plot(xi, log(mom$var), main = "log Variance GEV", pch = 19, col = "steelblue")
abline(v = 1/2, col = "red", lty = 3)
abline(h = 0.0, col = "red", lty = 3)
# check gevMoments for specific values
xi <- c(-1, 0, 0.3)
mu <- c(-1, 0, 1)
beta <- c(0.5, 1, 10)
for (i in seq(length(xi))) {
for (j in seq(length(xi))) {
for (k in seq(length(xi))) {
rg <- rgev(1000000, xi = xi[i], mu = mu[j], beta = beta[k])
rgMoments <- gevMoments(xi = xi[i], mu = mu[j], beta = beta[k])
checkEqualsNumeric(mean(rg), rgMoments$mean, tolerance = 0.1)
checkEqualsNumeric(var(rg), rgMoments$var, tolerance = 0.1)
}
}
}
# Return Value:
return()
}
# ------------------------------------------------------------------------------
test.gevSlider =
function()
{
# Distribution Slider:
# print("Activate Slider manually!")
# gevSlider(method = "dist")
NA
# Random Variates Slider:
# print("Activate Slider manually!")
# gevSlider(method = "rvs")
NA
# Return Value:
return()
}
################################################################################
fExtremes/tests/ 0000755 0001760 0000144 00000000000 12251673345 013416 5 ustar ripley users fExtremes/tests/doRUnit.R 0000644 0001760 0000144 00000001516 11370220751 015116 0 ustar ripley users #### doRUnit.R --- Run RUnit tests
####------------------------------------------------------------------------
### Origianlly follows Gregor Gojanc's example in CRAN package 'gdata'
### and the corresponding section in the R Wiki:
### http://wiki.r-project.org/rwiki/doku.php?id=developers:runit
### MM: Vastly changed: This should also be "runnable" for *installed*
## package which has no ./tests/
## ----> put the bulk of the code e.g. in ../inst/unitTests/runTests.R :
if(require("RUnit", quietly = TRUE)) {
## --- Setup ---
wd <- getwd()
pkg <- sub("\\.Rcheck$", '', basename(dirname(wd)))
library(package=pkg, character.only = TRUE)
path <- system.file("unitTests", package = pkg)
stopifnot(file.exists(path), file.info(path.expand(path))$isdir)
source(file.path(path, "runTests.R"), echo = TRUE)
}
fExtremes/NAMESPACE 0000644 0001760 0000144 00000005654 12157313044 013475 0 ustar ripley users
################################################
## Note this file has been automatically
## generated --- Do not edit it.
################################################
################################################
## import name space
################################################
import("methods")
import("timeDate")
import("timeSeries")
import("fBasics")
import("fGarch")
import("fTrading")
################################################
## S4 classes
################################################
exportClasses("fGEVFIT",
"fGPDFIT",
"fTHETA" )
exportMethods("$",
"$<-",
"+",
"-",
"[",
"[<-",
"cummax",
"cummin",
"cumprod",
"cumsum",
"dim",
"dim<-",
"dimnames",
"dimnames<-",
"is.na",
"names",
"names<-",
"show" )
################################################
## S3 classes
################################################
S3method("plot", "fGEVFIT")
S3method("plot", "fGPDFIT")
S3method("summary", "fGEVFIT")
S3method("summary", "fGPDFIT")
################################################
## functions
################################################
export(
".depd",
".devd",
".garch11MetricsPlot",
".gev1Plot",
".gev2Plot",
".gev3Plot",
".gev4Plot",
".gevFit",
".gevLLH",
".gevmleFit",
".gevpwmFit",
".gevrlevelLLH",
".gpd1Plot",
".gpd2Plot",
".gpd3Plot",
".gpd4Plot",
".gpdLLH",
".gpdmleFit",
".gpdmleFitCheck",
".gpdpwmFit",
".gpdpwmFitCheck",
".gumLLH",
".gummleFit",
".gumpwmFit",
".meanExcessPlot",
".pepd",
".pevd",
".qepd",
".qevd",
".repd",
".revd",
".riskMetricsPlot",
"CVaR",
"VaR",
"blockMaxima",
"blockTheta",
"clusterTheta",
"deCluster",
"dgev",
"dgpd",
"emdPlot",
"exindexPlot",
"exindexesPlot",
"ferrosegersTheta",
"findThreshold",
"gevFit",
"gevMoments",
"gevSim",
"gevSlider",
"gevrlevelPlot",
"ghMeanExcessFit",
"ghtMeanExcessFit",
"gpdFit",
"gpdMoments",
"gpdQPlot",
"gpdQuantPlot",
"gpdRiskMeasures",
"gpdSfallPlot",
"gpdShapePlot",
"gpdSim",
"gpdSlider",
"gpdTailPlot",
"gumbelFit",
"gumbelSim",
"hillPlot",
"hypMeanExcessFit",
"lilPlot",
"mePlot",
"mrlPlot",
"msratioPlot",
"mxfPlot",
"nigMeanExcessFit",
"normMeanExcessFit",
"pgev",
"pgpd",
"pointProcess",
"qgev",
"qgpd",
"qqparetoPlot",
"recordsPlot",
"rgev",
"rgpd",
"runTheta",
"shaparmDEHaan",
"shaparmHill",
"shaparmPickands",
"shaparmPlot",
"sllnPlot",
"ssrecordsPlot",
"tailPlot",
"tailRisk",
"tailSlider",
"thetaSim",
"xacfPlot" )
fExtremes/data/ 0000755 0001760 0000144 00000000000 12254133267 013162 5 ustar ripley users fExtremes/data/danishClaims.csv.gz 0000644 0001760 0000144 00000034542 12254133267 016725 0 ustar ripley users ‹ …½»²-¹®èë?®Y+ø&e)BF·ÓN[òåêÿ]a ræ½:u¦‘cçbò7Að?þç?ÿñ¿ÿùÿõïÿøïÿßÿûÿÿ?ÿ-/Jÿ¤üOªÿæ¿Au6ÊÓÑöoùK«ÎÔJw~yÖÒ)—¾ž€çš½¥2"ÜþF.)uêÞvNÿÒß,½Ì:W‰ðü£EÜJÎŽîHI”Z¯DÎFZiNÿb^üö\#Ï\S=pÉÜt-i´V ®u̶FmŽ64=Z.D-´!C/ø_oÞ‘ÂÉ2{c]páþñW¥î0ý[Æ_ÉÒüž¿‚5àÙN¥Ufs¸óüõš’¼ï0f›Zž½ôQÌóWÿ(YÛZÕa^ßö—KIsä û¯méµ,ÿ$O Gf/Í~à’ø“=÷:kíÞO`áR'þ¿££ikRªäÝ.Üž“Ñû*k:¬$Õ[ëi…/Î_²¬:¯Xá/–\ê1Æ?*™gVDù{YiµÜ/¿ëËðä ¡ÙWÊ+9,#g2mu•êm+éTþf#¼]0OÔ7Իà ÖU³’ ÁíŸ4>&ªa!¹fn(/‡3zÒÇêyÊáÆDÂmgê+´;Ö7Ï2Ç/£#ºŠ…Ʊóï§iYš±2Ï¢é°4ÂôÎÞt&o™×™sã‚É0fj’×g„ë_UH9žYÔ×ðDÛ³HÛ/4²Z4¡Ë¼R]QÀtLɯl`˜>ae„9Jî¥\pû£ÎâˆÒ
0¦¤7~¬ê0O`ýÌ‘+
ïvYl𨋠6M
̽Ž:çlf¢ç‰yÕ2VâY‹Ås=†a4Òz.©w†¯|tÖÌ`æ1Gáí!’±Í†¾8,Ü*JuXæä§8Êmæ3š©Tòòê9TnƒõOÀˆpg*¾¥ÃT5ö¥Ñq9Zb®¬¥9Œ/Ž9iåÑ,J¡‹±§ÌÈ`Z»ûQ0O=¥)ôãð)ÅÔCcP„×óãËûUñÇ3ͺŒŽ”Ÿ †Âb*±HË}/
aŒã¯æµry8,”
‚Jù†ï !ˆÔ(äï2#@>Ö%Šð/[“òËOÕªcÑGNÉJ`e3[Á*D¸r¯—ÐSwX¸½çÕçYÂ<ž˜§©¦a¹(„t„¨ÀX.ž;6)¼é*Ý^Ôkg‰á!º”óˆŸêH™QŽ5ÕvHdA‰c¢XK2ûµsÕÞ'U‡Ñ¿VF)-eÿ¤°/´,ÛXËÛfbm,-UŠÎCtÑþI¡aä—9¶@ü6Ìb
Dxò’1é`^î·'ø€Ú¼<µ‚ü“ ª™êðQÊ*P8¥yÛ,YX‡ÌI5ˆè A›æžŒT@óÅaUªÌ½0œ†åÀss,ͳyÉ"ž•ÜV,€…èäðúGË2ðD™64+²(¸Såf `—‹•Y*“²RŠhQ1€›èwЋ@¬™††ÃS¬e&Yð Ã1)×