Skip to content

Instantly share code, notes, and snippets.

@quantra-go-algo
Created December 14, 2023 11:57
Show Gist options
  • Select an option

  • Save quantra-go-algo/df394a7812220a8153eda95d0e6bf3e7 to your computer and use it in GitHub Desktop.

Select an option

Save quantra-go-algo/df394a7812220a8153eda95d0e6bf3e7 to your computer and use it in GitHub Desktop.
# Function to plot the strategy results
def plot_strategy(data):
plt.figure(figsize=(12, 6))
plt.plot(data['Close'], label='Close Price', alpha=0.5)
plt.scatter(data[data['Signal'] == 1].index, data['Close'][data['Signal'] == 1], marker='^', color='g', label='Buy Signal')
plt.scatter(data[data['Signal'] == -1].index, data['Close'][data['Signal'] == -1], marker='v', color='r', label='Sell Signal')
plt.plot(data['SAR'], label='Parabolic SAR', linestyle='dashed', alpha=0.5)
plt.title('Parabolic SAR Trading Strategy')
plt.xlabel('Date')
plt.ylabel('Price')
plt.legend()
plt.show()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment