Skip to content

Instantly share code, notes, and snippets.

@davidzhaodz
Created January 4, 2021 17:01
Show Gist options
  • Save davidzhaodz/382efad34d29ba33866a3bc066f6ef72 to your computer and use it in GitHub Desktop.
Save davidzhaodz/382efad34d29ba33866a3bc066f6ef72 to your computer and use it in GitHub Desktop.
def addVerticalBarrier(tEvents, close, numDays=1):
"""
:param t_events: (series) series of events (symmetric CUSUM filter)
  :param close: (series) close prices
  :param numDays: (int) maximum number of days a trade can be active
 :return: (series) timestamps of vertical barriers
"""
t1=close.index.searchsorted(tEvents+pd.Timedelta(days=numDays))
t1=t1[t1<close.shape[0]]
t1=(pd.Series(close.index[t1],index=tEvents[:t1.shape[0]]))
return t1
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment