Created
May 31, 2021 23:55
-
-
Save mindryu/dc093b5de67c3e42e1bbc88ce91dee5b to your computer and use it in GitHub Desktop.
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
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