Advances in Financial Machine Learning, Snippet 3.8 page 54. This function recursively eliminates rare observations.
drop_labels(events, min_pct = 0.05)
events | Events with labels |
---|---|
min_pct | A fraction used to decide if the observation occurs less than that fraction. |
data("spy") close <- subset(spy, select = c("index", "close")) daily_vol <- daily_volatility(close) cusum_events <- cusum_filter(close, 0.001) vertical_barriers <- add_vertical_barrier(cusum_events, spy$index, num_days = 1) events <- get_events(price = close, t_events = cusum_events, pt_sl = c(1, 2), target = daily_vol, min_ret = 0.005, vertical_barrier_times=vertical_barriers, side_prediction=NA) labels <- get_bins(events, close) labels_red <- drop_labels(labels, 0.05)