Skip to content

Instantly share code, notes, and snippets.

@quantra-go-algo
Last active December 28, 2021 07:39
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save quantra-go-algo/3b0a1048c651066f7fd26fde97624b2d to your computer and use it in GitHub Desktop.
Save quantra-go-algo/3b0a1048c651066f7fd26fde97624b2d to your computer and use it in GitHub Desktop.
# Create smooth graph of close price data
from scipy.signal import savgol_filter
# To find amount of data in months
month_diff = series.shape[0] // 30
# We need value to be greater than 0
if month_diff == 0:
month_diff = 1
# Algo to determine smoothness
smooth = int(2 * month_diff + 3)
# Smooth price data
points = savgol_filter(series, smooth, 7)
# Plot the smooth price graph over default price graph
plt.figure(figsize=(15,7))
plt.title(symbol)
plt.xlabel('Days')
plt.ylabel('Price')
# Close price data
plt.plot(series, label=symbol)
# Smooth close price data
plt.plot(points, label=f'Smooth {symbol}')
plt.legend()
plt.show()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment