[Quantmod-commits] r620 - pkg/R

noreply at r-forge.r-project.org noreply at r-forge.r-project.org
Sun Dec 7 22:13:40 CET 2014


Author: bodanker
Date: 2014-12-07 22:13:40 +0100 (Sun, 07 Dec 2014)
New Revision: 620

Modified:
   pkg/R/peak.R
Log:
- Fix bug #5807; make both findPeaks and findValleys more robust.


Modified: pkg/R/peak.R
===================================================================
--- pkg/R/peak.R	2014-12-07 20:23:45 UTC (rev 619)
+++ pkg/R/peak.R	2014-12-07 21:13:40 UTC (rev 620)
@@ -2,7 +2,9 @@
 function(x, thresh=0) {
   pks <- which(diff(sign(diff(x, na.pad=FALSE)),na.pad=FALSE) < 0) + 2
   if( !missing(thresh) ) {
-   pks[x[pks-1]-coredata(x[pks]) > thresh]
+    if(sign(thresh) < 0)
+      thresh <- -thresh
+    pks[x[pks-1]-coredata(x[pks]) > thresh]
   } else pks
 }
 
@@ -15,7 +17,9 @@
 function(x, thresh=0) {
   pks <- which(diff(sign(diff(x, na.pad=FALSE)),na.pad=FALSE) > 0) + 2
   if( !missing(thresh) ) {
-   pks[x[pks-1]-coredata(x[pks]) > thresh]
+    if(sign(thresh) > 0)
+      thresh <- -thresh
+    pks[x[pks-1]-coredata(x[pks]) < thresh]
   } else pks
 }
 



More information about the Quantmod-commits mailing list