1200字范文,内容丰富有趣,写作的好帮手!
1200字范文 > 量化分析入门2:上证指数走势图及移动平均线

量化分析入门2:上证指数走势图及移动平均线

时间:2018-11-19 09:51:29

相关推荐

量化分析入门2:上证指数走势图及移动平均线

#talib入门2:上证指数走势图及移动平均线

作者:冯德平(山野雪人)

本文程序中给出了详细的注释:

import pandas as pdimport talib as taimport matplotlib.pyplot as plt#正常显示画图时出现的中文和负号:from pylab import mplmpl.rcParams['font.sans-serif']=['SimHei'] #显示中文#mpl.rcParams['axes.unicode_minus']=False#显示正负号#从文件读取上证指数数据df=pd.read_csv(r'D:\temp\szzs.csv')print(df.tail(10)) #显示最后10行数据,默认是5行#画3、21指数移动平均线times=[3,21]for time in times:df['ma_'+str(time)]=ta.EMA(df.close,timeperiod=time) #timeperiod是时间,如3天,21天#df['ma_'+str(time)]=ta.SMA(df.close,timeperiod=time) #df['ma_'+str(time)]=ta.WMA(df.close,timeperiod=time) #df['ma_'+str(time)]=ta.DEMA(df.close,timeperiod=time) #df['ma_'+str(time)]=ta.TEMA(df.close,timeperiod=time) #df['ma_'+str(time)]=ta.TRIMA(df.close,timeperiod=time)#df['ma_'+str(time)]=ta.KAMA(df.close,timeperiod=time)#df['ma_'+str(time)]=ta.T3(df.close,timeperiod=time)#df['ma_'+str(time)]=ta.MAMA(df.close,timeperiod=time) #出现错误#MAMA不知为什么会出现错误,将3,21改成5,20则可以正常运行,有待进一步的研究#起始时间:-09-01;close为收盘价;figsize为图片尺寸:df.loc['-09-01':,['close','ma_3','ma_21']].plot(figsize=(20,8))ax = plt.gca() #获得当前的Axes对象axax.spines['right'].set_color('none') #隐藏右边的竖轴ax.spines['top'].set_color('none')#隐藏顶上的横轴plt.title('上证指数走势及移动平均线',fontsize=14) #标题plt.xlabel('时间') #标注X轴plt.ylabel('上证指数') #标注Y轴plt.show() #绘图'''dateopen closehighlow volume code5254 -09-06 3580.14 3621.86 3626.29 3580.14 521713276.0 sh5255 -09-07 3621.71 3676.59 3681.93 3615.14 547721875.0 sh5256 -09-08 3673.40 3675.19 3695.32 3661.00 586436193.0 sh5257 -09-09 3666.82 3693.13 3693.45 3662.16 604810330.0 sh5258 -09-10 3691.19 3703.11 3722.87 3681.64 63533.0 sh5259 -09-13 3699.25 3715.37 3716.83 3692.82 557484019.0 sh5260 -09-14 3709.63 3662.60 3723.85 3655.63 564952386.0 sh5261 -09-15 3651.16 3656.22 3677.53 3638.32 474970001.0 sh5262 -09-16 3664.84 3607.09 3677.92 3606.73 546741474.0 sh5263 -09-17 3595.27 3613.97 3620.96 3569.27 516850210.0 sh'''

本文数据地址:

链接:/s/1tDiO6QYi5kTYT6AiYlsGfw

提取码:bvq9

本内容不代表本网观点和政治立场,如有侵犯你的权益请联系我们处理。
网友评论
网友评论仅供其表达个人看法,并不表明网站立场。