Skip to content

Instantly share code, notes, and snippets.

@mindryu
Created May 31, 2021 23:55
Show Gist options
  • Save mindryu/dc093b5de67c3e42e1bbc88ce91dee5b to your computer and use it in GitHub Desktop.
Save mindryu/dc093b5de67c3e42e1bbc88ce91dee5b to your computer and use it in GitHub Desktop.
def get_wma(close, weights):
def wma(values, weights):
sum_of_weights = np.sum(weights)
weighted_average = np.sum(values * weights) / sum_of_weights
return weighted_average
return close.rolling(len(weights)).apply(lambda x: weighted_avg(x, weights))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment