R/peak.R

Defines functions valley findValleys peak findPeaks

Documented in findPeaks findValleys peak valley

findPeaks <-
function(x, thresh=0) {
  pks <- which(diff(sign(diff(x, na.pad=FALSE)),na.pad=FALSE) < 0) + 2
  if( !missing(thresh) ) {
    if(sign(thresh) < 0)
      thresh <- -thresh
    pks[x[pks-1]-coredata(x[pks]) > thresh]
  } else pks
}

peak <- function(x) {
  .Deprecated("findPeaks", package="quantmod")
  findPeaks(x)
}

findValleys <-
function(x, thresh=0) {
  pks <- which(diff(sign(diff(x, na.pad=FALSE)),na.pad=FALSE) > 0) + 2
  if( !missing(thresh) ) {
    if(sign(thresh) > 0)
      thresh <- -thresh
    pks[x[pks-1]-coredata(x[pks]) < thresh]
  } else pks
}

valley <- function(x) {
  .Deprecated("findValleys", package="quantmod")
  findValleys(x)
}

Try the quantmod package in your browser

Any scripts or data that you put into this service are public.

quantmod documentation built on Aug. 22, 2023, 9:09 a.m.