[Returnanalytics-commits] r4009 - pkg/PerformanceAnalytics/R

noreply at r-forge.r-project.org noreply at r-forge.r-project.org
Sun Mar 6 17:31:26 CET 2016


Author: bodanker
Date: 2016-03-06 17:31:25 +0100 (Sun, 06 Mar 2016)
New Revision: 4009

Modified:
   pkg/PerformanceAnalytics/R/Return.clean.R
Log:
Catch error and return original series if sd=0

We can't invert 'sigma' if the standard deviation is zero (all returns
are the same), so trap the potential error and return the original
return series.

Thanks to cloudcello for the report.


Modified: pkg/PerformanceAnalytics/R/Return.clean.R
===================================================================
--- pkg/PerformanceAnalytics/R/Return.clean.R	2016-03-06 16:01:29 UTC (rev 4008)
+++ pkg/PerformanceAnalytics/R/Return.clean.R	2016-03-06 16:31:25 UTC (rev 4009)
@@ -214,11 +214,17 @@
    MCD = robustbase::covMcd(as.matrix(R),alpha=1-alpha)
    mu = as.matrix(MCD$raw.center) #no reweighting
    sigma = MCD$raw.cov
-   invSigma = solve(sigma);
+   invSigma = try(solve(sigma), silent=TRUE)
    vd2t = c();
    cleaneddata = R
    outlierdate = c()
 
+   if(inherits(invSigma, "try-error")) {
+     warning("Returning original data; unable to clean data due to error:\n",
+       attr(invSigma, "condition")[["message"]])
+     return(list(cleaneddata,outlierdate))
+   }
+
    # 1. Sort the data in function of their extremeness
    # Extremeness is proxied by the robustly estimated squared Mahalanbobis distance
 



More information about the Returnanalytics-commits mailing list