indicators.py 文件源码

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

项目:Machine_Learning_Trading_System 作者: historycapital 项目源码 文件源码
def plot_bollinger_band_indicator(price,sma,upper_band, bottom_band,bbp, file_name):

    plt.clf()
    fig = plt.figure()
    ax = fig.add_subplot(211)
    ax.set(title = 'AAPL with Bollinger Band Indicator')
    ax.plot(price,label = 'AAPL Price')
    ax.plot(sma,label = 'SMA(21)')
    ax.plot(upper_band, label = 'upper_band', color='r')
    ax.plot(bottom_band,label = 'bottom_band',color='r')
    ax.set_ylabel('Price')
    #ax.set_ylim([0,2])
    #start, end = ax.get_xlim()
    #ax.xaxis.set_ticks(np.arange(start,end,90))
    L = plt.legend()
    L.get_texts()[0].set_text('AAPL Price')
    L.get_texts()[1].set_text('SMA(21)')
    L.get_texts()[2].set_text('Upper_band')
    L.get_texts()[3].set_text('Lower_band')
    ax.tick_params(labelbottom='off')
    ax.legend(loc = 'upper center',bbox_to_anchor = (0.55,1.0), prop = {'size':7})
    ###create font properties
    #fontP = FontProperties()
    #fontP.set_size('small')
    #plt.legend([ax], "title",prop = fontP)

    ax1 = fig.add_subplot(212)
    ax1.plot(bbp,label = 'bbp',color = 'r')
    ax1.set_ylabel('Bollinger Band (%BB)')
    ax1.set_xlabel('Date')
    ax1.axhline(0.0, color = 'black')
    ax1.axhline(1.0, color = 'black')
    fig.subplots_adjust(hspace=0.1)
    #start, end = ax.get_xlim()
    #ax1.xaxis.set_ticks(np.arange(start,end,90))
    plt.xticks(rotation=30)
    plt.savefig(file_name)
    #plt.show()
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号