def HARMONIC_MEAN(df, n, price='Close'):
"""
Harmonic mean of data
"""
harmonic_mean_list = []
i = 0
while i < len(df[price]):
if i + 1 < n:
harmonic_mean = float('NaN')
else:
start = i + 1 - n
end = i + 1
harmonic_mean = statistics.harmonic_mean(df[price][start:end])
harmonic_mean_list.append(harmonic_mean)
i += 1
return harmonic_mean_list
评论列表
文章目录