def get_myRatio(df_price, periods=20):
# Middle Band = 20-day simple moving average (SMA)
#df_middle_band = pd.rolling_mean(df_price, window=periods)
df_middle_band = df_price.rolling(center=False, window=periods).mean()
# 20-day standard deviation of price
""" Pandas uses the unbiased estimator (N-1 in the denominator),
whereas Numpy by default does not.
To make them behave the same, pass ddof=1 to numpy.std()."""
#df_std = pd.rolling_std(df_price, window=periods)
df_std = df_price.rolling(center=False, window=periods).std()
return (df_price - df_middle_band)/(df_std * 2)
评论列表
文章目录