importTkinterastkfromTkinterimport*importttkimportmatplotlib.pyplotaspltimportnumpyasnpimporttalibastaseries=np.random.choice([1,-1],size=200)close=np.cumsum(series).astype(float)#重叠指标defoverlap_process(event):print(event.widget.get())overlap=event.widget.get()upperband,middleband,lowerband=ta.BBANDS(close,timeperiod=5,nbdevup=2,nbdevdn=2,matype=0)fig,axes=plt.subplots(2,1,sharex=True)ax1,ax2=axes[0],axes[1]axes[0].plot(close,'',markersize=3)axes[0].plot(upperband,'')axes[0].plot(middleband,'')axes[0].plot(lowerband,'')axes[0].set_title(overlap,fontproperties=SimHei)ifoverlap=='布林线':passelifoverlap=='双指数移动平均线':real=ta.DEMA(close,timeperiod=30)axes[1].plot(real,'')elifoverlap=='指数移动平均线':real=ta.EMA(close,timeperiod=30)axes[1].plot(real,'')elifoverlap=='希尔伯特变换——瞬时趋势线':real=ta.HT_TRENDLINE(close)axes[1].plot(real,'')elifoverlap=='考夫曼自适应移动平均线':real=ta.KAMA(close,timeperiod=30)axes[1].plot(real,'')elifoverlap=='移动平均线':real=ta.MA(close,timeperiod=30,matype=0)axes[1].plot(real,'')elifoverlap=='MESA自适应移动平均':mama,fama=ta.MAMA(close,fastlimit=0,slowlimit=0)axes[1].plot(mama,'')axes[1].plot(fama,'')elifoverlap=='变周期移动平均线':real=ta.MAVP(close,periods,minperiod=2,maxperiod=30,matype=0)axes[1].plot(real,'')elifoverlap=='简单移动平均线':real=ta.SMA(close,timeperiod=30)axes[1].plot(real,'')elifoverlap=='三指数移动平均线(T3)':real=ta.T3(close,timeperiod=5,vfactor=0)axes[1].plot(real,'')elifoverlap=='三指数移动平均线':real=ta.TEMA(close,timeperiod=30)axes[1].plot(real,'')elifoverlap=='三角形加权法':real=ta.TRIMA(close,timeperiod=30)axes[1].plot(real,'')elifoverlap=='加权移动平均数':real=ta.WMA(close,timeperiod=30)axes[1].plot(real,'')plt.show()#动量指标defmomentum_process(event):print(event.widget.get())momentum=event.widget.get()upperband,middleband,lowerband=ta.BBANDS(close,timeperiod=5,nbdevup=2,nbdevdn=2,matype=0)fig,axes=plt.subplots(2,1,sharex=True)ax1,ax2=axes[0],axes[1]axes[0].plot(close,'',markersize=3)axes[0].plot(upperband,'')axes[0].plot(middleband,'')axes[0].plot(lowerband,'')axes[0].set_title(momentum,fontproperties=SimHei)ifmomentum=='绝对价格振荡器':real=ta.APO(close,fastperiod=12,slowperiod=26,matype=0)axes[1].plot(real,'')elifmomentum=='钱德动量摆动指标':real=ta.CMO(close,timeperiod=14)axes[1].plot(real,'')elifmomentum=='移动平均收敛/散度':macd,macdsignal,macdhist=ta.MACD(close,fastperiod=12,slowperiod=26,signalperiod=9)axes[1].plot(macd,'')axes[1].plot(macdsignal,'')axes[1].plot(macdhist,'')elifmomentum=='带可控MA类型的MACD':macd,macdsignal,macdhist=ta.MACDEXT(close,fastperiod=12,fastmatype=0,slowperiod=26,slowmatype=0,signalperiod=9,signalmatype=0)axes[1].plot(macd,'')axes[1].plot(macdsignal,'')axes[1].plot(macdhist,'')elifmomentum=='移动平均收敛/散度固定12/26':macd,macdsignal,macdhist=ta.MACDFIX(close,signalperiod=9)axes[1].plot(macd,'')axes[1].plot(macdsignal,'')axes[1].plot(macdhist,'')elifmomentum=='动量':real=ta.MOM(close,timeperiod=10)axes[1].plot(real,'')elifmomentum=='比例价格振荡器':real=ta.PPO(close,fastperiod=12,slowperiod=26,matype=0)axes[1].plot(real,'')elifmomentum=='变化率':real=ta.ROC(close,timeperiod=10)axes[1].plot(real,'')elifmomentum=='变化率百分比':real=ta.ROCP(close,timeperiod=10)axes[1].plot(real,'')elifmomentum=='变化率的比率':real=ta.ROCR(close,timeperiod=10)axes[1].plot(real,'')elifmomentum=='变化率的比率100倍':real=ta.ROCR100(close,timeperiod=10)axes[1].plot(real,'')elifmomentum=='相对强弱指数':real=ta.RSI(close,timeperiod=14)axes[1].plot(real,'')elifmomentum=='随机相对强弱指标':fastk,fastd=ta.STOCHRSI(close,timeperiod=14,fastk_period=5,fastd_period=3,fastd_matype=0)axes[1].plot(fastk,'')axes[1].plot(fastd,'')elifmomentum=='三重光滑EMA的日变化率':real=ta.TRIX(close,timeperiod=30)axes[1].plot(real,'')plt.show()#周期指标defcycle_process(event):print(event.widget.get())cycle=event.widget.get()upperband,middleband,lowerband=ta.BBANDS(close,timeperiod=5,nbdevup=2,nbdevdn=2,matype=0)fig,axes=plt.subplots(2,1,sharex=True)ax1,ax2=axes[0],axes[1]axes[0].plot(close,'',markersize=3)axes[0].plot(upperband,'')axes[0].plot(middleband,'')axes[0].plot(lowerband,'')axes[0].set_title(cycle,fontproperties=SimHei)ifcycle=='希尔伯特变换——主要的循环周期':real=ta.HT_DCPERIOD(close)axes[1].plot(real,'')elifcycle=='希尔伯特变换,占主导地位的周期阶段':real=ta.HT_DCPHASE(close)axes[1].plot(real,'')elifcycle=='希尔伯特变换——相量组件':inphase,quadrature=ta.HT_PHASOR(close)axes[1].plot(inphase,'')axes[1].plot(quadrature,'')elifcycle=='希尔伯特变换——正弦曲线':sine,leadsine=ta.HT_SINE(close)axes[1].plot(sine,'')axes[1].plot(leadsine,'')elifcycle=='希尔伯特变换——趋势和周期模式':integer=ta.HT_TRENDMODE(close)axes[1].plot(integer,'')plt.show()#统计功能defstatistic_process(event):print(event.widget.get())statistic=event.widget.get()upperband,middleband,lowerband=ta.BBANDS(close,timeperiod=5,nbdevup=2,nbdevdn=2,matype=0)fig,axes=plt.subplots(2,1,sharex=True)ax1,ax2=axes[0],axes[1]axes[0].plot(close,'',markersize=3)axes[0].plot(upperband,'')axes[0].plot(middleband,'')axes[0].plot(lowerband,'')axes[0].set_title(statistic,fontproperties=SimHei)ifstatistic=='线性回归':real=ta.LINEARREG(close,timeperiod=14)axes[1].plot(real,'')elifstatistic=='线性回归角度':real=ta.LINEARREG_ANGLE(close,timeperiod=14)axes[1].plot(real,'')elifstatis