Advances in Financial Machine Learning, Snippet 3.6 page 50. Getting the Time of the First Touch, with Meta Labels
get_events( price, t_events, pt_sl, target, min_ret, vertical_barrier_times = NA, side_prediction = NA )
price | xts or data.table with index and price columns |
---|---|
t_events | These are timestamps that will seed every triple barrier (e. g. CUSUM events) |
pt_sl | vector; Element 0, indicates the profit taking level; Element 1 is stop loss level. A non-negative float that sets the width of the two barriers. |
target | of values that are used to determine the width of the barrier. |
min_ret | he minimum target return required for running a triple barrier search. |
vertical_barrier_times | Verticla barrier timestamp |
side_prediction | Side of the bet (long/short) as decided by the primary model |
Events -events t0 is event's starttime -events t1 is event's endtime -events trgt is event's target -events side (optional) implies the algo's position side -events pt is profit taking multiple -events sl is stop loss multiple
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)