indicator.py 文件源码

python
阅读 24 收藏 0 点赞 0 评论 0

项目:trading-stock-thailand 作者: adminho 项目源码 文件源码
def BBANDS(df_price, periods=20, mul=2):    
    # Middle Band = 20-day simple moving average (SMA)
    df_middle_band = pd.rolling_mean(df_price, window=periods)
    #df_middle_band = pd.rolling(window=periods,center=False).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 = pd.rolling(window=periods,center=False).std()

    # Upper Band = 20-day SMA + (20-day standard deviation of price x 2)
    df_upper_band = df_middle_band + (df_std * mul)

    # Lower Band = 20-day SMA - (20-day standard deviation of price x 2)
    df_lower_band = df_middle_band - (df_std * mul) 

    return (df_upper_band, df_middle_band, df_lower_band)
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号