maCrossoverSignal: Compute a moving average cross-over momentum signal.

Description Usage Arguments Value Examples

View source: R/maCrossoverSignal.R

Description

This function computes a moving average cross-over signal from a price series. The series should be in xts format. The function will return +1 if the shorter moving average of the price series is above the longer moving average and -1 if below. It will return a 0 if the two moving averages are the same.

Usage

1
maCrossoverSignal(x, s = 50, l = 100)

Arguments

x

an xts time series of prices.

s

the number of periods for the shorter moving average (assumed to be in the same periodicity as x. Meaning, if you pass daily data and s = 20, then the shorter moving average will be calculated over 20 days. If you pass monthly data, and s = 20, then the shorter moving average will be calculated over 20 months.

l

the number of period for the longer moving average.

Value

a list containing a time series filled with -1, 0, or +1 signals based on the cross-over patterns of the moving averages, the short moving average series, and the long moving average series.

Examples

1
2
3
4
dts.long <- seq(Sys.Date()-499, Sys.Date(), 1)
ret.long <- matrix(rnorm(500),ncol = 1) * 100
long.xts <- xts(ret.long, dts.long)
ma.sig <- maCrossoverSignal(long.xts)

gtog/dMisc documentation built on May 17, 2019, 8:57 a.m.