Advances in Financial Machine Learning, Snippet 2.4, page 39. The Symmetric Dynamic/Fixed CUSUM Filter.

cusum_filter(price, threshold, return_datetime = TRUE)

Arguments

price

vector of prices

threshold

scalar or numeric vector of same size as price. When the change is larger than the threshold, the function captures it as an even

return_datetime

Should the function return datetime object or index of cusum filter

Value

vector of cusum events or datetime of cusum events

Examples

data("spy") cusum_events <- cusum_filter(subset(spy, select = c("index", "close")), 0.001)