Last chance! 50% off unlimited learning
Sale ends in
findPeaks(x, thresh=0)
findValleys(x, thresh=0)
As a peak[valley] is defined as the highest[lowest] value in a series, the function can only define it after a change in direction has occurred. This means that the function will always return the first period after the peak/valley of the data, so as not to accidentally induce a look-ahead bias.
findPeaks(sin(1:10))
p <- findPeaks(sin(seq(1,10,.1)))
sin(seq(1,10,.1))[p]
plot(sin(seq(1,10,.1))[p])
plot(sin(seq(1,10,.1)),type='l')
points(p,sin(seq(1,10,.1))[p])
Run the code above in your browser using DataLab