-
-
Save samchaaa/9b8073e54670fc230027c0ad7726696b 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 get_signals(close_time): | |
""" | |
Creates signals for pybacktest. | |
Note pybacktest specifically needs series named "buy", "sell", "short", "cover" to work. | |
Check out tutorial notebook: https://nbviewer.jupyter.org/github/ematvey/pybacktest/blob/master/examples/tutorial.ipynb | |
""" | |
bs = ohlc['C'] > ohlc['hb'] # sell signal | |
bb = ohlc['C'] < ohlc['lb'] # buy signal | |
nbs = ohlc['C'] > ohlc['hb'] # not sell signal | |
nbb = ohlc['C'] < ohlc['lb'] # not buy signal | |
buy = bb & nbb.shift() | |
sell = buy.shift(close_time) | |
short = bs & nbs.shift() | |
cover = short.shift(close_time) | |
return buy, cover, sell, short |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment