Created
January 4, 2021 17:01
-
-
Save davidzhaodz/382efad34d29ba33866a3bc066f6ef72 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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