which_jumps: Calculate a _Boolean_ vector that identifies isolated jumps...

View source: R/HighFreq.R

which_jumpsR Documentation

Calculate a Boolean vector that identifies isolated jumps (spikes) in a single-column xts time series or vector, over a rolling interval.

Description

Calculate a Boolean vector that identifies isolated jumps (spikes) in a single-column xts time series or vector, over a rolling interval.

Usage

which_jumps(xtsv, look_back = 51, vol_mult = 2)

Details

The function which_jumps() calculates a Boolean vector, with TRUE for values that are isolated jumps (spikes).

The function which_jumps() applies a version of the Hampel median filter to identify jumps, but instead of using the median absolute deviation (MAD), it uses the 0.9 quantile of returns calculated over a rolling interval. This is in contrast to function which_extreme(), which applies a Hampel filter to the values themselves, instead of the returns. Returns are defined as simple differences between neighboring values.

Jumps (or spikes), are defined as isolated values that are very different from the neighboring values, either before or after. Jumps create pairs of large neighboring returns of opposite sign.

Jumps (spikes) must satisfy two conditions:

  1. Neighboring returns both exceed a multiple of the rolling quantile,

  2. The sum of neighboring returns doesn't exceed that multiple.

The quantile multiplier vol_mult controls the threshold at which values are identified as jumps. Smaller quantile multiplier values will cause more values to be identified as jumps.

Value

A Boolean vector with the same number of rows as the input time series or vector.

Examples

# Create local copy of SPY TAQ data
taq <- SPY_TAQ
# Calculate mid prices
mid_prices <- 0.5 * (taq[, "Bid.Price"] + taq[, "Ask.Price"])
# Replace whole rows containing suspect price jumps with NA, and perform locf()
taq[which_jumps(mid_prices, look_back=31, vol_mult=1.0), ] <- NA
taq <- xts:::na.locf.xts(taq)


algoquant/HighFreq documentation built on Feb. 9, 2024, 8:15 p.m.