财务策划
finplot的Python项目详细描述
金融地块
用python绘制财务数据在很大程度上很糟糕。mpl_finance非常慢-- 还有情节——当显示100k或更多烛台时
见见财务策划人,或finplot它利用了下面的pyqtgraph,令我惊讶的是它是一个优秀的库。金融地块建成 以移植matplotlib的api,但具有更好的默认外观和更好的性能
还包括一些缩放+缩放逻辑,因此您不会像通常在 大多数非金融绘图库。加上手工画线,每个线段显示百分比和时间变化。
鼠标左键平移,鼠标滚轮缩放,按住CTRL键可以绘制线。
易于安装
$ pip install finplot
示例
这25行从Bittrex中提取一些比特币数据,并显示上面的内容:
importfinplotasfpltimportnumpyasnpimportpandasaspdimportrequests# pull some datasymbol='USDT-BTC'url='https://bittrex.com/Api/v2.0/pub/market/GetTicks?marketName=%s&tickInterval=fiveMin'%symboldata=requests.get(url).json()# format it in pandasdf=pd.DataFrame(data['result'])df=df.rename(columns={'T':'time','O':'open','C':'close','H':'high','L':'low','V':'volume'})df=df.astype({'time':'datetime64[ns]'})# create three plotsax,ax2,ax3=fplt.create_plot(symbol,rows=3)# plot candle stickscandle_src=fplt.PandasDataSource(df[['time','open','close','high','low']])fplt.candlestick_ochl(candle_src,ax=ax)# put an MA in therefplt.plot(df['time'],df['close'].rolling(25).mean(),ax=ax,color='#0000ff',legend='ma-25')# place some dumb markershi_wicks=df['high']-df[['open','close']].T.max().Tdf.loc[(hi_wicks>hi_wicks.quantile(0.99)),'marker']=df['close']fplt.plot(df['time'],df['marker'],ax=ax,color='#000000',style='^',legend='dumb mark')# draw some random crap on our second plotdf['rnd']=np.random.normal(size=len(df))fplt.plot(df['time'],df['rnd'],ax=ax2,color='#992277',legend='stuff')fplt.set_y_range(ax2,-1.4,+1.7)# fix y-axis range# finally a volume bar chart in our third plotvolume_src=fplt.PandasDataSource(df[['time','open','close','volume']])fplt.volume_ocv(volume_src,ax=ax3)# we're donefplt.show()
用真实指示器实时更新
本回购协议包括a 40-liner Bitfinex example和 a slightly longer BitMEX websocket example, 它们都是用比特币/美元实时更新的。它们还显示了现实和有用的指标(bfx和 为bitmex乐队)。
享受吧!