peak: Find Peaks and Valleys In A Series

Description Usage Arguments Value Author(s) Examples

View source: R/peak.R

Description

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

Usage

1
2
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

1
2
3
4
5
6
7
8
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])

Example output

Loading required package: xts
Loading required package: zoo

Attaching package: 'zoo'

The following objects are masked from 'package:base':

    as.Date, as.Date.numeric

Loading required package: TTR
Version 0.4-0 included new data defaults. See ?getSymbols.
[1] 3 9
[1] 0.9916648 0.9893582

quantmod documentation built on June 20, 2017, 5:02 p.m.

Search within the quantmod package
Search all R packages, documentation and source code