python怎么实现计算趋势图的指数、线性、对数、多项式?

股票 浏览

python怎么实现计算趋势图的指数、线性、对数、多项式?

推荐你去找一个pandas,scipy,pandas,matplotlib库来做,网上有书籍,《利用Python进行数据分析》,基本就是介绍这样内容的,pandas去做数据采集、清洗等都不错,然后利用上面的例子慢慢实现你上面的方法。

怎么利用python代码绘制k线图

import matplotlib.pyplot as pltfrom matplotlib.dates import DateFormatter, WeekdayLocator, DayLocator, MONDAY,YEARLYfrom matplotlib.finance import quotes_historical_yahoo_ohlc, candlestick_ohlcplt.rcParams['font.sans-serif'] = ['SimHei']plt.rcParams['axes.unicode_minus'] = Falseticker = '600028' # 600028 是中国石化的股票代码ticker += '.ss' # .ss 表示上证 .sz表示深证date1 = (2015, 8, 1) # 起始日期,格式:(年,月,日)元组date2 = (2016, 1, 1) # 结束日期,格式:(年,月,日)元组mondays = WeekdayLocator(MONDAY) # 主要刻度alldays = DayLocator() # 次要刻度#weekFormatter = DateFormatter('%b %d') # 如:Jan 12mondayFormatter = DateFormatter('%m-%d-%Y') # 如:2-29-2015dayFormatter = DateFormatter('%d') # 如:12quotes = quotes_historical_yahoo_ohlc(ticker, date1, date2)if len(quotes) == 0: raise SystemExitfig, ax = plt.subplots()fig.subplots_adjust(bottom=0.2)ax.xaxis.set_major_locator(mondays)ax.xaxis.set_minor_locator(alldays)ax.xaxis.set_major_formatter(mondayFormatter)#ax.xaxis.set_minor_formatter(dayFormatter)#plot_day_summary(ax, quotes, ticksize=3)candlestick_ohlc(ax, quotes, width=0.6, colorup='r', colordown='g')ax.xaxis_date()ax.autoscale_view()plt.setp(plt.gca().get_xticklabels(), rotation=45, horizontalalignment='right')ax.grid(True)plt.title('中国石化 600028')plt.show()

转载请注明:IT财经网 » python怎么实现计算趋势图的指数、线性、对数、多项式?