which_jumps | R Documentation |
Calculate a Boolean vector that identifies isolated jumps (spikes) in a single-column xts time series or vector, over a rolling interval.
which_jumps(xtsv, look_back = 51, vol_mult = 2)
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:
Neighboring returns both exceed a multiple of the rolling quantile,
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.
A Boolean vector with the same number of rows as the input time series or vector.
# 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)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.