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
# Take long positions | |
data['long_positions'] = np.where(data['short_mavg'] > data['long_mavg'], 1, 0) | |
# Take short positions | |
data['short_positions'] = np.where(data['short_mavg'] < data['long_mavg'], -1, 0) | |
data['positions'] = data['long_positions'] + data['short_positions'] | |
# Plot close price and moving averages | |
plot_data = data[-3000:] |