Skip to content

Instantly share code, notes, and snippets.

@ayatsuro
Last active August 26, 2018 12:50
Show Gist options
  • Save ayatsuro/d2a7e4ab9c7836c80e441bd3ac704d13 to your computer and use it in GitHub Desktop.
Save ayatsuro/d2a7e4ab9c7836c80e441bd3ac704d13 to your computer and use it in GitHub Desktop.
AI for Trading - Breakout Strategy: clear_signals accepting long and short
def clear_signals(signals, window_size):
clean_signals = [0] * window_size
for signal_i, current_signal in enumerate(signals):
signal_slice = clean_signals[signal_i:signal_i + window_size]
has_past_signal = next((s for s in signal_slice if s != 0), None)
clean_signals.append(not has_past_signal and current_signal)
clean_signals = clean_signals[window_size:]
return pd.Series(np.array(clean_signals).astype(np.int64), signals.index)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment