Last active
January 9, 2021 11:14
-
-
Save davidzhaodz/892dd775f7d3bd60580282037f3c8878 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
# compute bands | |
window = 50 | |
data['avg'], data['upper'], data['lower'] = bbands(data['close'],window, no_of_stdev=1.5) | |
# compute sides | |
data['side'] = np.nan | |
long_signals = (data['close'] <= data['lower']) | |
short_signals = (data['close'] >= data['upper']) | |
data.loc[long_signals, 'side'] = 1 | |
data.loc[short_signals, 'side'] = -1 | |
print(data.side.value_counts()) | |
# remove Look ahead bias by lagging the signal | |
data['side'] = data['side'].shift(1) | |
# drop the NaN values from our data set | |
data.dropna(axis=0, how='any', inplace=True) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment