[R-sig-finance] decluster - Dangerous use of t-apply and match

Diethelm Wuertz wuertz at itp.phys.ethz.ch
Thu Mar 30 13:42:49 CEST 2006


The R package evir and also Finmetrics in SPlus (evis) use the
function decluster() for declustering a time series for Risk
Management with the POT method. But the functions work
only correct if there are no degeneracies in the time series,
otherwise the time can run backwards in the declustered
series! Especially for time series with discrete values and
many identical values this can become problematic. Let us
consider the following example:


    require(evir)
   
    # Decluster Danish Claims:
    data(danish)
    out = pot(danish, threshold = 4)
    X = decluster(out$data, 10, picture = FALSE)
    # Plot - Time is running backward! :
    x = as.POSIXlt(attr(X, "times"))
    y = as.vector(X)
    plot(x, y, type = "l")
   
   
    # Dirty Bug Fix - Lift degeneracy by adding marginal noise:
    data(danish)
    danish = danish + runif(length(danish), -1e-6, 1e-6)
    out = pot(danish, threshold = 4)
    X = decluster(out$data, 10, picture = FALSE)
    # Plot:
    x = as.POSIXlt(attr(X, "times"))
    y = as.vector(X)
    plot(x, y, type = "l")
   

For SPlus/Finmetrics users, try:

    out = pot(danish, threshold = 4)
    X = decluster(out$data, 10, plot = F)
    plot(X)


Since currently Rmetrics uses the same method as implemented
in evir and SPlus/Finmetrics you will encounter the same problems.
It will be fixed in Rmetrics with the next version using an approach
based on the function applySeries() instead of the functions
tapply()/match().

RECOMMENDATION: Use carefully evir, Rmetrics, and
SPlus/Finmetrics  for risk management with declustered time
series with the function decluster() from evis, otherwise you
are sure that your time series is not degenerated! In this
case everything is fine. To be on the save side I always 
recommend to check at least that your positions are properly
time ordered! If not, add some marginal noise to the series.

Diethelm Wuertz



More information about the R-sig-finance mailing list