Become an expert in R — Interactive courses, Cheat Sheets, certificates and more!
Get Started for Free

peak

Find Peaks and Valleys In A Series


Description

Functions to find the peaks (tops) and valleys (bottoms) of a given series.

Usage

findPeaks(x, thresh=0)
findValleys(x, thresh=0)

Arguments

x

a time series or vector

thresh

minimum peak/valley threshold

Value

A vector of integers corresponding to peaks/valleys.

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.

Author(s)

Jeffrey A. Ryan

Examples

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])

quantmod

Quantitative Financial Modelling Framework

v0.4.18
GPL-3
Authors
Jeffrey A. Ryan [aut, cph], Joshua M. Ulrich [cre, aut], Wouter Thielen [ctb], Paul Teetor [ctb], Steve Bronder [ctb]
Initial release

We don't support your browser anymore

Please choose more modern alternatives, such as Google Chrome or Mozilla Firefox.