#' find_peaks
#' @param x price
#' @param m size
#' @importFrom dplyr case_when mutate
#' @export
#' @return peaks
find_peaks <- function (x, m = 10){
shape <- diff(sign(diff(x, na.pad = FALSE)))
pks <- sapply(which(shape < 0), FUN = function(i){
z <- i - m + 1
z <- ifelse(z > 0, z, 1)
w <- i + m + 1
w <- ifelse(w < length(x), w, length(x))
if(all(x[c(z : i, (i + 2) : w)] <= x[i + 1])) return(i + 1) else return(numeric(0))
})
pks <- unlist(pks)
pks
}
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.