Skip to content

Instantly share code, notes, and snippets.

@davidzhaodz
Last active January 9, 2021 11:14
Show Gist options
  • Save davidzhaodz/8e13d3b42a0360c692f254102456f492 to your computer and use it in GitHub Desktop.
Save davidzhaodz/8e13d3b42a0360c692f254102456f492 to your computer and use it in GitHub Desktop.
close = data['close']
# determining daily volatility using the last 50 days
daily_vol = get_daily_vol(close=close, lookback=50)
# creating our event triggers using the CUSUM filter
cusum_events = get_t_events(close, threshold=daily_vol.mean()*0.1)
# adding vertical barriers with a half day expiration window
vertical_barriers = add_vertical_barrier(t_events=cusum_events,
close=close, num_days=0.5)
# determining timestamps of first touch
pt_sl = [1, 2] # setting profit-take and stop-loss at 1% and 2%
min_ret = 0.0005 # setting a minimum return of 0.05%
triple_barrier_events = get_events(close=close,
t_events=cusum_events,
pt_sl=pt_sl,
target=daily_vol,
min_ret=min_ret,
num_threads=2,
vertical_barrier_times=vertical_barriers,
side=data['side'])
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment