Skip to content

Instantly share code, notes, and snippets.

@anthonymorast
Created August 17, 2021 18:48
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 anthonymorast/a5a10e8b831026ccea4f9ac466e2920b to your computer and use it in GitHub Desktop.
Save anthonymorast/a5a10e8b831026ccea4f9ac466e2920b to your computer and use it in GitHub Desktop.
def get_sma(data, period):
return data.rolling(window=period).mean() # moving average using panda's rolling
def get_bollinger_bands(data, sma, periods):
std = data.rolling(window=periods).std()
upper = sma + std * 2 # add 2 standard deviations (upper band)
lower = sma - std * 2 # substract 2 standard deviations (lower band)
return upper, lower
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment